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