Skip to content

Commit 3ec4b9f

Browse files
Merge pull request #1649 from JuliaSymbolics/as/su-v4
[BREAKING] feat: update to SymbolicUtils@4
2 parents 68565de + 171aedc commit 3ec4b9f

File tree

95 files changed

+3610
-5187
lines changed

Some content is hidden

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

95 files changed

+3610
-5187
lines changed

Project.toml

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Symbolics"
22
uuid = "0c5d862f-8b57-4792-8d23-62f2024744c7"
33
authors = ["Shashi Gowda <[email protected]>"]
4-
version = "6.57.0"
4+
version = "7.0.0"
55

66
[deps]
77
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
@@ -11,25 +11,24 @@ CommonWorldInvalidations = "f70d9fcc-98c5-4d4a-abd7-e4cdeebd8ca8"
1111
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
1212
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
1313
DiffRules = "b552c78f-8df3-52c6-915a-8e097449b14b"
14-
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
1514
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
1615
DomainSets = "5b8099bc-c8ec-5219-889f-1d9e522a28bf"
1716
DynamicPolynomials = "7c1d4256-1411-5781-91ec-d7bc3513ac07"
18-
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
19-
Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
2017
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
2118
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
2219
LogExpFunctions = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
2320
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
2421
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
22+
Moshi = "2e0e35c7-a2e4-4343-998d-7ef72827ed2d"
23+
MultivariatePolynomials = "102ac46a-7ee4-5c85-9060-abc95bfdeaa3"
24+
MutableArithmetics = "d8a4904e-b15c-11e9-3269-09a3773c0cb0"
2525
NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
26-
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
2726
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
27+
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
2828
Primes = "27ebfcd6-29c5-5fa9-bf4b-fb8fc14df3ae"
2929
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
3030
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
3131
RuntimeGeneratedFunctions = "7e49a35a-f44a-4d26-94aa-eba1b4ca6b47"
32-
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
3332
SciMLPublic = "431bcebd-1456-4ced-9d72-93c2757fff0b"
3433
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
3534
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
@@ -42,20 +41,27 @@ TermInterface = "8ea1fca8-c5ef-4a55-8b96-4e9afe9c9a3c"
4241

4342
[weakdeps]
4443
D3Trees = "e3df1716-f71e-5df9-9e2d-98e193103c45"
44+
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
4545
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
4646
Groebner = "0b43b601-686d-58a3-8a1c-6623616c7cd4"
47+
Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
48+
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
4749
Lux = "b2108857-7c20-44ae-9111-449ecde12c47"
4850
Nemo = "2edaba10-b0f1-5616-af89-8c11ac63239a"
51+
PlutoRunner = "dc6b355a-2368-4481-ae6d-ae0351418d79"
4952
PreallocationTools = "d236fae5-4411-538c-8e31-a6e3d9e00b46"
5053
SymPy = "24249f21-da20-56a4-8eb1-6a02cf4ae2e6"
5154
SymPyPythonCall = "bc8888f7-b21e-4b7c-a06a-5d9c9496438c"
5255

5356
[extensions]
5457
SymbolicsD3TreesExt = "D3Trees"
58+
SymbolicsDistributionsExt = "Distributions"
5559
SymbolicsForwardDiffExt = "ForwardDiff"
5660
SymbolicsGroebnerExt = "Groebner"
61+
SymbolicsLatexifyExt = ["Latexify", "LaTeXStrings"]
5762
SymbolicsLuxExt = "Lux"
5863
SymbolicsNemoExt = "Nemo"
64+
SymbolicsPlutoRunnerExt = "PlutoRunner"
5965
SymbolicsPreallocationToolsExt = ["PreallocationTools", "ForwardDiff"]
6066
SymbolicsSymPyExt = "SymPy"
6167
SymbolicsSymPyPythonCallExt = "SymPyPythonCall"
@@ -84,19 +90,21 @@ Latexify = "0.16"
8490
LogExpFunctions = "0.3"
8591
Lux = "1"
8692
MacroTools = "0.5"
93+
Moshi = "0.3.7"
94+
MultivariatePolynomials = "0.5.12"
95+
MutableArithmetics = "1.6.5"
8796
NaNMath = "1"
8897
Nemo = "0.46, 0.47, 0.48, 0.49, 0.52"
89-
OffsetArrays = "1.15.0"
9098
PkgBenchmark = "0.2"
9199
PreallocationTools = "0.4"
92100
PrecompileTools = "1"
101+
Preferences = "1.5.0"
93102
Primes = "0.5"
94103
RecipesBase = "1.1"
95104
Reexport = "1"
96105
ReferenceTests = "0.10"
97106
RuntimeGeneratedFunctions = "0.5.9"
98107
SafeTestsets = "0.1.0"
99-
SciMLBase = "2"
100108
SciMLPublic = "1.0.0"
101109
Setfield = "1"
102110
SnoopCompile = "3.1"
@@ -106,7 +114,7 @@ SymPy = "2.2"
106114
SymPyPythonCall = "0.5"
107115
SymbolicIndexingInterface = "0.3.14"
108116
SymbolicLimits = "0.2.2"
109-
SymbolicUtils = "3.24"
117+
SymbolicUtils = "4.3"
110118
TermInterface = "2"
111119
julia = "1.10"
112120

