Skip to content

Commit a9867cc

Browse files
committed
Merge remote-tracking branch 'origin/s/rewriter-tweaks' into s/rewriter-tweaks
2 parents 1517c40 + 3680e8a commit a9867cc

File tree

126 files changed

+377
-2029
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+377
-2029
lines changed

.github/dependabot.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
2+
version: 2
3+
updates:
4+
- package-ecosystem: "github-actions"
5+
directory: "/" # Location of package manifests
6+
schedule:
7+
interval: "weekly"
8+
ignore:
9+
- dependency-name: "crate-ci/typos"
10+
update-types: ["version-update:semver-patch"]

.github/workflows/SpellCheck.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Spell Check
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
typos-check:
7+
name: Spell Check with Typos
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout Actions Repository
11+
uses: actions/checkout@v3
12+
- name: Check spelling
13+
uses: crate-ci/[email protected]

.typos.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[default.extend-words]
2+
nd = "nd"
3+
siz = "siz"

Project.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SymbolicUtils"
22
uuid = "d1185830-fcd6-423d-90d6-eec64667417b"
33
authors = ["Shashi Gowda"]
4-
version = "1.2.0"
4+
version = "1.6.0"
55

66
[deps]
77
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
@@ -21,11 +21,13 @@ Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
2121
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
2222
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
2323
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
24+
SymbolicIndexingInterface = "2efcf032-c050-4f8e-a9bb-153293bab1f5"
25+
TermInterface = "8ea1fca8-c5ef-4a55-8b96-4e9afe9c9a3c"
2426
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
2527
Unityper = "a7c27f48-0311-42f6-a7f8-2c11e75eb415"
2628

2729
[compat]
28-
AbstractTrees = "0.3, 0.4"
30+
AbstractTrees = "0.4"
2931
Bijections = "0.1.2"
3032
ChainRulesCore = "1"
3133
Combinatorics = "1.0"
@@ -40,6 +42,8 @@ NaNMath = "0.3, 1"
4042
Setfield = "0.7, 0.8, 1"
4143
SpecialFunctions = "0.10, 1.0, 2"
4244
StaticArrays = "0.12, 1.0"
45+
SymbolicIndexingInterface = "0.3"
46+
TermInterface = "0.4"
4347
TimerOutputs = "0.5"
4448
Unityper = "0.1.2"
4549
julia = "1.3"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Octonian algebras, you've come to the right place.
2525

