carl  24.04
Computer ARithmetic Library
Representation.h
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include "../MultivariatePolynomial.h"
6 #include "../UnivariatePolynomial.h"
7 
8 namespace carl {
9 
10 /**
11  * Switches the main variable using a purely syntactical restructuring.
12  * The resulting polynomial will be algebraicly identical, but have the given variable as its main variable.
13  * @param p The polynomial.
14  * @param newVar New main variable.
15  * @return Restructured polynomial.
16  */
17 template<typename Coeff>
19  assert(p.is_consistent());
21  return to_univariate_polynomial(MP(p), newVar);
22 }
23 
24 /**
25  * Replaces the main variable in a polynomial.
26  * @param p The polynomial.
27  * @param newVar New main variable.
28  * @return New polynomial.
29  */
30 template<typename Coeff>
32  if constexpr (carl::is_number_type<Coeff>::value) {
33  return UnivariatePolynomial<Coeff>(newVar, p.coefficients());
34  } else {
36  return to_univariate_polynomial(substitute(MP(p), p.main_var(), MP(newVar)), newVar);
37  }
38 }
39 
40 template<typename C, typename O, typename P>
42  return substitute(p, old_var, MultivariatePolynomial<C,O,P>(new_var));
43 }
44 
45 }
carl is the main namespace for the library.
UnivariatePolynomial< C > to_univariate_polynomial(const MultivariatePolynomial< C, O, P > &p)
Convert a univariate polynomial that is currently (mis)represented by a 'MultivariatePolynomial' into...
UnivariatePolynomial< Coeff > replace_main_variable(const UnivariatePolynomial< Coeff > &p, Variable newVar)
Replaces the main variable in a polynomial.
MultivariatePolynomial< C, O, P > switch_variable(const MultivariatePolynomial< C, O, P > &p, Variable old_var, Variable new_var)
Coeff substitute(const Monomial &m, const std::map< Variable, Coeff > &substitutions)
Applies the given substitutions to a monomial.
Definition: Substitution.h:19
UnivariatePolynomial< MultivariatePolynomial< typename UnderlyingNumberType< Coeff >::type > > switch_main_variable(const UnivariatePolynomial< Coeff > &p, Variable newVar)
Switches the main variable using a purely syntactical restructuring.
A Variable represents an algebraic variable that can be used throughout carl.
Definition: Variable.h:85
This class represents a univariate polynomial with coefficients of an arbitrary type.
const std::vector< Coefficient > & coefficients() const &
Retrieves the coefficients defining this polynomial.
Variable main_var() const
Retrieves the main variable of this polynomial.
bool is_consistent() const
Asserts that this polynomial over numeric coefficients complies with the requirements and assumptions...
The general-purpose multivariate polynomial class.
States if a type is a number type.
Definition: typetraits.h:237