g | x | w | all
Bytes Lang Time Link
nanWolfram Language Mathematica210216T011408Zatt
nanJavaScript Node.js240412T170221Z2pichar
014APLNARS240111T141237ZRosario
055R210323T165623ZGiuseppe
nanC gcc lm210217T105957ZErikF
nanJavaScript210216T094112Zuser1006
nan05AB1E210216T083426ZKevin Cr
nanJ210216T003434ZJonah
nanCharcoal210216T004910ZNeil
nanFactor210216T003400ZBubbler
nanAPL Dyalog Unicode210216T001312Zuser
nanSageMath210216T000034ZNoodle9
nanScala210215T233601Zuser
nanJelly210215T223915Zcaird co

Wolfram Language (Mathematica), 30/32=0.9375 30/31=0.9677 \$\frac{30}{30}=1\$

{-1,a=1}.Sum[i/a#2^a++,{i,#}]&

Try it online!

Input [{coeffs...}, {a, b}]. Takes coefficients in ascending order.


some older solutions:

31 bytes

c(a=0;c^++a.{-1,1}/a&/@#).#&

Try it online! Input [{a, b}][{coeffs...}].

32 bytes

FromDigits[#,]~Integrate~{,##2}&

Try it online! Input [{coeffs...}, a, b]. Integrates using Null as the variable.

JavaScript (Node.js), \$\frac{30}{70}\approx0.4286\$

I=b=>c=>(F=x=>c.reduce((s,e,i)=>s+(e/(i+1)*x**(i+1)),0))(b[1])-F(b[0])

Try it online!

Takes coefficients in ascending order (\$k_0,\dots,k_n\$ for \$x^0,\dots,x^n\$)

APL(NARS), 14 chars

a←⎕⋄-/{⍵⊥a}∫¨⎕

For the input of polynom the list

$$ a_n a_{n-1} ... a_1 a_0 $$

means polynom

$$ a_n X^n+a_{n-1} X^{n-1} ... a_1 X+a_0 $$

test:

    a←⎕⋄-/{⍵⊥a}∫¨⎕
⎕:
      4 5 2 7
⎕:
      3 2
108.6666667 

R, 55 bytes, score: \$\frac{30}{55}=0.\overline{54}\$

function(b,k)diff(outer(b,a<-rev(seq(!k)),"^")%*%(k/a))

Try it online!

If we could take the coefficients in ascending order of degree, this would be 5 bytes shorter and get a score of \$0.6\$ instead, by removing the rev().

C (gcc) (-lm), score: \$\frac{30}{90}= 0.\bar3\$

Sums the bounds for each term in descending order. Due to quirks with -O0, I was able to write this function without the usual return or explicit value assignment at the end of the function.

double f(b,t,n,i,j)int*b,*t;{for(double s=i=0;j=n-i;)s+=t[i++]*(pow(b[1],j)-pow(*b,j))/j;}

Try it online!

JavaScript, score: \$\frac{30}{71}\approx 0.42\$

n=>k=>(x=y=>k.reduce((a,b,c)=>a+b*y**(z=k.length-c)/z,0))(n[1])-x(n[0])

Demonstration:

f=n=>k=>(x=y=>k.reduce((a,b,c)=>a+b*y**(z=k.length-c)/z,0))(n[1])-x(n[0]);
// test case
console.log(f([2,3])([4,5,2,7]));
// large polynomial of degree 30
console.log(f([3,5])(new Array(31).fill(1) /*shortcut*/));

How it works

Constructs a function dynamically which calls reduce on the coefficients array. Then invokes it on both bounds and takes the difference.

05AB1E, \$\frac{30}{8} = 3.75\$

āR/0ªIβÆ

Port of @Neil's Charcoal answer, so make sure to upvote him as well!

First input is the list of coefficients; second is a pair of \$[b,a]\$ bounds.

Try it online.

Explanation:

ā         # Push a list in the range [1, (implicit) coefficients-length]
 R        # Reverse this range to [length,1]
  /       # Divide the coefficients by the ranged list (at the same postitions)
   0ª     # Append a 0 at the end of this list
     Iβ   # Convert this list to base-b and base-a using the second input-pair
       Æ  # And reduce that pair by subtracting
          # (after which the result is output implicitly)

J, \$\frac{30}{12}\approx2.5\$

[:-/[-p..p.[

Try it online!

-1 thanks to Bubbler

Charcoal, \$ \frac {30} {20} = 1.5 \$

UMθ∕ι⁻Lθκ⊞θ⁰I⁻↨θζ↨θη

Try it online! Link is to verbose version of code. Explanation:

UMθ∕ι⁻Lθκ

Divide each element of the polynomial by the 1-indexed reverse index.

⊞θ⁰

Append a zero.

I⁻↨θζ↨θη

Calculate the value at each bound and take the difference.

Factor, \$\frac{30}{56}\approx0.5357\$

[ [ 1 + 3dup nip v^n first2 - swap / * ] map-index sum ]

Try it online!

Takes the bounds and coefficients in reverse, e.g. { 3 2 } { 7 2 5 4 }, and returns a rational number, e.g. 108+2/3.

To take the inputs as given and return a float, add a reverse, a neg, and a >float to get 75 bytes:

Factor, \$\frac{30}{75}=0.4\$

[ reverse [ 1 + 3dup nip v^n first2 - swap / * ] map-index sum neg >float ]

Try it online!

APL (Dyalog Unicode), \$\frac{30}{20}=1.5\$

{-/⌽⊥∘(0,⍨⍵÷⌽⍳≢⍵)¨⍺}

Try it online!

Takes the bounds on the left and the coefficients on the right. This is a great place to use APL's ⊥, which can evaluate polynomials (although appending a zero is necessary because we want to use n+1 and not n).

SageMath, \$\frac{30}{67}\approx 0.44776\$

lambda c,b:RR(integrate(sum(a*x**e for e,a in enumerate(c)),[x]+b))

Try it online!

Inputs the coefficients (from the constant to the highest degree) and bounds as lists.

Can surely work for much higher degrees of a polynomial but got tired waiting for it to finish \$10000\$.
Works quite quickly for degree of \$3000\$.

Scala, \$\frac{30}{88}\approx0.3409\$

p=>_.:\(.0)((x,r)=>p.reverse.zipWithIndex.map{case(k,n)=>k*math.pow(x,n+1)/(n+1)}.sum-r)

Try it in Scastie

The question's IO format actually works out quiet well here (although I could save 8 bytes by taking the coefficients in reverse to avoid .reverse).

Jelly, \$\frac {30} 7 = 4.29\$

÷J$ŻUḅI

Try it online!

Takes the polynomial as a list of coefficients in little-endian format (i.e. the example is 7,2,5,4). This can handle any (positive) degree you want, but I've limited it at 30 as the question states \$0 < N < 30\$

+2 bytes and a score of \$3.33\$ if the polynomial must be taken in big-endian format

How it works

÷J$ŻUḅI - Main link. Takes coeffs on the left and [a, b] on the right
  $     - To the coeffs:
 J      -   Yield [1, 2, 3, ..., N]
÷       -   Divide each coeff by the orders
   Ż    - Prepend 0
    U   - Reverse
     ḅ  - Calculate as polynomials, with x = a and x = b
      I - Reduce by subtraction