@@ -48,10 +48,27 @@ function as_polynomial(f, exprs...; polyform=false, T=Real)
4848 @assert length (exprs) >= 1 " At least one expression must be passed to `multivariatepolynomial`."
4949
5050 pvar2sym, sym2term = get_pvar2sym (), get_sym2term ()
51- ps = map (x-> PolyForm (x, pvar2sym, sym2term), exprs)
52- convert_back = polyform ? x -> PolyForm {T} (x, pvar2sym, sym2term) :
53- x -> unpolyize (PolyForm {T} (x, pvar2sym, sym2term)) # substitute back
54- res = f (convert_back, map (x-> x. p, ps)... )
51+ ps = map (exprs) do x
52+ if istree (x) && operation (x) == (/ )
53+ num, den = arguments (x)
54+ PolyForm (num, pvar2sym, sym2term). p /
55+ PolyForm (den, pvar2sym, sym2term). p
56+ else
57+ PolyForm (x, pvar2sym, sym2term). p
58+ end
59+ end
60+
61+ convert_back_f = function (x)
62+ if x isa MultivariatePolynomials. RationalPoly
63+ PolyForm {T} (numerator (x), pvar2sym, sym2term) /
64+ PolyForm {T} (denominator (x), pvar2sym, sym2term)
65+ else
66+ PolyForm {T} (x, pvar2sym, sym2term)
67+ end
68+ end
69+
70+ convert_back = polyform ? convert_back_f : unpolyize ∘ convert_back_f
71+ res = f (convert_back, ps... )
5572end
5673
5774# We use the same PVAR2SYM bijection to maintain the PolyVar <-> Sym mapping,
0 commit comments