Iterate over coefficients from a polynomial constructed from a string in JavaScript

TL;DR: I need a way to create a polynomial from some given coordinates in a such a way to allow for iterating over its coefficients and optionally to even allow evaluating the polynomial at any given point

I am working on creating a crude algorithm in JavaScript/TypeScript for KZG commitments and one of the steps for this algorithm includes multiplying coefficients of the polynomial constructed for some given string with the Structured Reference String (SRS) raised to the appropriate power.

Anyway, that basically means I need to iterate over all of the coefficients of this newly constructed polynomial (at least that is what I think I need to do, I am open to suggestions here).

I am trying to achieve the following:

  1. Take an input string
  2. Convert the string into coordinates on the XY-coordinate plane
  3. Calculate the polynomial that passes through these coordinates
  4. **Iterate over coefficients of this polynomial **<– this is where I am stuck
  5. (optional) evaluate the polynomial at a given point Z <– it would be awesome if this could still be possible alongside the previous requirement

I am stuck at step 4).

I know how to construct a polynomial from a given string in JS/TS using Lagrange Interpolation, but I am having difficulties extracting its coefficients, which I need to be able to multiply them with SRS.

Below is my Lagrange Interpolation algorithm – note that it can solve 5) for me, but I do not see an obvious way to get the exact coefficients from it:

type Point = { x: number; y: number };

// The function basically reconstructs the whole Lagrange Polynomial each time
// it needs to evaluate it at some given point `newX`, which is a problem as
// there is no way to extract the coefficients.
function lagrangeInterpolation(points: Point[], newX: number) {
  const n = points.length;
  let newY = 0;

  for (let i = 0; i < n; i++) {
    let { x, y } = points[i];

    let term = y;
    for (let j = 0; j < n; j++) {
      if (i !== j) {
        let { x: xj } = points[j];
        term = (term * (newX - xj)) / (x - xj);
      }
    }
    newY = newY + term;
  }

  return newY;
}

Maybe another interpolation algorithm would allow to calculate the exact coefficients?

I could not find any JS libraries that solve this exact problem. The closest ones I could find were the following, but they are still not applicable to solving this problem:

  • polynomial -> problem: the library neither has an inbuilt way to return coefficients nor can it take a Lagrange-like polynomial as an input and shorten it to allow for coefficient extraction using regex.
  • nerdamer-prime -> problem: the library can take any polynomial and shorten it, but it doesn’t guarantee the order of terms (sorted by the power of x) which makes it difficult to extract coefficients using regex; it also has no inbuilt way to get coefficients.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật