Skip to content

Commit 1d79051

Browse files
Add comprehensive docstrings for all public API functions
This commit adds missing docstrings and updates the API documentation: Added docstrings for core functions: - term: Create symbolic terms - showraw: Display raw structure of expressions - hasmetadata, getmetadata, setmetadata: Metadata manipulation - sorted_arguments: Get canonically sorted arguments Added docstrings for rule system: - @acrule: Associative-commutative rule macro Added docstrings for all rewriter types: - Empty, IfElse, If, Chain, RestartedChain - Fixpoint, Postwalk, Prewalk, PassThrough Added docstrings for code generation utilities: - AtIndex: Array indexing representation - Multithreaded: Threading parallelism type - cse: Common subexpression elimination Updated docs/src/api.md: - Reorganized into logical sections - Added all documented exported symbols - Improved categorization of API elements 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 7e4daa2 commit 1d79051

File tree

5 files changed

+511
-2
lines changed

5 files changed

+511
-2
lines changed

docs/src/api.md

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,118 @@
11
# API Reference
22

33
## Symbols and Terms
4+
5+
### Creating Symbols and Terms
46
```@docs
57
SymbolicUtils.@syms
8+
SymbolicUtils.term
69
SymbolicUtils.Sym
10+
```
11+
12+
### Inspecting Terms
13+
```@docs
714
SymbolicUtils.issym
815
SymbolicUtils.symtype
16+
SymbolicUtils.iscall
17+
SymbolicUtils.operation
18+
SymbolicUtils.arguments
19+
SymbolicUtils.sorted_arguments
20+
SymbolicUtils.showraw
21+
```
22+
23+
### Term Types
24+
```@docs
925
SymbolicUtils.Term
1026
SymbolicUtils.Add
1127
SymbolicUtils.Mul
1228
SymbolicUtils.Pow
29+
```
30+
31+
### Metadata
32+
```@docs
33+
SymbolicUtils.hasmetadata
34+
SymbolicUtils.getmetadata
35+
SymbolicUtils.setmetadata
36+
```
37+
38+
### Type Promotion
39+
```@docs
1340
SymbolicUtils.promote_symtype
1441
```
1542

16-
## Rewriters
43+
## Rewriting System
1744

45+
### Rule Creation
1846
```@docs
1947
@rule
48+
@acrule
49+
```
50+
51+
### Rewriters
52+
```@docs
2053
SymbolicUtils.Rewriters
54+
SymbolicUtils.Rewriters.Empty
55+
SymbolicUtils.Rewriters.IfElse
56+
SymbolicUtils.Rewriters.If
57+
SymbolicUtils.Rewriters.Chain
58+
SymbolicUtils.Rewriters.RestartedChain
59+
SymbolicUtils.Rewriters.Fixpoint
60+
SymbolicUtils.Rewriters.FixpointNoCycle
61+
SymbolicUtils.Rewriters.Postwalk
62+
SymbolicUtils.Rewriters.Prewalk
63+
SymbolicUtils.Rewriters.PassThrough
2164
```
2265

23-
## Simplify
66+
## Simplification and Transformation
2467

2568
```@docs
2669
SymbolicUtils.simplify
2770
SymbolicUtils.expand
2871
SymbolicUtils.substitute
2972
```
3073

74+
## Polynomial Forms
75+
76+
```@docs
77+
SymbolicUtils.PolyForm
78+
SymbolicUtils.simplify_fractions
79+
SymbolicUtils.quick_cancel
80+
SymbolicUtils.flatten_fractions
81+
```
82+
83+
## Code Generation
84+
85+
### Core Functions
86+
```@docs
87+
SymbolicUtils.toexpr
88+
SymbolicUtils.cse
89+
```
90+
91+
### Code Generation Types
92+
```@docs
93+
SymbolicUtils.Assignment
94+
SymbolicUtils.Let
95+
SymbolicUtils.Func
96+
SymbolicUtils.DestructuredArgs
97+
SymbolicUtils.LiteralExpr
98+
SymbolicUtils.ForLoop
99+
```
100+
101+
### Array Operations
102+
```@docs
103+
SymbolicUtils.SetArray
104+
SymbolicUtils.MakeArray
105+
SymbolicUtils.MakeSparseArray
106+
SymbolicUtils.MakeTuple
107+
SymbolicUtils.AtIndex
108+
```
109+
110+
### Parallelism
111+
```@docs
112+
SymbolicUtils.SpawnFetch
113+
SymbolicUtils.Multithreaded
114+
```
115+
31116
## Utilities
32117

33118
```@docs

src/code.jl

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,17 @@ SetArray
446446

447447
SetArray(inbounds, arr, elems) = SetArray(inbounds, arr, elems, false)
448448

449+
"""
450+
AtIndex(i, elem)
451+
452+
Represent an element at a specific index in an array.
453+
454+
This is used internally for array indexing operations in code generation.
455+
456+
# Fields
457+
- `i`: The index
458+
- `elem`: The element at that index
459+
"""
449460
@matchable struct AtIndex <: CodegenPrimitive
450461
i
451462
elem
@@ -666,6 +677,21 @@ function toexpr(a::MakeTuple, st)
666677
:(($(toexpr.(a.elems, (st,))...),))
667678
end
668679

680+
"""
681+
Multithreaded
682+
683+
A parallelism type for `SpawnFetch` that uses Julia's threading system.
684+
685+
When used with `SpawnFetch{Multithreaded}`, expressions are executed
686+
in parallel using `Threads.@spawn`.
687+
688+
# Examples
689+
```julia
690+
julia> SpawnFetch{Multithreaded}([func1, func2], combine_func)
691+
```
692+
693+
See also: [`SpawnFetch`](@ref)
694+
"""
669695
struct Multithreaded end
670696
"""
671697
SpawnFetch{ParallelType}(funcs [, args], reduce)
@@ -837,6 +863,26 @@ end
837863
Perform Common Subexpression Elimination on the given expression `expr`. Return an
838864
equivalent `expr` with optimized computation.
839865
"""
866+
"""
867+
cse(expr)
868+
869+
Perform common subexpression elimination on an expression.
870+
871+
This optimization identifies repeated subexpressions and replaces them with
872+
variables to avoid redundant computation.
873+
874+
# Arguments
875+
- `expr`: The expression to optimize
876+
877+
# Returns
878+
An optimized expression with common subexpressions eliminated
879+
880+
# Examples
881+
```julia
882+
julia> expr = :(sin(x) + sin(x) * cos(y))
883+
julia> cse(expr) # sin(x) is computed only once
884+
```
885+
"""
840886
function cse(expr)
841887
state = CSEState()
842888
newexpr = cse!(expr, state)

0 commit comments

Comments
 (0)