Skip to content

Commit 7db9064

Browse files
Merge pull request #50 from shahriariravanian/main
upgraded to work with Symbolics 5
2 parents 32ef5e6 + 639611a commit 7db9064

File tree

11 files changed

+387
-370
lines changed

11 files changed

+387
-370
lines changed

Project.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
name = "SymbolicNumericIntegration"
22
uuid = "78aadeae-fbc0-11eb-17b6-c7ec0477ba9e"
33
authors = ["Shahriar Iravanian <[email protected]>"]
4-
version = "1.1.0"
4+
version = "1.2.0"
55

66
[deps]
77
DataDrivenDiffEq = "2445eb08-9709-466a-b3fc-47e12bd697a2"
8+
DataDrivenSparse = "5b588203-7d8b-4fab-a537-c31a7f73f46b"
89
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
910
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1011
Optim = "429524aa-4258-5aef-a3af-852621145aeb"
@@ -14,12 +15,12 @@ SymbolicUtils = "d1185830-fcd6-423d-90d6-eec64667417b"
1415
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"
1516

1617
[compat]
17-
DataDrivenDiffEq = "0.8"
18+
DataDrivenDiffEq = "1.0"
1819
DataStructures = "0.18"
1920
Optim = "1"
21+
SymbolicUtils = "1"
22+
Symbolics = "5"
2023
SpecialFunctions = "2"
21-
SymbolicUtils = "0.19"
22-
Symbolics = "4"
2324
julia = "1.6"
2425

2526
[extras]

docs/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ SymbolicNumericIntegration = "78aadeae-fbc0-11eb-17b6-c7ec0477ba9e"
44

55
[compat]
66
Documenter = "0.27"
7-
SymbolicNumericIntegration = "0.9, 1"
7+
SymbolicNumericIntegration = "1"

docs/make.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using Documenter, SymbolicNumericIntegration
22

3-
cp("./docs/Manifest.toml", "./docs/src/assets/Manifest.toml", force = true)
4-
cp("./docs/Project.toml", "./docs/src/assets/Project.toml", force = true)
3+
# cp("./docs/Manifest.toml", "./docs/src/assets/Manifest.toml", force = true)
4+
# cp("./docs/Project.toml", "./docs/src/assets/Project.toml", force = true)
55

66
include("pages.jl")
77