@@ -117,7 +125,9 @@ D3Trees = "e3df1716-f71e-5df9-9e2d-98e193103c45"
117125
DynamicQuantities = "06fc5a27-2a28-4c7c-a15d-362465fb6821"
118126
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
119127
Groebner = "0b43b601-686d-58a3-8a1c-6623616c7cd4"
128+
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
120129
LambertW = "984bce1d-4616-540c-a9ee-88d1112d94c9"
130+
Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
121131
Lux = "b2108857-7c20-44ae-9111-449ecde12c47"
122132
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
123133
PkgBenchmark = "32113eaa-f34f-5b0d-bd6c-c81e245fc73d"
@@ -126,8 +136,7 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
126136
ReferenceTests = "324d217c-45ce-50fc-942e-d289b448e8cf"
127137
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
128138
SnoopCompile = "aa65fe97-06da-5843-b5b1-d5d13cad87d2"
129-
SymPyPythonCall = "bc8888f7-b21e-4b7c-a06a-5d9c9496438c"
130139
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
131140

132141
[targets]
133-
test = ["Test", "SafeTestsets", "Pkg", "PkgBenchmark", "PreallocationTools", "ForwardDiff", "Groebner", "BenchmarkTools", "ReferenceTests", "SymPyPythonCall", "Random", "LambertW", "Lux", "ComponentArrays", "Nemo", "DynamicQuantities", "D3Trees", "SnoopCompile"]
142+
test = ["Test", "SafeTestsets", "Pkg", "PkgBenchmark", "PreallocationTools", "ForwardDiff", "Groebner", "BenchmarkTools", "ReferenceTests", "Random", "LambertW", "Lux", "ComponentArrays", "Nemo", "DynamicQuantities", "D3Trees", "SnoopCompile", "Latexify", "LaTeXStrings"]

docs/Project.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
44
Groebner = "0b43b601-686d-58a3-8a1c-6623616c7cd4"
55
Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
66
Nemo = "2edaba10-b0f1-5616-af89-8c11ac63239a"
7-
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
7+
# OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
88
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
99
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1010
SymbolicUtils = "d1185830-fcd6-423d-90d6-eec64667417b"
@@ -16,8 +16,8 @@ Documenter = "1"
1616
Groebner = "0.8.2, 0.9, 0.10"
1717
Latexify = "0.15, 0.16"
1818
Nemo = "0.46, 0.47, 0.48, 0.49, 0.52"
19-
OrdinaryDiffEq = "6.31"
19+
# OrdinaryDiffEq = "6.31"
2020
Plots = "1.36"
2121
StaticArrays = "1.5"
22-
SymbolicUtils = "2.0.2, 3"
23-
Symbolics = "6"
22+
SymbolicUtils = "4.2"
23+
Symbolics = "7"

docs/src/manual/functions.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,18 @@ also supplied.
9595

9696
### Defining Derivatives of Registered Functions
9797

98-
In order for symbolic differentiation to work, an overload of `Symbolics.derivative` is
99-
required. The syntax is `derivative(typeof(f), args::NTuple{i,Any}, ::Val{j})` where
100-
`i` is the number of arguments to the function and `j` is which argument is being
101-
differentiated. So for example:
98+
In order for symbolic differentiation to work, defining [`@register_derivative`](@ref) for
99+
registered functions is required. For example,
102100

