Clearmatics Libsnark  0.1
C++ library for zkSNARK proofs
variable_operators.hpp
Go to the documentation of this file.
1 
14 #ifndef LIBSNARK_GADGETLIB2_INCLUDE_GADGETLIB2_VARIABLEOPERATORS_HPP_
15 #define LIBSNARK_GADGETLIB2_INCLUDE_GADGETLIB2_VARIABLEOPERATORS_HPP_
16 
18 
19 namespace gadgetlib2
20 {
21 
22 /*************************************************************************************************/
23 /*************************************************************************************************/
24 /******************* ******************/
25 /******************* lots o' operators ******************/
26 /******************* ******************/
27 /*************************************************************************************************/
28 /*************************************************************************************************/
29 
30 /***********************************/
31 /*** operator+ ***/
32 /***********************************/
33 
34 // Polynomial
35 inline Polynomial operator+(const Polynomial &first, const Polynomial &second)
36 {
37  auto retval = first;
38  return retval += second;
39 }
40 
41 // Monomial
42 inline Polynomial operator+(const Monomial &first, const Polynomial &second)
43 {
44  return Polynomial(first) + second;
45 }
46 inline Polynomial operator+(const Monomial &first, const Monomial &second)
47 {
48  return Polynomial(first) + Polynomial(second);
49 }
50 
51 // LinearCombination
53  const LinearCombination &first, const Polynomial &second)
54 {
55  return Polynomial(first) + second;
56 }
58  const LinearCombination &first, const Monomial &second)
59 {
60  return Polynomial(first) + second;
61 }
63  const LinearCombination &first, const LinearCombination &second)
64 {
65  auto retval = first;
66  return retval += second;
67 }
68 
69 // LinearTerm
70 inline Polynomial operator+(const LinearTerm &first, const Polynomial &second)
71 {
72  return LinearCombination(first) + second;
73 }
74 inline Polynomial operator+(const LinearTerm &first, const Monomial &second)
75 {
76  return LinearCombination(first) + second;
77 }
79  const LinearTerm &first, const LinearCombination &second)
80 {
81  return LinearCombination(first) + second;
82 }
84  const LinearTerm &first, const LinearTerm &second)
85 {
86  return LinearCombination(first) + LinearCombination(second);
87 }
88 
89 // Variable
90 inline Polynomial operator+(const Variable &first, const Polynomial &second)
91 {
92  return LinearTerm(first) + second;
93 }
94 inline Polynomial operator+(const Variable &first, const Monomial &second)
95 {
96  return LinearTerm(first) + second;
97 }
99  const Variable &first, const LinearCombination &second)
100 {
101  return LinearTerm(first) + second;
102 }
104  const Variable &first, const LinearTerm &second)
105 {
106  return LinearTerm(first) + second;
107 }
109  const Variable &first, const Variable &second)
110 {
111  return LinearTerm(first) + LinearTerm(second);
112 }
113 
114 // FElem
115 inline Polynomial operator+(const FElem &first, const Polynomial &second)
116 {
117  return LinearCombination(first) + second;
118 }
119 inline Polynomial operator+(const FElem &first, const Monomial &second)
120 {
121  return LinearCombination(first) + second;
122 }
124  const FElem &first, const LinearCombination &second)
125 {
126  return LinearCombination(first) + second;
127 }
128 inline LinearCombination operator+(const FElem &first, const LinearTerm &second)
129 {
130  return LinearCombination(first) + LinearCombination(second);
131 }
132 inline LinearCombination operator+(const FElem &first, const Variable &second)
133 {
134  return LinearCombination(first) + LinearCombination(second);
135 }
136 inline FElem operator+(const FElem &first, const FElem &second)
137 {
138  auto retval = first;
139  return retval += second;
140 }
141 
142 // int
143 inline FElem operator+(const int first, const FElem &second)
144 {
145  return FElem(first) + second;
146 }
147 inline LinearCombination operator+(const int first, const Variable &second)
148 {
149  return FElem(first) + second;
150 }
151 inline LinearCombination operator+(const int first, const LinearTerm &second)
152 {
153  return FElem(first) + second;
154 }
156  const int first, const LinearCombination &second)
157 {
158  return FElem(first) + second;
159 }
160 inline Polynomial operator+(const int first, const Monomial &second)
161 {
162  return FElem(first) + second;
163 }
164 inline Polynomial operator+(const int first, const Polynomial &second)
165 {
166  return FElem(first) + second;
167 }
168 
169 // symetrical operators
170 inline Polynomial operator+(const Polynomial &first, const Monomial &second)
171 {
172  return second + first;
173 }
175  const Monomial &first, const LinearCombination &second)
176 {
177  return second + first;
178 }
180  const Polynomial &first, const LinearCombination &second)
181 {
182  return second + first;
183 }
185  const LinearCombination &first, const LinearTerm &second)
186 {
187  return second + first;
188 }
189 inline Polynomial operator+(const Monomial &first, const LinearTerm &second)
190 {
191  return second + first;
192 }
193 inline Polynomial operator+(const Polynomial &first, const LinearTerm &second)
194 {
195  return second + first;
196 }
198  const LinearTerm &first, const Variable &second)
199 {
200  return second + first;
201 }
203  const LinearCombination &first, const Variable &second)
204 {
205  return second + first;
206 }
207 inline Polynomial operator+(const Monomial &first, const Variable &second)
208 {
209  return second + first;
210 }
211 inline Polynomial operator+(const Polynomial &first, const Variable &second)
212 {
213  return second + first;
214 }
215 inline LinearCombination operator+(const Variable &first, const FElem &second)
216 {
217  return second + first;
218 }
219 inline LinearCombination operator+(const LinearTerm &first, const FElem &second)
220 {
221  return second + first;
222 }
224  const LinearCombination &first, const FElem &second)
225 {
226  return second + first;
227 }
228 inline Polynomial operator+(const Monomial &first, const FElem &second)
229 {
230  return second + first;
231 }
232 inline Polynomial operator+(const Polynomial &first, const FElem &second)
233 {
234  return second + first;
235 }
236 inline FElem operator+(const FElem &first, const int second)
237 {
238  return second + first;
239 }
240 inline LinearCombination operator+(const Variable &first, const int second)
241 {
242  return second + first;
243 }
244 inline LinearCombination operator+(const LinearTerm &first, const int second)
245 {
246  return second + first;
247 }
249  const LinearCombination &first, const int second)
250 {
251  return second + first;
252 }
253 inline Polynomial operator+(const Monomial &first, const int second)
254 {
255  return second + first;
256 }
257 inline Polynomial operator+(const Polynomial &first, const int second)
258 {
259  return second + first;
260 }
261 
262 /***********************************/
263 /*** operator- ***/
264 /***********************************/
265 inline LinearTerm operator-(const Variable &src) { return LinearTerm(src, -1); }
266 
267 inline Polynomial operator-(const Polynomial &first, const Polynomial &second)
268 {
269  return first + (-second);
270 }
271 inline Polynomial operator-(const Monomial &first, const Polynomial &second)
272 {
273  return first + (-second);
274 }
275 inline Polynomial operator-(const Monomial &first, const Monomial &second)
276 {
277  return first + (-second);
278 }
280  const LinearCombination &first, const Polynomial &second)
281 {
282  return first + (-second);
283 }
285  const LinearCombination &first, const Monomial &second)
286 {
287  return first + (-second);
288 }
290  const LinearCombination &first, const LinearCombination &second)
291 {
292  return first + (-second);
293 }
294 inline Polynomial operator-(const LinearTerm &first, const Polynomial &second)
295 {
296  return first + (-second);
297 }
298 inline Polynomial operator-(const LinearTerm &first, const Monomial &second)
299 {
300  return first + (-second);
301 }
303  const LinearTerm &first, const LinearCombination &second)
304 {
305  return first + (-second);
306 }
308  const LinearTerm &first, const LinearTerm &second)
309 {
310  return first + (-second);
311 }
312 inline Polynomial operator-(const Variable &first, const Polynomial &second)
313 {
314  return first + (-second);
315 }
316 inline Polynomial operator-(const Variable &first, const Monomial &second)
317 {
318  return first + (-second);
319 }
321  const Variable &first, const LinearCombination &second)
322 {
323  return first + (-second);
324 }
326  const Variable &first, const LinearTerm &second)
327 {
328  return first + (-second);
329 }
331  const Variable &first, const Variable &second)
332 {
333  return first + (-second);
334 }
335 inline Polynomial operator-(const FElem &first, const Polynomial &second)
336 {
337  return first + (-second);
338 }
339 inline Polynomial operator-(const FElem &first, const Monomial &second)
340 {
341  return first + (-second);
342 }
344  const FElem &first, const LinearCombination &second)
345 {
346  return first + (-second);
347 }
348 inline LinearCombination operator-(const FElem &first, const LinearTerm &second)
349 {
350  return first + (-second);
351 }
352 inline LinearCombination operator-(const FElem &first, const Variable &second)
353 {
354  return first + (-second);
355 }
356 inline FElem operator-(const FElem &first, const FElem &second)
357 {
358  return first + (-second);
359 }
360 inline FElem operator-(const int first, const FElem &second)
361 {
362  return first + (-second);
363 }
364 inline LinearCombination operator-(const int first, const Variable &second)
365 {
366  return first + (-second);
367 }
368 inline LinearCombination operator-(const int first, const LinearTerm &second)
369 {
370  return first + (-second);
371 }
373  const int first, const LinearCombination &second)
374 {
375  return first + (-second);
376 }
377 inline Polynomial operator-(const int first, const Monomial &second)
378 {
379  return first + (-second);
380 }
381 inline Polynomial operator-(const int first, const Polynomial &second)
382 {
383  return first + (-second);
384 }
385 inline Polynomial operator-(const Polynomial &first, const Monomial &second)
386 {
387  return first + (-second);
388 }
390  const Monomial &first, const LinearCombination &second)
391 {
392  return first + (-second);
393 }
395  const Polynomial &first, const LinearCombination &second)
396 {
397  return first + (-second);
398 }
400  const LinearCombination &first, const LinearTerm &second)
401 {
402  return first + (-second);
403 }
404 inline Polynomial operator-(const Monomial &first, const LinearTerm &second)
405 {
406  return first + (-second);
407 }
408 inline Polynomial operator-(const Polynomial &first, const LinearTerm &second)
409 {
410  return first + (-second);
411 }
413  const LinearTerm &first, const Variable &second)
414 {
415  return first + (-second);
416 }
418  const LinearCombination &first, const Variable &second)
419 {
420  return first + (-second);
421 }
422 inline Polynomial operator-(const Monomial &first, const Variable &second)
423 {
424  return first + (-second);
425 }
426 inline Polynomial operator-(const Polynomial &first, const Variable &second)
427 {
428  return first + (-second);
429 }
430 inline LinearCombination operator-(const Variable &first, const FElem &second)
431 {
432  return first + (-second);
433 }
434 inline LinearCombination operator-(const LinearTerm &first, const FElem &second)
435 {
436  return first + (-second);
437 }
439  const LinearCombination &first, const FElem &second)
440 {
441  return first + (-second);
442 }
443 inline Polynomial operator-(const Monomial &first, const FElem &second)
444 {
445  return first + (-second);
446 }
447 inline Polynomial operator-(const Polynomial &first, const FElem &second)
448 {
449  return first + (-second);
450 }
451 inline FElem operator-(const FElem &first, const int second)
452 {
453  return first + (-second);
454 }
455 inline LinearCombination operator-(const Variable &first, const int second)
456 {
457  return first + (-second);
458 }
459 inline LinearCombination operator-(const LinearTerm &first, const int second)
460 {
461  return first + (-second);
462 }
464  const LinearCombination &first, const int second)
465 {
466  return first + (-second);
467 }
468 inline Polynomial operator-(const Monomial &first, const int second)
469 {
470  return first + (-second);
471 }
472 inline Polynomial operator-(const Polynomial &first, const int second)
473 {
474  return first + (-second);
475 }
476 
477 /***********************************/
478 /*** operator* ***/
479 /***********************************/
480 
481 // Polynomial
482 inline Polynomial operator*(const Polynomial &first, const Polynomial &second)
483 {
484  auto retval = first;
485  return retval *= second;
486 }
487 
488 // Monomial
489 inline Polynomial operator*(const Monomial &first, const Polynomial &second)
490 {
491  return Polynomial(first) * second;
492 }
493 inline Monomial operator*(const Monomial &first, const Monomial &second)
494 {
495  auto retval = first;
496  return retval *= second;
497 }
498 
499 // LinearCombination
501  const LinearCombination &first, const Polynomial &second)
502 {
503  return Polynomial(first) * second;
504 }
506  const LinearCombination &first, const Monomial &second)
507 {
508  return first * Polynomial(second);
509 }
511  const LinearCombination &first, const LinearCombination &second)
512 {
513  return first * Polynomial(second);
514 }
515 
516 // LinearTerm
517 inline Polynomial operator*(const LinearTerm &first, const Polynomial &second)
518 {
519  return LinearCombination(first) * second;
520 }
521 inline Monomial operator*(const LinearTerm &first, const Monomial &second)
522 {
523  return Monomial(first) * second;
524 }
526  const LinearTerm &first, const LinearCombination &second)
527 {
528  return LinearCombination(first) * second;
529 }
530 inline Monomial operator*(const LinearTerm &first, const LinearTerm &second)
531 {
532  return Monomial(first) * Monomial(second);
533 }
534 
535 // Variable
536 inline Polynomial operator*(const Variable &first, const Polynomial &second)
537 {
538  return LinearTerm(first) * second;
539 }
540 inline Monomial operator*(const Variable &first, const Monomial &second)
541 {
542  return Monomial(first) * second;
543 }
545  const Variable &first, const LinearCombination &second)
546 {
547  return LinearTerm(first) * second;
548 }
549 inline Monomial operator*(const Variable &first, const LinearTerm &second)
550 {
551  return LinearTerm(first) * second;
552 }
553 inline Monomial operator*(const Variable &first, const Variable &second)
554 {
555  return LinearTerm(first) * LinearTerm(second);
556 }
557 
558 // FElem
559 inline Polynomial operator*(const FElem &first, const Polynomial &second)
560 {
561  return LinearCombination(first) * second;
562 }
563 inline Monomial operator*(const FElem &first, const Monomial &second)
564 {
565  return Monomial(first) * second;
566 }
568  const FElem &first, const LinearCombination &second)
569 {
570  auto retval = second;
571  return retval *= first;
572 }
573 inline LinearTerm operator*(const FElem &first, const LinearTerm &second)
574 {
575  auto retval = second;
576  return retval *= first;
577 }
578 inline LinearTerm operator*(const FElem &first, const Variable &second)
579 {
580  return LinearTerm(second) *= first;
581 }
582 inline FElem operator*(const FElem &first, const FElem &second)
583 {
584  auto retval = first;
585  return retval *= second;
586 }
587 
588 // int
589 inline FElem operator*(const int first, const FElem &second)
590 {
591  return FElem(first) * second;
592 }
593 inline LinearTerm operator*(const int first, const Variable &second)
594 {
595  return FElem(first) * second;
596 }
597 inline LinearTerm operator*(const int first, const LinearTerm &second)
598 {
599  return FElem(first) * second;
600 }
602  const int first, const LinearCombination &second)
603 {
604  return FElem(first) * second;
605 }
606 inline Monomial operator*(const int first, const Monomial &second)
607 {
608  return FElem(first) * second;
609 }
610 inline Polynomial operator*(const int first, const Polynomial &second)
611 {
612  return FElem(first) * second;
613 }
614 
615 // symetrical operators
616 inline Polynomial operator*(const Polynomial &first, const Monomial &second)
617 {
618  return second * first;
619 }
621  const Monomial &first, const LinearCombination &second)
622 {
623  return second * first;
624 }
626  const Polynomial &first, const LinearCombination &second)
627 {
628  return second * first;
629 }
631  const LinearCombination &first, const LinearTerm &second)
632 {
633  return second * first;
634 }
635 inline Monomial operator*(const Monomial &first, const LinearTerm &second)
636 {
637  return second * first;
638 }
639 inline Polynomial operator*(const Polynomial &first, const LinearTerm &second)
640 {
641  return second * first;
642 }
643 inline Monomial operator*(const LinearTerm &first, const Variable &second)
644 {
645  return second * first;
646 }
648  const LinearCombination &first, const Variable &second)
649 {
650  return second * first;
651 }
652 inline Monomial operator*(const Monomial &first, const Variable &second)
653 {
654  return second * first;
655 }
656 inline Polynomial operator*(const Polynomial &first, const Variable &second)
657 {
658  return second * first;
659 }
660 inline LinearTerm operator*(const Variable &first, const FElem &second)
661 {
662  return second * first;
663 }
664 inline LinearTerm operator*(const LinearTerm &first, const FElem &second)
665 {
666  return second * first;
667 }
669  const LinearCombination &first, const FElem &second)
670 {
671  return second * first;
672 }
673 inline Monomial operator*(const Monomial &first, const FElem &second)
674 {
675  return second * first;
676 }
677 inline Polynomial operator*(const Polynomial &first, const FElem &second)
678 {
679  return second * first;
680 }
681 inline FElem operator*(const FElem &first, const int second)
682 {
683  return second * first;
684 }
685 inline LinearTerm operator*(const Variable &first, const int second)
686 {
687  return second * first;
688 }
689 inline LinearTerm operator*(const LinearTerm &first, const int second)
690 {
691  return second * first;
692 }
694  const LinearCombination &first, const int second)
695 {
696  return second * first;
697 }
698 inline Monomial operator*(const Monomial &first, const int second)
699 {
700  return second * first;
701 }
702 inline Polynomial operator*(const Polynomial &first, const int second)
703 {
704  return second * first;
705 }
706 
707 /***********************************/
708 /*** END OF OPERATORS ***/
709 /***********************************/
710 
711 } // namespace gadgetlib2
712 
713 #endif // LIBSNARK_GADGETLIB2_INCLUDE_GADGETLIB2_VARIABLEOPERATORS_HPP_
gadgetlib2::operator+
Polynomial operator+(const Polynomial &first, const Polynomial &second)
Definition: variable_operators.hpp:35
gadgetlib2::LinearTerm
LinearTerm.
Definition: variable.hpp:474
gadgetlib2::Polynomial
Polynomial.
Definition: variable.hpp:574
gadgetlib2::operator-
LinearCombination operator-(const LinearCombination &lc)
Definition: variable.hpp:533
gadgetlib2::FElem
Definition: variable.hpp:101
variable.hpp
gadgetlib2::operator*
Polynomial operator*(const Polynomial &first, const Polynomial &second)
Definition: variable_operators.hpp:482
gadgetlib2::Variable
A formal variable, field agnostic.
Definition: variable.hpp:306
gadgetlib2::Monomial
Monomial.
Definition: variable.hpp:543
gadgetlib2::LinearCombination
LinearCombination.
Definition: variable.hpp:503
gadgetlib2
Definition: adapters.cpp:15