-
Notifications
You must be signed in to change notification settings - Fork 116
/
Copy pathsimplify.jl
50 lines (42 loc) · 1.53 KB
/
simplify.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
```julia
simplify(x; expand=false,
threaded=false,
thread_subtree_cutoff=100,
rewriter=nothing)
```
Simplify an expression (`x`) by applying `rewriter` until there are no changes.
`expand=true` applies [`expand`](/api/#expand) in the beginning of each fixpoint iteration.
By default, simplify will assume denominators are not zero and allow cancellation in fractions.
Pass `simplify_fractions=false` to prevent this.
"""
function simplify(x;
expand=false,
polynorm=nothing,
threaded=false,
simplify_fractions=true,
thread_subtree_cutoff=100,
rewriter=nothing)
if polynorm !== nothing
Base.depwarn("simplify(..; polynorm=$polynorm) is deprecated, use simplify(..; expand=$polynorm) instead",
:simplify)
end
f = if rewriter === nothing
if threaded
threaded_simplifier(thread_subtree_cutoff)
elseif expand
serial_expand_simplifier
else
serial_simplifier
end
else
Fixpoint(rewriter)
end
x = PassThrough(f)(x)
simplify_fractions && has_operation(x, /) ?
SymbolicUtils.simplify_fractions(x) : x
end
has_operation(x, op) = (iscall(x) && (operation(x) == op ||
any(a->has_operation(a, op),
unsorted_arguments(x))))
Base.@deprecate simplify(x, ctx; kwargs...) simplify(x; rewriter=ctx, kwargs...)