From 2fdca110b23786feaefd9055c8b34248e2bb1379 Mon Sep 17 00:00:00 2001 From: Shashi Gowda Date: Fri, 17 Sep 2021 13:24:28 -0400 Subject: [PATCH 1/3] fix expand for expressions with array indexing --- src/polyform.jl | 4 ++++ test/polyform.jl | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/polyform.jl b/src/polyform.jl index 060b7eda8..067e050b8 100644 --- a/src/polyform.jl +++ b/src/polyform.jl @@ -160,6 +160,10 @@ function PolyForm(x, recurse=false, metadata=metadata(x)) + if !(symtype(x) <: Number) + return x + end + # Polyize and return a PolyForm p = polyize(x, pvar2sym, sym2term, vtype, pow, Fs, recurse) PolyForm{symtype(x)}(p, pvar2sym, sym2term, metadata) diff --git a/test/polyform.jl b/test/polyform.jl index 414c09fc0..9f7ecfb33 100644 --- a/test/polyform.jl +++ b/test/polyform.jl @@ -32,6 +32,10 @@ end #@test expand(Term{Number}(zero, 0)) == 0 #@test expand(identity(a * b) - b * a) == 0 @test expand(a * b - b * a) == 0 + + @syms A::Vector{Real} + # test that the following works + expand(Term{Real}(getindex, [A, 3]) - 3) end @testset "simplify_fractions with quick-cancel" begin From f643b887e26106d1826380228607dbcffe0c1bea Mon Sep 17 00:00:00 2001 From: Shashi Gowda Date: Fri, 17 Sep 2021 13:48:14 -0400 Subject: [PATCH 2/3] make it work even if promote_symtype is not defined --- src/polyform.jl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/polyform.jl b/src/polyform.jl index 067e050b8..f399fe941 100644 --- a/src/polyform.jl +++ b/src/polyform.jl @@ -229,8 +229,12 @@ Expand expressions by distributing multiplication over addition, e.g., multivariate polynomials implementation. `variable_type` can be any subtype of `MultivariatePolynomials.AbstractVariable`. """ -expand(expr) = Postwalk(identity)(PolyForm(expr, Fs=Union{typeof(+), typeof(*), typeof(^)}, recurse=true)) +expand(expr) = unpolyize(PolyForm(expr, Fs=Union{typeof(+), typeof(*), typeof(^)}, recurse=true)) +function unpolyize(x) + simterm(x, f, args; kw...) = similarterm(x, f, args, symtype(x); kw...) + Postwalk(identity, similarterm=simterm)(x) +end ## Rational Polynomial form with Div @@ -284,7 +288,7 @@ function simplify_fractions(x; polyform=false) expr = Postwalk(sdiv ∘ quick_cancel)(Postwalk(add_with_div)(x)) - polyform ? expr : Postwalk(identity)(expr) + polyform ? expr : unpolyize(expr) end function add_with_div(x, flatten=true) From 02bf51cd9ad35109b500d631fad7326fa7a48efd Mon Sep 17 00:00:00 2001 From: Shashi Gowda Date: Fri, 17 Sep 2021 13:48:42 -0400 Subject: [PATCH 3/3] bump patch --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 6273543eb..dd5893b19 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "SymbolicUtils" uuid = "d1185830-fcd6-423d-90d6-eec64667417b" authors = ["Shashi Gowda"] -version = "0.15.4" +version = "0.15.5" [deps] AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"