23 #ifndef PLLL_INCLUDE_GUARD__RATIONAL_OPS_HPP
24 #define PLLL_INCLUDE_GUARD__RATIONAL_OPS_HPP
39 template<
class D1,
class D2,
template<
typename,
typename>
class O2,
class E>
41 const AddOp<RationalContext, std::pair<D1, Expression<RationalContext, Expression<IntegerContext, D2, O2>, ConvertOp_Context> > > &,
42 const std::pair<D1, Expression<RationalContext, Expression<IntegerContext, D2, O2>, ConvertOp_Context> > & data)
44 add_z(x, data.first.evaluate(), data.second.data().evaluate());
47 template<
class D1,
class D2,
template<
typename,
typename>
class O2,
class E>
49 const AddOp<RationalContext, std::pair<Expression<RationalContext, Expression<IntegerContext, D2, O2>, ConvertOp_Context>, D1> > &,
50 const std::pair<Expression<RationalContext, Expression<IntegerContext, D2, O2>, ConvertOp_Context>, D1> & data)
52 add_z(x, data.second.evaluate(), data.first.data().evaluate());
56 template<
class D1,
class D2,
template<
typename,
typename>
class O2,
class E>
58 const SubOp<RationalContext, std::pair<D1, Expression<RationalContext, Expression<IntegerContext, D2, O2>, ConvertOp_Context> > > &,
59 const std::pair<D1, Expression<RationalContext, Expression<IntegerContext, D2, O2>, ConvertOp_Context> > & data)
61 sub_z(x, data.first.evaluate(), data.second.data().evaluate());
64 template<
class D1,
class D2,
template<
typename,
typename>
class O2,
class E>
66 const SubOp<RationalContext, std::pair<Expression<RationalContext, Expression<IntegerContext, D2, O2>, ConvertOp_Context>, D1> > &,
67 const std::pair<Expression<RationalContext, Expression<IntegerContext, D2, O2>, ConvertOp_Context>, D1> & data)
69 z_sub(x, data.first.data().evaluate(), data.second.evaluate());
73 template<
class D1,
class D2,
template<
typename,
typename>
class O2,
class E>
75 const MulOp<RationalContext, std::pair<D1, Expression<RationalContext, Expression<IntegerContext, D2, O2>, ConvertOp_Context> > > &,
76 const std::pair<D1, Expression<RationalContext, Expression<IntegerContext, D2, O2>, ConvertOp_Context> > & data)
78 mul_z(x, data.first.evaluate(), data.second.data().evaluate());
81 template<
class D1,
class D2,
template<
typename,
typename>
class O2,
class E>
83 const MulOp<RationalContext, std::pair<Expression<RationalContext, Expression<IntegerContext, D2, O2>, ConvertOp_Context>, D1> > &,
84 const std::pair<Expression<RationalContext, Expression<IntegerContext, D2, O2>, ConvertOp_Context>, D1> & data)
86 mul_z(x, data.second.evaluate(), data.first.data().evaluate());
90 template<
class D1,
class D2,
template<
typename,
typename>
class O2,
class E>
92 const DivOp<RationalContext, std::pair<D1, Expression<RationalContext, Expression<IntegerContext, D2, O2>, ConvertOp_Context> > > &,
93 const std::pair<D1, Expression<RationalContext, Expression<IntegerContext, D2, O2>, ConvertOp_Context> > & data)
95 div_z(x, data.first.evaluate(), data.second.data().evaluate());
98 template<
class D1,
class D2,
template<
typename,
typename>
class O2,
class E>
100 const DivOp<RationalContext, std::pair<Expression<RationalContext, Expression<IntegerContext, D2, O2>, ConvertOp_Context>, D1> > &,
101 const std::pair<Expression<RationalContext, Expression<IntegerContext, D2, O2>, ConvertOp_Context>, D1> & data)
103 z_div(x, data.first.data().evaluate(), data.second.evaluate());
107 template<
class D1,
class D2,
template<
typename,
typename>
class O2,
class E>
109 const ModOp<RationalContext, std::pair<D1, Expression<RationalContext, Expression<IntegerContext, D2, O2>, ConvertOp_Context> > > &,
110 const std::pair<D1, Expression<RationalContext, Expression<IntegerContext, D2, O2>, ConvertOp_Context> > & data)
112 mod_z(x, data.first.evaluate(), data.second.data().evaluate());
115 template<
class D1,
class D2,
template<
typename,
typename>
class O2,
class E>
117 const ModOp<RationalContext, std::pair<Expression<RationalContext, Expression<IntegerContext, D2, O2>, ConvertOp_Context>, D1> > &,
118 const std::pair<Expression<RationalContext, Expression<IntegerContext, D2, O2>, ConvertOp_Context>, D1> & data)
120 z_mod(x, data.first.data().evaluate(), data.second.evaluate());
124 template<
class D,
template<
typename,
typename>
class O,
class E>
126 const ShiftCOp<RationalContext, Expression<RationalContext, Expression<IntegerContext, D, O>, ConvertOp_Context> > & op,
127 Expression<RationalContext, Expression<IntegerContext, D, O>, ConvertOp_Context> & data)
129 shl_z(x, data.data().evaluate(), op.shift());
133 template<
class D,
template<
typename,
typename>
class O>
135 const NegOp<RationalContext, Expression<RationalContext, Expression<IntegerContext, D, O>, ConvertOp_Context> > & op,
136 Expression<RationalContext, Expression<IntegerContext, D, O>, ConvertOp_Context> & data)
138 neg_z(x, data.op().value());
141 template<
class D,
template<
typename,
typename>
class O>
143 const AbsOp<RationalContext, Expression<RationalContext, Expression<IntegerContext, D, O>, ConvertOp_Context> > & op,
144 Expression<RationalContext, Expression<IntegerContext, D, O>, ConvertOp_Context> & data)
146 abs_z(x, data.op().value());
149 template<
class D,
template<
typename,
typename>
class O>
151 const AbsOp_Context<RationalContext, Expression<RationalContext, Expression<IntegerContext, D, O>, ConvertOp_Context> > & op,
152 Expression<RationalContext, Expression<IntegerContext, D, O>, ConvertOp_Context> & data)
154 abs_z(x, data.op().value());
157 template<
class D,
template<
typename,
typename>
class O>
159 const SquareOp<RationalContext, Expression<RationalContext, Expression<IntegerContext, D, O>, ConvertOp_Context> > & op,
160 Expression<RationalContext, Expression<IntegerContext, D, O>, ConvertOp_Context> & data)
162 square_z(x, data.op().value());
165 template<
class D,
template<
typename,
typename>
class O>
167 const SquareOp_Context<RationalContext, Expression<RationalContext, Expression<IntegerContext, D, O>, ConvertOp_Context> > & op,
168 Expression<RationalContext, Expression<IntegerContext, D, O>, ConvertOp_Context> & data)
170 square_z(x, data.op().value());
174 template<
class D,
template<
typename,
typename>
class O>
176 const PowerCOp<signed long>::impl<RationalContext, Expression<RationalContext, Expression<IntegerContext, D, O>, ConvertOp_Context> > & op,
177 Expression<RationalContext, Expression<IntegerContext, D, O>, ConvertOp_Context> & data)
179 power_z(x, data.op().value(), op.value());
182 template<
class D,
template<
typename,
typename>
class O>
184 const PowerCOp<unsigned long>::impl<RationalContext, Expression<RationalContext, Expression<IntegerContext, D, O>, ConvertOp_Context> > & op,
185 Expression<RationalContext, Expression<IntegerContext, D, O>, ConvertOp_Context> & data)
187 power_z(x, data.op().value(), op.value());
190 template<
class D,
template<
typename,
typename>
class O,
template<
typename,
typename>
class IO,
typename ID>
192 const PowerOp<RationalContext, std::pair<Expression<RationalContext, Expression<IntegerContext, D, O>, ConvertOp_Context>, Expression<IntegerContext, ID, IO> > > & op,
193 std::pair<Expression<RationalContext, Expression<IntegerContext, D, O>, ConvertOp_Context>, Expression<IntegerContext, ID, IO> > & data)
195 power_z(x, data.first.op().value(), data.second.evaluate());
229 submul(cur, E.
data().first.evaluate(), E.
data().second.evaluate());
259 addmul(cur, E.
data().first.evaluate(), E.
data().second.evaluate());
330 template<
class D,
typename D2,
template<
typename,
typename>
class O2>
332 const expressions::Expression<RationalContext,
333 std::pair<D, expressions::Expression<RationalContext,
334 expressions::Expression<IntegerContext, D2, O2>,
335 expressions::ConvertOp_Context> >,
336 expressions::MulOp> & E)
338 submul_z(cur, E.data().first.evaluate(), E.data().second.data().evaluate());
342 template<
class D,
typename D2,
template<
typename,
typename>
class O2>
344 const expressions::Expression<RationalContext,
345 std::pair<expressions::Expression<RationalContext,
346 expressions::Expression<IntegerContext, D2, O2>,
347 expressions::ConvertOp_Context>, D>,
348 expressions::MulOp> & E)
350 submul_z(cur, E.data().second.evaluate(), E.data().first.data().evaluate());
354 template<
class D,
typename D2,
template<
typename,
typename>
class O2>
356 const expressions::Expression<RationalContext,
357 std::pair<D, expressions::Expression<RationalContext,
358 expressions::Expression<IntegerContext, D2, O2>,
359 expressions::ConvertOp_Context> >,
360 expressions::MulOp> & E)
362 addmul_z(cur, E.data().first.evaluate(), E.data().second.data().evaluate());
366 template<
class D,
typename D2,
template<
typename,
typename>
class O2>
368 const expressions::Expression<RationalContext,
369 std::pair<expressions::Expression<RationalContext,
370 expressions::Expression<IntegerContext, D2, O2>,
371 expressions::ConvertOp_Context>, D>,
372 expressions::MulOp> & E)
374 addmul_z(cur, E.data().second.evaluate(), E.data().first.data().evaluate());
513 template<
class A2,
template<
typename,
typename>
class O2>
514 inline bool operator == (
const Rational & a,
const expressions::Expression<RationalContext, A2, O2> & b)
516 return expressions::make_expression<RationalContext>(a) == b;
519 template<
class A2,
template<
typename,
typename>
class O2>
520 inline bool operator != (
const Rational & a,
const expressions::Expression<RationalContext, A2, O2> & b)
522 return expressions::make_expression<RationalContext>(a) != b;
525 template<
class A2,
template<
typename,
typename>
class O2>
526 inline bool operator <= (const Rational & a, const expressions::Expression<RationalContext, A2, O2> & b)
528 return expressions::make_expression<RationalContext>(a) <= b;
531 template<
class A2,
template<
typename,
typename>
class O2>
532 inline bool operator >= (
const Rational & a,
const expressions::Expression<RationalContext, A2, O2> & b)
534 return expressions::make_expression<RationalContext>(a) >= b;
537 template<
class A2,
template<
typename,
typename>
class O2>
538 inline bool operator < (const Rational & a, const expressions::Expression<RationalContext, A2, O2> & b)
540 return expressions::make_expression<RationalContext>(a) < b;
543 template<
class A2,
template<
typename,
typename>
class O2>
544 inline bool operator > (
const Rational & a,
const expressions::Expression<RationalContext, A2, O2> & b)
546 return expressions::make_expression<RationalContext>(a) > b;
549 namespace expressions
552 template<
class A1,
template<
typename,
typename>
class O1>
553 inline bool operator == (
const expressions::Expression<RationalContext, A1, O1> & a,
const arithmetic::Rational & b)
555 return a == expressions::make_expression<RationalContext>(b);
558 template<
class A1,
template<
typename,
typename>
class O1>
559 inline bool operator != (
const expressions::Expression<RationalContext, A1, O1> & a,
const arithmetic::Rational & b)
561 return a != expressions::make_expression<RationalContext>(b);
564 template<
class A1,
template<
typename,
typename>
class O1>
565 inline bool operator <= (const expressions::Expression<RationalContext, A1, O1> & a,
const arithmetic::Rational & b)
567 return a <= expressions::make_expression<RationalContext>(b);
570 template<
class A1,
template<
typename,
typename>
class O1>
571 inline bool operator >= (
const expressions::Expression<RationalContext, A1, O1> & a,
const arithmetic::Rational & b)
573 return a >= expressions::make_expression<RationalContext>(b);
576 template<
class A1,
template<
typename,
typename>
class O1>
577 inline bool operator < (const expressions::Expression<RationalContext, A1, O1> & a,
const arithmetic::Rational & b)
579 return a < expressions::make_expression<RationalContext>(b);
582 template<
class A1,
template<
typename,
typename>
class O1>
583 inline bool operator > (
const expressions::Expression<RationalContext, A1, O1> & a,
const arithmetic::Rational & b)
585 return a > expressions::make_expression<RationalContext>(b);
589 template<
class A1,
template<
typename,
typename>
class O1,
class A2,
template<
typename,
typename>
class O2>
590 inline bool operator == (
const expressions::Expression<RationalContext, A1, O1> & a,
591 const expressions::Expression<RationalContext, A2, O2> & b)
596 template<
class A1,
template<
typename,
typename>
class O1,
class A2,
template<
typename,
typename>
class O2>
597 inline bool operator != (
const expressions::Expression<RationalContext, A1, O1> & a,
598 const expressions::Expression<RationalContext, A2, O2> & b)
603 template<
class A1,
template<
typename,
typename>
class O1,
class A2,
template<
typename,
typename>
class O2>
604 inline bool operator <= (const expressions::Expression<RationalContext, A1, O1> & a,
605 const expressions::Expression<RationalContext, A2, O2> & b)
610 template<
class A1,
template<
typename,
typename>
class O1,
class A2,
template<
typename,
typename>
class O2>
611 inline bool operator >= (
const expressions::Expression<RationalContext, A1, O1> & a,
612 const expressions::Expression<RationalContext, A2, O2> & b)
617 template<
class A1,
template<
typename,
typename>
class O1,
class A2,
template<
typename,
typename>
class O2>
618 inline bool operator < (const expressions::Expression<RationalContext, A1, O1> & a,
619 const expressions::Expression<RationalContext, A2, O2> & b)
624 template<
class A1,
template<
typename,
typename>
class O1,
class A2,
template<
typename,
typename>
class O2>
625 inline bool operator > (
const expressions::Expression<RationalContext, A1, O1> & a,
626 const expressions::Expression<RationalContext, A2, O2> & b)
633 template<
class A2,
template<
typename,
typename>
class O2,
class A1,
template<
typename,
typename>
class O1>
634 inline bool operator == (
const expressions::Expression<RationalContext, expressions::Expression<IntegerContext, A1, O1>,
635 expressions::ConvertOp_Context> & a,
636 const expressions::Expression<RationalContext, A2, O2> & b)
637 {
return compare_z(b.evaluate(), a.op().value()) == 0; }
638 template<
class A2,
template<
typename,
typename>
class O2,
class A1,
template<
typename,
typename>
class O1>
639 inline bool operator != (
const expressions::Expression<RationalContext, expressions::Expression<IntegerContext, A1, O1>,
640 expressions::ConvertOp_Context> & a,
641 const expressions::Expression<RationalContext, A2, O2> & b)
642 {
return compare_z(b.evaluate(), a.op().value()) != 0; }
643 template<
class A2,
template<
typename,
typename>
class O2,
class A1,
template<
typename,
typename>
class O1>
644 inline bool operator <= (const expressions::Expression<RationalContext, expressions::Expression<IntegerContext, A1, O1>,
645 expressions::ConvertOp_Context> & a,
646 const expressions::Expression<RationalContext, A2, O2> & b)
647 {
return compare_z(b.evaluate(), a.op().value()) >= 0; }
648 template<
class A2,
template<
typename,
typename>
class O2,
class A1,
template<
typename,
typename>
class O1>
649 inline bool operator >= (
const expressions::Expression<RationalContext, expressions::Expression<IntegerContext, A1, O1>,
650 expressions::ConvertOp_Context> & a,
651 const expressions::Expression<RationalContext, A2, O2> & b)
652 {
return compare_z(b.evaluate(), a.op().value()) <= 0; }
653 template<
class A2,
template<
typename,
typename>
class O2,
class A1,
template<
typename,
typename>
class O1>
654 inline bool operator < (const expressions::Expression<RationalContext, expressions::Expression<IntegerContext, A1, O1>,
655 expressions::ConvertOp_Context> & a,
656 const expressions::Expression<RationalContext, A2, O2> & b)
657 {
return compare_z(b.evaluate(), a.op().value()) > 0; }
658 template<
class A2,
template<
typename,
typename>
class O2,
class A1,
template<
typename,
typename>
class O1>
659 inline bool operator > (
const expressions::Expression<RationalContext, expressions::Expression<IntegerContext, A1, O1>,
660 expressions::ConvertOp_Context> & a,
661 const expressions::Expression<RationalContext, A2, O2> & b)
662 {
return compare_z(b.evaluate(), a.op().value()) < 0; }
665 template<
class A1,
template<
typename,
typename>
class O1,
class A2,
template<
typename,
typename>
class O2>
666 inline bool operator == (
const expressions::Expression<RationalContext, A1, O1> & a,
667 const expressions::Expression<RationalContext, expressions::Expression<IntegerContext, A2, O2>,
668 expressions::ConvertOp_Context> & b)
669 {
return compare_z(a.evaluate(), b.op().value()) == 0; }
670 template<
class A1,
template<
typename,
typename>
class O1,
class A2,
template<
typename,
typename>
class O2>
671 inline bool operator != (
const expressions::Expression<RationalContext, A1, O1> & a,
672 const expressions::Expression<RationalContext, expressions::Expression<IntegerContext, A2, O2>,
673 expressions::ConvertOp_Context> & b)
674 {
return compare_z(a.evaluate(), b.op().value()) != 0; }
675 template<
class A1,
template<
typename,
typename>
class O1,
class A2,
template<
typename,
typename>
class O2>
676 inline bool operator <= (const expressions::Expression<RationalContext, A1, O1> & a,
677 const expressions::Expression<RationalContext, expressions::Expression<IntegerContext, A2, O2>,
678 expressions::ConvertOp_Context> & b)
679 {
return compare_z(a.evaluate(), b.op().value()) <= 0; }
680 template<
class A1,
template<
typename,
typename>
class O1,
class A2,
template<
typename,
typename>
class O2>
681 inline bool operator >= (
const expressions::Expression<RationalContext, A1, O1> & a,
682 const expressions::Expression<RationalContext, expressions::Expression<IntegerContext, A2, O2>,
683 expressions::ConvertOp_Context> & b)
684 {
return compare_z(a.evaluate(), b.op().value()) >= 0; }
685 template<
class A1,
template<
typename,
typename>
class O1,
class A2,
template<
typename,
typename>
class O2>
686 inline bool operator < (const expressions::Expression<RationalContext, A1, O1> & a,
687 const expressions::Expression<RationalContext, expressions::Expression<IntegerContext, A2, O2>,
688 expressions::ConvertOp_Context> & b)
689 {
return compare_z(a.evaluate(), b.op().value()) < 0; }
690 template<
class A1,
template<
typename,
typename>
class O1,
class A2,
template<
typename,
typename>
class O2>
691 inline bool operator > (
const expressions::Expression<RationalContext, A1, O1> & a,
692 const expressions::Expression<RationalContext, expressions::Expression<IntegerContext, A2, O2>,
693 expressions::ConvertOp_Context> & b)
694 {
return compare_z(a.evaluate(), b.op().value()) > 0; }
697 template<
class A,
template<
typename,
typename>
class O>
698 inline bool isZero(
const expressions::Expression<RationalContext, A, O> & r)
700 return isZero(Rational(r));
703 template<
class A,
template<
typename,
typename>
class O>
704 inline bool isOne(
const expressions::Expression<RationalContext, A, O> & r)
706 return isOne(Rational(r));
709 template<
class A,
template<
typename,
typename>
class O>
710 inline bool isPositive(
const expressions::Expression<RationalContext, A, O> & r)
712 return isPositive(Rational(r));
715 template<
class A,
template<
typename,
typename>
class O>
716 inline bool isNonNegative(
const expressions::Expression<RationalContext, A, O> & r)
718 return isNonNegative(Rational(r));
721 template<
class A,
template<
typename,
typename>
class O>
722 inline bool isNegative(
const expressions::Expression<RationalContext, A, O> & r)
724 return isNegative(Rational(r));
727 template<
class A,
template<
typename,
typename>
class O>
728 inline bool isNonPositive(
const expressions::Expression<RationalContext, A, O> & r)
730 return isZero(Rational(r));
744 inline expressions::Expression<RationalContext, expressions::Wrapper<RationalContext>,
755 inline expressions::Expression<RationalContext, std::pair<expressions::Wrapper<RationalContext>,
756 expressions::Wrapper<RationalContext> >,
760 expressions::Wrapper<RationalContext>(b))); }
768 inline expressions::Expression<RationalContext, std::pair<expressions::Wrapper<RationalContext>,
769 expressions::Wrapper<RationalContext> >,
774 expressions::Wrapper<RationalContext>(b))); }
782 inline expressions::Expression<RationalContext, std::pair<expressions::Wrapper<RationalContext>,
783 expressions::Wrapper<RationalContext> >,
788 expressions::Wrapper<RationalContext>(b))); }
796 inline expressions::Expression<RationalContext, std::pair<expressions::Wrapper<RationalContext>,
797 expressions::Wrapper<RationalContext> >,
802 expressions::Wrapper<RationalContext>(b))); }
810 inline expressions::Expression<RationalContext, std::pair<expressions::Wrapper<RationalContext>,
811 expressions::Wrapper<RationalContext> >,
816 expressions::Wrapper<RationalContext>(b))); }
825 inline expressions::Expression<RationalContext, expressions::Wrapper<RationalContext>,
837 inline expressions::Expression<RationalContext, expressions::Wrapper<RationalContext>,
845 template<
class A,
template<
typename,
typename>
class O>
846 inline expressions::Expression<RationalContext, std::pair<expressions::Wrapper<RationalContext>,
847 expressions::Expression<RationalContext, A, O> >,
848 expressions::AddOp>
operator + (
const Rational & a,
const expressions::Expression<RationalContext, A, O> & b)
849 {
return expressions::Expression<RationalContext, std::pair<expressions::Wrapper<RationalContext>,
850 expressions::Expression<RationalContext, A, O> >,
851 expressions::AddOp>(std::make_pair(expressions::Wrapper<RationalContext>(a), b)); }
852 template<
class A,
template<
typename,
typename>
class O>
853 inline expressions::Expression<RationalContext, std::pair<expressions::Wrapper<RationalContext>,
854 expressions::Expression<RationalContext, A, O> >,
855 expressions::SubOp>
operator - (
const Rational & a,
const expressions::Expression<RationalContext, A, O> & b)
856 {
return expressions::Expression<RationalContext, std::pair<expressions::Wrapper<RationalContext>,
857 expressions::Expression<RationalContext, A, O> >,
858 expressions::SubOp>(std::make_pair(expressions::Wrapper<RationalContext>(a), b)); }
859 template<
class A,
template<
typename,
typename>
class O>
860 inline expressions::Expression<RationalContext, std::pair<expressions::Wrapper<RationalContext>,
861 expressions::Expression<RationalContext, A, O> >,
862 expressions::MulOp>
operator * (
const Rational & a,
const expressions::Expression<RationalContext, A, O> & b)
863 {
return expressions::Expression<RationalContext, std::pair<expressions::Wrapper<RationalContext>,
864 expressions::Expression<RationalContext, A, O> >,
865 expressions::MulOp>(std::make_pair(expressions::Wrapper<RationalContext>(a), b)); }
866 template<
class A,
template<
typename,
typename>
class O>
867 inline expressions::Expression<RationalContext, std::pair<expressions::Wrapper<RationalContext>,
868 expressions::Expression<RationalContext, A, O> >,
869 expressions::DivOp>
operator / (
const Rational & a,
const expressions::Expression<RationalContext, A, O> & b)
870 {
return expressions::Expression<RationalContext, std::pair<expressions::Wrapper<RationalContext>,
871 expressions::Expression<RationalContext, A, O> >,
872 expressions::DivOp>(std::make_pair(expressions::Wrapper<RationalContext>(a), b)); }
873 template<
class A,
template<
typename,
typename>
class O>
874 inline expressions::Expression<RationalContext, std::pair<expressions::Wrapper<RationalContext>,
875 expressions::Expression<RationalContext, A, O> >,
876 expressions::ModOp>
operator % (
const Rational & a,
const expressions::Expression<RationalContext, A, O> & b)
877 {
return expressions::Expression<RationalContext, std::pair<expressions::Wrapper<RationalContext>,
878 expressions::Expression<RationalContext, A, O> >,
879 expressions::ModOp>(std::make_pair(expressions::Wrapper<RationalContext>(a), b)); }
881 namespace expressions
884 template<
class A,
template<
typename,
typename>
class O>
885 inline expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
886 expressions::NegOp> operator - (
const expressions::Expression<RationalContext, A, O> & a)
887 {
return expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
888 expressions::NegOp>(a); }
889 template<
class A,
template<
typename,
typename>
class O>
890 inline expressions::Expression<RationalContext, std::pair<expressions::Expression<RationalContext, A, O>,
891 expressions::Wrapper<RationalContext> >,
892 expressions::AddOp> operator + (
const expressions::Expression<RationalContext, A, O> & a,
893 const arithmetic::Rational & b)
894 {
return expressions::Expression<RationalContext, std::pair<expressions::Expression<RationalContext, A, O>, expressions::Wrapper<RationalContext> >,
895 expressions::AddOp>(std::make_pair(a, expressions::Wrapper<RationalContext>(b))); }
896 template<
class A,
template<
typename,
typename>
class O>
897 inline expressions::Expression<RationalContext, std::pair<expressions::Expression<RationalContext, A, O>,
898 expressions::Wrapper<RationalContext> >,
899 expressions::SubOp> operator - (
const expressions::Expression<RationalContext, A, O> & a,
900 const arithmetic::Rational & b)
901 {
return expressions::Expression<RationalContext, std::pair<expressions::Expression<RationalContext, A, O>,
902 expressions::Wrapper<RationalContext> >,
903 expressions::SubOp>(std::make_pair(a, expressions::Wrapper<RationalContext>(b))); }
904 template<
class A,
template<
typename,
typename>
class O>
905 inline expressions::Expression<RationalContext, std::pair<expressions::Expression<RationalContext, A, O>,
906 expressions::Wrapper<RationalContext> >,
907 expressions::MulOp> operator * (
const expressions::Expression<RationalContext, A, O> & a,
908 const arithmetic::Rational & b)
909 {
return expressions::Expression<RationalContext, std::pair<expressions::Expression<RationalContext, A, O>,
910 expressions::Wrapper<RationalContext> >,
911 expressions::MulOp>(std::make_pair(a, expressions::Wrapper<RationalContext>(b))); }
912 template<
class A,
template<
typename,
typename>
class O>
913 inline expressions::Expression<RationalContext, std::pair<expressions::Expression<RationalContext, A, O>,
914 expressions::Wrapper<RationalContext> >,
915 expressions::DivOp> operator / (
const expressions::Expression<RationalContext, A, O> & a,
916 const arithmetic::Rational & b)
917 {
return expressions::Expression<RationalContext, std::pair<expressions::Expression<RationalContext, A, O>,
918 expressions::Wrapper<RationalContext> >,
919 expressions::DivOp>(std::make_pair(a, expressions::Wrapper<RationalContext>(b))); }
920 template<
class A,
template<
typename,
typename>
class O>
921 inline expressions::Expression<RationalContext, std::pair<expressions::Expression<RationalContext, A, O>,
922 expressions::Wrapper<RationalContext> >,
923 expressions::ModOp> operator % (
const expressions::Expression<RationalContext, A, O> & a,
924 const arithmetic::Rational & b)
925 {
return expressions::Expression<RationalContext, std::pair<expressions::Expression<RationalContext, A, O>,
926 expressions::Wrapper<RationalContext> >,
927 expressions::ModOp>(std::make_pair(a, expressions::Wrapper<RationalContext>(b))); }
928 template<
class A,
template<
typename,
typename>
class O>
929 inline expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
930 expressions::ShiftCOp> operator << (const expressions::Expression<RationalContext, A, O> & a,
932 {
return expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
933 expressions::ShiftCOp>(a, b); }
935 template<
class A,
template<
typename,
typename>
class O>
936 inline expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
937 expressions::ShiftCOp> operator >> (
const expressions::Expression<RationalContext, A, O> & a,
939 {
return expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
940 expressions::ShiftCOp>(a, -b); }
943 template<
class A1,
template<
typename,
typename>
class O1,
class A,
template<
typename,
typename>
class O>
944 inline expressions::Expression<RationalContext, std::pair<expressions::Expression<RationalContext, A1, O1>,
945 expressions::Expression<RationalContext, A, O> >,
946 expressions::AddOp> operator + (
const expressions::Expression<RationalContext, A1, O1> & a,
947 const expressions::Expression<RationalContext, A, O> & b)
948 {
return expressions::Expression<RationalContext, std::pair<expressions::Expression<RationalContext, A1, O1>,
949 expressions::Expression<RationalContext, A, O> >,
950 expressions::AddOp>(std::make_pair(a, b)); }
951 template<
class A1,
template<
typename,
typename>
class O1,
class A,
template<
typename,
typename>
class O>
952 inline expressions::Expression<RationalContext, std::pair<expressions::Expression<RationalContext, A1, O1>,
953 expressions::Expression<RationalContext, A, O> >,
954 expressions::SubOp> operator - (
const expressions::Expression<RationalContext, A1, O1> & a,
955 const expressions::Expression<RationalContext, A, O> & b)
956 {
return expressions::Expression<RationalContext, std::pair<expressions::Expression<RationalContext, A1, O1>,
957 expressions::Expression<RationalContext, A, O> >,
958 expressions::SubOp>(std::make_pair(a, b)); }
959 template<
class A1,
template<
typename,
typename>
class O1,
class A,
template<
typename,
typename>
class O>
960 inline expressions::Expression<RationalContext, std::pair<expressions::Expression<RationalContext, A1, O1>,
961 expressions::Expression<RationalContext, A, O> >,
962 expressions::MulOp> operator * (
const expressions::Expression<RationalContext, A1, O1> & a,
963 const expressions::Expression<RationalContext, A, O> & b)
964 {
return expressions::Expression<RationalContext, std::pair<expressions::Expression<RationalContext, A1, O1>,
965 expressions::Expression<RationalContext, A, O> >,
966 expressions::MulOp>(std::make_pair(a, b)); }
967 template<
class A1,
template<
typename,
typename>
class O1,
class A,
template<
typename,
typename>
class O>
968 inline expressions::Expression<RationalContext, std::pair<expressions::Expression<RationalContext, A1, O1>,
969 expressions::Expression<RationalContext, A, O> >,
970 expressions::DivOp> operator / (
const expressions::Expression<RationalContext, A1, O1> & a,
971 const expressions::Expression<RationalContext, A, O> & b)
972 {
return expressions::Expression<RationalContext, std::pair<expressions::Expression<RationalContext, A1, O1>,
973 expressions::Expression<RationalContext, A, O> >,
974 expressions::DivOp>(std::make_pair(a, b)); }
975 template<
class A1,
template<
typename,
typename>
class O1,
class A,
template<
typename,
typename>
class O>
976 inline expressions::Expression<RationalContext, std::pair<expressions::Expression<RationalContext, A1, O1>,
977 expressions::Expression<RationalContext, A, O> >,
978 expressions::ModOp> operator % (
const expressions::Expression<RationalContext, A1, O1> & a,
979 const expressions::Expression<RationalContext, A, O> & b)
980 {
return expressions::Expression<RationalContext, std::pair<expressions::Expression<RationalContext, A1, O1>,
981 expressions::Expression<RationalContext, A, O> >,
982 expressions::ModOp>(std::make_pair(a, b)); }
994 inline expressions::Expression<RationalContext, expressions::Wrapper<RationalContext>,
1004 inline expressions::Expression<RationalContext, expressions::Wrapper<RationalContext>,
1019 inline expressions::Expression<RationalContext, expressions::Wrapper<RationalContext>,
1030 inline expressions::Expression<RationalContext, expressions::Wrapper<RationalContext>,
1041 inline expressions::Expression<RationalContext, std::pair<expressions::Wrapper<RationalContext>,
1042 expressions::Wrapper<IntegerContext> >,
1047 expressions::Wrapper<IntegerContext>(b))); }
1059 inline expressions::Expression<RationalContext, expressions::Wrapper<RationalContext>,
1070 inline expressions::Expression<RationalContext, expressions::Wrapper<RationalContext>,
1086 inline expressions::Expression<RationalContext, expressions::Wrapper<RationalContext>,
1098 inline expressions::Expression<RationalContext, expressions::Wrapper<RationalContext>,
1110 inline expressions::Expression<RationalContext, std::pair<expressions::Wrapper<RationalContext>,
1111 expressions::Wrapper<IntegerContext> >,
1116 expressions::Wrapper<IntegerContext>(b))); }
1120 template<
class A,
template<
typename,
typename>
class O>
1121 inline expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
1122 expressions::AbsOp>
abs(
const expressions::Expression<RationalContext, A, O> & b)
1123 {
return expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
1124 expressions::AbsOp>(b); }
1125 template<
class A,
template<
typename,
typename>
class O>
1126 inline expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
1127 expressions::SquareOp>
square(
const expressions::Expression<RationalContext, A, O> & b)
1128 {
return expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
1129 expressions::SquareOp>(b); }
1130 template<
class A,
template<
typename,
typename>
class O>
1131 inline expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
1132 expressions::PowerCOp<signed long>::impl>
power(
const expressions::Expression<RationalContext, A, O> & a,
1134 {
return expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
1135 expressions::PowerCOp<signed long>::impl>(a, b); }
1136 template<
class A,
template<
typename,
typename>
class O>
1137 inline expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
1138 expressions::PowerCOp<unsigned long>::impl>
power(
const expressions::Expression<RationalContext, A, O> & a,
1140 {
return expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
1141 expressions::PowerCOp<unsigned long>::impl>(a, b); }
1142 template<
class A,
template<
typename,
typename>
class O>
1143 inline expressions::Expression<RationalContext, std::pair<expressions::Expression<RationalContext, A, O>,
1144 expressions::Wrapper<IntegerContext> >,
1145 expressions::PowerOp>
power(
const expressions::Expression<RationalContext, A, O> & a,
1147 {
return expressions::Expression<RationalContext, std::pair<expressions::Expression<RationalContext, A, O>,
1148 expressions::Wrapper<IntegerContext> >,
1149 expressions::PowerOp>(std::make_pair(a, expressions::Wrapper<IntegerContext>(b))); }
1150 template<
class A,
template<
typename,
typename>
class O>
1151 inline expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
1152 expressions::AbsOp>
abs(
const expressions::Expression<RationalContext, A, O> & b,
1153 const RationalContext &)
1154 {
return expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
1155 expressions::AbsOp>(b); }
1156 template<
class A,
template<
typename,
typename>
class O>
1157 inline expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
1158 expressions::SquareOp>
square(
const expressions::Expression<RationalContext, A, O> & b,
1159 const RationalContext &)
1160 {
return expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
1161 expressions::SquareOp>(b); }
1162 template<
class A,
template<
typename,
typename>
class O>
1163 inline expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
1164 expressions::PowerCOp<signed long>::impl>
power(
const expressions::Expression<RationalContext, A, O> & a,
1165 signed long b,
const RationalContext &)
1166 {
return expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
1167 expressions::PowerCOp<signed long>::impl>(a, b); }
1168 template<
class A,
template<
typename,
typename>
class O>
1169 inline expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
1170 expressions::PowerCOp<unsigned long>::impl>
power(
const expressions::Expression<RationalContext, A, O> & a,
1171 unsigned long b,
const RationalContext &)
1172 {
return expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
1173 expressions::PowerCOp<unsigned long>::impl>(a, b); }
1174 template<
class A,
template<
typename,
typename>
class O>
1175 inline expressions::Expression<RationalContext, std::pair<expressions::Expression<RationalContext, A, O>,
1176 expressions::Wrapper<IntegerContext> >,
1177 expressions::PowerOp>
power(
const expressions::Expression<RationalContext, A, O> & a,
1178 const Integer & b,
const RationalContext &)
1179 {
return expressions::Expression<RationalContext, std::pair<expressions::Expression<RationalContext, A, O>,
1180 expressions::Wrapper<IntegerContext> >,
1181 expressions::PowerOp>(std::make_pair(a, expressions::Wrapper<IntegerContext>(b))); }
1183 namespace expressions
1186 template<
class A,
template<
typename,
typename>
class O>
1187 inline expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
1188 expressions::AbsOp>
abs(
const expressions::Expression<RationalContext, A, O> & b)
1189 {
return expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
1190 expressions::AbsOp>(b); }
1191 template<
class A,
template<
typename,
typename>
class O>
1192 inline expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
1193 expressions::SquareOp>
square(
const expressions::Expression<RationalContext, A, O> & b)
1194 {
return expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
1195 expressions::SquareOp>(b); }
1196 template<
class A,
template<
typename,
typename>
class O>
1197 inline expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
1198 expressions::PowerCOp<signed long>::impl>
power(
const expressions::Expression<RationalContext, A, O> & a,
1200 {
return expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
1201 expressions::PowerCOp<signed long>::impl>(a, b); }
1202 template<
class A,
template<
typename,
typename>
class O>
1203 inline expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
1204 expressions::PowerCOp<unsigned long>::impl>
power(
const expressions::Expression<RationalContext, A, O> & a,
1206 {
return expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
1207 expressions::PowerCOp<unsigned long>::impl>(a, b); }
1208 template<
class A,
template<
typename,
typename>
class O>
1209 inline expressions::Expression<RationalContext, std::pair<expressions::Expression<RationalContext, A, O>,
1210 expressions::Wrapper<IntegerContext> >,
1211 expressions::PowerOp>
power(
const expressions::Expression<RationalContext, A, O> & a,
1213 {
return expressions::Expression<RationalContext, std::pair<expressions::Expression<RationalContext, A, O>,
1214 expressions::Wrapper<IntegerContext> >,
1215 expressions::PowerOp>(std::make_pair(a, expressions::Wrapper<IntegerContext>(b))); }
1216 template<
class A,
template<
typename,
typename>
class O>
1217 inline expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
1218 expressions::AbsOp>
abs(
const expressions::Expression<RationalContext, A, O> & b,
1219 const RationalContext &)
1220 {
return expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
1221 expressions::AbsOp>(b); }
1222 template<
class A,
template<
typename,
typename>
class O>
1223 inline expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
1224 expressions::SquareOp>
square(
const expressions::Expression<RationalContext, A, O> & b,
1225 const RationalContext &)
1226 {
return expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
1227 expressions::SquareOp>(b); }
1228 template<
class A,
template<
typename,
typename>
class O>
1229 inline expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
1230 expressions::PowerCOp<signed long>::impl>
power(
const expressions::Expression<RationalContext, A, O> & a,
1231 signed long b,
const RationalContext &)
1232 {
return expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
1233 expressions::PowerCOp<signed long>::impl>(a, b); }
1234 template<
class A,
template<
typename,
typename>
class O>
1235 inline expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
1236 expressions::PowerCOp<unsigned long>::impl>
power(
const expressions::Expression<RationalContext, A, O> & a,
1237 unsigned long b,
const RationalContext &)
1238 {
return expressions::Expression<RationalContext, expressions::Expression<RationalContext, A, O>,
1239 expressions::PowerCOp<unsigned long>::impl>(a, b); }
1240 template<
class A,
template<
typename,
typename>
class O>
1241 inline expressions::Expression<RationalContext, std::pair<expressions::Expression<RationalContext, A, O>,
1242 expressions::Wrapper<IntegerContext> >,
1243 expressions::PowerOp>
power(
const expressions::Expression<RationalContext, A, O> & a,
1244 const Integer & b,
const RationalContext &)
1245 {
return expressions::Expression<RationalContext, std::pair<expressions::Expression<RationalContext, A, O>,
1246 expressions::Wrapper<IntegerContext> >,
1247 expressions::PowerOp>(std::make_pair(a, expressions::Wrapper<IntegerContext>(b))); }
1249 template<
class A,
template<
typename,
typename>
class O>
1250 inline std::ostream & operator << (std::ostream & s, const expressions::Expression<RationalContext, A, O> & E)
1252 return s << Rational(E);
1259 r.add_r_neq_1st(p, r);
1265 r.sub_r_neq_1st(p, r,
true);
Returns the sum of the operands.
void submul(Integer &r, const Integer &a, const Integer &b)
Multiplies a and b and subtracts the result from r.
Integer & operator<<=(Integer &cur, const Integer &i)
Computes the bitwise left shift of cur by i bits, and stores the result in cur.
Integer & operator+=(Integer &cur, const expressions::Expression< IntegerContext, D, expressions::MulOp > &E)
Adds the given multiplication expression to cur.
bool operator<(const Integer &a, const Integer &b)
Compares the current integer with the given one.
Integer & operator%=(Integer &cur, const Integer &i)
Divides cur by the given integer i and stores the remainder in cur.
int compare(const Integer &a, const Integer &b)
Compares the two integers.
expressions::Expression< IntegerContext, expressions::Wrapper< IntegerContext >, expressions::NegOp > operator-(const Integer &a)
Negates the integer.
void shr(Integer &r, const Integer &a, long b)
Shifts a by b bits to the left and stores the result in r.
void do_assign(typename Context::Type &x, const Op &op, const Data &data)
Performs the assignment of the expression to x.
Returns the negative of the operand.
Integer & operator*=(Integer &cur, const Integer &i)
Multiplies the given integer i with cur.
Integer operator--(Integer &cur, int)
Decrements the integer by one and returns the previous value.
expressions::Expression< IntegerContext, expressions::Wrapper< IntegerContext >, expressions::AbsOp > abs(const Integer &i)
Computes and returns the absolute value of i.
expressions::Expression< IntegerContext, std::pair< expressions::Wrapper< IntegerContext >, expressions::Wrapper< IntegerContext > >, expressions::ShLOp > operator<<(const Integer &a, const Integer &b)
Computes the bitwise left shift of the first integer by the number of bits given by the second intege...
bool operator<=(const Integer &a, const Integer &b)
Compares the current integer with the given one.
Integer & operator-=(Integer &cur, const expressions::Expression< IntegerContext, D, expressions::MulOp > &E)
Subtracts the multiplication expression E from cur.
Returns the operand multiplied by 2 to the power of a constant.
void mul(Integer &r, const Integer &a, const Integer &b)
Multiplies a with b and stores the result in r.
void div(Integer &r, const Integer &a, const Integer &b)
Divides a by b and stores the result in r.
Returns the quotient of the operands.
const Data & data() const
Allows to access the expression's data.
void mod(Integer &r, const Integer &a, const Integer &b)
Takes the remainder of the division of a by b and stores it in r.
void increment(Integer &r, const Integer &a)
Increments a by one and stores the result in r.
bool operator==(const Integer &a, const Integer &b)
Compares the current integer with the given one for equality.
Integer & operator/=(Integer &cur, const Integer &i)
Divides cur by the given integer i.
expressions::Expression< IntegerContext, std::pair< expressions::Wrapper< IntegerContext >, expressions::Wrapper< IntegerContext > >, expressions::MulOp > operator*(const Integer &a, const Integer &b)
Multiplies the two integers and returns the result.
Represents a rational number as a quotient of two arbitrary precision integers.
expressions::Expression< IntegerContext, std::pair< expressions::Wrapper< IntegerContext >, expressions::Wrapper< IntegerContext > >, expressions::PowerOp > power(const Integer &a, const Integer &b)
Computes and returns a raised to the power of b.
Represents an expression.
Returns the product of the operands.
Integer operator++(Integer &cur, int)
Increments the integer by one and returns the previous value.
bool operator>(const Integer &a, const Integer &b)
Compares the current integer with the given one.
void shl(Integer &r, const Integer &a, long b)
Shifts a by b bits to the left and stores the result in r.
Returns the remainder of the operands.
expressions::Expression< IntegerContext, std::pair< expressions::Wrapper< IntegerContext >, expressions::Wrapper< IntegerContext > >, expressions::ShROp > operator>>(const Integer &a, const Integer &b)
Computes the bitwise right shift of the first integer by the number of bits given by the second integ...
Returns the power of the first operand to the second operand.
void addmul(Integer &r, const Integer &a, const Integer &b)
Multiplies a and b and adds the result to r.
expressions::Expression< IntegerContext, std::pair< expressions::Wrapper< IntegerContext >, expressions::Wrapper< IntegerContext > >, expressions::ModOp > operator%(const Integer &a, const Integer &b)
Divides the first by the second integer and returns the remainder.
Integer & operator>>=(Integer &cur, const Integer &i)
Computes the bitwise right shift of cur by i bits, and stores the result in cur.
void add(Integer &r, const Integer &a, const Integer &b)
Adds a and b and stores the result in r.
Implementation of raising to a power by a constant exponent.
expressions::Expression< IntegerContext, expressions::Wrapper< IntegerContext >, expressions::SquareOp > square(const Integer &i)
Computes and returns the square of i.
void decrement(Integer &r, const Integer &a)
Decrements a by one and stores the result in r.
Returns the absolute value of the operand.
Returns the square of the operand.
expressions::Expression< IntegerContext, std::pair< expressions::Wrapper< IntegerContext >, expressions::Wrapper< IntegerContext > >, expressions::AddOp > operator+(const Integer &a, const Integer &b)
Adds the two integers and returns the result.
expressions::Expression< IntegerContext, std::pair< expressions::Wrapper< IntegerContext >, expressions::Wrapper< IntegerContext > >, expressions::DivOp > operator/(const Integer &a, const Integer &b)
Divides the first by the second integer and returns the result.
Represents an arbitrary precision integer.
bool operator!=(const Integer &a, const Integer &b)
Compares the current integer with the given one for inequality.
Wraps a variable to behave similarly to an Expression<> object.
Returns the difference of the operands.
bool operator>=(const Integer &a, const Integer &b)
Compares the current integer with the given one.
Represents an arithmetic context for rational numbers.
void sub(Integer &r, const Integer &a, const Integer &b)
Subtracts b from a and stores the result in r.