2626
[Symbols in SymbolicUtils](https://symbolicutils.juliasymbolics.org/#creating_symbolic_expressions) carry type information. Operations on them propagate this information. [A rule-based rewriting language](https://symbolicutils.juliasymbolics.org/rewrite/#rule-based_rewriting) can be used to find subexpressions that satisfy arbitrary conditions and apply arbitrary transformations on the matches. The library also contains a set of useful [simplification](https://juliasymbolics.github.io/SymbolicUtils.jl/#simplification) rules for expressions of numeric symbols and numbers. These can be remixed and extended for special purposes.
2727

28-
If you are a Julia package develper in need of a rule rewriting system for your own types, have a look at the [interfacing guide](https://symbolicutils.juliasymbolics.org/interface/).
28+
If you are a Julia package developer in need of a rule rewriting system for your own types, have a look at the [interfacing guide](https://symbolicutils.juliasymbolics.org/interface/).
2929

3030

3131
### "I don't want to read your manual, just show me some cool code"

docs/src/api.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,6 @@ SymbolicUtils.Pow
1212
SymbolicUtils.promote_symtype
1313
```
1414

15-
## Interfacing
16-
17-
```@docs
18-
SymbolicUtils.istree
19-
SymbolicUtils.operation
20-
SymbolicUtils.arguments
21-
SymbolicUtils.similarterm
22-
```
23-
2415
## Rewriters
2516

2617
```@docs

docs/src/index.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,8 @@ g(2//5, g(1, β))
108108

109109
Symbolic expressions are of type `Term{T}`, `Add{T}`, `Mul{T}`, `Pow{T}` or `Div{T}` and denote some function call where one or more arguments are themselves such expressions or `Sym`s. See more about the representation [here](/representation/).
110110

111-
All the expression types support the following:
112-
113-
- `istree(x)` -- always returns `true` denoting, `x` is not a leaf node like Sym or a literal.
114-
- `operation(x)` -- the function being called
115-
- `arguments(x)` -- a vector of arguments
116-
- `symtype(x)` -- the "inferred" type (`T`)
117-
118-
See more on the interface [here](/interface)
119-
111+
All the expression types support the [TermInterface.jl](https://github.com/0x0f0f0f/TermInterface.jl) interface.
112+
Please refer to the package for the complete reference of the interface.
120113

121114
## Term rewriting
122115

docs/src/manual/representation.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Performance of symbolic simplification depends on the datastructures used to represent terms. Efficient datastructures often have the advantage of automatic simplification, and of efficient storage.
44

5-
The most basic term representation simply holds a function call and stores the function and the arguments it is called with. This is done by the `Term` type in SymbolicUtils. Functions that aren't commutative or associative, such as `sin` or `hypot` are stored as `Term`s. Commutatative and associative operations like `+`, `*`, and their supporting operations like `-`, `/` and `^`, when used on terms of type `<:Number`, stand to gain from the use of more efficient datastrucutres.
5+
The most basic term representation simply holds a function call and stores the function and the arguments it is called with. This is done by the `Term` type in SymbolicUtils. Functions that aren't commutative or associative, such as `sin` or `hypot` are stored as `Term`s. Commutative and associative operations like `+`, `*`, and their supporting operations like `-`, `/` and `^`, when used on terms of type `<:Number`, stand to gain from the use of more efficient datastrucutres.
66

77
All term representations must support `operation` and `arguments` functions. And they must define `istree` to return `true` when called with an instance of the type. Generic term-manipulation programs such as the rule-based rewriter make use of this interface to inspect expressions. In this way, the interface wins back the generality lost by having a zoo of term representations instead of one. (see [interface](/interface/) section for more on this.)
88

@@ -16,7 +16,7 @@ Similarly, $x_1^{m_1}x_2^{m_2}...x_{m_n}$ is represented by
1616

1717
Note that `Add` and `Mul` types perform a preliminary simplification which suffices to simplify numeric expressions to a large extent during construction.
1818

19-
$p / q$ is represented by `Div(p, q)`. The result of `*` on `Div` is maintainted as a `Div`. For example, `Div(p_1, q_1) * Div(p_2, q_2)` results in `Div(p_1 * p_2, q_1 * q_2)` and so on. The effect is, in `Div(p, q)`, `p` or `q` or, if they are Mul, any of their multiplicands is not a Div. So `Mul`s must always be nested inside a `Div` and can never show up immediately wrapping it. This rule sets up an expression so that it helps the `simplify_fractions` procedure described two sections below.
19+
$p / q$ is represented by `Div(p, q)`. The result of `*` on `Div` is maintained as a `Div`. For example, `Div(p_1, q_1) * Div(p_2, q_2)` results in `Div(p_1 * p_2, q_1 * q_2)` and so on. The effect is, in `Div(p, q)`, `p` or `q` or, if they are Mul, any of their multiplicands is not a Div. So `Mul`s must always be nested inside a `Div` and can never show up immediately wrapping it. This rule sets up an expression so that it helps the `simplify_fractions` procedure described two sections below.
2020

2121

2222
### Polynomial representation
@@ -67,9 +67,9 @@ Note that in this case `recurse=true` was necessary as otherwise the polynomiali
6767

6868
### Simplifying fractions
6969

70-
`simplify_fractions(expr)` recurses through `expr` finding `Div`s and simplifying them using polynomial divison.
70+
`simplify_fractions(expr)` recurses through `expr` finding `Div`s and simplifying them using polynomial division.
7171

72-
First the factors of the numerators and the denominators are converted into PolyForm objects, then numerators and denominators are divided by their respective pairwise GCDs. The conversion of the numerator and denominator into PolyForm is set up so that `simplify_fractions` does not result in increase in the expression size due to polynomial expansion. Specifically, the factors are individually converted into PolyForm objects, and any powers of polynomial is not expanded, but the divison process repeatedly divides them as many times as the power.
72+
First the factors of the numerators and the denominators are converted into PolyForm objects, then numerators and denominators are divided by their respective pairwise GCDs. The conversion of the numerator and denominator into PolyForm is set up so that `simplify_fractions` does not result in increase in the expression size due to polynomial expansion. Specifically, the factors are individually converted into PolyForm objects, and any powers of polynomial is not expanded, but the division process repeatedly divides them as many times as the power.
7373

7474

7575
```julia

docs/src/manual/rewrite.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Notice that the expression was autosimplified before application of the rule.
7474

7575
Matcher pattern may contain slot variables with attached predicates, written as `~x::f` where `f` is a function that takes a matched expression and returns a boolean value. Such a slot will be considered a match only if `f` returns true.
7676

77-
Similarly `~~x::g` is a way of attaching a predicate `g` to a segment variable. In the case of segment variables `g` gets a vector of 0 or more expressions and must return a boolean value. If the same slot or segment variable appears twice in the matcher pattern, then at most one of the occurance should have a predicate.
77+
Similarly `~~x::g` is a way of attaching a predicate `g` to a segment variable. In the case of segment variables `g` gets a vector of 0 or more expressions and must return a boolean value. If the same slot or segment variable appears twice in the matcher pattern, then at most one of the occurrence should have a predicate.
7878

7979
For example,
8080

@@ -133,7 +133,7 @@ acpyid = @acrule sin(~x)^2 + cos(~x)^2 => 1
133133
acpyid(cos(x)^2 + sin(x)^2 + 2cos(x)*sin(x))
134134
```
135135

136-
It has been some work. Fortunately rules may be [chained together](#chaining rewriters) into more sophisticated rewirters to avoid manual application of the rules.
136+
It has been some work. Fortunately rules may be [chained together](#chaining rewriters) into more sophisticated rewriters to avoid manual application of the rules.
137137

138138

139139
## Composing rewriters
@@ -152,7 +152,7 @@ rewriters.
152152
- `RestartedChain(itr)` like `Chain(itr)` but restarts from the first rewriter once on the
153153
first successful application of one of the chained rewriters.
154154
- `IfElse(cond, rw1, rw2)` runs the `cond` function on the input, applies `rw1` if cond
155-
returns true, `rw2` if it retuns false
155+
returns true, `rw2` if it returns false
156156
- `If(cond, rw)` is the same as `IfElse(cond, rw, Empty())`
157157
- `Prewalk(rw; threaded=false, thread_cutoff=100)` returns a rewriter which does a pre-order
158158
(*from top to bottom and from left to right*) traversal of a given expression and applies

page/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)