@@ -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.,
225229multivariate 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)
284292end
285293
286294function add_with_div (x, flatten= true )
0 commit comments