1
1
# Based on an adaptive quadrature algorithm by Pedro Gonnet
2
+ from __future__ import annotations
2
3
3
4
from collections import defaultdict
4
5
from fractions import Fraction
8
9
import scipy .linalg
9
10
10
11
11
- def legendre (n ) :
12
+ def legendre (n : int ) -> list [ list [ Fraction ]] :
12
13
"""Return the first n Legendre polynomials.
13
14
14
15
The polynomials have *standard* normalization, i.e.
@@ -29,7 +30,7 @@ def legendre(n):
29
30
return result
30
31
31
32
32
- def newton (n ) :
33
+ def newton (n : int ) -> np . ndarray :
33
34
"""Compute the monomial coefficients of the Newton polynomial over the
34
35
nodes of the n-point Clenshaw-Curtis quadrature rule.
35
36
"""
@@ -86,7 +87,7 @@ def newton(n):
86
87
return cf
87
88
88
89
89
- def scalar_product (a , b ) :
90
+ def scalar_product (a : list [ Fraction ] , b : list [ Fraction ]) -> Fraction :
90
91
"""Compute the polynomial scalar product int_-1^1 dx a(x) b(x).
91
92
92
93
The args must be sequences of polynomial coefficients. This
@@ -107,7 +108,7 @@ def scalar_product(a, b):
107
108
return 2 * sum (c [i ] / (i + 1 ) for i in range (0 , lc , 2 ))
108
109
109
110
110
- def calc_bdef (ns ) :
111
+ def calc_bdef (ns : tuple [ int , int , int , int ]) -> list [ np . ndarray ] :
111
112
"""Calculate the decompositions of Newton polynomials (over the nodes
112
113
of the n-point Clenshaw-Curtis quadrature rule) in terms of
113
114
Legandre polynomials.
@@ -133,7 +134,7 @@ def calc_bdef(ns):
133
134
return result
134
135
135
136
136
- def calc_V (x , n ) :
137
+ def calc_V (x : np . ndarray , n : int ) -> np . ndarray :
137
138
V = [np .ones (x .shape ), x .copy ()]
138
139
for i in range (2 , n ):
139
140
V .append ((2 * i - 1 ) / i * x * V [- 1 ] - (i - 1 ) / i * V [- 2 ])
0 commit comments