Skip to content

Commit 14a7fd0

Browse files
fixing homotopy
1 parent e39039e commit 14a7fd0

File tree

5 files changed

+50
-42
lines changed

5 files changed

+50
-42
lines changed

src/candidates.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ using DataStructures
22

33
# this is the main heurisctic used to find the test fragments
44
function generate_basis(eq, x; homotopy=false)
5-
if homotopy
6-
return generate_homotopy(eq, x)
7-
end
8-
95
eq = expand(eq)
106
S = Set{Any}()
117
for t in terms(eq)

src/homotopy.jl

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,23 @@ transformer(eq::SymbolicUtils.Div, f) = transformer(arguments(eq)[1],f) * transf
2222
function transformer(eq::SymbolicUtils.Pow, f)
2323
y, k = arguments(eq)
2424

25-
r = nice_parameter(k)
26-
if r isa Rational || isinteger(r)
27-
a, b = numerator(r), denominator(r)
25+
# if is_poly(y)
26+
# return next_variable!(f, y)^k
27+
# end
28+
29+
# r = nice_parameter(k)
30+
# if r isa Rational || isinteger(r)
31+
if isinteger(k)
32+
a, b = k, 1
33+
# a, b = numerator(r), denominator(r)
2834
if k < 0
2935
y = inv(y)
3036
end
3137
f.deg = max(f.deg, abs(a))
3238
μ = next_variable!(f, b == 1 ? y : y ^(1/b))
3339
return μ ^ abs(a)
3440
else
35-
return next_variable!(f, y ^ k)
41+
return next_variable!(f, y^k)
3642
end
3743
end
3844

@@ -48,7 +54,11 @@ end
4854
function transform(eq, x)
4955
eq = substitute(eq, Dict(x => 𝑥))
5056
f = Transform(1, Dict(), 1, false)
51-
return transformer(eq, f), f.sub, f.deg
57+
p = transformer(eq, f)
58+
if !any(is_poly, values(f.sub))
59+
p *= next_variable!(f, 1)
60+
end
61+
return p, f.sub, f.deg
5262
end
5363

5464
function homotopy_integrand(eq, x)
@@ -68,30 +78,30 @@ function homotopy_integrand(eq, x)
6878
end
6979

7080
function expand_integrand(I, x, deg)
71-
E = sum((Differential(x)^i)(I) for i=1:deg-1; init=I) #* (1+x)
72-
S = Set{Any}()
73-
enqueue_expr_ex!(S, expand(expand_derivatives(E)), x)
74-
return [one(x); [s for s in S]]
75-
81+
# E = sum((Differential(x)^i)(I) for i=1:deg-1; init=I) #* (1+x)
7682
# S = Set{Any}()
77-
# # T = Set{Any}()
78-
# Q₁ = Queue{Any}()
79-
#
80-
# enqueue_expr_ex!(S, Q₁, expand(I), x)
81-
#
82-
# D = Differential(x)
83-
#
84-
# for i = 1:deg
85-
# Q₂ = Queue{Any}()
86-
# while !isempty(Q₁) # && length(S) < max_terms
87-
# y = dequeue!(Q₁)
88-
# E = expand(expand_derivatives(D(y)))
89-
# enqueue_expr_ex!(S, Q₂, E, x)
90-
# end
91-
# Q₁ = Q₂
92-
# end
93-
#
83+
# enqueue_expr_ex!(S, expand(expand_derivatives(E)), x)
9484
# return [one(x); [s for s in S]]
85+
86+
S = Set{Any}()
87+
# T = Set{Any}()
88+
Q₁ = Queue{Any}()
89+
90+
enqueue_expr_ex!(S, Q₁, expand(I), x)
91+
92+
D = Differential(x)
93+
94+
for i = 1:deg
95+
Q₂ = Queue{Any}()
96+
while !isempty(Q₁) # && length(S) < max_terms
97+
y = dequeue!(Q₁)
98+
E = expand(expand_derivatives(D(y)))
99+
enqueue_expr_ex!(S, Q₂, E, x)
100+
end
101+
Q₁ = Q₂
102+
end
103+
104+
return [one(x); [s for s in S]]
95105
end
96106

