Polynomial -> Integrate

Python 2, 315 bytes * 5113 = 1610595 score

I'm still working on golfing the score. Golfing is going to be difficult, because I can't golf just the code or just the output, and I therefore do not know if a change will help or hurt my score until I try it, which sucks in my opinion.

Despite the annoyance of golfing this, I did enjoy the calculus.

t='t'
Z=lambda n:N(Z(-n))if n<0else[1,t,N(1),Z(n-1)]if n>1else[[1,t,1,1],1][n]
N=lambda a:[1,t,a,Z(0)]
x=lambda n:n>1and[x(n-1),t,Z(0),'x']or'x'
M=lambda a,b:[b,t,Z(0),a]
print reduce(lambda a,b:[1,t,N(a),b],[M((lambda a,b:M(Z(a),[x(b-1)if b>1else 1,'x',Z(0),1]))(*c),x(i)if i else 1)for i,c in enumerate(input())])

Try it online!

Run all test cases - to score, count all [ in the output.

The input polynomial is taken as a list of (numerator, denominator) coefficient pairs in order from lowest to highest power of x. (0, 1) (zero) is used for missing powers.

Output is given with each integral represented by a list [f,t,a,b] to represent ∫abf dt

Verification

Here is a slightly less golfed version that outputs valid Mathematica syntax for integration, which may be tested in an online notebook. Unfortunately, decently-sized programs will not complete in a free notebook.

Go here, scroll to bottom, "Create New Notebook", paste (Wolfram Language Input), and evaluate (Shift+Enter) (Note that using num-pad Enter doesn't work).

Explanation

Uses these equations:

-a = \int_a^{0} 1 ~ dt

n = \int_{-1}^{n-1} 1 ~ dt, n>1

x^n = \int_0^{x} x^{n-1} ~ dt

a+b = \int_{-a}^b 1 ~ dt

ab = \int_0^a b ~ dt

\frac{1}{n} = \int_0^{1} x^{n-1} ~ dx

Links

  • Tool that converts the output to Mathematica nested functions

  • Tool that converts the output to Mathematica, avoiding recursion

  • Run the Mathematica output on TIO

  • Equation images made with this tool.