Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
283 commits
Select commit Hold shift + click to select a range
6cb9c1c
refactor: use `Polyform` instead of `Add` in several places
AayushSabharwal Aug 6, 2025
a72c4e6
refactor: use `try..finally` for `@manually_scope`
AayushSabharwal Aug 6, 2025
e0f4e3b
refactor: use `Polyform` instead of `Mul`
AayushSabharwal Aug 7, 2025
e1ed1dd
refactor: use `Polyform` in `^` implementation
AayushSabharwal Aug 7, 2025
329fb43
refactor: remove `AddOrMul` variant
AayushSabharwal Aug 7, 2025
13ebf88
refactor: remove `Pow` variant
AayushSabharwal Aug 7, 2025
5ce6aaa
refactor: remove old `PolyForm`, rewrite `expand`
AayushSabharwal Aug 8, 2025
6aaa59e
feat: add `get_mul_coefficient`
AayushSabharwal Aug 8, 2025
41912f1
fix: fix coefficient elimination in `Div`
AayushSabharwal Aug 8, 2025
7d8a981
refactor: ensure ordering of unsafes in `add_worker`, `mul_worker`
AayushSabharwal Aug 8, 2025
3deeaa6
fix: handle edge case in `^` implementation
AayushSabharwal Aug 8, 2025
e73af3b
refactor: rewrite other algorithms in `polyform.jl`
AayushSabharwal Aug 8, 2025
c82c78c
test: update basics test to new variant structure
AayushSabharwal Aug 8, 2025
e06fec2
test: update rewrite tests to new variant structure
AayushSabharwal Aug 9, 2025
5cd9c83
test: update polyform tests to new variant structure
AayushSabharwal Aug 9, 2025
f919417
fix: handle empty iterable edge case in `add_worker`
AayushSabharwal Aug 10, 2025
ba0fe81
feat: implement `Base.empty!` for `SmallVec`, `Backing`
AayushSabharwal Aug 10, 2025
b91b2c8
test: update codegen tests to new variant structure
AayushSabharwal Aug 10, 2025
40c734a
test: update hashconsing tests to new variant structure
AayushSabharwal Aug 10, 2025
588c424
refactor: no need to disable hashconsing in `fraction_iszero`
AayushSabharwal Aug 14, 2025
2113246
refactor: avoid extra allocations in Postwalk/Prewalk
AayushSabharwal Aug 14, 2025
3d840b9
feat: implement `getindex` with `Vector{Int}` for small arrays
AayushSabharwal Aug 14, 2025
1e61a70
feat: implement `copy` for small arrays
AayushSabharwal Aug 14, 2025
e6d5a1f
fix: fix implementation of `hash`
AayushSabharwal Aug 14, 2025
e081b5a
refactor: `@nospecialize` in `maketerm`
AayushSabharwal Aug 14, 2025
2db015b
refactor: performance improvements to `basicsymbolic` function
AayushSabharwal Aug 14, 2025
cfae4b6
refactor: rewrite `mul_worker`
AayushSabharwal Aug 14, 2025
0f34baa
refactor: use `Rewriters` for `substitute`
AayushSabharwal Aug 14, 2025
c61f65b
TEMP COMMIT: use branches of polynomial packages
AayushSabharwal Aug 20, 2025
b0aa6bb
refactor: reove old `makepow` function
AayushSabharwal Aug 20, 2025
aa62103
Merge pull request #766 from AayushSabharwal/as/fix-threading
AayushSabharwal Aug 11, 2025
cb9caa6
Merge pull request #771 from AayushSabharwal/as/poly-variant
AayushSabharwal Aug 20, 2025
76fc4e2
TEMP COMMIT: run benchmark CI on PR to `v4`
AayushSabharwal Aug 26, 2025
cfa2428
feat: initial implementation of `Const` variant
AayushSabharwal Aug 4, 2025
527dcbe
fix: handle `Const` in `_iszero`, `_isone`
AayushSabharwal Aug 4, 2025
aa212bb
fix: handle `Const` in `occursin`
AayushSabharwal Aug 4, 2025
9b0a2af
feat: allow creating empty `SmallVec` with `undef`
AayushSabharwal Aug 4, 2025
40d72d1
fix: fix `map` on `SmallVec`
AayushSabharwal Aug 4, 2025
e549b57
fix: handle `Const` in rules
AayushSabharwal Aug 4, 2025
9613d37
fix: handle `Const` in `polyize`
AayushSabharwal Aug 4, 2025
26681e1
fix: fix `add_with_div`
AayushSabharwal Aug 4, 2025
1a555d1
fix: handle `Const` in ordering
AayushSabharwal Aug 4, 2025
d78b7d2
fix: handle `Const` in rewriters, improve performance
AayushSabharwal Aug 4, 2025
34e4cf1
fix: handle `Const` in tests
AayushSabharwal Aug 4, 2025
db9a4bc
refactor: export `unwrap_const`
AayushSabharwal Aug 4, 2025
e6e95e4
fix: improve inference of `assoc`
AayushSabharwal Aug 4, 2025
2edf5e3
fix: fix codegen involving `Const`
AayushSabharwal Aug 22, 2025
7400f93
fix: fix predicate and literal matching involving `Const`
AayushSabharwal Aug 22, 2025
4cb9ba2
fix: fix argument ordering involving `Const`
AayushSabharwal Aug 22, 2025
1dcc25a
fix: fix `substitute` folding involving `Const`
AayushSabharwal Aug 22, 2025
8c7e222
fix: fix `arguments` implementation of `Polyform` variant
AayushSabharwal Aug 22, 2025
1d1473c
fix: fix edge case in `subs_poly`
AayushSabharwal Aug 22, 2025
f34de99
fix: fix printing of `Const` variant
AayushSabharwal Aug 22, 2025
1371c1f
fix: handle common factors in `mul_worker`
AayushSabharwal Aug 22, 2025
7eecb2b
fix: handle `Const` variant in `/`
AayushSabharwal Aug 22, 2025
3185877
fix: handle `Const` variant in `^`
AayushSabharwal Aug 22, 2025
4e5f536
fix: canonicalize integer coefficients in `simplify_div`
AayushSabharwal Aug 22, 2025
901851d
fix: handle `Const` variant in `simplify_div`
AayushSabharwal Aug 22, 2025
8c38996
fix: handle `Const` variant in `quick_cancel`
AayushSabharwal Aug 22, 2025
e6affd0
test: improve reproducibility of failing fuzz tests
AayushSabharwal Aug 22, 2025
d5f5e95
test: handle `Const` variant in polyform tests
AayushSabharwal Aug 22, 2025
e9b366d
test: handle `Const` variant in rewrite tests
AayushSabharwal Aug 22, 2025
c70e9a8
test: update codegen tests
AayushSabharwal Aug 22, 2025
f820fca
refactor: use `copy_if_mutable` instead of `deepcopy`
AayushSabharwal Aug 25, 2025
b5540bc
fix: fix codegen involving `Const`
AayushSabharwal Aug 25, 2025
be9ec32
refactor: slots and segments are no longer `Symbolic`
AayushSabharwal Aug 25, 2025
e54f7ea
fix: fix `quick_cancel` for `Const` variant
AayushSabharwal Aug 25, 2025
153287c
refactor: improve `Walk` performance
AayushSabharwal Aug 25, 2025
6b95b96
refactor: make struct fields more concretely typed
AayushSabharwal Aug 25, 2025
09c13f2
fix: handle `Const` in `subs_poly`
AayushSabharwal Aug 25, 2025
1425c7b
fix: handle `Const` in `arguments`
AayushSabharwal Aug 25, 2025
964f303
fix: handle `Const` variant in `term`
AayushSabharwal Aug 25, 2025
91b426a
refactor: minor refactor of `metadata`
AayushSabharwal Aug 25, 2025
9206417
fix: handle `Const` in `^`
AayushSabharwal Aug 25, 2025
c743a08
refactor: minor performance improvement to `operation`
AayushSabharwal Aug 25, 2025
55617ef
test: update tests according to new Rewriter wrapping
AayushSabharwal Aug 25, 2025
da799ec
test: update cache tests to handle `Const` properly
AayushSabharwal Aug 25, 2025
e97136b
refactor: update BSImpl to use type tag instead of parametric `symtype`
AayushSabharwal Aug 28, 2025
ce2f111
fix: don't try to handle partial polyvar name collisions
AayushSabharwal Aug 28, 2025
33f8f12
refactor: add and use `_name_as_operator` for polyvar naming
AayushSabharwal Aug 28, 2025
f7ab05d
refactor: `ArgsT` and `ROArgsT` are parametric
AayushSabharwal Aug 28, 2025
7df8dc5
refactor: update `symtype`, symbolic_type` and add `vartype`
AayushSabharwal Aug 28, 2025
595ebb3
fix: fix `ConstructionBase`-esque methods
AayushSabharwal Aug 28, 2025
dd85bed
refactor: update `isequal` to new struct type
AayushSabharwal Aug 28, 2025
9cdd36a
fix: fix `swap_polynomial_vars`
AayushSabharwal Aug 28, 2025
a00ba01
fix: update `hash` to new struct type
AayushSabharwal Aug 28, 2025
b27cb31
refactor: fix `nameof` type annotation
AayushSabharwal Aug 28, 2025
e519436
docs: add TODO
AayushSabharwal Aug 28, 2025
db30e2c
refactor: fix `SmallVec` usage on new struct type
AayushSabharwal Aug 28, 2025
2634558
refactor: remove `maybe_const`, `closest_const`
AayushSabharwal Aug 28, 2025
4055797
refactor: update `parse_args`
AayushSabharwal Aug 28, 2025
95cacdb
feat: `BSImpl.Const` ctor replaces `maybe_const`, `closest_const`
AayushSabharwal Aug 28, 2025
0476657
refactor: remove `abstract type Symbolic`
AayushSabharwal Aug 26, 2025
b2b8ccb
refactor: update `BSImpl.Variant` constructors
AayushSabharwal Aug 28, 2025
f28c027
Merge pull request #761 from JuliaSymbolics/as/const-variant
AayushSabharwal Aug 26, 2025
8f38aaf
refactor: update `Const`, `Sym`, `Term`, `Polyform`, `Div` ctors
AayushSabharwal Aug 28, 2025
f7b4e53
refactor: use dispatch in `unwrap_const`
AayushSabharwal Aug 28, 2025
5832ff5
refactor: remove dead code
AayushSabharwal Aug 28, 2025
606aa1e
refactor: update printing
AayushSabharwal Aug 28, 2025
21fb411
refactor: update `FnType` implementation
AayushSabharwal Aug 28, 2025
9332bef
fixup! refactor: update printing
AayushSabharwal Aug 28, 2025
ac5b46b
feat: allow specifying `vartype` in `@syms`
AayushSabharwal Aug 28, 2025
4af9424
refactor: update arithmetic to new struct variant
AayushSabharwal Aug 28, 2025
bf48936
refactor: update `term`, `basicsymbolic`
AayushSabharwal Aug 28, 2025
b16abe1
refactor: update `subs_poly` to new struct type
AayushSabharwal Aug 28, 2025
5cf3166
refactor: update `arguments` and `sorted_arguments` to new struct type
AayushSabharwal Aug 28, 2025
015693d
refactor: update `substitute` to new struct type
AayushSabharwal Aug 28, 2025
caf2d8a
feat: support `resize!` for small arrays
AayushSabharwal Aug 28, 2025
3f5302c
refactor: minor improvement to `is_operation`
AayushSabharwal Aug 28, 2025
fe6cd41
refactor: update rules to new struct type
AayushSabharwal Aug 28, 2025
889cf79
refactor: update matchers to new struct type
AayushSabharwal Aug 28, 2025
20d5f9d
refactor: update `to_poly!` to new struct type
AayushSabharwal Aug 28, 2025
15c33bc
refactor: update `expand` to new struct type
AayushSabharwal Aug 28, 2025
21dc1de
refactor: update `simplify_div` to new struct type
AayushSabharwal Aug 28, 2025
0ebf917
refactor: update `quick_cancel` to new struct type
AayushSabharwal Aug 28, 2025
24722f9
refactor: update `add_with_div` to new struct type
AayushSabharwal Aug 28, 2025
8197054
refactor: update fraction manipulation to new struct type
AayushSabharwal Aug 28, 2025
873d873
refactor: update `@number_methods` calls for `BasicSymbolic`
AayushSabharwal Aug 28, 2025
f48b581
refactor: update `rem2pi`, `inv`, `literal_pow`
AayushSabharwal Aug 28, 2025
71b7ac7
refactor: fix `promote_symtype` definitions for monadic functions
AayushSabharwal Aug 28, 2025
cc0461e
refactor: update trivial array operation definition
AayushSabharwal Aug 28, 2025
8e76f85
refactor: update `real`, `conj`, `imag` and `adjoint` definitions
AayushSabharwal Aug 28, 2025
8210c0d
refactor: update comparison operation implementations
AayushSabharwal Aug 28, 2025
e6ec94b
refactor: update negation operator implementations
AayushSabharwal Aug 28, 2025
a688c22
refactor: update negation operator implementations
AayushSabharwal Aug 28, 2025
6ce11a4
refactor: update `size`, `ndims`, `length` and `broadcastable` implem…
AayushSabharwal Aug 28, 2025
419eead
refactor: improve type-stability of matchers
AayushSabharwal Aug 28, 2025
71573d5
refactor: update codegen to new struct type
AayushSabharwal Aug 28, 2025
6bb7df2
test: update tests to new struct type
AayushSabharwal Aug 28, 2025
5fb6d1a
fix: canonicalize/clean polynomials when constructing `Polyform`
AayushSabharwal Aug 28, 2025
33ba1b2
fix: make `hash` and `isequal` deterministic
AayushSabharwal Aug 28, 2025
1181f77
refactor: fix potential dynamic dispatch when calling `unwrap_const`
AayushSabharwal Aug 28, 2025
1ef8d6f
refactor: fix type-stability of `assoc`
AayushSabharwal Aug 28, 2025
6a3e9fb
fix: fix some inference issues
AayushSabharwal Aug 28, 2025
9bb08fd
test: add extensive inference tests
AayushSabharwal Aug 28, 2025
547ae2d
refactor: use task-local preallocated buffer in `mul_worker`
AayushSabharwal Aug 28, 2025
ac65416
refactor: improve type-stability of WCS
AayushSabharwal Aug 28, 2025
ff8da7b
refactor: improve allocations in `simplify_div`
AayushSabharwal Aug 28, 2025
35639a7
test: update tests
AayushSabharwal Aug 28, 2025
f4a4dfe
refactor: remove `partial_polyvars` from `Polyform` variant
AayushSabharwal Aug 29, 2025
b839a94
refactor: make polynomial `hash` and `isequal` independent of variabl…
AayushSabharwal Aug 29, 2025
2795a18
refactor: do not `cleanpoly!` in `BSImpl.Polyform`, avoid copies
AayushSabharwal Aug 29, 2025
e7dab6c
fix: bug fix in `coeff_dict_to_term`
AayushSabharwal Aug 29, 2025
90854cc
benchmark: add arithmetic benchmarks
AayushSabharwal Aug 29, 2025
e5f7245
fix: fix bug in polynomial subtraction
AayushSabharwal Aug 29, 2025
0b56790
ci: improve benchmark workflow script
AayushSabharwal Aug 29, 2025
662203b
ci: run benchmarks using script in PR
AayushSabharwal Aug 29, 2025
9481f41
refactor: minor `substitute` performance improvement
AayushSabharwal Aug 29, 2025
080acf6
refactor: move `@syms` to its own file
AayushSabharwal Aug 29, 2025
14c13c0
test: fix `substitute` tests
AayushSabharwal Aug 29, 2025
27594b4
refactor: remove unnecessary deps
AayushSabharwal Aug 29, 2025
8af6e8d
Merge pull request #781 from JuliaSymbolics/as/type-tag
AayushSabharwal Aug 29, 2025
19e1c95
refactor: move adjoint to ChainRulesCoreExt
AayushSabharwal Aug 29, 2025
d1ea87d
ci: remove bad CI config
AayushSabharwal Aug 29, 2025
6d4fe85
refactor: move printing to its own file
AayushSabharwal Aug 29, 2025
47a7cf8
Merge pull request #784 from JuliaSymbolics/as/restructuring
AayushSabharwal Sep 1, 2025
0f6a9ab
refactor: revert `Polyform` to `AddMul`
AayushSabharwal Sep 1, 2025
81478c7
refactor: update tests to use `AddMul`
AayushSabharwal Sep 1, 2025
d66bf47
ci: fix incorrect benchmark phrasing
AayushSabharwal Sep 1, 2025
570374c
refactor: improve `hash`, `isequal` performance with some manual disp…
AayushSabharwal Sep 2, 2025
27df55f
ci: fix misleading benchmarks
AayushSabharwal Sep 2, 2025
b19b05b
Merge pull request #786 from JuliaSymbolics/as/revert
AayushSabharwal Sep 2, 2025
13dde72
refactor: remove `issafecanon` and `unsafes` handling
AayushSabharwal Sep 4, 2025
824c224
refactor: store `ndims` in `Unknown`, add `shape` function
AayushSabharwal Sep 3, 2025
04e663b
feat: improve `@syms` syntax and parsing
AayushSabharwal Sep 2, 2025
8dd75c7
feat: propagate shape when calling symbolics
AayushSabharwal Sep 2, 2025
37193c0
feat: add `Bool` to `SCALARS`
AayushSabharwal Sep 3, 2025
4fc06e5
refactor: use new `shape` in `size`, `length`, `ndims`
AayushSabharwal Sep 3, 2025
52a8f2b
feat: define `promote_shape`
AayushSabharwal Sep 3, 2025
99bd238
fix: generalize `promoted_symtype`
AayushSabharwal Sep 4, 2025
904043d
feat: support array addition
AayushSabharwal Sep 3, 2025
6e04fc2
fix: remove accidential code duplication
AayushSabharwal Sep 3, 2025
bc0d125
feat: support array multiplication
AayushSabharwal Sep 4, 2025
f34a99e
refactor: refactor symtype checks in `/`
AayushSabharwal Sep 4, 2025
f7a5a71
feat: support array exponentiation
AayushSabharwal Sep 4, 2025
20f42ff
feat: support `insert!` for `SmallVec`
AayushSabharwal Sep 4, 2025
afa6510
test: comprehensively test array arithmetic
AayushSabharwal Sep 4, 2025
1aab0d1
fix: improve `getindex` inference for `Backing`
AayushSabharwal Sep 4, 2025
2be68b5
refactor: fix `hash_addmuldict`
AayushSabharwal Sep 4, 2025
e4e6c70
refactor: manual dispatch in `_numeric_or_arrnumeric_symtype`
AayushSabharwal Sep 4, 2025
74a14a6
refactor: improve `hash` performance for `SmallVec`
AayushSabharwal Sep 4, 2025
ac56354
refactor: improve `hash` performance for `BasicSymbolic`
AayushSabharwal Sep 4, 2025
8e317f4
fix: fix `Div` for non-scalar symtype
AayushSabharwal Sep 5, 2025
18d384c
feat: implement array division
AayushSabharwal Sep 5, 2025
dbaf2cb
test: test array division
AayushSabharwal Sep 5, 2025
abbbe7d
feat: define `shape(::Colon)` differently for indexing
AayushSabharwal Sep 5, 2025
79950b4
fix: handle zero denominator in `Div`
AayushSabharwal Sep 5, 2025
c45ea89
feat: implement `getindex` for symbolic arrays
AayushSabharwal Sep 5, 2025
f048c3b
test: test symbolic `getindex`
AayushSabharwal Sep 5, 2025
3b5a660
fix: canonicalize coefficients in `mul_worker`
AayushSabharwal Sep 8, 2025
98a602c
fix: remove old `BasicSymbolic * Array` methods
AayushSabharwal Sep 8, 2025
4421504
feat: define promotion and conversion to `BasicSymbolic`
AayushSabharwal Sep 8, 2025
19858d2
feat: turn arrays of symbolics into `hvncat` terms in `Const`
AayushSabharwal Sep 8, 2025
be9a45a
feat: specialize `getindex` for `hvncat` terms
AayushSabharwal Sep 8, 2025
f4d83cb
feat: handle arrays of symbolics in symtype checking functions
AayushSabharwal Sep 8, 2025
6e96bb2
feat: support `+` with arrays of symbolics
AayushSabharwal Sep 8, 2025
3330b88
feat: support `-` with arrays of symbolics
AayushSabharwal Sep 8, 2025
96e1639
feat: support `*` with arrays of symbolics
AayushSabharwal Sep 8, 2025
77a3a18
feat: support `/`, `//`, `\` with arrays of symbolics
AayushSabharwal Sep 8, 2025
707afe8
feat: support `^` with arrays of symbolics
AayushSabharwal Sep 8, 2025
8d1a4ea
feat: improve `getindex` on tree-ified arrays of symbolics
AayushSabharwal Sep 8, 2025
425dcca
test: test arithmetic on arrays of symbolics
AayushSabharwal Sep 8, 2025
7ed3704
feat: implement `eachindex` and `collect` for `BasicSymbolic`
AayushSabharwal Sep 9, 2025
a176ec8
feat: allow indexing `BasicSymbolic` with `CartesianIndex`
AayushSabharwal Sep 9, 2025
da80889
fix: remove automatic promotion to `BasicSymbolic` in array literals
AayushSabharwal Sep 9, 2025
60cd853
fix: retain metadata in `arguments`
AayushSabharwal Sep 4, 2025
0920887
feat: add `BS[...]` for easy array-of-symbolic literals
AayushSabharwal Sep 9, 2025
d337c66
fix: fix `hash` implementation
AayushSabharwal Sep 8, 2025
df3fc65
Merge pull request #790 from JuliaSymbolics/as/rm-issafecanon
AayushSabharwal Sep 4, 2025
50c87c3
test: test new array literal syntax
AayushSabharwal Sep 9, 2025
2029175
Merge pull request #791 from JuliaSymbolics/as/fix-hash
AayushSabharwal Sep 8, 2025
b09b432
feat: add `search_variables!`
AayushSabharwal Sep 9, 2025
8d949f9
Merge pull request #789 from JuliaSymbolics/as/array-ops
AayushSabharwal Sep 9, 2025
380c579
feat: add `ArrayOp`
AayushSabharwal Sep 9, 2025
6a60d91
feat: add `@arrayop`
AayushSabharwal Sep 9, 2025
0df4e50
feat: add pretty-printing for `ArrayOp`
AayushSabharwal Sep 9, 2025
4e3440a
refactor: use `-1` as unknown ndims
AayushSabharwal Sep 10, 2025
5072621
fix: ensure `Base.size` is always a `Tuple` for known sizes
AayushSabharwal Sep 10, 2025
615571b
feat: implement broadcasting using `ArrayOp`
AayushSabharwal Sep 10, 2025
ed2ab27
refactor: improve `empty!` for `Backing{T}`
AayushSabharwal Sep 10, 2025
5661ce3
feat: allow arbitrary `getindex` on `Symbol`
AayushSabharwal Sep 10, 2025
260e4cb
feat: initial codegen for `ArrayOp`
AayushSabharwal Sep 10, 2025
c961d96
feat: support `inv` on arrays
AayushSabharwal Sep 11, 2025
fcc2805
fix: fix `conj` on `arrays
AayushSabharwal Sep 11, 2025
689f8e7
feat: implement `adjoint` for arrays
AayushSabharwal Sep 11, 2025
9beaa3f
fix: fix `ifelse` implementation
AayushSabharwal Sep 11, 2025
d084c4e
feat: support iterating `BasicSymbolic`
AayushSabharwal Sep 11, 2025
39e98e4
feat: support `substitute` on arrays
AayushSabharwal Sep 11, 2025
205962f
feat: implement `scalarize`
AayushSabharwal Sep 11, 2025
2da05ba
fix: fix `@syms` creating function returning array
AayushSabharwal Sep 11, 2025
d04fdee
fix: fix `shape` for non-array non-numeric values
AayushSabharwal Sep 11, 2025
4dcf8af
fix: propagate shape in `term`
AayushSabharwal Sep 11, 2025
cbeda4f
fix: fix matrix multiplication shape calculation
AayushSabharwal Sep 11, 2025
24f8748
fix: fix multiplication with arrays of symbolics
AayushSabharwal Sep 11, 2025
1b0d02d
feat: special-case `ArrayOp` in `getindex`
AayushSabharwal Sep 11, 2025
977b888
feat: allow `getindex` on scalar symbolics
AayushSabharwal Sep 11, 2025
6846512
fix: fix `Const ^ Const`
AayushSabharwal Sep 11, 2025
7d25668
feat: create `ArrayOp` for matmul
AayushSabharwal Sep 11, 2025
6dc5a19
test: add arrayop tests
AayushSabharwal Sep 11, 2025
52cf0d4
feat: add shape promotion methods for default functions
AayushSabharwal Sep 11, 2025
48698e4
fix: fix rules with new `term` shape propagation
AayushSabharwal Sep 11, 2025
9ec63f5
feat: add `query!`
AayushSabharwal Sep 11, 2025
302940f
test: update tests to new `ArrayOp` representation of matmul
AayushSabharwal Sep 11, 2025
d221915
Merge pull request #793 from JuliaSymbolics/as/arrayop
AayushSabharwal Sep 11, 2025
e2a4db8
fix: remove vendored `WeakCacheSets`
AayushSabharwal Sep 11, 2025
500ad84
fix: use `vartype` instead of `symtype` in matchers
AayushSabharwal Sep 11, 2025
3bc17c9
fix: handle `Const` in new matchers
AayushSabharwal Sep 12, 2025
4d5a4d6
fix: fix handling of negative coefficient exponent
AayushSabharwal Sep 12, 2025
af5891c
test: fix failing tests
AayushSabharwal Sep 12, 2025
cbf10c7
test: make rewrite tests independent of hash order
AayushSabharwal Sep 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 14 additions & 67 deletions .github/workflows/benchmark_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,75 +4,22 @@ on:
pull_request_target:
branches:
- master
- v4

permissions:
pull-requests: write

jobs:
generate_plots:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: "1"
- uses: julia-actions/cache@v2
- name: Extract Package Name from Project.toml
id: extract-package-name
run: |
PACKAGE_NAME=$(grep "^name" Project.toml | sed 's/^name = "\(.*\)"$/\1/')
echo "::set-output name=package_name::$PACKAGE_NAME"
- name: Build AirspeedVelocity
env:
JULIA_NUM_THREADS: 2
run: |
# Lightweight build step, as sometimes the runner runs out of memory:
julia -e 'ENV["JULIA_PKG_PRECOMPILE_AUTO"]=0; import Pkg; Pkg.add("AirspeedVelocity")'
julia -e 'ENV["JULIA_PKG_PRECOMPILE_AUTO"]=0; import Pkg; Pkg.build("AirspeedVelocity")'
- name: Add ~/.julia/bin to PATH
run: |
echo "$HOME/.julia/bin" >> $GITHUB_PATH
- name: Run benchmarks
run: |
echo $PATH
ls -l ~/.julia/bin
mkdir results
benchpkg ${{ steps.extract-package-name.outputs.package_name }} --rev="${{github.event.repository.default_branch}},${{github.event.pull_request.head.sha}}" --url=${{ github.event.repository.clone_url }} --bench-on="${{github.event.repository.default_branch}}" --output-dir=results/ --tune --exeflags="-O3 --threads=auto"
- name: Create plots from benchmarks
run: |
mkdir -p plots
benchpkgplot ${{ steps.extract-package-name.outputs.package_name }} --rev="${{github.event.repository.default_branch}},${{github.event.pull_request.head.sha}}" --npart=10 --format=png --input-dir=results/ --output-dir=plots/
- name: Upload plot as artifact
uses: actions/upload-artifact@v4
with:
name: plots
path: plots
- name: Create markdown table from benchmarks
run: |
benchpkgtable ${{ steps.extract-package-name.outputs.package_name }} --rev="${{github.event.repository.default_branch}},${{github.event.pull_request.head.sha}}" --input-dir=results/ --ratio > table.md
echo '### Benchmark Results' > body.md
echo '' >> body.md
echo '' >> body.md
cat table.md >> body.md
echo '' >> body.md
echo '' >> body.md
echo '### Benchmark Plots' >> body.md
echo 'A plot of the benchmark results have been uploaded as an artifact to the workflow run for this PR.' >> body.md
echo 'Go to "Actions"->"Benchmark a pull request"->[the most recent run]->"Artifacts" (at the bottom).' >> body.md

- name: Find Comment
uses: peter-evans/find-comment@v2
id: fcbenchmark
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Benchmark Results

- name: Comment on PR
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ steps.fcbenchmark.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body-path: body.md
edit-mode: replace
bench:
name: "Benchmarks"
strategy:
matrix:
version:
- "1"
- "lts"
runs-on: ubuntu-latest
steps:
- uses: MilesCranmer/AirspeedVelocity.jl@action-v1
with:
julia-version: "${{ matrix.version }}"
script: "benchmark/benchmarks.jl"
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
pull_request:
branches:
- master
- v4
push:
branches:
- master
Expand All @@ -20,6 +21,7 @@ jobs:
version:
- 'min'
- '1'
fail-fast: false
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
Expand Down
28 changes: 21 additions & 7 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,67 @@ version = "3.32.0"
[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
Bijections = "e2ed5e7c-b2de-5872-ae92-c73ca462fb04"
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
ConcurrentUtilities = "f0e56b4a-5159-44fe-b623-3e5288b988bb"
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
DynamicPolynomials = "7c1d4256-1411-5781-91ec-d7bc3513ac07"
EnumX = "4e289a0a-7415-4d19-859d-a7e5c4648b56"
ExproniconLite = "55351af7-c7e9-48d6-89ff-24e801d99491"
LabelledArrays = "2ee39098-c373-598a-b85f-a56591580800"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
Moshi = "2e0e35c7-a2e4-4343-998d-7ef72827ed2d"
MultivariatePolynomials = "102ac46a-7ee4-5c85-9060-abc95bfdeaa3"
MutableArithmetics = "d8a4904e-b15c-11e9-3269-09a3773c0cb0"
NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
ReadOnlyArrays = "988b38a3-91fc-5605-94a2-ee2116b3bd83"
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
SymbolicIndexingInterface = "2efcf032-c050-4f8e-a9bb-153293bab1f5"
TaskLocalValues = "ed4db957-447d-4319-bfb6-7fa9ae7ecf34"
TermInterface = "8ea1fca8-c5ef-4a55-8b96-4e9afe9c9a3c"
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
Unityper = "a7c27f48-0311-42f6-a7f8-2c11e75eb415"
WeakCacheSets = "d30d5f5c-d141-4870-aa07-aabb0f5fe7d5"

[weakdeps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
LabelledArrays = "2ee39098-c373-598a-b85f-a56591580800"
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"

[sources]
DynamicPolynomials = {rev = "as/new-poly-merge", url = "https://github.com/AayushSabharwal/DynamicPolynomials.jl"}
MultivariatePolynomials = {rev = "as/poly-merge-nonconcrete", url = "https://github.com/AayushSabharwal/MultivariatePolynomials.jl"}
MutableArithmetics = {rev = "as+bl/simplify_promote_type_fallback", url = "https://github.com/AayushSabharwal/MutableArithmetics.jl"}

[extensions]
SymbolicUtilsChainRulesCoreExt = "ChainRulesCore"
SymbolicUtilsLabelledArraysExt = "LabelledArrays"
SymbolicUtilsReverseDiffExt = "ReverseDiff"

[compat]
AbstractTrees = "0.4"
ArrayInterface = "7.8"
Bijections = "0.1.2, 0.2"
ChainRulesCore = "1"
Combinatorics = "1 - 1.0.2"
ConcurrentUtilities = "2.5.0"
ConstructionBase = "1.5.7"
DataStructures = "0.18, 0.19"
DocStringExtensions = "0.8, 0.9"
DynamicPolynomials = "0.5, 0.6"
EnumX = "1.0.5"
ExproniconLite = "0.10.14"
LabelledArrays = "1.5"
LinearAlgebra = "1"
MacroTools = "0.5.16"
Moshi = "0.3.6"
MultivariatePolynomials = "0.5"
MutableArithmetics = "1.6.4"
NaNMath = "0.3, 1.1.2"
OhMyThreads = "0.7"
ReadOnlyArrays = "0.2.0"
ReverseDiff = "1"
RuntimeGeneratedFunctions = "0.5.13"
Setfield = "0.7, 0.8, 1"
Expand All @@ -59,8 +75,6 @@ StaticArrays = "0.12, 1.0"
SymbolicIndexingInterface = "0.3"
TaskLocalValues = "0.1.2"
TermInterface = "2.0"
TimerOutputs = "0.5"
Unityper = "0.1.2"
julia = "1.10"

[extras]
Expand Down
9 changes: 9 additions & 0 deletions bench.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using SymbolicUtils, BenchmarkTools

@syms a b c d e f g h i
ex = (f + ((((g*(c^2)*(e^2)) / d - e*h*(c^2)) / b + (-c*e*f*g) / d + c*e*i) /
(i + ((c*e*g) / d - c*h) / b + (-f*g) / d) - c*e) / b +
((g*(f^2)) / d + ((-c*e*f*g) / d + c*f*h) / b - f*i) /
(i + ((c*e*g) / d - c*h) / b + (-f*g) / d)) / d

@benchmark SymbolicUtils.fraction_iszero($ex)
4 changes: 4 additions & 0 deletions benchmark/Project.toml
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
[deps]

[sources]
WeakCacheSets = {url="https://github.com/JuliaCollections/WeakCacheSets.jl"}
Moshi = {url="https://github.com/AayushSabharwal/Moshi.jl", rev="as/mutable-adt"}
63 changes: 49 additions & 14 deletions benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ SUITE = BenchmarkGroup()

@syms a b c d x y[1:3] z[1:2, 1:2]; Random.seed!(123);

function random_term(len; atoms, funs, fallback_atom=1)
xs = rand(atoms, len)
while length(xs) > 1
xs = map(Iterators.partition(xs, 2)) do xy
x = xy[1]; y = get(xy, 2, fallback_atom)
rand(funs)(x, y)
end
end
xs[]
end

let r = @rule(~x => ~x), rs = RuleSet([r]),
acr = @rule(~x::is_literal_number + ~y => ~y)

Expand Down Expand Up @@ -34,16 +45,6 @@ let r = @rule(~x => ~x), rs = RuleSet([r]),
overhead["simplify"]["noop:Sym"] = @benchmarkable simplify($a)
overhead["simplify"]["noop:Term"] = @benchmarkable simplify($(a+2))

function random_term(len; atoms, funs, fallback_atom=1)
xs = rand(atoms, len)
while length(xs) > 1
xs = map(Iterators.partition(xs, 2)) do xy
x = xy[1]; y = get(xy, 2, fallback_atom)
rand(funs)(x, y)
end
end
xs[]
end
ex1 = random_term(1000, atoms=[a, b, c, d, a^(-1), b^(-1), 1, 2.0], funs=[+, *])
ex2 = random_term(1000, atoms=[a, b, c, d, a^(-1), b^(-1), 1, 2.0], funs=[/, *])

Expand All @@ -55,15 +56,17 @@ let r = @rule(~x => ~x), rs = RuleSet([r]),
overhead["substitute"] = BenchmarkGroup()


overhead["substitute"]["a"] = @benchmarkable substitute(subs_expr, $(Dict(a=>1))) setup=begin
# we use `fold = false` since otherwise it dynamic dispatches to `sin`/`cos` whenever
# both arguments in the contained addition are substituted.
overhead["substitute"]["a"] = @benchmarkable substitute(subs_expr, $(Dict(a=>1)); fold = false) setup=begin
subs_expr = (sin(a+b) + cos(b+c)) * (sin(b+c) + cos(c+a)) * (sin(c+a) + cos(a+b))
end

overhead["substitute"]["a,b"] = @benchmarkable substitute(subs_expr, $(Dict(a=>1, b=>2))) setup=begin
overhead["substitute"]["a,b"] = @benchmarkable substitute(subs_expr, $(Dict(a=>1, b=>2)); fold = false) setup=begin
subs_expr = (sin(a+b) + cos(b+c)) * (sin(b+c) + cos(c+a)) * (sin(c+a) + cos(a+b))
end

overhead["substitute"]["a,b,c"] = @benchmarkable substitute(subs_expr, $(Dict(a=>1, b=>2, c=>3))) setup=begin
overhead["substitute"]["a,b,c"] = @benchmarkable substitute(subs_expr, $(Dict(a=>1, b=>2, c=>3)); fold = false) setup=begin
subs_expr = (sin(a+b) + cos(b+c)) * (sin(b+c) + cos(c+a)) * (sin(c+a) + cos(a+b))
end

Expand Down Expand Up @@ -94,6 +97,38 @@ let
(-f*(g + (-d*g) / d)) / (i + (-c*(h + (-e*g) / d)) / b + (-f*g) / d)) / d
pform["simplify_fractions"] = @benchmarkable simplify_fractions($ex)
pform["iszero"] = @benchmarkable SymbolicUtils.fraction_iszero($ex)
pform["isone"] = @benchmarkable SymbolicUtils.fraction_isone($o)
pform["isone"] = @benchmarkable SymbolicUtils.fraction_isone($ex)
pform["isone:noop"] = @benchmarkable SymbolicUtils.fraction_isone($o)
pform["iszero:noop"] = @benchmarkable SymbolicUtils.fraction_iszero($o)
pform["easy_iszero"] = @benchmarkable SymbolicUtils.fraction_iszero($((b*(h + (-e*g) / d)) / b + (e*g) / d - h))
end

let
arith = SUITE["arithmetic"] = BenchmarkGroup()
atoms = [a, b, c, d, a^2, b^2, a^1.5, (b + c), b^c, 1, 2.0]
funs = [+, *]
exs = [random_term(5; atoms, funs) for _ in 1:50]
@static if isdefined(SymbolicUtils, :SymReal)
arith["addition"] = @benchmarkable SymbolicUtils.add_worker(SymReal, $exs)
elseif isdefined(SymbolicUtils, :add_worker)
arith["addition"] = @benchmarkable SymbolicUtils.add_worker($exs)
else
exs = Tuple(exs)
arith["addition"] = @benchmarkable +($(exs)...)
end

funs = [*, /]
exs = [random_term(5; atoms, funs) for _ in 1:50]
@static if isdefined(SymbolicUtils, :SymReal)
arith["multiplication"] = @benchmarkable SymbolicUtils.mul_worker(SymReal, $exs)
elseif isdefined(SymbolicUtils, :mul_worker)
arith["multiplication"] = @benchmarkable SymbolicUtils.mul_worker($exs)
else
exs = Tuple(exs)
arith["multiplication"] = @benchmarkable *($(exs)...)
end

ex1 = random_term(50; atoms, funs)
ex2 = random_term(50; atoms, funs)
arith["division"] = @benchmarkable $ex1 / $ex2
end
12 changes: 6 additions & 6 deletions docs/src/manual/rewrite.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ r1 = @rule sin(2(~x)) => 2sin(~x)*cos(~x)
r1(sin(2z))

# output
2sin(z)*cos(z)
2cos(z)*sin(z)
```

