barretenberg
Loading...
Searching...
No Matches
ffterm.hpp
1#pragma once
2#include "barretenberg/smt_verification/solver/solver.hpp"
3
4namespace smt_terms {
5using namespace smt_solver;
6
15class FFTerm {
16 public:
17 Solver* solver;
18 cvc5::Term term;
19
20 FFTerm()
21 : solver(nullptr)
22 , term(cvc5::Term()){};
23
24 explicit FFTerm(const std::string& t, Solver* slv, bool isconst = false, uint32_t base = 16);
25 FFTerm(cvc5::Term& term, Solver* s)
26 : solver(s)
27 , term(term){};
28 FFTerm(const FFTerm& other) = default;
29 FFTerm(FFTerm&& other) = default;
30
31 static FFTerm Var(const std::string& name, Solver* slv);
32 static FFTerm Const(const std::string& val, Solver* slv, uint32_t base = 16);
33
34 FFTerm& operator=(const FFTerm& right) = default;
35 FFTerm& operator=(FFTerm&& right) = default;
36
37 FFTerm operator+(const FFTerm& other) const;
38 void operator+=(const FFTerm& other);
39 FFTerm operator-(const FFTerm& other) const;
40 void operator-=(const FFTerm& other);
41 FFTerm operator*(const FFTerm& other) const;
42 void operator*=(const FFTerm& other);
43 FFTerm operator/(const FFTerm& other) const;
44 void operator/=(const FFTerm& other);
45
46 void operator==(const FFTerm& other) const;
47 void operator!=(const FFTerm& other) const;
48
49 operator std::string() const { return term.isFiniteFieldValue() ? term.getFiniteFieldValue() : term.toString(); };
50 operator cvc5::Term() const { return term; };
51
52 ~FFTerm() = default;
53 friend std::ostream& operator<<(std::ostream& out, const FFTerm& k) { return out << k.term; }
54
55 friend FFTerm batch_add(const std::vector<FFTerm>& children)
56 {
57 Solver* slv = children[0].solver;
58 std::vector<cvc5::Term> terms(children.begin(), children.end());
59 cvc5::Term res = slv->s.mkTerm(cvc5::Kind::FINITE_FIELD_ADD, terms);
60 return { res, slv };
61 }
62
63 friend FFTerm batch_mul(const std::vector<FFTerm>& children)
64 {
65 Solver* slv = children[0].solver;
66 std::vector<cvc5::Term> terms(children.begin(), children.end());
67 cvc5::Term res = slv->s.mkTerm(cvc5::Kind::FINITE_FIELD_MULT, terms);
68 return { res, slv };
69 }
70};
71
72} // namespace smt_terms
Class for the solver.
Definition: solver.hpp:28
Finite Field element class.
Definition: ffterm.hpp:15
void operator!=(const FFTerm &other) const
Definition: ffterm.cpp:131
static FFTerm Var(const std::string &name, Solver *slv)
Definition: ffterm.cpp:12
FFTerm operator/(const FFTerm &other) const
Division operation.
Definition: ffterm.cpp:85
void operator==(const FFTerm &other) const
Definition: ffterm.cpp:121
static FFTerm Const(const std::string &val, Solver *slv, uint32_t base=16)
Definition: ffterm.cpp:25