|
1 | 1 | ##### Numeric simplification |
2 | 2 |
|
3 | | -default_rules(::EmptyCtx) = SIMPLIFY_RULES |
4 | 3 | """ |
5 | | - simplify(x, [rules=SIMPLIFY_RULES]; fixpoint=true, applyall=true, recurse=true) |
| 4 | + default_rules(expr, context::T)::RuleSet |
6 | 5 |
|
7 | | -Apply a `RuleSet` of rules provided in `rules`. By default |
8 | | -these rules are `SymbolicUtils.SIMPLIFY_RULES`. If `fixpoint=true` |
9 | | -repeatedly applies the set of rules until there are no changes. |
| 6 | +The `RuleSet` to be used by default for a given expression and the context. |
| 7 | +Julia packages defining their own context types should define this method. |
| 8 | +
|
| 9 | +By default SymbolicUtils will try to apply appropriate rules for expressions |
| 10 | +of symtype Number. |
| 11 | +""" |
| 12 | +default_rules(x, ctx) = SIMPLIFY_RULES |
| 13 | + |
| 14 | +""" |
| 15 | + simplify(x, ctx=EmptyCtx(); |
| 16 | + rules=default_rules(x, ctx), |
| 17 | + fixpoint=true, |
| 18 | + applyall=true, |
| 19 | + recurse=true) |
| 20 | +
|
| 21 | +Simplify an expression by applying `rules` until there are no changes. |
| 22 | +The second argument, the context is passed to every [`Contextual`](#Contextual) |
| 23 | +predicate and can be accessed as `(@ctx)` in the right hand side of `@rule` expression. |
| 24 | +
|
| 25 | +By default the context is an `EmptyCtx()` -- which means there is no contextual information. |
| 26 | +Any arbitrary type can be used as a context, and packages defining their own contexts |
| 27 | +should define `default_rules(ctx::TheContextType)` to return a `RuleSet` that will |
| 28 | +be used by default while simplifying under that context. |
| 29 | +
|
| 30 | +If `fixpoint=true` this will repeatedly apply the set of rules until there are no changes. |
10 | 31 | Applies them once if `fixpoint=false`. |
11 | 32 |
|
12 | 33 | The `applyall` and `recurse` keywords are forwarded to the enclosed |
13 | | -`RuleSet`. |
| 34 | +`RuleSet`, they are mainly used for internal optimization. |
14 | 35 | """ |
15 | | -function simplify(x, ctx=EmptyCtx(); rules=default_rules(ctx), fixpoint=true, applyall=true, recurse=true) |
| 36 | +function simplify(x, ctx=EmptyCtx(); rules=default_rules(x, ctx), fixpoint=true, applyall=true, recurse=true) |
16 | 37 | if fixpoint |
17 | 38 | SymbolicUtils.fixpoint(rules, x, ctx; recurse=recurse, applyall=recurse) |
18 | 39 | else |
|
0 commit comments