Skip to content

Commit 53aacb1

Browse files
committed
switch to Documenter
1 parent 490011e commit 53aacb1

File tree

12 files changed

+646
-50
lines changed

12 files changed

+646
-50
lines changed

.github/Documentation.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Documentation
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
tags: '*'
8+
pull_request:
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
- uses: julia-actions/setup-julia@latest
16+
with:
17+
version: '1'
18+
- name: Install dependencies
19+
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
20+
- name: Build and deploy
21+
env:
22+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # For authentication with GitHub Actions token
23+
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # For authentication with SSH deploy key
24+
run: julia --project=docs/ docs/make.jl

.github/workflows/DeployPage.yml

Lines changed: 0 additions & 47 deletions
This file was deleted.

docs/Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[deps]
2+
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
3+
SymbolicUtils = "d1185830-fcd6-423d-90d6-eec64667417b"

docs/make.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Documenter, SymbolicUtils
2+
3+
include("pages.jl")
4+
5+
makedocs(
6+
sitename="SymbolicUtils.jl",
7+
authors="Shashi Gowda",
8+
modules=[SymbolicUtils],
9+
clean=true,doctest=false,
10+
strict=[
11+
:doctest,
12+
:linkcheck,
13+
:parse_error,
14+
:example_block,
15+
# Other available options are
16+
# :autodocs_block, :cross_references, :docs_block, :eval_block, :example_block, :footnote, :meta_block, :missing_docs, :setup_block
17+
],
18+
format = Documenter.HTML(#analytics = "UA-90474609-3",
19+
assets = ["assets/favicon.ico"],
20+
canonical="https://docs.sciml.ai/SymbolicUtils/stable/"),
21+
pages=pages
22+
)
23+
24+
deploydocs(
25+
repo = "github.com/JuliaSymbolics/SymbolicUtils.jl.git";
26+
push_preview = true
27+
)

docs/pages.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pages = Any["index.md",
2+
"Manual" => Any["manual/representation.md",
3+
"manual/rewrite.md",
4+
"manual/interface.md",
5+
"manual/codegen.md"],
6+
"api.md"
7+
]

docs/src/README.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

docs/src/api.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# API Reference
2+
3+
## Symbols and Terms
4+
```@docs
5+
SymbolicUtils.@syms
6+
SymbolicUtils.Sym
7+
SymbolicUtils.symtype
8+
SymbolicUtils.Term
9+
SymbolicUtils.Add
10+
SymbolicUtils.Mul
11+
SymbolicUtils.Pow
12+
SymbolicUtils.promote_symtype
13+
```
14+
15+
## Interfacing
16+
17+
```@docs
18+
SymbolicUtils.istree
19+
SymbolicUtils.operation
20+
SymbolicUtils.arguments
21+
SymbolicUtils.similarterm
22+
```
23+
24+
## Rewriters
25+
26+
```@docs
27+
@rule
28+
SymbolicUtils.Rewriters
29+
```
30+
31+
## Simplify
32+
33+
```@docs
34+
SymbolicUtils.simplify
35+
SymbolicUtils.expand
36+
SymbolicUtils.substitute
37+
```
38+
39+
## Utilities
40+
41+
```@docs
42+
SymbolicUtils.@timerewrite
43+
```

