Refactored type abbr for rationals

This commit is contained in:
Alex Dyachenko 2014-05-23 16:22:17 -04:00
parent b876961ff7
commit a29eebb9a0
5 changed files with 87 additions and 79 deletions

View File

@ -34,7 +34,8 @@ along with the MPIR Library. If not, see http://www.gnu.org/licenses/.
c = reader->Peek(); \
nread++;
#define TYPE_FOR_ABBR_Int MPTYPE^
#define TYPE_FOR_ABBR_Int HugeInt^
#define TYPE_FOR_ABBR_Rat HugeRational^
#define TYPE_FOR_ABBR_Expr MPEXPR_NAME^
#define TYPE_FOR_ABBR_Si mpir_si
#define TYPE_FOR_ABBR_Ui mpir_ui

View File

@ -131,10 +131,10 @@ private ref class MPEXPR(name) : base
//one-arg functions
#define MAKE_FUNCTION_WITH_ONE(base, action, op, argTypeAbbr) \
MAKE_FUNCTION_WITH_ONE_##action(base, op, Expr, op##Int##argTypeAbbr)
MAKE_FUNCTION_WITH_ONE_##action(base, op, Expr, CONCAT(op, LIT(Mpt))argTypeAbbr)
#define MAKE_FUNCTION_WITH_LIMB(base, action, op, argTypeAbbr) \
MAKE_FUNCTION_WITH_ONE_##action(base, op, argTypeAbbr, op##Int##argTypeAbbr)
MAKE_FUNCTION_WITH_ONE_##action(base, op, argTypeAbbr, CONCAT(op, LIT(Mpt))argTypeAbbr)
#define MAKE_FUNCTION_WITH_ONE_DECLARE(base, op, argTypeAbbr, result) \
base^ op(TYPE_FOR_ABBR_##argTypeAbbr a);
@ -144,10 +144,10 @@ private ref class MPEXPR(name) : base
//two-arg functions
#define MAKE_FUNCTION_WITH_TWO(base, action, op, leftTypeAbbr, rightTypeAbbr) \
MAKE_FUNCTION_WITH_TWO_##action(base, op, Expr, Expr, op##Int##leftTypeAbbr##rightTypeAbbr)
MAKE_FUNCTION_WITH_TWO_##action(base, op, Expr, Expr, CONCAT(op, LIT(Mpt))leftTypeAbbr##rightTypeAbbr)
#define MAKE_FUNCTION_WITH_TWO_LLIMB(base, action, op, leftTypeAbbr, rightTypeAbbr) \
MAKE_FUNCTION_WITH_TWO_##action(base, op, leftTypeAbbr, Expr, op##Int##leftTypeAbbr##rightTypeAbbr)
MAKE_FUNCTION_WITH_TWO_##action(base, op, leftTypeAbbr, Expr, CONCAT(op, LIT(Mpt))leftTypeAbbr##rightTypeAbbr)
#define MAKE_FUNCTION_WITH_TWO_DECLARE(base, op, leftTypeAbbr, rightTypeAbbr, result) \
base^ op(TYPE_FOR_ABBR_##leftTypeAbbr a, TYPE_FOR_ABBR_##rightTypeAbbr b);

View File

@ -34,8 +34,10 @@ using namespace System::Runtime::InteropServices;
#undef MPEXPR
#undef CTXT
#undef ASSIGN_TO
#undef Mpt
#endif
#define SPECIALIZE_EXPRESSIONS
#define Mpt Int
#define CUSTOM_MP(x) custom_mpz_##x
#define MPSTRUCT __mpz_struct
#define MP(x) mpz_##x
@ -1347,6 +1349,7 @@ namespace MPIR
DEFINE_BINARY_EXPRESSION_WITH_TWO (MPEXPR_NAME, Invert, Int)
DEFINE_BINARY_EXPRESSION_WITH_BUILT_IN_RIGHT (MPEXPR_NAME, NextPrimeCandidate, Int, Rnd)
DEFINE_BINARY_EXPRESSION_WITH_TWO (MPEXPR(Gcd), Gcd, Int)
DEFINE_BINARY_EXPRESSION_WITH_TWO (MPEXPR(RemoveFactors), RemoveFactors, Int)

View File

@ -260,71 +260,71 @@ namespace MPIR
#pragma region Arithmetic
MAKE_BINARY_OPERATOR_STANDARD (MPEXPR_NAME, DEFINE, +, Add, Int, Int)
MAKE_BINARY_OPERATOR_RLIMB (MPEXPR_NAME, DEFINE, +, Add, Int, Ui)
MAKE_BINARY_OPERATOR_LLIMB_R (MPEXPR_NAME, DEFINE, +, Add, Int, Ui)
MAKE_BINARY_OPERATOR_RLIMB (MPEXPR_NAME, DEFINE, +, Add, Int, Si)
MAKE_BINARY_OPERATOR_LLIMB_R (MPEXPR_NAME, DEFINE, +, Add, Int, Si)
MAKE_BINARY_OPERATOR_RLIMB (MPEXPR_NAME, DEFINE, +, Add, Int, IExpr)
MAKE_BINARY_OPERATOR_LLIMB_R (MPEXPR_NAME, DEFINE, +, Add, Int, IExpr)
MAKE_BINARY_OPERATOR_STANDARD (MPEXPR_NAME, DEFINE, +, Add, Rat, Rat)
MAKE_BINARY_OPERATOR_RLIMB (MPEXPR_NAME, DEFINE, +, Add, Rat, Ui)
MAKE_BINARY_OPERATOR_LLIMB_R (MPEXPR_NAME, DEFINE, +, Add, Rat, Ui)
MAKE_BINARY_OPERATOR_RLIMB (MPEXPR_NAME, DEFINE, +, Add, Rat, Si)
MAKE_BINARY_OPERATOR_LLIMB_R (MPEXPR_NAME, DEFINE, +, Add, Rat, Si)
MAKE_BINARY_OPERATOR_RLIMB (MPEXPR_NAME, DEFINE, +, Add, Rat, IExpr)
MAKE_BINARY_OPERATOR_LLIMB_R (MPEXPR_NAME, DEFINE, +, Add, Rat, IExpr)
MAKE_BINARY_OPERATOR_STANDARD (MPEXPR_NAME, DEFINE, -, Subtract, Int, Int)
MAKE_BINARY_OPERATOR_RLIMB (MPEXPR_NAME, DEFINE, -, Subtract, Int, Ui)
MAKE_BINARY_OPERATOR_LLIMB (MPEXPR_NAME, DEFINE, -, Subtract, Int, Ui)
MAKE_BINARY_OPERATOR_RLIMB (MPEXPR_NAME, DEFINE, -, Subtract, Int, Si)
MAKE_BINARY_OPERATOR_LLIMB (MPEXPR_NAME, DEFINE, -, Subtract, Int, Si)
MAKE_BINARY_OPERATOR_STANDARD (MPEXPR_NAME, DEFINE, -, Subtract, Rat, Rat)
MAKE_BINARY_OPERATOR_RLIMB (MPEXPR_NAME, DEFINE, -, Subtract, Rat, Ui)
MAKE_BINARY_OPERATOR_LLIMB (MPEXPR_NAME, DEFINE, -, Subtract, Rat, Ui)
MAKE_BINARY_OPERATOR_RLIMB (MPEXPR_NAME, DEFINE, -, Subtract, Rat, Si)
MAKE_BINARY_OPERATOR_LLIMB (MPEXPR_NAME, DEFINE, -, Subtract, Rat, Si)
MAKE_BINARY_OPERATOR_STANDARD (MPEXPR_NAME, DEFINE, *, Multiply, Int, Int)
MAKE_BINARY_OPERATOR_RLIMB (MPEXPR_NAME, DEFINE, *, Multiply, Int, Ui)
MAKE_BINARY_OPERATOR_LLIMB_R (MPEXPR_NAME, DEFINE, *, Multiply, Int, Ui)
MAKE_BINARY_OPERATOR_RLIMB (MPEXPR_NAME, DEFINE, *, Multiply, Int, Si)
MAKE_BINARY_OPERATOR_LLIMB_R (MPEXPR_NAME, DEFINE, *, Multiply, Int, Si)
MAKE_BINARY_OPERATOR_STANDARD (MPEXPR_NAME, DEFINE, *, Multiply, Rat, Rat)
MAKE_BINARY_OPERATOR_RLIMB (MPEXPR_NAME, DEFINE, *, Multiply, Rat, Ui)
MAKE_BINARY_OPERATOR_LLIMB_R (MPEXPR_NAME, DEFINE, *, Multiply, Rat, Ui)
MAKE_BINARY_OPERATOR_RLIMB (MPEXPR_NAME, DEFINE, *, Multiply, Rat, Si)
MAKE_BINARY_OPERATOR_LLIMB_R (MPEXPR_NAME, DEFINE, *, Multiply, Rat, Si)
MAKE_BINARY_OPERATOR_RLIMB (MPEXPR_NAME, DEFINE, <<, ShiftLeft, Int, Bits)
MAKE_BINARY_OPERATOR_RLIMB (MPEXPR_NAME, DEFINE, >>, ShiftRight, Int, Bits)
MAKE_BINARY_OPERATOR_RLIMB (MPEXPR_NAME, DEFINE, <<, ShiftLeft, Rat, Bits)
MAKE_BINARY_OPERATOR_RLIMB (MPEXPR_NAME, DEFINE, >>, ShiftRight, Rat, Bits)
MAKE_BINARY_OPERATOR_RLIMB (MPEXPR_NAME, DEFINE, ^, Power, Int, Ui)
MAKE_BINARY_OPERATOR_RLIMB (MPEXPR_NAME, DEFINE, ^, Power, Rat, Ui)
MAKE_UNARY_OPERATOR (MPEXPR_NAME, DEFINE, -, Negate, Int)
MAKE_VOID_FUNCTION (MPEXPR_NAME, DEFINE, Abs, Int)
MAKE_VOID_FUNCTION (MPEXPR_NAME, DEFINE, Invert, Int)
MAKE_UNARY_OPERATOR (MPEXPR_NAME, DEFINE, -, Negate, Rat)
MAKE_VOID_FUNCTION (MPEXPR_NAME, DEFINE, Abs, Rat)
MAKE_VOID_FUNCTION (MPEXPR_NAME, DEFINE, Invert, Rat)
MAKE_BINARY_OPERATOR_STANDARD (MPEXPR_NAME, DEFINE, /, Divide, Int, Int)
MAKE_BINARY_OPERATOR_RLIMB (MPEXPR_NAME, DEFINE, /, Divide, Int, Ui)
MAKE_BINARY_OPERATOR_LLIMB (MPEXPR_NAME, DEFINE, /, Divide, Int, Ui)
MAKE_BINARY_OPERATOR_RLIMB (MPEXPR_NAME, DEFINE, /, Divide, Int, Si)
MAKE_BINARY_OPERATOR_LLIMB (MPEXPR_NAME, DEFINE, /, Divide, Int, Si)
MAKE_BINARY_OPERATOR_STANDARD (MPEXPR_NAME, DEFINE, /, Divide, Rat, Rat)
MAKE_BINARY_OPERATOR_RLIMB (MPEXPR_NAME, DEFINE, /, Divide, Rat, Ui)
MAKE_BINARY_OPERATOR_LLIMB (MPEXPR_NAME, DEFINE, /, Divide, Rat, Ui)
MAKE_BINARY_OPERATOR_RLIMB (MPEXPR_NAME, DEFINE, /, Divide, Rat, Si)
MAKE_BINARY_OPERATOR_LLIMB (MPEXPR_NAME, DEFINE, /, Divide, Rat, Si)
DEFINE_UNARY_ASSIGNMENT_REF(Negate, Int, MP(neg))
DEFINE_UNARY_ASSIGNMENT_REF(Invert, Int, MP(inv))
DEFINE_UNARY_ASSIGNMENT_REF(Abs, Int, MP(abs))
DEFINE_UNARY_ASSIGNMENT_REF(Negate, Rat, MP(neg))
DEFINE_UNARY_ASSIGNMENT_REF(Invert, Rat, MP(inv))
DEFINE_UNARY_ASSIGNMENT_REF(Abs, Rat, MP(abs))
DEFINE_BINARY_ASSIGNMENT_REF_REF(Add, Int, MP(add))
DEFINE_BINARY_ASSIGNMENT_REF_RATVAL(Add, Int, Ui, MP(add))
DEFINE_BINARY_ASSIGNMENT_REF_RATVAL(Add, Int, Si, MP(add))
DEFINE_BINARY_ASSIGNMENT_REF_INTVAL(Add, Int, IExpr, MP(add))
DEFINE_BINARY_ASSIGNMENT_REF_REF(Add, Rat, MP(add))
DEFINE_BINARY_ASSIGNMENT_REF_RATVAL(Add, Rat, Ui, MP(add))
DEFINE_BINARY_ASSIGNMENT_REF_RATVAL(Add, Rat, Si, MP(add))
DEFINE_BINARY_ASSIGNMENT_REF_INTVAL(Add, Rat, IExpr, MP(add))
DEFINE_BINARY_ASSIGNMENT_REF_REF(Subtract, Int, MP(sub))
DEFINE_BINARY_ASSIGNMENT_REF_RATVAL(Subtract, Int, Ui, MP(sub))
DEFINE_BINARY_ASSIGNMENT_RATVAL_REF(Subtract, Ui, Int, MP(sub))
DEFINE_BINARY_ASSIGNMENT_REF_RATVAL(Subtract, Int, Si, MP(sub))
DEFINE_BINARY_ASSIGNMENT_RATVAL_REF(Subtract, Si, Int, MP(sub))
DEFINE_BINARY_ASSIGNMENT_REF_REF(Subtract, Rat, MP(sub))
DEFINE_BINARY_ASSIGNMENT_REF_RATVAL(Subtract, Rat, Ui, MP(sub))
DEFINE_BINARY_ASSIGNMENT_RATVAL_REF(Subtract, Ui, Rat, MP(sub))
DEFINE_BINARY_ASSIGNMENT_REF_RATVAL(Subtract, Rat, Si, MP(sub))
DEFINE_BINARY_ASSIGNMENT_RATVAL_REF(Subtract, Si, Rat, MP(sub))
DEFINE_BINARY_ASSIGNMENT_REF_REF(Multiply, Int, MP(mul))
DEFINE_BINARY_ASSIGNMENT_REF_RATVAL(Multiply, Int, Ui, MP(mul))
DEFINE_BINARY_ASSIGNMENT_REF_RATVAL(Multiply, Int, Si, MP(mul))
DEFINE_BINARY_ASSIGNMENT_REF_REF(Multiply, Rat, MP(mul))
DEFINE_BINARY_ASSIGNMENT_REF_RATVAL(Multiply, Rat, Ui, MP(mul))
DEFINE_BINARY_ASSIGNMENT_REF_RATVAL(Multiply, Rat, Si, MP(mul))
DEFINE_BINARY_ASSIGNMENT_REF_REF(Divide, Int, MP(div))
DEFINE_BINARY_ASSIGNMENT_REF_RATVAL(Divide, Int, Ui, MP(div))
DEFINE_BINARY_ASSIGNMENT_RATVAL_REF(Divide, Ui, Int, MP(div))
DEFINE_BINARY_ASSIGNMENT_REF_RATVAL(Divide, Int, Si, MP(div))
DEFINE_BINARY_ASSIGNMENT_RATVAL_REF(Divide, Si, Int, MP(div))
DEFINE_BINARY_ASSIGNMENT_REF_REF(Divide, Rat, MP(div))
DEFINE_BINARY_ASSIGNMENT_REF_RATVAL(Divide, Rat, Ui, MP(div))
DEFINE_BINARY_ASSIGNMENT_RATVAL_REF(Divide, Ui, Rat, MP(div))
DEFINE_BINARY_ASSIGNMENT_REF_RATVAL(Divide, Rat, Si, MP(div))
DEFINE_BINARY_ASSIGNMENT_RATVAL_REF(Divide, Si, Rat, MP(div))
DEFINE_BINARY_ASSIGNMENT_REF_VAL(ShiftLeft, Int, Bits, MP(mul_2exp))
DEFINE_BINARY_ASSIGNMENT_REF_VAL(ShiftRight, Int, Bits, MP(div_2exp))
DEFINE_BINARY_ASSIGNMENT_REF_VAL(ShiftLeft, Rat, Bits, MP(mul_2exp))
DEFINE_BINARY_ASSIGNMENT_REF_VAL(ShiftRight, Rat, Bits, MP(div_2exp))
DEFINE_ASSIGNMENT_PROLOG(PowerIntUi)
DEFINE_ASSIGNMENT_PROLOG(PowerRatUi)
{
IN_CONTEXT(Left);
mpz_pow_ui(&destination->_mp_num, &CTXT(0)->_mp_num, Right);

View File

@ -34,8 +34,11 @@ using namespace System::Runtime::InteropServices;
#undef MPEXPR
#undef CTXT
#undef CTXTI
#undef ASSIGN_TO
#undef Mpt
#endif
#define SPECIALIZE_EXPRESSIONS
#define Mpt Rat
#define CUSTOM_MP(x) custom_mpq_##x
#define MPSTRUCT __mpq_struct
#define MP(x) mpq_##x
@ -45,6 +48,7 @@ using namespace System::Runtime::InteropServices;
#define MPEXPR(x) LIT(MPTYPE_NAME)##x##Expression
#define CTXT(x) context.RationalArgs[x]
#define CTXTI(x) context.IntArgs[x]
#define ASSIGN_TO CONCAT(AssignTo, LIT(MPTYPE_NAME))
#include "ExpressionMacros.h"
namespace MPIR
@ -736,35 +740,35 @@ namespace MPIR
#pragma region concrete expressions
DEFINE_BINARY_EXPRESSION_WITH_TWO (MPEXPR_NAME, Add, Int)
DEFINE_BINARY_EXPRESSION_WITH_BUILT_IN_RIGHT (MPEXPR_NAME, Add, Int, Ui)
DEFINE_BINARY_EXPRESSION_WITH_BUILT_IN_RIGHT (MPEXPR_NAME, Add, Int, Si)
DEFINE_BINARY_EXPRESSION_WITH_BUILT_IN_RIGHT (MPEXPR_NAME, Add, Int, IExpr)
DEFINE_BINARY_EXPRESSION_WITH_TWO (MPEXPR_NAME, Add, Rat)
DEFINE_BINARY_EXPRESSION_WITH_BUILT_IN_RIGHT (MPEXPR_NAME, Add, Rat, Ui)
DEFINE_BINARY_EXPRESSION_WITH_BUILT_IN_RIGHT (MPEXPR_NAME, Add, Rat, Si)
DEFINE_BINARY_EXPRESSION_WITH_BUILT_IN_RIGHT (MPEXPR_NAME, Add, Rat, IExpr)
DEFINE_BINARY_EXPRESSION_WITH_TWO (MPEXPR_NAME, Subtract, Int)
DEFINE_BINARY_EXPRESSION_WITH_BUILT_IN_RIGHT (MPEXPR_NAME, Subtract, Int, Ui)
DEFINE_BINARY_EXPRESSION_WITH_BUILT_IN_LEFT (MPEXPR_NAME, Subtract, Ui, Int)
DEFINE_BINARY_EXPRESSION_WITH_BUILT_IN_RIGHT (MPEXPR_NAME, Subtract, Int, Si)
DEFINE_BINARY_EXPRESSION_WITH_BUILT_IN_LEFT (MPEXPR_NAME, Subtract, Si, Int)
DEFINE_BINARY_EXPRESSION_WITH_TWO (MPEXPR_NAME, Subtract, Rat)
DEFINE_BINARY_EXPRESSION_WITH_BUILT_IN_RIGHT (MPEXPR_NAME, Subtract, Rat, Ui)
DEFINE_BINARY_EXPRESSION_WITH_BUILT_IN_LEFT (MPEXPR_NAME, Subtract, Ui, Rat)
DEFINE_BINARY_EXPRESSION_WITH_BUILT_IN_RIGHT (MPEXPR_NAME, Subtract, Rat, Si)
DEFINE_BINARY_EXPRESSION_WITH_BUILT_IN_LEFT (MPEXPR_NAME, Subtract, Si, Rat)
DEFINE_BINARY_EXPRESSION_WITH_TWO (MPEXPR_NAME, Multiply, Int)
DEFINE_BINARY_EXPRESSION_WITH_BUILT_IN_RIGHT (MPEXPR_NAME, Multiply, Int, Ui)
DEFINE_BINARY_EXPRESSION_WITH_BUILT_IN_RIGHT (MPEXPR_NAME, Multiply, Int, Si)
DEFINE_BINARY_EXPRESSION_WITH_TWO (MPEXPR_NAME, Multiply, Rat)
DEFINE_BINARY_EXPRESSION_WITH_BUILT_IN_RIGHT (MPEXPR_NAME, Multiply, Rat, Ui)
DEFINE_BINARY_EXPRESSION_WITH_BUILT_IN_RIGHT (MPEXPR_NAME, Multiply, Rat, Si)
DEFINE_BINARY_EXPRESSION_WITH_TWO (MPEXPR_NAME, Divide, Int)
DEFINE_BINARY_EXPRESSION_WITH_BUILT_IN_RIGHT (MPEXPR_NAME, Divide, Int, Ui)
DEFINE_BINARY_EXPRESSION_WITH_BUILT_IN_LEFT (MPEXPR_NAME, Divide, Ui, Int)
DEFINE_BINARY_EXPRESSION_WITH_BUILT_IN_RIGHT (MPEXPR_NAME, Divide, Int, Si)
DEFINE_BINARY_EXPRESSION_WITH_BUILT_IN_LEFT (MPEXPR_NAME, Divide, Si, Int)
DEFINE_BINARY_EXPRESSION_WITH_TWO (MPEXPR_NAME, Divide, Rat)
DEFINE_BINARY_EXPRESSION_WITH_BUILT_IN_RIGHT (MPEXPR_NAME, Divide, Rat, Ui)
DEFINE_BINARY_EXPRESSION_WITH_BUILT_IN_LEFT (MPEXPR_NAME, Divide, Ui, Rat)
DEFINE_BINARY_EXPRESSION_WITH_BUILT_IN_RIGHT (MPEXPR_NAME, Divide, Rat, Si)
DEFINE_BINARY_EXPRESSION_WITH_BUILT_IN_LEFT (MPEXPR_NAME, Divide, Si, Rat)
DEFINE_BINARY_EXPRESSION_WITH_BUILT_IN_RIGHT (MPEXPR_NAME, ShiftLeft, Int, Bits)
DEFINE_BINARY_EXPRESSION_WITH_BUILT_IN_RIGHT (MPEXPR_NAME, ShiftRight, Int, Bits)
DEFINE_BINARY_EXPRESSION_WITH_BUILT_IN_RIGHT (MPEXPR_NAME, ShiftLeft, Rat, Bits)
DEFINE_BINARY_EXPRESSION_WITH_BUILT_IN_RIGHT (MPEXPR_NAME, ShiftRight, Rat, Bits)
DEFINE_BINARY_EXPRESSION_WITH_BUILT_IN_RIGHT (MPEXPR_NAME, Power, Int, Ui)
DEFINE_BINARY_EXPRESSION_WITH_BUILT_IN_RIGHT (MPEXPR_NAME, Power, Rat, Ui)
DEFINE_UNARY_EXPRESSION_WITH_ONE (MPEXPR_NAME, Negate, Int)
DEFINE_UNARY_EXPRESSION_WITH_ONE (MPEXPR_NAME, Abs, Int)
DEFINE_UNARY_EXPRESSION_WITH_ONE (MPEXPR_NAME, Invert, Int)
DEFINE_UNARY_EXPRESSION_WITH_ONE (MPEXPR_NAME, Negate, Rat)
DEFINE_UNARY_EXPRESSION_WITH_ONE (MPEXPR_NAME, Abs, Rat)
DEFINE_UNARY_EXPRESSION_WITH_ONE (MPEXPR_NAME, Invert, Rat)
#pragma endregion