The `@rule` macro takes a pair of patterns -- the _matcher_ and the _consequent_ (`@rule matcher => consequent`). If an expression matches the matcher pattern, it is rewritten to the consequent pattern. `@rule` returns a callable object that applies the rule to an expression.
Expand All @@ -40,7 +40,7 @@ Slot variable (matcher) is not necessary a single variable:
r1(sin(2*(w-z)))

# output
2cos(w - z)*sin(w - z)
2sin(w - z)*cos(w - z)
```

And can also match a function:
Expand All @@ -61,7 +61,7 @@ r2 = @rule sin(~x + ~y) => sin(~x)*cos(~y) + cos(~x)*sin(~y);
r2(sin(α+β))

# output
sin(β)*cos(α) + cos(β)*sin(α)
cos(β)*sin(α) + sin(β)*cos(α)
```

Now let's say you want to catch the coefficients of a second degree polynomial in z. You can do that with:
Expand Down Expand Up @@ -102,10 +102,10 @@ If you want to match a variable number of subexpressions at once, you will need
@rule(+(~~xs) => ~~xs)(x + y + z)

# output
3-element view(::SymbolicUtils.SmallVec{Any, Vector{Any}}, 1:3) with eltype Any:
z
y
3-element view(::ReadOnlyArrays.ReadOnlyVector{Any, SymbolicUtils.SmallVec{Any, Vector{Any}}}, 1:3) with eltype Any:
x
y
z
```

`~~xs` is a vector of subexpressions matched. You can use it to construct something more useful:
Expand Down
16 changes: 16 additions & 0 deletions ext/SymbolicUtilsChainRulesCoreExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module SymbolicUtilsChainRulesCoreExt

using ChainRulesCore
import ChainRulesCore: rrule
import SymbolicUtils.Code

function rrule(::typeof(Code.create_array), A::Type{<:AbstractArray}, T, u::Val{j}, d::Val{dims}, elems...) where {dims, j}
y = Code.create_array(A, T, u, d, elems...)
function create_array_pullback(Δ)
dx = Δ
(ZeroTangent(), NoTangent(), NoTangent(), NoTangent(), NoTangent(), dx..., ntuple(_ -> NoTangent(), length(elems) - prod(dims) + j)...)
end
y, create_array_pullback
end

end
Loading
Loading