Skip to content

Commit b767669

Browse files
authored
Merge pull request #358 from JuliaSymbolics/s/un-polyform
Make simplify_fractions un-PolyForm terms
2 parents f29f7b3 + efcddec commit b767669

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/polyform.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,19 +263,24 @@ add_divs(x, y::Div) = (x * y.den + y.num) / y.den
263263
add_divs(x, y) = x + y
264264

265265
"""
266-
simplify_fractions(x)
266+
simplify_fractions(x; polyform=false)
267267
268268
Find `Div` nodes and simplify them by cancelling a set of factors of numerators
269-
and denominators. It may leave some expressions in `PolyForm` format.
269+
and denominators. If `polyform=true` the factors which were converted into PolyForm
270+
for the purpose of finding polynomial GCDs will be left as they are.
271+
Note that since PolyForms have different `hash`es than SymbolicUtils expressions,
272+
`substitute` may not work if `polyform=true`
270273
"""
271-
function simplify_fractions(x)
274+
function simplify_fractions(x; polyform=false)
272275
x = Postwalk(quick_cancel)(x)
273276

274277
!needs_div_rules(x) && return x
275278

276279
sdiv(a) = a isa Div ? simplify_div(a) : a
277280

278-
Postwalk(sdiv quick_cancel)(Postwalk(add_with_div)(x))
281+
expr = Postwalk(sdiv quick_cancel)(Postwalk(add_with_div)(x))
282+
283+
polyform ? expr : Postwalk(identity)(expr)
279284
end
280285

281286
function add_with_div(x, flatten=true)

0 commit comments

Comments
 (0)