@@ -25,159 +25,45 @@ RuntimeGeneratedFunctions.init(@__MODULE__)
25
25
using RecursiveArrayTools
26
26
27
27
import SymbolicUtils
28
- import SymbolicUtils: Term, Add, Mul, Pow, Sym, FnType ,
29
- @rule , Rewriters, substitute, similarterm ,
30
- promote_symtype
31
-
28
+ import SymbolicUtils: istree, arguments, operation, similarterm, promote_symtype ,
29
+ Symbolic, Term, Add, Mul, Pow, Sym, FnType ,
30
+ @rule , Rewriters, substitute
31
+ using SymbolicUtils . Code
32
32
import SymbolicUtils. Code: toexpr
33
-
34
33
import SymbolicUtils. Rewriters: Chain, Postwalk, Prewalk, Fixpoint
34
+
35
+ using Reexport
36
+ @reexport using Symbolics
37
+ export @derivatives
38
+ using Symbolics: _parse_vars, value, makesym, @derivatives , get_variables,
39
+ exprs_occur_in, solve_for, build_expr
40
+ import Symbolics: rename, get_variables!, _solve, hessian_sparsity,
41
+ jacobian_sparsity, islinear, _iszero, _isone,
42
+ tosymbol, lower_varname, diff2term, var_from_nested_derivative,
43
+ BuildTargets, JuliaTarget, StanTarget, CTarget, MATLABTarget,
44
+ ParallelForm, SerialForm, MultithreadedForm, build_function,
45
+ unflatten_long_ops
46
+
35
47
import DiffEqBase: @add_kwonly
36
- using LinearAlgebra: LU, BlasInt
37
48
38
49
import LightGraphs: SimpleDiGraph, add_edge!
39
50
40
51
import TreeViews
41
52
42
53
using Requires
43
54
44
- export Num, Variable
45
- """
46
- $(TYPEDEF)
47
-
48
- Wrap anything in a type that is a subtype of Real
49
- """
50
- struct Num <: Real
51
- val
52
- end
53
-
54
- const show_numwrap = Ref (false )
55
-
56
- Num (x:: Num ) = x # ideally this should never be called
57
- (n:: Num )(args... ) = Num (value (n)(map (value,args)... ))
58
- value (x) = x
59
- value (x:: Num ) = x. val
60
-
61
- SciMLBase. issymbollike (:: Num ) = true
62
- SciMLBase. issymbollike (:: SymbolicUtils.Symbolic ) = true
63
-
64
- SymbolicUtils. @number_methods (Num,
65
- Num (f (value (a))),
66
- Num (f (value (a), value (b))))
67
-
68
- for C in [Complex, Complex{Bool}]
55
+ for fun in [:toexpr ]
69
56
@eval begin
70
- Base.:* (x:: Num , z:: $C ) = Complex (x * real (z), x * imag (z))
71
- Base.:* (z:: $C , x:: Num ) = Complex (real (z) * x, imag (z) * x)
72
- end
73
- end
74
-
75
- Base.:+ (x:: Num , z:: Complex ) = Complex (x + real (z), imag (z))
76
- Base.:+ (z:: Complex , x:: Num ) = Complex (real (z) + x, imag (z))
77
- Base.:- (x:: Num , z:: Complex ) = Complex (x - real (z), - imag (z))
78
- Base.:- (z:: Complex , x:: Num ) = Complex (real (z) - x, imag (z))
79
-
80
- function Base. inv (z:: Complex{Num} )
81
- a, b = reim (z)
82
- den = a^ 2 + b^ 2
83
- Complex (a/ den, - b/ den)
84
- end
85
- function Base.:/ (x:: Complex{Num} , y:: Complex{Num} )
86
- a, b = reim (x)
87
- c, d = reim (y)
88
- den = c^ 2 + d^ 2
89
- Complex ((a* c + b* d)/ den, (b* c - a* d)/ den)
90
- end
57
+ function $fun (eq:: Equation ; kw... )
58
+ Expr (:(= ), $ fun (eq. lhs; kw... ), $ fun (eq. rhs; kw... ))
59
+ end
91
60
92
- function Base. show (io:: IO , z:: Complex{<:Num} )
93
- r, i = reim (z)
94
- compact = get (io, :compact , false )
95
- show (io, r)
96
- print (io, (compact ? " +" : " + " ) * " (" )
97
- show (io, i)
98
- print (io, " )*im" )
99
- end
100
-
101
- SymbolicUtils. simplify (n:: Num ; kw... ) = Num (SymbolicUtils. simplify (value (n); kw... ))
102
-
103
- SymbolicUtils. symtype (n:: Num ) = symtype (n. val)
104
-
105
- function Base. iszero (x:: Num )
106
- _x = SymbolicUtils. to_mpoly (value (x))[1 ]
107
- return (_x isa Number || _x isa SymbolicUtils. MPoly) && iszero (_x)
108
- end
109
-
110
- import SymbolicUtils: < ₑ, Symbolic, Term, operation, arguments
111
-
112
- Base. show (io:: IO , n:: Num ) = show_numwrap[] ? print (io, :(Num ($ (value (n))))) : Base. show (io, value (n))
113
-
114
- Base. promote_rule (:: Type{<:Number} , :: Type{<:Num} ) = Num
115
- Base. promote_rule (:: Type{<:Symbolic{<:Number}} , :: Type{<:Num} ) = Num
116
- function Base. getproperty (t:: Union{Add, Mul, Pow, Term} , f:: Symbol )
117
- if f === :op
118
- Base. depwarn (" `x.op` is deprecated, use `operation(x)` instead" , :getproperty , force= true )
119
- operation (t)
120
- elseif f === :args
121
- Base. depwarn (" `x.args` is deprecated, use `arguments(x)` instead" , :getproperty , force= true )
122
- arguments (t)
123
- else
124
- getfield (t, f)
125
- end
126
- end
127
- < ₑ (s:: Num , x) = value (s) < ₑ value (x)
128
- < ₑ (s, x:: Num ) = value (s) < ₑ value (x)
129
- < ₑ (s:: Num , x:: Num ) = value (s) < ₑ value (x)
130
-
131
- for T in (Integer, Rational)
132
- @eval Base.:(^ )(n:: Num , i:: $T ) = Num (value (n)^ i)
133
- end
134
-
135
- macro num_method (f, expr, Ts= nothing )
136
- if Ts === nothing
137
- Ts = [Any]
138
- else
139
- @assert Ts. head == :tuple
140
- # e.g. a tuple or vector
141
- Ts = Ts. args
61
+ $ fun (eqs:: AbstractArray ; kw... ) = map (eq-> $ fun (eq; kw... ), eqs)
62
+ $ fun (x:: Integer ; kw... ) = x
63
+ $ fun (x:: AbstractFloat ; kw... ) = x
142
64
end
143
-
144
- ms = [quote
145
- $ f (a:: $T , b:: $Num ) = $ expr
146
- $ f (a:: $Num , b:: $T ) = $ expr
147
- end for T in Ts]
148
- quote
149
- $ f (a:: $Num , b:: $Num ) = $ expr
150
- $ (ms... )
151
- end |> esc
152
65
end
153
66
154
- """
155
- tosymbolic(a::Union{Sym,Num}) -> Sym{Real}
156
- tosymbolic(a::T) -> T
157
- """
158
- tosymbolic (a:: Num ) = tosymbolic (value (a))
159
- tosymbolic (a:: Sym ) = tovar (a)
160
- tosymbolic (a) = a
161
- @num_method Base. isless (val = isless (tosymbolic (a), tosymbolic (b)); val isa Bool ? val : Num (val)) (Real,)
162
- @num_method Base.:(< ) (val = tosymbolic (a) < tosymbolic (b) ; val isa Bool ? val : Num (val)) (Real,)
163
- @num_method Base.:(<= ) (val = tosymbolic (a) <= tosymbolic (b) ; val isa Bool ? val : Num (val)) (Real,)
164
- @num_method Base.:(> ) (val = tosymbolic (a) > tosymbolic (b) ; val isa Bool ? val : Num (val)) (Real,)
165
- @num_method Base.:(>= ) (val = tosymbolic (a) >= tosymbolic (b) ; val isa Bool ? val : Num (val)) (Real,)
166
- @num_method Base.:(== ) (val = tosymbolic (a) == tosymbolic (b) ; val isa Bool ? val : Num (val)) (AbstractFloat,Number)
167
- @num_method Base. isequal isequal (tosymbolic (a), tosymbolic (b)) (AbstractFloat, Number, Symbolic)
168
-
169
- Base. hash (x:: Num , h:: UInt ) = hash (value (x), h)
170
-
171
- Base. convert (:: Type{Num} , x:: Symbolic{<:Number} ) = Num (x)
172
- Base. convert (:: Type{Num} , x:: Number ) = Num (x)
173
- Base. convert (:: Type{Num} , x:: Num ) = x
174
-
175
- Base. convert (:: Type{<:Array{Num}} , x:: AbstractArray ) = map (Num, x)
176
- Base. convert (:: Type{<:Array{Num}} , x:: AbstractArray{Num} ) = x
177
- Base. convert (:: Type{Sym} , x:: Num ) = value (x) isa Sym ? value (x) : error (" cannot convert $x to Sym" )
178
-
179
- LinearAlgebra. lu (x:: Array{Num} ; check= true , kw... ) = sym_lu (x; check= check)
180
-
181
67
"""
182
68
$(TYPEDEF)
183
69
@@ -211,16 +97,10 @@ include("bipartite_graph.jl")
211
97
using . BipartiteGraphs
212
98
213
99
include (" variables.jl" )
214
- include (" context_dsl.jl" )
215
- include (" differentials.jl" )
100
+ include (" parameters.jl" )
216
101
217
- include (" equations.jl" )
218
102
include (" utils.jl" )
219
- include (" linearity.jl" )
220
- include (" solve.jl" )
221
- include (" direct.jl" )
222
103
include (" domains.jl" )
223
- include (" register_function.jl" )
224
104
225
105
include (" systems/abstractsystem.jl" )
226
106
@@ -252,10 +132,6 @@ include("systems/alias_elimination.jl")
252
132
include (" structural_transformation/StructuralTransformations.jl" )
253
133
@reexport using . StructuralTransformations
254
134
255
- include (" latexify_recipes.jl" )
256
- include (" build_function.jl" )
257
- include (" extra_functions.jl" )
258
-
259
135
export ODESystem, ODEFunction, ODEFunctionExpr, ODEProblemExpr
260
136
export SDESystem, SDEFunction, SDEFunctionExpr, SDESystemExpr
261
137
export SystemStructure
@@ -296,7 +172,6 @@ export asgraph, asdigraph
296
172
export toexpr, get_variables
297
173
export simplify, substitute
298
174
export build_function
299
- export @register
300
175
export modelingtoolkitize
301
176
export @variables , @parameters
302
177
export @named
0 commit comments