11# Based on an adaptive quadrature algorithm by Pedro Gonnet
2+ from __future__ import annotations
23
34from collections import defaultdict
45from fractions import Fraction
89import scipy .linalg
910
1011
11- def legendre (n ) :
12+ def legendre (n : int ) -> list [ list [ Fraction ]] :
1213 """Return the first n Legendre polynomials.
1314
1415 The polynomials have *standard* normalization, i.e.
@@ -29,7 +30,7 @@ def legendre(n):
2930 return result
3031
3132
32- def newton (n ) :
33+ def newton (n : int ) -> np . ndarray :
3334 """Compute the monomial coefficients of the Newton polynomial over the
3435 nodes of the n-point Clenshaw-Curtis quadrature rule.
3536 """
@@ -86,7 +87,7 @@ def newton(n):
8687 return cf
8788
8889
89- def scalar_product (a , b ) :
90+ def scalar_product (a : list [ Fraction ] , b : list [ Fraction ]) -> Fraction :
9091 """Compute the polynomial scalar product int_-1^1 dx a(x) b(x).
9192
9293 The args must be sequences of polynomial coefficients. This
@@ -107,7 +108,7 @@ def scalar_product(a, b):
107108 return 2 * sum (c [i ] / (i + 1 ) for i in range (0 , lc , 2 ))
108109
109110
110- def calc_bdef (ns ) :
111+ def calc_bdef (ns : tuple [ int , int , int , int ]) -> list [ np . ndarray ] :
111112 """Calculate the decompositions of Newton polynomials (over the nodes
112113 of the n-point Clenshaw-Curtis quadrature rule) in terms of
113114 Legandre polynomials.
@@ -133,7 +134,7 @@ def calc_bdef(ns):
133134 return result
134135
135136
136- def calc_V (x , n ) :
137+ def calc_V (x : np . ndarray , n : int ) -> np . ndarray :
137138 V = [np .ones (x .shape ), x .copy ()]
138139 for i in range (2 , n ):
139140 V .append ((2 * i - 1 ) / i * x * V [- 1 ] - (i - 1 ) / i * V [- 2 ])
0 commit comments