Skip to content

Commit 488eec3

Browse files
committed
Fix accept_solution returning symbolic instead of numeric
- Ensure accept_solution always returns a numeric value (Number type) - Also substitute symbols from the solution, not just the input equation - Fall back to Inf if result remains symbolic after substitution - Format test/runtests.jl with SciMLStyle Fixes TypeError in numeric comparisons when ε is symbolic. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 0cc36bd commit 488eec3

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

src/numeric_utils.jl

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,25 @@ function accept_solution(eq, x, sol; plan = default_plan())
2424
# x₀ = test_point(plan.complex_plane, plan.radius)
2525
# Δ = substitute(diff(sol, x) - expr(eq), Dict(x => x₀))
2626
S = subs_symbols(eq, x; include_x = true, plan.radius)
27+
# Also substitute any symbols in sol that may not be in eq
28+
for v in get_variables(value(sol))
29+
if !haskey(S, v) && !isequal(v, x)
30+
S[v] = Complex(randn())
31+
end
32+
end
2733
Δ = substitute(diff(sol, x) - expr(eq), S)
28-
return abs(Δ)
34+
result = abs(Δ)
35+
# Ensure result is numeric, not symbolic
36+
if result isa Number
37+
return result
38+
else
39+
# Try to extract numeric value
40+
val = Symbolics.unwrap(result)
41+
if val isa Number
42+
return abs(val)
43+
end
44+
return Inf
45+
end
2946
catch e
3047
#
3148
end

test/runtests.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,8 @@ end
333333

334334
# Test that vector expressions throw an appropriate error
335335
@test_throws ErrorException("Vector expressions are not supported. Please use element-wise integration with `integrate.([expr1, expr2, ...], x)` instead.") integrate([x])
336-
@test_throws ErrorException("Vector expressions are not supported. Please use element-wise integration with `integrate.([expr1, expr2, ...], x)` instead.") integrate([1, 2 * α], α)
336+
@test_throws ErrorException("Vector expressions are not supported. Please use element-wise integration with `integrate.([expr1, expr2, ...], x)` instead.") integrate(
337+
[1, 2 * α], α)
337338

338339
# Test that scalar integration still works
339340
@test integrate(x) == ((1//2)*(x^2), 0, 0)

0 commit comments

Comments
 (0)