18 #include <libff/common/utils.hpp>
35 const size_t pos = 3 - ((X ? 2 : 0) + (Y ? 1 : 0));
37 return (((
int)
type) & (1u << pos));
42 const std::map<size_t, std::string> &variable_annotations)
51 auto it = variable_annotations.find(wire);
55 (it == variable_annotations.end() ?
"no annotation"
56 : it->second.c_str()));
61 const std::map<size_t, std::string> &variable_annotations)
const
71 printf(
"X_AND_NOT_Y");
77 printf(
"NOT_X_AND_Y");
92 printf(
"EQUIVALENCE");
98 printf(
"IF_Y_THEN_X");
104 printf(
"IF_X_THEN_Y");
110 printf(
"CONSTANT_1");
113 printf(
"Invalid type");
129 this->right_wire == other.
right_wire && this->type == other.
type &&
130 this->output == other.
output &&
138 out << (int)g.
type <<
"\n";
148 libff::consume_newline(in);
150 libff::consume_newline(in);
154 libff::consume_newline(in);
165 for (
auto &g :
gates) {
167 std::max(depths[g.left_wire], depths[g.right_wire]) + 1);
184 std::vector<size_t> all_depths = this->
wire_depths();
185 return *(std::max_element(all_depths.begin(), all_depths.end()));
190 for (
size_t i = 0; i <
num_gates(); ++i) {
219 result.insert(result.end(), primary_input.begin(), primary_input.end());
220 result.insert(result.end(), auxiliary_input.begin(), auxiliary_input.end());
224 for (
auto &g :
gates) {
225 const bool gate_output = g.evaluate(result);
226 result.push_back(gate_output);
240 for (
auto &g :
gates) {
241 if (g.is_circuit_output) {
242 all_outputs.push_back(all_wires[g.output - 1]);
255 for (
size_t i = 0; i < all_outputs.size(); ++i) {
256 if (all_outputs[i]) {
267 gates.emplace_back(g);
273 gates.emplace_back(g);
275 gate_annotations[g.
output] = annotation;
277 libff::UNUSED(annotation);
286 this->gates == other.
gates);
294 out << OUTPUT_NEWLINE;
302 libff::consume_newline(in);
304 libff::consume_newline(in);
306 libff::consume_OUTPUT_NEWLINE(in);
313 libff::print_indent();
314 printf(
"General information about the circuit:\n");
316 libff::print_indent();
317 printf(
"All gates:\n");
318 for (
size_t i = 0; i <
gates.size(); ++i) {
319 std::string annotation =
"no annotation";
321 auto it = gate_annotations.find(i);
322 if (it != gate_annotations.end()) {
323 annotation = it->second;
326 printf(
"Gate %zu (%s):\n", i, annotation.c_str());
328 gates[i].print(variable_annotations);
337 libff::print_indent();
338 printf(
"* Number of inputs: %zu\n", this->
num_inputs());
339 libff::print_indent();
340 printf(
"* Number of gates: %zu\n", this->
num_gates());
341 libff::print_indent();
342 printf(
"* Number of wires: %zu\n", this->
num_wires());
343 libff::print_indent();
344 printf(
"* Depth: %zu\n", this->
depth());