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