From 9541fb6c608f6a6c00732b27bc3e0e4f254cf1f4 Mon Sep 17 00:00:00 2001 From: Shahriar Iravanian Date: Sat, 24 Aug 2024 17:15:01 -0400 Subject: [PATCH 1/4] TermInterface added --- Project.toml | 6 ++++-- src/SymbolicNumericIntegration.jl | 4 ++-- src/integral.jl | 25 ++++++++++++++++--------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Project.toml b/Project.toml index 0cfe411..a7416e1 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "SymbolicNumericIntegration" uuid = "78aadeae-fbc0-11eb-17b6-c7ec0477ba9e" authors = ["Shahriar Iravanian "] -version = "1.8.0" +version = "1.9.0" [deps] DataDrivenDiffEq = "2445eb08-9709-466a-b3fc-47e12bd697a2" @@ -12,6 +12,7 @@ SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" SymbolicUtils = "d1185830-fcd6-423d-90d6-eec64667417b" Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7" +TermInterface = "8ea1fca8-c5ef-4a55-8b96-4e9afe9c9a3c" [compat] DataDrivenDiffEq = "1.5" @@ -20,8 +21,9 @@ DataStructures = "0.18.13" LinearAlgebra = "<0.0.1, 1" SpecialFunctions = "2" Statistics = "<0.0.1, 1" -SymbolicUtils = "2.1, 3" +SymbolicUtils = "3" Symbolics = "5.31, 6" +TermInterface = "2" julia = "1.9" [extras] diff --git a/src/SymbolicNumericIntegration.jl b/src/SymbolicNumericIntegration.jl index 2295364..bb77edd 100644 --- a/src/SymbolicNumericIntegration.jl +++ b/src/SymbolicNumericIntegration.jl @@ -1,7 +1,8 @@ module SymbolicNumericIntegration +using TermInterface: iscall using SymbolicUtils -using SymbolicUtils: iscall, operation, arguments +using SymbolicUtils: operation, arguments using Symbolics using Symbolics: value, get_variables, expand_derivatives, coeff, Equation using SymbolicUtils.Rewriters @@ -33,7 +34,6 @@ export Ei, Si, Ci, Li include("numeric_utils.jl") include("sparse.jl") -# include("optim.jl") include("integral.jl") export integrate, generate_basis, best_hints diff --git a/src/integral.jl b/src/integral.jl index b6d794c..c461b83 100644 --- a/src/integral.jl +++ b/src/integral.jl @@ -99,7 +99,7 @@ function integrate(eq, x = nothing; plan = NumericalPlan(abstol, radius, complex_plane, opt) - s, u, ε = integrate_sum(eq, x; plan, bypass, num_trials, num_steps, + s, u, ε = integrate_term(eq, x; plan, bypass, num_trials, num_steps, show_basis, symbolic, max_basis, verbose, use_optim) s = beautify(s) @@ -226,14 +226,7 @@ function integrate_term(eq, x; kwargs...) end if symbolic - y = integrate_symbolic(eq, x; plan) - if y == nothing - if has_sym_consts - @info("Symbolic integration failed. Try changing constant parameters ([$(join(params, ", "))]) to numerical values.") - end - - return 0, eq, Inf - end + return try_symbolic(eq, x, has_sym_consts, params) end eq = cache(eq) @@ -308,6 +301,20 @@ function try_integrate(eq, x, basis; plan = default_plan()) return solve_sparse(eq, x, basis; plan) end +function try_symbolic(eq, x, has_sym_consts = false, params = []; plan = default_plan()) + y = integrate_symbolic(eq, x; plan) + + if y == nothing + if has_sym_consts && !isempty(params) + @info("Symbolic integration failed. Try changing constant parameters ([$(join(params, ", "))]) to numerical values.") + end + + return 0, eq, Inf + else + return y, 0, 0 + end +end + function deprecation_warnings(; use_optim = false, homotopy = true) if use_optim @warn("use_optim is deprecated and will be removed in a future version") From 4428e3b6bd2fba7f3b8188368e8e4b5a666f3f74 Mon Sep 17 00:00:00 2001 From: Shahriar Iravanian Date: Sat, 24 Aug 2024 17:25:44 -0400 Subject: [PATCH 2/4] minor revision to integral() --- src/integral.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/integral.jl b/src/integral.jl index c461b83..02934d8 100644 --- a/src/integral.jl +++ b/src/integral.jl @@ -99,7 +99,7 @@ function integrate(eq, x = nothing; plan = NumericalPlan(abstol, radius, complex_plane, opt) - s, u, ε = integrate_term(eq, x; plan, bypass, num_trials, num_steps, + s, u, ε = integrate_sum(eq, x; plan, bypass, num_trials, num_steps, show_basis, symbolic, max_basis, verbose, use_optim) s = beautify(s) From 7c4cfd908fd06100160fd9242e9efbb8c040786a Mon Sep 17 00:00:00 2001 From: Shahriar Iravanian Date: Sat, 24 Aug 2024 17:37:33 -0400 Subject: [PATCH 3/4] Update Project.toml --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index a7416e1..2c851b3 100644 --- a/Project.toml +++ b/Project.toml @@ -21,7 +21,7 @@ DataStructures = "0.18.13" LinearAlgebra = "<0.0.1, 1" SpecialFunctions = "2" Statistics = "<0.0.1, 1" -SymbolicUtils = "3" +SymbolicUtils = "2.1, 3" Symbolics = "5.31, 6" TermInterface = "2" julia = "1.9" From 331f1907f064af1ac4c35f1efbaa7ba6b74d86f3 Mon Sep 17 00:00:00 2001 From: Shahriar Iravanian Date: Sat, 24 Aug 2024 18:07:01 -0400 Subject: [PATCH 4/4] Update Project.toml --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 2c851b3..3cdbdf8 100644 --- a/Project.toml +++ b/Project.toml @@ -22,7 +22,7 @@ LinearAlgebra = "<0.0.1, 1" SpecialFunctions = "2" Statistics = "<0.0.1, 1" SymbolicUtils = "2.1, 3" -Symbolics = "5.31, 6" +Symbolics = "6" TermInterface = "2" julia = "1.9"