97107
function expand_integrand(I, x, deg)
@@ -113,7 +123,8 @@ function substitute_x(eq, x, sub)
113123
end
114124

115125
function generate_homotopy2(eq, x)
116-
q, sub, deg = transform(eq, x)
126+
q, sub = transform(eq, x)
127+
d = degree(q)
117128
n = length(sub)
118129

119130
S = Set{Any}()
@@ -126,17 +137,17 @@ function generate_homotopy2(eq, x)
126137
h₁ = substitute_x(h₁, x, sub)
127138
h₂ = substitute_x(h₂, x, sub)
128139

129-
H = sum((Differential(x)^i)(h* h₂) for i=1:deg-1; init=h₁*h₂)
130-
I = expand(expand_derivatives(H))
140+
H = sum((Differential(x)^i)(h₂) for i=1:d-1; init=(1 + h₂))
141+
I = expand(expand_derivatives((1 + h₁) * H))
131142
enqueue_expr_ex!(S, I, x)
132143
end
133144

134-
H = sum((Differential(x)^i)(eq) for i=1:deg-1; init=eq)
135-
I = expand((1+x) * expand_derivatives(H))
145+
# H = sum((Differential(x)^i)(eq) for i=1:deg-1; init=eq)
146+
# I = expand((1+x) * expand_derivatives(H))
136147
# enqueue_expr_ex!(S, I, x)
137148

138149
# return [one(x); [s for s in S]]
139-
return [[x^i for i=0:deg]; [s for s in S]]
150+
return [one(x); [s for s in S]]
140151
end
141152

142153
##############################################################################

src/integral.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Base.signbit(z::Complex{T}) where T<:Number = signbit(real(z))
2222
a pair of expressions, solved is the solved integral and unsolved is the residual unsolved
2323
portion of the input
2424
"""
25-
function integrate(eq, x=nothing; abstol=1e-6, num_steps=3, num_trials=5, radius=1.0,
25+
function integrate(eq, x=nothing; abstol=1e-6, num_steps=2, num_trials=5, radius=1.0,
2626
show_basis=false, opt = STLSQ(exp.(-10:1:0)), bypass=false,
2727
symbolic=true, bypart=true, max_basis=100,
2828
verbose=false, complex_plane=true, prune_basis=false, homotopy=false)
@@ -52,6 +52,8 @@ function integrate(eq, x=nothing; abstol=1e-6, num_steps=3, num_trials=5, radius
5252
# eq = q
5353
# end
5454

55+
homotopy = homotopy && !bypass
56+
5557
s₁, u₁, ϵ = integrate_sum(eq, x, l; bypass, abstol, num_trials, num_steps,
5658
radius, show_basis, opt, symbolic,
5759
max_basis, verbose, complex_plane, prune_basis, homotopy)

src/rules.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,6 @@ function decompose_rational(eq)
178178
end
179179
F = unique(F)
180180

181-
println(F)
182-
183181
n = length(F)
184182
A = zeros(Complex, (n,n))
185183
b = zeros(Complex, n)

test/runtests.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,19 +190,20 @@ basic_integrals = [
190190
]
191191

192192
function test_integrals(; kw...)
193-
bypass = false
193+
args = Dict(kw)
194194
misses = []
195195
k = 1
196196

197197
for eq in basic_integrals
198198
if isequal(eq, β)
199199
printstyled("**** bypass on ****\n"; color=:red)
200200
bypass = true
201+
args[:bypass] = true
201202
else
202203
printstyled(k, ": "; color=:blue)
203204
k += 1
204205
printstyled(eq, " =>\n"; color=:green)
205-
solved, unsolved = integrate(eq; kw...)
206+
solved, unsolved = integrate(eq; args...)
206207
printstyled('\t', solved; color=:cyan)
207208
if isequal(unsolved, 0)
208209
println()

0 commit comments

Comments
 (0)