carl  24.04
Computer ARithmetic Library
VariableAssignment.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "VariableComparison.h"
6 
7 namespace carl {
8  template<typename Poly>
10  private:
12  public:
13  using Number = typename Base::Number;
14  using MR = typename Base::MR;
15  using RAN = typename Base::RAN;
16  private:
18  public:
21 
22  Variable var() const {
23  return m_comparison.var();
24  }
25  const RAN& value() const {
26  assert(std::holds_alternative<RAN>(m_comparison.value()));
27  return std::get<RAN>(m_comparison.value());
28  }
29  const auto& base_value() const {
30  return m_comparison.value();
31  }
32  bool negated() const {
33  return m_comparison.negated();
34  }
36  return VariableAssignment(var(), value(), !negated());
37  }
38  operator const VariableComparison<Poly>&() const {
39  return m_comparison;
40  }
41 
42  template<typename Pol>
43  friend inline void variables(const VariableAssignment<Pol>& f, carlVariables& vars);
44  };
45 
46  template<typename Pol>
47  inline void variables(const VariableAssignment<Pol>& f, carlVariables& vars) {
48  variables(f.m_comparison, vars);
49  }
50 
51  template<typename Poly>
53  return static_cast<VariableComparison<Poly>>(lhs) == static_cast<VariableComparison<Poly>>(rhs);
54  }
55  template<typename Poly>
57  return static_cast<VariableComparison<Poly>>(lhs) < static_cast<VariableComparison<Poly>>(rhs);
58  }
59  template<typename Poly>
60  std::ostream& operator<<(std::ostream& os, const VariableAssignment<Poly>& va) {
61  return os << "(" << va.var() << (va.negated() ? " -!> " : " -> ") << va.base_value() << ")";
62  }
63 }
64 
65 namespace std {
66  template<typename Pol>
67  struct hash<carl::VariableAssignment<Pol>> {
68  std::size_t operator()(const carl::VariableAssignment<Pol>& va) const {
69  return std::hash<carl::VariableComparison<Pol>>()(va);
70  }
71  };
72 }
carl is the main namespace for the library.
bool operator<(const BasicConstraint< P > &lhs, const BasicConstraint< P > &rhs)
std::ostream & operator<<(std::ostream &os, const BasicConstraint< Poly > &c)
Prints the given constraint on the given stream.
bool operator==(const BasicConstraint< P > &lhs, const BasicConstraint< P > &rhs)
Relation
Definition: Relation.h:20
void variables(const BasicConstraint< Pol > &c, carlVariables &vars)
A Variable represents an algebraic variable that can be used throughout carl.
Definition: Variable.h:85
typename Base::Number Number
VariableAssignment(Variable v, const Number &value, bool negated=false)
const auto & base_value() const
VariableAssignment(Variable v, const RAN &value, bool negated=false)
VariableAssignment negation() const
friend void variables(const VariableAssignment< Pol > &f, carlVariables &vars)
const RAN & value() const
std::size_t operator()(const carl::VariableAssignment< Pol > &va) const
Represent a sum type/variant of an (in)equality between a variable on the left-hand side and multivar...
const std::variant< MR, RAN > & value() const
typename MultivariateRoot< Poly >::RAN RAN
typename UnderlyingNumberType< Poly >::type Number
MultivariateRoot< Poly > MR