HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →
Live examsInternational live exams are comingTell us which exam you want first. Timed practice papers are open now.See what is coming →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Space Science and Astronomy
  • Earth and Environmental Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Python Labs
  2. /Interpolation and the roots-of-unity filter
MathematicsHardHigh School (11–12)Roots of Polynomial Equations

Interpolation and the roots-of-unity filter

You will build the polynomial through given points with Lagrange's formula, and count binomial coefficients in steps of three in two ways.

The idea. The value at xxx of the polynomial through (xi,yi)(x_i, y_i)(xi​,yi​) is ∑iyi∏j≠ix−xjxi−xj\sum_i y_i\prod_{j \ne i}\dfrac{x - x_j}{x_i - x_j}∑i​yi​∏j=i​xi​−xj​x−xj​​. Use Fraction so the answers are exact. The sum of (nk)\binom{n}{k}(kn​) over k≡r(mod3)k \equiv r \pmod 3k≡r(mod3) can be found directly with math.comb, or from (1+1)n(1 + 1)^n(1+1)n, (1+ω)n(1 + \omega)^n(1+ω)n and (1+ω2)n(1 + \omega^2)^n(1+ω2)n.

Your tasks.

  1. Finish lagrange(points, x). Return the exact value at x.
  2. Finish direct(n, r). Return the sum of comb(n, k) for k with k % 3 == r.
  3. Finish filtered(n, r). Return the rounded real part of 13∑j=02ω−jr(1+ωj)n\dfrac{1}{3}\sum_{j=0}^{2}\omega^{-jr}(1 + \omega^j)^n31​∑j=02​ω−jr(1+ωj)n.

Run it first, just as it is. The checker at the end prints FAIL for each task. Then do the tasks one at a time, and run the program again after each one. A Hint appears under every check that still fails.

When every line says PASS, find the polynomial through (1, 1), (2, 1/2), (3, 1/3), (4, 1/4) and its value at 5. Is it what you expected?

StemPy LabContributed by StemPy Lab
python
Loading Python runtime…

A worked solution

Run your code once to unlock the worked solution.

Have you tried it?

Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.

Log in to save
← All Labs
← The roots of unity in PythonHyperbolic functions from the exponential →
More onRoots of Polynomial Equations

Discussion (0)

Log in to join the discussion.

Loading…

Learn it in

  1. Polynomial identitiesComplex Roots and Roots of Unity

More labs on this topic

  1. Rational roots, exactlyHard
  2. Transforming the coefficientsHard
  3. Newton's sums for any polynomialHard
  4. From roots to coefficientsHard
All labs on this topic →