You will need to evaluate the definite integral (bounded by \$a\$ and \$b\$) of a certain polynomial function that takes the form of:
$$\int_a^b \left( k_n x^n + k_{n-1} x^{n-1} + \cdots + k_2x^2 + k_1x + k_0 \: \right) dx$$
Normally, this can be done using the fundamental theorem of calculus and power rules. For example:
$$\int_b^c ax^n dx = a \frac{x^{n+1}} {n+1} \Big|^c_b = a\left[ \frac{c^{n+1}} {n+1} - \frac{b^{n+1}} {n+1} \right]$$
The challenge here is to replicate that process using the shortest amount of code as possible. You will decide the degree your program can solve. Somewhere in your answer, specify how many degrees your program can solve up to. For example:
My program can solve all polynomials up to the 5th degree. (quintic polynomial)
Input
Input will be two arrays consisting of bounds and coefficients. For example:
bounds = [2, 3]
coefficients = [4, 5, 2, 7]
The above input will yield this expression:
$$ \int_2^3 (4x^3 + 5x^2 + 2x + 7) \mathop{dx} $$
Output
The output will be a single decimal number rounded to at least 3 decimal places. So the above expression will yield:108.666666666667 // correct
108.6667 // correct
109 // wrong
Constraints
$$ -10^9 < k_n, ..., k_1, k_0 < 10^9 $$ $$ 0 < N < 30 $$ Integral bounds \$a, b\$ satisfy no additional constraints.
Rules & Scoring
Standard loopholes apply here as it does anywhere else.
You may not write a program that only solves a specific integral. Once you pick your degree, that program must work under all constraints up to that degree.
Your score will be calculated by this equation:
degree of polynomial / num of bytes
, and the highest score wins.If your program works for all degrees above 30, set your numerator to be 30, otherwise 29 is the maximum possible numerator.
Please post a working version of your code on any website so that it can be tested.
29
or is it30
? \$\endgroup\$108+2/3
or326/3
? \$\endgroup\$