From b6ecff163a78cb4aa8ca5a5e8ff9a1cee7a0d349 Mon Sep 17 00:00:00 2001 From: MasonProtter Date: Thu, 19 Nov 2020 10:43:46 -0700 Subject: [PATCH 1/4] make MPOLY_CLEANUP a const --- src/abstractalgebra.jl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/abstractalgebra.jl b/src/abstractalgebra.jl index 820972167..9576f1e0d 100644 --- a/src/abstractalgebra.jl +++ b/src/abstractalgebra.jl @@ -65,11 +65,9 @@ let @acrule(~x::ismpoly * ~y::ismpoly => ~x * ~y) @rule(*(~x) => ~x) @rule((~x::ismpoly)^(~a::isnonnegint) => (~x)^(~a))] - MPOLY_CLEANUP = Fixpoint(Postwalk(PassThrough(RestartedChain(mpoly_preprocess)))) + global const MPOLY_CLEANUP = Fixpoint(Postwalk(PassThrough(RestartedChain(mpoly_preprocess)))) MPOLY_MAKER = Fixpoint(Postwalk(PassThrough(RestartedChain(mpoly_rules)))) - global MPOLY_CLEANUP - global to_mpoly function to_mpoly(t, dicts=_dicts()) # term2sym is only used to assign the same From a723820947e0bf49f47322cb678c267b59f769c1 Mon Sep 17 00:00:00 2001 From: MasonProtter Date: Thu, 19 Nov 2020 11:16:44 -0700 Subject: [PATCH 2/4] don't introduce symbolic `inv` --- src/methods.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/methods.jl b/src/methods.jl index 6cd97ad10..8ca0d8654 100644 --- a/src/methods.jl +++ b/src/methods.jl @@ -1,4 +1,4 @@ -const monadic = [deg2rad, rad2deg, transpose, -, conj, asind, log1p, acsch, acos, asec, acosh, acsc, cscd, log, tand, log10, csch, asinh, abs2, cosh, sin, cos, atan, cospi, cbrt, acosd, acoth, inv, acotd, asecd, exp, acot, sqrt, sind, sinpi, asech, log2, tan, exp10, sech, coth, asin, cotd, cosd, sinh, abs, csc, tanh, secd, atand, sec, acscd, cot, exp2, expm1, atanh, real] +const monadic = [deg2rad, rad2deg, transpose, -, conj, asind, log1p, acsch, acos, asec, acosh, acsc, cscd, log, tand, log10, csch, asinh, abs2, cosh, sin, cos, atan, cospi, cbrt, acosd, acoth, acotd, asecd, exp, acot, sqrt, sind, sinpi, asech, log2, tan, exp10, sech, coth, asin, cotd, cosd, sinh, abs, csc, tanh, secd, atand, sec, acscd, cot, exp2, expm1, atanh, real] const diadic = [+, -, max, min, *, /, \, hypot, atan, mod, rem, ^, copysign] @@ -135,3 +135,5 @@ function cond(_if::Symbolic{Bool}, _then, _else) Term{Union{symtype(_then), symtype(_else)}}(cond, Any[_if, _then, _else]) end +# Specially handle inv +Base.inv(x::Symbolic) = x ^ -1 From f64acefa1cfc19199bb65e66dadaaad6ea497985 Mon Sep 17 00:00:00 2001 From: MasonProtter Date: Thu, 19 Nov 2020 11:18:36 -0700 Subject: [PATCH 3/4] get rid of `inv` if it somehow appears --- src/simplify_rules.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/simplify_rules.jl b/src/simplify_rules.jl index 800c914e7..ee6bac6d8 100644 --- a/src/simplify_rules.jl +++ b/src/simplify_rules.jl @@ -39,6 +39,7 @@ let @rule((((~x)^(~p::isliteral(Integer)))^(~q::isliteral(Integer))) => (~x)^((~p)*(~q))) @rule(^(~x, ~z::_iszero) => 1) @rule(^(~x, ~z::_isone) => ~x) + @rule(inv(~x) => ~x ^ -1) ] ASSORTED_RULES = [ From b6484ddd0d3d20681387eab2665b042609b44cfa Mon Sep 17 00:00:00 2001 From: MasonProtter Date: Thu, 19 Nov 2020 12:01:17 -0700 Subject: [PATCH 4/4] avoid literal pow --- src/methods.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/methods.jl b/src/methods.jl index 8ca0d8654..5abfc5497 100644 --- a/src/methods.jl +++ b/src/methods.jl @@ -136,4 +136,4 @@ function cond(_if::Symbolic{Bool}, _then, _else) end # Specially handle inv -Base.inv(x::Symbolic) = x ^ -1 +Base.inv(x::Symbolic) = Base.:^(x, -1)