Skip to content

Commit

Permalink
Add poly_min_exp (#24)
Browse files Browse the repository at this point in the history
* Update polymint.11.cpp

* Update polymint.11.cpp

* Update polymint.11.cpp
  • Loading branch information
Sprdalo authored Jun 12, 2024
1 parent f0e1231 commit 2ecf198
Showing 1 changed file with 59 additions and 4 deletions.
63 changes: 59 additions & 4 deletions polynomials/polymint.11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,68 @@ struct poly_mint {
}
return rn;
}

poly_mint derive(){
int n = size();
poly_mint b(n-1);
for (int i = 1; i < n; ++i){
b[i-1] = a[i] * i;
}

if (n == 1)
return b = {0};

return b;
}

poly_mint integrate(){
int n = size();
poly_mint b(n+1);
b[0] = 0;
for (int i = 0; i < n; ++i){
b[i+1] = a[i] / (i+1);
}

return b;
}

void trim(int n){
if ((int)a.size() > n)
a.resize(n);
}

// @n=size() - power of two
// @a[0] = 0
poly_mint poly_exp(){
poly_mint f; f.a = {1};
poly_mint g; g.a = {1};
int m = 1, n = size();

while (m <= n/2){
g = (g + g - f * g * g);
g.trim(m);

auto q = derive();
q.trim(m-1);

auto w = q + g * (f.derive() - f * q);
w.trim(2*m-1);

f = f + f * (*this - w.integrate());
f.trim(2*m);

m *= 2;
}
return f;
}
};
/*snippet-end*/

int main() {
int main() {
poly_mint<mod> a;
a.a = {1, 2, 3};
a *= a;
a.a = {0,1,1,0};

auto t = a.poly_exp();

return a.a != vector<mint> {1, 4, 10, 12, 9};
return (t.a != vector<mint>{1,1,mint(3)/mint(2),mint(7)/mint(6)});
}

0 comments on commit 2ecf198

Please sign in to comment.