snarkjs/src/polfield.js
src/polfield.jsRaw
1/*
2 This library do operations on polinomials where their coefficients are in field F
3
4 The polynomial P(x) = p0 + p1 * x + p2 * x^2 + p3 * x^3, ...
5 is represented by the array [ p0, p1, p2, p3, ... ]
6 */
7
8class PolField {
9 constructor (F) {
10 this.F = F;
11 }
12
13 _reduce(a) {
14 let i = a.length-1;
15 while ((i>=0) && (this.F.isZero(a[i])) ) i--;
16 return (i < a.length-1) ? a.slice(0, i+1) : a;
17 }
18
19 add(a, b) {
20 const maxGrade = Math.max(a.length, b.length);
21 const res = new Array(maxGrade);
22 for (let i=0; i<maxGrade; i++) {
23 res[i] = this.F.add(a[i], b[i]);
24 }
25 return this._reduce(res);
26 }
27
28 sub(a, b) {
29 throw new Error("Not Implementted");
30 }
31
32 mul(a, b) {
33 throw new Error("Not Implementted");
34 }
35
36 div(a, b) {
37 throw new Error("Not Implementted");
38 }
39
40 eval(p, x) {
41 throw new Error("Not Implementted");
42 }
43
44 lagrange(points) {
45 throw new Error("Not Implementted");
46 }
47}
48
49
50module.exports = PolField;