103101
```julia
104-
function derivative(::typeof(min), args::NTuple{2,Any}, ::Val{1})
105-
x, y = args
106-
ifelse(x < y, one(x), zero(x))
107-
end
102+
@register_derivative min(x, y) 1 ifelse(x < y, 1, 0)
108103
```
109104

110-
is the partial derivative of the Julia `min(x,y)` function with respect to `x`.
105+
is the partial derivative of the Julia `min(x,y)` function with respect to `x`. Refer to
106+
the documentation of [`@register_derivative`](@ref) for an in-depth explanation of the macro
107+
syntax.
108+
109+
Querying the rules defined using this method requires the use of [`@derivative_rule`](@ref).
111110

112111
!!! note
113112
Downstream symbolic derivative functionality only work if every partial derivative that
@@ -147,6 +146,8 @@ Note that at this time array derivatives cannot be defined.
147146
```@docs
148147
@register_symbolic
149148
@register_array_symbolic
149+
@register_derivative
150+
@derivative_rule
150151
```
151152

152153
## Direct Registration API (Advanced, Experimental)
@@ -181,11 +182,12 @@ Additionally a symbolic name is required:
181182
Base.nameof(interp::AbstractInterpolation) = :Interpolation
182183
```
183184

184-
The derivative is defined similarly to the macro case:
185+
With Symbolics.jl v7 we don't expose a direct API for defining derivatives. It
186+
requires using the macro.
185187

186188
```julia
187-
function Symbolics.derivative(interp::AbstractInterpolation, args::NTuple{1, Any}, ::Val{1})
188-
Symbolics.unwrap(derivative(interp, Symbolics.wrap(args[1])))
189+
@register_derivative (interp::AbstractInterpolation)(x) 1 begin
190+
# ...
189191
end
190192
```
191193

docs/src/tutorials/auto_parallel.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Now let's set up the parabolic PDE to be solved by DifferentialEquations.jl.
8484
We will set up the vanilla version and the sparse multithreaded
8585
version:
8686

87-
```@example auto_parallel
87+
```julia
8888
using OrdinaryDiffEq
8989
u0 = zeros(N, N, 3)
9090
MyA = zeros(N, N);
@@ -99,7 +99,7 @@ fastprob = ODEProblem(ODEFunction((du, u, p, t) -> fastf(du, u),
9999

100100
Let's see the timing difference:
101101

102-
```@example auto_parallel
102+
```julia
103103
using BenchmarkTools
104104
#@btime solve(prob, TRBDF2()); # 33.073 s (895404 allocations: 23.87 GiB)
105105
#warning the following solve takes a long time to compile, but afterwards is very fast.

ext/SymbolicsDistributionsExt.jl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module SymbolicsDistributionsExt
2+
3+
using Symbolics
4+
using Distributions
5+
using Symbolics: Num, Arr, VartypeT, unwrap, BasicSymbolic, shape
6+
7+
8+
for f in [pdf, logpdf, cdf, logcdf, quantile]
9+
@eval function (::$(typeof(f)))(dist::Distributions.Distribution, x::Num)
10+
$f(dist, unwrap(x))
11+
end
12+
@eval function (::$(typeof(f)))(dist::Distributions.Distribution, x::Arr)
13+
$f(dist, unwrap(x))
14+
end
15+
@eval function (::$(typeof(f)))(dist::BasicSymbolic{VartypeT}, x::Num)
16+
$f(dist, unwrap(x))
17+
end
18+
@eval function (::$(typeof(f)))(dist::BasicSymbolic{VartypeT}, x::Arr)
19+
$f(dist, unwrap(x))
20+
end
21+
@eval function (::$(typeof(f)))(dist::BasicSymbolic{VartypeT}, x)
22+
$f(dist, unwrap(x))
23+
end
24+
end
25+
26+
for f in [Distributions.Uniform, Distributions.Normal]
27+
for (T1, T2) in Iterators.product(Iterators.repeated([Real, BasicSymbolic{VartypeT}, Num], 2)...)
28+
if T1 != Num && T2 != Num
29+
continue
30+
end
31+
@eval function (::Type{$f})(a::$T1, b::$T2)
32+
$f(unwrap(a), unwrap(b))
33+
end
34+
end
35+
end
36+
37+
end

0 commit comments

Comments
 (0)