carl  24.04
Computer ARithmetic Library
Chebyshev.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../UnivariatePolynomial.h"
5 
6 namespace carl {
7 
8 /**
9  * Implements a generator for Chebyshev polynomials.
10  */
11 template<typename Number>
12 struct Chebyshev {
14  explicit Chebyshev(Variable v): mVar(v) {}
15 
17  UnivariatePolynomial<Number> t0(mVar, Number(1), 0);
18  if (n == 0) return t0;
19  UnivariatePolynomial<Number> t1(mVar, Number(1), 1);
20  if (n == 1) return t1;
21  UnivariatePolynomial<Number> twox(mVar, Number(2), 1);
22  while (n >= 2) {
23  UnivariatePolynomial<Number> tn = twox * t1 - t0;
24  if (n == 2) return tn;
25  t0 = t1;
26  t1 = tn;
27  --n;
28  }
29  assert(false);
30  return t0;
31  }
32 };
33 
34 }
carl is the main namespace for the library.
A Variable represents an algebraic variable that can be used throughout carl.
Definition: Variable.h:85
Implements a generator for Chebyshev polynomials.
Definition: Chebyshev.h:12
UnivariatePolynomial< Number > operator()(std::size_t n) const
Definition: Chebyshev.h:16
Variable mVar
Definition: Chebyshev.h:13
Chebyshev(Variable v)
Definition: Chebyshev.h:14