Skip to content

Commit 162d419

Browse files
Merge branch 'master' into pja/capture-macro
2 parents e0c9b37 + 609f7a2 commit 162d419

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SymbolicUtils"
22
uuid = "d1185830-fcd6-423d-90d6-eec64667417b"
33
authors = ["Shashi Gowda"]
4-
version = "0.16.4"
4+
version = "0.16.0"
55

66
[deps]
77
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
@@ -37,7 +37,7 @@ IfElse = "0.1"
3737
LabelledArrays = "1.5"
3838
MultivariatePolynomials = "0.3"
3939
NaNMath = "0.3"
40-
Setfield = "0.7"
40+
Setfield = "0.7, 0.8"
4141
SpecialFunctions = "0.10, 1.0"
4242
StaticArrays = "0.12, 1.0"
4343
TermInterface = "0.1.8"

src/polyform.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ function PolyForm(x,
160160
recurse=false,
161161
metadata=metadata(x))
162162

163+
if !(symtype(x) <: Number)
164+
return x
165+
end
166+
163167
# Polyize and return a PolyForm
164168
p = polyize(x, pvar2sym, sym2term, vtype, pow, Fs, recurse)
165169
PolyForm{symtype(x)}(p, pvar2sym, sym2term, metadata)
@@ -225,8 +229,12 @@ Expand expressions by distributing multiplication over addition, e.g.,
225229
multivariate polynomials implementation.
226230
`variable_type` can be any subtype of `MultivariatePolynomials.AbstractVariable`.
227231
"""
228-
expand(expr) = Postwalk(identity)(PolyForm(expr, Fs=Union{typeof(+), typeof(*), typeof(^)}, recurse=true))
232+
expand(expr) = unpolyize(PolyForm(expr, Fs=Union{typeof(+), typeof(*), typeof(^)}, recurse=true))
229233

234+
function unpolyize(x)
235+
simterm(x, f, args; kw...) = similarterm(x, f, args, symtype(x); kw...)
236+
Postwalk(identity, similarterm=simterm)(x)
237+
end
230238

231239
## Rational Polynomial form with Div
232240

@@ -280,7 +288,7 @@ function simplify_fractions(x; polyform=false)
280288

281289
expr = Postwalk(sdiv quick_cancel)(Postwalk(add_with_div)(x))
282290

283-
polyform ? expr : Postwalk(identity)(expr)
291+
polyform ? expr : unpolyize(expr)
284292
end
285293

286294
function add_with_div(x, flatten=true)

test/polyform.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ end
3232
#@test expand(Term{Number}(zero, 0)) == 0
3333
#@test expand(identity(a * b) - b * a) == 0
3434
@test expand(a * b - b * a) == 0
35+
36+
@syms A::Vector{Real}
37+
# test that the following works
38+
expand(Term{Real}(getindex, [A, 3]) - 3)
3539
end
3640

3741
@testset "simplify_fractions with quick-cancel" begin

0 commit comments

Comments
 (0)