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