Skip to content

Commit 85fe0ee

Browse files
Merge pull request #78 from shahriariravanian/main
fixed integrate_sum
2 parents 0d35c56 + b2042d3 commit 85fe0ee

File tree

4 files changed

+52
-25
lines changed

4 files changed

+52
-25
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SymbolicNumericIntegration"
22
uuid = "78aadeae-fbc0-11eb-17b6-c7ec0477ba9e"
33
authors = ["Shahriar Iravanian <[email protected]>"]
4-
version = "1.3.1"
4+
version = "1.3.2"
55

66
[deps]
77
DataDrivenDiffEq = "2445eb08-9709-466a-b3fc-47e12bd697a2"

src/integral.jl

+48-22
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,20 @@ Returns a tuple of (solved, unsolved, err) if `detailed == true`, where
5656
Returns the resulting integral or nothing if `detailed == false`
5757
"""
5858
function integrate(eq, x = nothing;
59-
abstol = 1e-6,
60-
num_steps = 2,
61-
num_trials = 10,
62-
radius = 5.0,
63-
show_basis = false,
64-
opt = STLSQ(exp.(-10:1:0)),
65-
bypass = false,
66-
symbolic = false,
67-
max_basis = 100,
68-
verbose = false,
69-
complex_plane = true,
70-
homotopy = true,
71-
use_optim = false,
72-
detailed = true)
59+
abstol = 1e-6,
60+
num_steps = 2,
61+
num_trials = 10,
62+
radius = 5.0,
63+
show_basis = false,
64+
opt = STLSQ(exp.(-10:1:0)),
65+
bypass = false,
66+
symbolic = false,
67+
max_basis = 100,
68+
verbose = false,
69+
complex_plane = true,
70+
homotopy = true,
71+
use_optim = false,
72+
detailed = true)
7373
deprecation_warnings(; homotopy, use_optim)
7474

7575
eq = expand(eq)
@@ -130,6 +130,32 @@ function integrate(eq, xx::Tuple; kwargs...)
130130
return nothing
131131
end
132132

133+
function get_solved(p, sol)
134+
if sol isa Tuple
135+
s = sol[1]
136+
return s == nothing ? 0 : s
137+
else
138+
return sol == nothing ? 0 : sol
139+
end
140+
end
141+
142+
function get_unsolved(p, sol)
143+
if sol isa Tuple
144+
u = sol[2]
145+
return u == nothing ? 0 : u
146+
else
147+
return sol == 0 || sol == nothing ? p : 0
148+
end
149+
end
150+
151+
function get_err(p, sol)
152+
if sol isa Tuple
153+
return sol[3]
154+
else
155+
return sol == 0 || sol == nothing ? Inf : 0
156+
end
157+
end
158+
133159
# integrate_sum applies the integral summation rule ∫ Σᵢ fᵢ(x) dx = Σᵢ ∫ fᵢ(x) dx
134160
function integrate_sum(eq, x; bypass = false, kwargs...)
135161
solved = 0
@@ -138,10 +164,10 @@ function integrate_sum(eq, x; bypass = false, kwargs...)
138164
ts = bypass ? [eq] : terms(eq)
139165

140166
for p in ts
141-
s, u, ε = integrate_term(p, x; kwargs...)
142-
solved += s
143-
unsolved += u
144-
ε₀ = max(ε₀, ε)
167+
sol = integrate_term(p, x; kwargs...)
168+
solved += get_solved(p, sol)
169+
unsolved += get_unsolved(p, sol)
170+
ε₀ = max(ε₀, get_err(p, sol))
145171
end
146172

147173
if !isequal(unsolved, 0) && isempty(sym_consts(unsolved, x))
@@ -154,10 +180,10 @@ function integrate_sum(eq, x; bypass = false, kwargs...)
154180
ts = bypass ? [eq] : terms(eq)
155181

156182
for p in ts
157-
s, u, ε = integrate_term(p, x; kwargs...)
158-
solved += s
159-
unsolved += u
160-
ε₀ = max(ε₀, ε)
183+
sol = integrate_term(p, x; kwargs...)
184+
solved += get_solved(p, sol)
185+
unsolved += get_unsolved(p, sol)
186+
ε₀ = max(ε₀, get_err(p, sol))
161187

162188
if !isequal(u, 0) # premature termination on the first failure
163189
return 0, eq, ε₀

src/sparse.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ end
123123

124124
# This is needed to fix a bug/omission in DataDrivenSparse
125125
function DataDrivenSparse.active_set!(idx::BitMatrix, p::SoftThreshold,
126-
x::Matrix{ComplexF64}, λ::Float64)
126+
x::Matrix{ComplexF64}, λ::Float64)
127127
DataDrivenSparse.active_set!(idx, p, abs.(x), λ)
128128
end
129129

test/0/Stewart Problems.input

+2-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ lst: '[
275275
[(1+x^5)/(-10*x-3*x^2+x^3),x,3,19*x+3/2*x^2+1/3*x^3+3126/35*log(5-x)-1/10*log(x)-31/14*log(2+x)],
276276
[1/(x*sqrt(log(x))),x,2,2*sqrt(log(x))],
277277
[(5+2*x)/(-3+x),x,2,2*x+11*log(3-x)],
278-
[%e^(%e^x+x),x,2,%e^(%e^x)],
278+
-- the following is changed from %e^(%e^x+x) to %e^(%e^x)*%e^(x) (SI)
279+
[%e^(%e^x)*%e^(x),x,2,%e^(%e^x)],
279280
[cos(x)^2*sin(x)^2,x,3,1/8*x+1/8*cos(x)*sin(x)-1/4*cos(x)^3*sin(x)],
280281
[(-cos(x)+sin(x))/(cos(x)+sin(x)),x,1,-log(cos(x)+sin(x))],
281282
[x/sqrt(1-x^2),x,1,-sqrt(1-x^2)],

0 commit comments

Comments
 (0)