docs/src/index.md

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
# SymbolicUtils.jl — Symbolic programming in Julia
2+
3+
## Features
4+
5+
- Fast expressions
6+
- A [rule-based rewriting language](/rewrite/#rule-based_rewriting).
7+
- A [combinator library](/rewrite/#composing_rewriters) for making rewriters.
8+
- [Efficient representation](/representation/) of numeric expressions
9+
- Type promotion:
10+
- Symbols (`Sym`s) carry type information. ([read more](#creating_symbolic_expressions))
11+
- Compound expressions composed of `Sym`s propagate type information. ([read more](#expression_interface))
12+
- Set of extendable [simplification rules](#simplification).
13+
14+
15+
## Creating symbolic expressions
16+
17+
First, let's use the `@syms` macro to create a few symbols.
18+
19+
```julia:syms1
20+
using SymbolicUtils
21+
22+
@syms w z α::Real β::Real
23+
24+
(w, z, α, β) # hide
25+
26+
```
27+
28+
Type annotations are optional when creating symbols. Here `α`, `β` behave like Real numbers. `w` and `z` behave like `Number`, which is the default. You can use the `symtype` function to find the type of a symbol.
29+
30+
```julia:symtype
31+
using SymbolicUtils: symtype
32+
33+
symtype(w), symtype(z), symtype(α), symtype(β)
34+
```
35+
36+
Note however that they are not subtypes of these types!
37+
38+
```julia:symtype2
39+
@show w isa Number
40+
@show α isa Real
41+
```
42+
43+
As their types are different:
44+
45+
```julia:symtype3
46+
@show typeof(w)
47+
@show typeof(α)
48+
```
49+
50+
(see [this post](https://discourse.julialang.org/t/ann-symbolicutils-jl-groundwork-for-a-symbolic-ecosystem-in-julia/38455/13?u=shashi) for why they are all not just subtypes of `Number`)
51+
52+
You can do basic arithmetic on symbols to get symbolic expressions:
53+
54+
```julia:expr
55+
expr1 = α*sin(w)^2 + β*cos(z)^2
56+
expr2 = α*cos(z)^2 + β*sin(w)^2
57+
58+
expr1 + expr2
59+
```
60+
61+
SymbolicUtils automatically simplifies
62+
63+
```julia:creating1
64+
2w + 3w - 3z + α
65+
```
66+
67+
and reorders
68+
69+
```julia:creating2
70+
(z + w)*(α + β)
71+
```
72+
73+
expressions of type `Symbolic{<:Number}` (which includes `Sym{Real}`) when they are created. It also does constant elimination (including rational numbers)
74+
75+
```julia:creating3
76+
5 + 2w - 3z + α - (β + 5//3) + 3w - 2 + 3//2 * β
77+
```
78+
79+
It's worth remembering that the expression may be transformed with respect to the input when it's created.
80+
81+
82+
## Function-like symbols
83+
84+
Symbols can be defined to behave like functions. Both the input and output types for the function can be specified. Any application to that function will only admit either values of those types or symbols of the same `symtype`.
85+
86+
```julia:syms2
87+
using SymbolicUtils
88+
@syms f(x) g(x::Real, y::Real)::Real
89+
90+
f(z) + g(1, α) + sin(w)
91+
```
92+
93+
This does not work since `z` is a `Number`, not a `Real`.
94+
95+
```julia:sym3
96+
g(1, z)
97+
```
98+
99+
This works because `g` "returns" a `Real`.
100+
101+
```julia:sym4
102+
g(2//5, g(1, β))
103+
```
104+
105+
106+
107+
## Expression interface
108+
109+
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/).
110+
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+
120+
121+
## Term rewriting
122+
123+
SymbolicUtils contains [a rule-based rewriting language](/rewrite/#rule-based_rewriting) for easy pattern matching and rewriting of expression. There is also a [combinator library](/rewrite/#composing_rewriters) to combine rules to chain, branch and loop over rules.
124+
125+
## Simplification
126+
127+
By default `+`, `*` and `^` operations apply the most basic simplification upon construction of the expression.
128+
129+
The rules with which the canonical form of `Symbolic{<:Number}` terms are constructed are the next (where `x isa Symbolic` and `c isa Number`)
130+
131+
- `0 + x`, `1 * x` and `x^1` always gives `x`
132+
- `0 * x` always gives `0` and `x ^ 0` gives `1`
133+
- `-x` becomes `(-1)*x`
134+
- commutativity and associativity over `+` and `*` are assumed. Re-ordering of terms will be done under a [total order](https://github.com/JuliaSymbolics/SymbolicUtils.jl/blob/master/src/ordering.jl)
135+
- `p/q * x` or `x * p/q` results in `(p*x)/q`
136+
- `p/q * x/y` results in `(p*x)/(q*y)`
137+
- `x + ... + x` will be fused into `n*x` with type `Mul`
138+
- `x * ... * x` will be fused into `x^n` with type `Pow`
139+
- sum of `Add`'s are fused
140+
- product of `Mul`'s are fused
141+
- `c * (c₁x₁ + ... + cₙxₙ)` will be converted into `c*c₁*x₁ + ... + c*cₙ*xₙ`
142+
- `(x₁^c₁ * ... * xₙ^cₙ)^c` will be converted into `x₁^(c*c₁) * ... * xₙ^(c*cₙ)`
143+
- there are come other simplifications on construction that you can check [here](https://github.com/JuliaSymbolics/SymbolicUtils.jl/blob/master/src/methods.jl)
144+
145+
146+
Here is an example of this
147+
148+
```julia:simplify1
149+
2 * (w+w+α+β + sin(z)^2 + cos(z)^2 - 1)
150+
```
151+
152+
The `simplify` function applies a built-in set of rules to rewrite expressions in order to simplify it.
153+
154+
```julia:simplify2
155+
simplify(2 * (w+w+α+β + sin(z)^2 + cos(z)^2 - 1))
156+
```
157+
158+
The rules in the default simplify applies simple constant elimination and trigonometric identities.
159+
160+
If you read the previous section on the rules DSL, you should be able to read and understand the [rules](https://github.com/JuliaSymbolics/SymbolicUtils.jl/blob/master/src/simplify_rules.jl) that are used by `simplify`.
161+
162+
## Code generation
163+
164+
**Experimental feature**
165+
166+
It is common to want to generate executable code from symbolic expressions and blocks of them. We are working on experimental support for turning Symbolic expressions into executable functions with specific focus on array input and output and performance which is critical to the Differential Equations ecosystem which is making heavy use of this package.
167+
168+
See [Code generation](/codegen/) for more about this.
169+
170+
## Learn more
171+
172+
If you have a package that you would like to utilize rule-based rewriting in, look at the suggestions in the [Interfacing](/interface/) section to find out how you can do that without any fundamental changes to your package. Look at the [API documentation](/api/) for docstrings about specific functions or macros.
173+
174+
Head over to the github repository to ask questions and [report problems](https://github.com/JuliaSymbolics/SymbolicUtils.jl)! Join the [Zulip stream](https://julialang.zulipchat.com/#narrow/stream/236639-symbolic-programming) to chat!
175+

docs/src/manual/codegen.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Code generation
2+
3+
**Note: this feature is experimental and the API might change frequently**
4+
5+
`toexpr(ex)` turns any expression (`ex`) into the equivalent `Expr` which is suitable for `eval`. The `SymbolicUtils.Code` module provides some combinators which provides the ability to construct more complex expressions than just function calls. These include:
6+
7+
8+
9+
- Let blocks
10+
- Functions with arguments and keyword arguments
11+
- Functions with arguments which are to be de-structured
12+
- Expressions that set array elements in-place
13+
- Expressions that create an array similar in type to a reference array (currently supports `Array`, `StaticArrays.SArray`, and `LabelledArrays.SLArray`)
14+
- Expressions that create sparse arrays
15+
16+
**Do `using SymbolicUtils.Code` to get the following bindings**
17+
18+
## `toexpr`
19+
20+
```@docs
21+
SymbolicUtils.Code.toexpr
22+
```
23+
24+
## Code Combinators
25+
26+
These are all exported when you do `using SymbolicUtils.Code`
27+
28+
```@docs
29+
SymbolicUtils.Code.Assignment
30+
SymbolicUtils.Code.Let
31+
SymbolicUtils.Code.Func
32+
SymbolicUtils.Code.SpawnFetch
33+
SymbolicUtils.Code.SetArray
34+
SymbolicUtils.Code.MakeArray
35+
SymbolicUtils.Code.MakeSparseArray
36+
SymbolicUtils.Code.MakeTuple
37+
SymbolicUtils.Code.LiteralExpr
38+
```

docs/src/manual/interface.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Interfacing with SymbolicUtils.jl
2+
3+
This section is for Julia package developers who may want to use the `simplify` and rule rewriting system on their own expression types.
4+
5+
## Defining the interface
6+
7+
SymbolicUtils matchers can match any Julia object that implements an interface to traverse it as a tree. The interface in question, is defined in the [TermInterface.jl](https://github.com/JuliaSymbolics/TermInterface.jl) package. Its purpose is to provide a shared interface between various symbolic programming Julia packages.
8+
9+
In particular, you should define methods from TermInterface.jl for an expression tree type `T` with symbol types `S` to work
10+
with SymbolicUtils.jl
11+
12+
You can read the documentation of [TermInterface.jl](https://github.com/JuliaSymbolics/TermInterface.jl) on the [Github repository](https://github.com/JuliaSymbolics/TermInterface.jl).
13+
14+
## SymbolicUtils.jl only methods
15+
16+
`promote_symtype(f, arg_symtypes...)`
17+
18+
Returns the appropriate output type of applying `f` on arguments of type `arg_symtypes`.

0 commit comments

Comments
 (0)