barretenberg
Loading...
Searching...
No Matches
ultra_arithmetic_relation.hpp
1#pragma once
2#include "barretenberg/relations/relation_types.hpp"
3
4namespace proof_system {
5
6template <typename FF_> class UltraArithmeticRelationImpl {
7 public:
8 using FF = FF_;
9
10 static constexpr std::array<size_t, 2> SUBRELATION_PARTIAL_LENGTHS{
11 6, // primary arithmetic sub-relation
12 5 // secondary arithmetic sub-relation
13 };
14
66 template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
67 inline static void accumulate(ContainerOverSubrelations& evals,
68 const AllEntities& in,
69 const Parameters&,
70 const FF& scaling_factor)
71 {
72 {
73 using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>;
74 using View = typename Accumulator::View;
75 auto w_l = View(in.w_l);
76 auto w_r = View(in.w_r);
77 auto w_o = View(in.w_o);
78 auto w_4 = View(in.w_4);
79 auto w_4_shift = View(in.w_4_shift);
80 auto q_m = View(in.q_m);
81 auto q_l = View(in.q_l);
82 auto q_r = View(in.q_r);
83 auto q_o = View(in.q_o);
84 auto q_4 = View(in.q_4);
85 auto q_c = View(in.q_c);
86 auto q_arith = View(in.q_arith);
87
88 static const FF neg_half = FF(-2).invert();
89
90 auto tmp = (q_arith - 3) * (q_m * w_r * w_l) * neg_half;
91 tmp += (q_l * w_l) + (q_r * w_r) + (q_o * w_o) + (q_4 * w_4) + q_c;
92 tmp += (q_arith - 1) * w_4_shift;
93 tmp *= q_arith;
94 tmp *= scaling_factor;
95 std::get<0>(evals) += tmp;
96 }
97 {
98 using Accumulator = std::tuple_element_t<1, ContainerOverSubrelations>;
99 using View = typename Accumulator::View;
100 auto w_l = View(in.w_l);
101 auto w_4 = View(in.w_4);
102 auto w_l_shift = View(in.w_l_shift);
103 auto q_m = View(in.q_m);
104 auto q_arith = View(in.q_arith);
105
106 auto tmp = w_l + w_4 - w_l_shift + q_m;
107 tmp *= (q_arith - 2);
108 tmp *= (q_arith - 1);
109 tmp *= q_arith;
110 tmp *= scaling_factor;
111 std::get<1>(evals) += tmp;
112 };
113 };
114};
115
116template <typename FF> using UltraArithmeticRelation = Relation<UltraArithmeticRelationImpl<FF>>;
117} // namespace proof_system
Definition: ultra_arithmetic_relation.hpp:6
static void accumulate(ContainerOverSubrelations &evals, const AllEntities &in, const Parameters &, const FF &scaling_factor)
Expression for the Ultra Arithmetic gate.
Definition: ultra_arithmetic_relation.hpp:67