Skip to content

Commit 07147ba

Browse files
committed
some docs
1 parent 1e2e5ad commit 07147ba

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/polyform.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@ Abstracts a [MultivariatePolynomials.jl](https://juliaalgebra.github.io/Multivar
99
1010
The SymbolicUtils term interface (`istree`, `operation, and `arguments`) works on PolyForm lazily: the `operation` and `arguments` are created by converting one level of arguments into SymbolicUtils expressions. They may further contain PolyForm within them.
1111
We use this to hold polynomials in memory while doing `simplify_fractions`.
12+
13+
PolyForm{T}(x; Fs=Union{typeof(*),typeof(+),typeof(^)}, recurse=false)
14+
15+
Turn a Symbolic expression `x` into a polynomial and return a PolyForm that abstracts it.
16+
17+
`Fs` are the types of functions which should be applied if arguments are themselves
18+
polynomialized. For example, if you only want to polynomialize the base of power
19+
expressions, you would leave out `typeof(^)` from the union. In this case `^`
20+
is not called, but maintained as a `Pow` term.
21+
22+
`recurse` is a flag which calls `PolyForm` recursively on subexpressions. For example:
23+
24+
```julia
25+
PolyForm(sin((x+y)^2)) #=> sin((x+y)^2)
26+
PolyForm(sin((x+y)^2), recurse=true) #=> sin((x^2 + (2x)y + y^2))
27+
```
1228
"""
1329
struct PolyForm{T, M} <: Symbolic{T}
1430
p::MP.AbstractPolynomialLike
@@ -213,6 +229,8 @@ expand(expr) = PolyForm(expr)
213229
function polyform_factors(d::Div, pvar2sym, sym2term)
214230
make(xs) = map(xs) do x
215231
if x isa Pow && arguments(x)[2] isa Integer && arguments(x)[2] > 0
232+
# here we do want to recurse one level, that's why it's wrong to just
233+
# use Fs = Union{typeof(+), typeof(*)} here.
216234
Pow(PolyForm(arguments(x)[1], pvar2sym, sym2term), arguments(x)[2])
217235
else
218236
PolyForm(x, pvar2sym, sym2term)
@@ -242,6 +260,12 @@ function add_divs(x::Div, y::Div)
242260
Div(_mul(x_num, y_den) + _mul(x_den, y_num), _mul(x_den, y_den))
243261
end
244262

263+
"""
264+
simplify_fractions(x)
265+
266+
Find `Div` nodes and simplify them by cancelling a set of factors of numerators
267+
and denominators. It may leave some expressions in `PolyForm` format.
268+
"""
245269
function simplify_fractions(x)
246270
isdiv(x) = x isa Div
247271

0 commit comments

Comments
 (0)