@@ -11,7 +11,7 @@ makedocs(sitename = "SymbolicNumericIntegration.jl",
1111
clean = true, doctest = false, linkcheck = true,
1212
strict = [
1313
:doctest,
14-
:linkcheck,
14+
# :linkcheck,
1515
:parse_error,
1616
:example_block,
1717
# Other available options are

src/SymbolicNumericIntegration.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ using SymbolicUtils: istree, operation, arguments
55
using Symbolics
66
using Symbolics: value, get_variables, expand_derivatives
77
using SymbolicUtils.Rewriters
8+
using SymbolicUtils: exprtype, BasicSymbolic
89

9-
using DataDrivenDiffEq
10+
using DataDrivenDiffEq, DataDrivenSparse
1011

1112
include("utils.jl")
1213
include("special.jl")

src/candidates.jl

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using DataStructures
22

33
# this is the main heurisctic used to find the test fragments
4-
function generate_basis(eq, x, try_kernel = true; homotopy = true)
5-
if homotopy && !try_kernel
4+
function generate_basis(eq, x, try_kernel = true)
5+
if !try_kernel
66
S = sum(generate_homotopy(expr(eq), x))
7-
return cache.(unique([one(x); [equivalent(t, x) for t in terms(S)]]))
7+
return cache.(unique([equivalent(t, x) for t in terms(S)]))
88
end
99

1010
S = 0
@@ -13,33 +13,39 @@ function generate_basis(eq, x, try_kernel = true; homotopy = true)
1313
for t in terms(eq)
1414
q = equivalent(t, x)
1515
f = kernel(q)
16+
p = q / f
1617

17-
C₁ = closure(f, x)
18-
p = q * inverse(f)
19-
20-
if homotopy
21-
if isdependent(p, x)
22-
C₂ = generate_homotopy(p, x)
23-
else
24-
C₂ = 1
25-
end
18+
if isdependent(p, x)
19+
C₂ = generate_homotopy(p, x)
2620
else
27-
C₂ = find_candidates(p, x)
21+
C₂ = 1
2822
end
2923

24+
C₁ = closure(f, x)
25+
3026
S += sum(c₁ * c₂ for c₁ in C₁ for c₂ in C₂)
3127
end
32-
return cache.(unique([one(x); [equivalent(t, x) for t in terms(S)]]))
28+
return cache.(unique([equivalent(t, x) for t in terms(S)]))
3329
end
3430

35-
function expand_basis(basis, x)
31+
function expand_basis(basis, x; Kmax = 1000)
32+
if isempty(basis)
33+
return basis, false
34+
end
35+
3636
b = sum(expr.(basis))
37+
38+
Kb = complexity(b)# Kolmogorov complexity
39+
if is_proper(Kb) && Kb > Kmax
40+
return basis, false
41+
end
42+
3743
δb = sum(deriv!.(basis, x))
3844
eq = (1 + x) * (b + δb)
3945
eq = expand(eq)
4046
S = Set{Any}()
4147
enqueue_expr!(S, eq, x)
42-
return cache.([one(x); [s for s in S]])
48+
return cache.([s for s in S]), true
4349
end
4450

4551
function closure(eq, x; max_terms = 50)
@@ -55,23 +61,7 @@ function closure(eq, x; max_terms = 50)
5561
y = dequeue!(q)
5662
enqueue_expr!(S, q, expand_derivatives(D(y)), x)
5763
end
58-
unique([one(x); [s for s in S]; [s * x for s in S]])
59-
end
60-
61-
function find_candidates(eq, x)
62-
eq = apply_d_rules(eq)
63-
D = Differential(x)
64-
65-
S = Set{Any}()
66-
q = Queue{Any}()
67-
enqueue_expr!(S, q, eq, x)
68-
69-
for y in q
70-
∂y = expand_derivatives(D(y))
71-
enqueue_expr!(S, ∂y, x)
72-
end
73-
74-
return unique([one(x); [s for s in S]])
64+
unique([[s for s in S]; [s * x for s in S]])
7565
end
7666

7767
function candidate_pow_minus(p, k; abstol = 1e-8)
@@ -142,27 +132,31 @@ end
142132

143133
###############################################################################
144134

145-
function enqueue_expr!(S, q, eq::SymbolicUtils.Add, x)
135+
enqueue_expr!(S, q, eq, x) = enqueue_expr!!(S, q, ops(eq)..., x)
136+
137+
function enqueue_expr!!(S, q, ::Add, eq, x)
146138
for t in arguments(eq)
147139
enqueue_expr!(S, q, t, x)
148140
end
149141
end
150142

151-
function enqueue_expr!(S, q, eq, x)
143+
function enqueue_expr!!(S, q, ::Any, eq, x)
152144
y = eq / coef(eq, x)
153145
if y S && isdependent(y, x)
154146
enqueue!(q, y)
155147
push!(S, y)
156148
end
157149
end
158150

159-
function enqueue_expr!(S, eq::SymbolicUtils.Add, x)
151+
enqueue_expr!(S, eq, x) = enqueue_expr!!(S, ops(eq)..., x)
152+
153+
function enqueue_expr!!(S, ::Add, eq, x)
160154
for t in arguments(eq)
161155
enqueue_expr!(S, t, x)
162156
end
163157
end
164158

165-
function enqueue_expr!(S, eq, x)
159+
function enqueue_expr!!(S, ::Any, eq, x)
166160
y = eq / coef(eq, x)
167161
if y S && isdependent(y, x)
168162
push!(S, y)

0 commit comments

Comments
 (0)