Skip to content

Commit bd1c739

Browse files
bugfix
1 parent c58f6d5 commit bd1c739

File tree

6 files changed

+67
-25
lines changed

6 files changed

+67
-25
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ SymbolicUtils = "d1185830-fcd6-423d-90d6-eec64667417b"
1212
[compat]
1313
AbstractAlgebra = "0.23.0"
1414
Nemo = "0.28.0"
15-
SymbolicUtils = "0.18, 0.19"
16-
julia = "1.7"
15+
SymbolicUtils = "0.18"
16+
julia = "1.7"

src/algebraic_functions.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ function IntegralBasis(E::AbstractAlgebra.ResField{P}) where {T<:FieldElement, P
170170
# Compute only upper triangle of TM, lower triangle by symmetry:
171171
TM = [i<=j ? numerator(sum([coeff(data(S[i, j]*y^l), l) for l=0:n-1])) : ZK for i=1:n, j=1:n]
172172
for i=1:n
173-
for j=1:p-1
173+
for j=1:i-1
174174
TM[i, j] = TM[j, i]
175175
end
176176
end

src/frontend.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ end
218218

219219
function subst_tower(f::F, vars::Vector, h::Int) where
220220
{T<:FieldElement, P<:PolyElem{T}, F<:FracElem{P}}
221-
if isa(vars[h], SymbolicUtils.Term) && operation(vars[h])==tan
221+
if isa(vars[h], SymbolicUtils.Term) && operation(vars[h])==tan && !isone(denominator(f))
222222
return tan2sincos(f, arguments(vars[h])[1], vars, h)
223223
end
224224
if isone(denominator(f))

test/bronstein_examples.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ using Test
1818
expected = (-x*1//t, 0, -x)
1919
@test (g, h, r) == expected
2020

21-
21+
2222
@info "PolynomialReduce, example 5.4.1, p. 141"
2323
QQx, x = PolynomialRing(Nemo.QQ, :x)
2424
k = FractionField(QQx)
@@ -31,7 +31,7 @@ using Test
3131
expected = (t, x*t)
3232
@test (q, r) == expected
3333

34-
34+
#=
3535
@info "ResidueReduce, ConstantPart, example 5.6.3, p. 151"
3636
QQx, x = PolynomialRing(Nemo.QQ, :x)
3737
k = FractionField(QQx)
@@ -50,7 +50,7 @@ using Test
5050
@test gs == [-(2*x^2+3*x+1)*(t-x)//2, -(2*x^2-3*x+1)*(t+x)//2]
5151
Dg = sum([αs[i]*D(gs[i])//gs[i] for i=1:length(αs) ])
5252
@test f-Dg == 1//t - (6*x^2-3)//(4*x^4-5*x^2+1)
53-
53+
=#
5454

5555
@info "IntegratePrimitivePolynomial, example 5.8.1, p. 158"
5656
QQx, x = PolynomialRing(Nemo.QQ, :x)

test/test_stewart.jl

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ using SymbolicIntegration, SymbolicUtils
22
using Symbolics # fopr derivative
33
SI = SymbolicIntegration
44

5-
@syms x a b c n t y Pi
5+
@syms x t y Pi p q r
6+
n =7
7+
a = 2//3
8+
b = -1//5
9+
c = 5//4
610

711
#Integration Test Problems from
812
#https:////rulebasedintegration.org//testProblems.html
@@ -13,10 +17,10 @@ SI = SymbolicIntegration
1317
problems = [
1418

1519
# Section 7.1 - Integration by Parts
16-
[x^n, x, 1, x^(1+n)/(1+n), SI.NotImplementedError], # n
20+
[x^n, x, 1, x^(1+n)/(1+n)],
1721
[exp(x), x, 1, exp(x)],
1822
[1/x, x, 1, log(x)],
19-
[a^x, x, 1, a^x/log(a), SI.NotImplementedError], # a
23+
[a^x, x, 1, a^x/log(a)],
2024
[sin(x), x, 1, -cos(x)],
2125
[cos(x), x, 1, sin(x)],
2226
[sec(x)^2, x, 2, tan(x)],
@@ -47,7 +51,7 @@ problems = [
4751
[exp(2*t)*sin(3*t), t, 1, -3//13*exp(2*t)*cos(3*t)+2//13*exp(2*t)*sin(3*t)],
4852
[cos(3*t)/exp(t), t, 1, -1//10*cos(3*t)/exp(t)+3//10*sin(3*t)/exp(t)],
4953
[y*sinh(y), y, 2, y*cosh(y)-sinh(y)],
50-
[y*cosh(a*y), y, 2, -cosh(a*y)/a^2+y*sinh(a*y)/a, SI.NotImplementedError], # a
54+
[y*cosh(a*y), y, 2, -cosh(a*y)/a^2+y*sinh(a*y)/a],
5155
[t/exp(t), t, 2, (-1)/exp(t)-t/exp(t)],
5256
[log(t)*sqrt(t), t, 1, -4//9*t^(3//2)+2//3*t^(3//2)*log(t), SI.NotImplementedError],
5357
[x*cos(2*x), x, 2, 1//4*cos(2*x)+1//2*x*sin(2*x)],
@@ -199,7 +203,7 @@ problems = [
199203
[(-1+4*x)//((-1+x)*(2+x)), x, 2, log(1-x)+3*log(2+x)],
200204
[1//((1+x)*(2+x)), x, 3, log(1+x)-log(2+x)],
201205
[(-5+6*x)//(3+2*x), x, 2, 3*x-7*log(3+2*x)],
202-
[1//((a+x)*(b+x)), x, 3, -log(a+x)//(a-b)+log(b+x)//(a-b), SI.NotImplementedError], # a, b
206+
[1//((a+x)*(b+x)), x, 3, -log(a+x)/(a-b)+log(b+x)/(a-b)],
203207
[(1+x^2)//(-x+x^2), x, 3, x+2*log(1-x)-log(x)],
204208
[(1-12*x+x^2+x^3)//(-12+x+x^2), x, 5, 1//2*x^2+1//7*log(3-x)-1//7*log(4+x)],
205209
[(3+2*x)//(1+x)^2, x, 2, (-1)//(1+x)+2*log(1+x)],
@@ -270,8 +274,8 @@ problems = [
270274
[1//(sin(x)+tan(x)), x, 6, -1//2*atanh(cos(x))+1//2*cot(x)*csc(x)-1//2*csc(x)^2],
271275
[1//(2*sin(x)+sin(2*x)), x, 4, 1//4*log(tan(1//2*x))+1//8*tan(1//2*x)^2],
272276
[sec(x)//(1+sin(x)), x, 4, 1//2*atanh(sin(x))+(-1//2)//(1+sin(x))],
273-
[1//(b*cos(x)+a*sin(x)), x, 2, -atanh((a*cos(x)-b*sin(x))//sqrt(a^2+b^2))//sqrt(a^2+b^2), SI.NotImplementedError], #a, b
274-
[1//(b^2*cos(x)^2+a^2*sin(x)^2), x, 2, atan(a*tan(x)//b)//(a*b), SI.NotImplementedError], # a, b
277+
[1//(b*cos(x)+a*sin(x)), x, 2, -atanh((a*cos(x)-b*sin(x))/sqrt(a^2+b^2))/sqrt(a^2+b^2)],
278+
[1//(b^2*cos(x)^2+a^2*sin(x)^2), x, 2, atan(a*tan(x)/b)/(a*b)],
275279

276280
# Section 7.6 - Strategy for Integration
277281
[x//(-1+x^2), x, 1, 1//2*log(1-x^2)],
@@ -347,12 +351,12 @@ problems = [
347351
[log(1//2*x), x, 1, -x+x*log(1//2*x)],
348352
[sqrt((1+x)//(1-x)), x, 3, 2*atan(sqrt((1+x)//(1-x)))-(1-x)*sqrt((1+x)//(1-x)), SI.NotImplementedError],
349353
[x*log(x)//sqrt(-1+x^2), x, 5, atan(sqrt(-1+x^2))-sqrt(-1+x^2)+log(x)*sqrt(-1+x^2), SI.NotImplementedError],
350-
[(a+x)//(a^2+x^2), x, 3, atan(x//a)+1//2*log(a^2+x^2), SI.NotImplementedError], # a
354+
[(a+x)//(a^2+x^2), x, 3, atan(x//a)+1//2*log(a^2+x^2)],
351355
[sqrt(1+x-x^2), x, 3, -5//8*asin((1-2*x)/sqrt(5))-1//4*(1-2*x)*sqrt(1+x-x^2), SI.NotImplementedError],
352356
[x^4//(16+x^10), x, 2, 1//20*atan(1//4*x^5)],
353357
[(2+x)//(2+x+x^2), x, 4, 1//2*log(2+x+x^2)+3*atan((1+2*x)/sqrt(7))/sqrt(7)],
354358
[x*sec(x)*tan(x), x, 2, -atanh(sin(x))+x*sec(x)],
355-
[x//(-a^4+x^4), x, 2, -1//2*atanh(x^2//a^2)//a^2, SI.NotImplementedError], # a
359+
[x//(-a^4+x^4), x, 2, -1//2*atanh(x^2//a^2)//a^2],
356360
[1//(sqrt(x)+sqrt(1+x)), x, 3, -2//3*x^(3//2)+2//3*(1+x)^(3//2), SI.NotImplementedError],
357361
[1//(1+(-1)//exp(x)+2*exp(x)), x, 4, 1//3*log(1-2*exp(x))-1//3*log(1+exp(x))],
358362
[atan(sqrt(x))//sqrt(x), x, 2, -log(1+x)+2*atan(sqrt(x))*sqrt(x), SI.NotImplementedError],
@@ -401,9 +405,47 @@ problems = [
401405
[x*sqrt(1+2*x), x, 2, -1//6*(1+2*x)^(3//2)+1//10*(1+2*x)^(5//2), SI.NotImplementedError],
402406
[sin(x)^4, x, 3, 3//8*x-3//8*cos(x)*sin(x)-1//4*cos(x)*sin(x)^3],
403407
[tan(x)^3, x, 2, log(cos(x))+1//2*tan(x)^2],
404-
[x^5*sqrt(1+x^2), x, 3, 1//3*(1+x^2)^(3//2)-2//5*(1+x^2)^(5//2)+1//7*(1+x^2)^(7//2), SI.NotImplementedError]
408+
[x^5*sqrt(1+x^2), x, 3, 1//3*(1+x^2)^(3//2)-2//5*(1+x^2)^(5//2)+1//7*(1+x^2)^(7//2), SI.NotImplementedError],
409+
410+
#=
411+
# David Jeffrey - Rectifying Transformations for Trig Integration (1997)
412+
# Problem (1.2)
413+
[3/(5-4*cos(x)), x, 2, x+2*atan(sin(x)/(2-cos(x)))],
414+
# Problem (1.4)
415+
[(1+cos(x)+2*sin(x))/(3+cos(x)^2+2*sin(x)-2*cos(x)*sin(x)), x, -43, -atan((2*cos(x)-sin(x))/(2+sin(x)))],
416+
# Problem (1.5)
417+
[(2+cos(x)+5*sin(x))/(4*cos(x)-2*sin(x)+cos(x)*sin(x)-2*sin(x)^2), x, -25, -log(1-3*cos(x)+sin(x))+log(3+cos(x)+sin(x))],
418+
# Problem (3.3)
419+
[(3+7*cos(x)+2*sin(x))/(1+4*cos(x)+3*cos(x)^2-5*sin(x)-cos(x)*sin(x)), x , -32, -log(1+cos(x)-2*sin(x))+log(3+cos(x)+sin(x))],
420+
# Problem
421+
[(-1+4*cos(x)+5*cos(x)^2)/(-1-4*cos(x)-3*cos(x)^2+4*cos(x)^3), x, -2, x-2*atan(sin(x)/(3+cos(x)))-2*atan((3*sin(x)+7*cos(x)*sin(x))/(1+2*cos(x)+5*cos(x)^2))],
422+
# Problem
423+
[(-5+2*cos(x)+7*cos(x)^2)/(-1+2*cos(x)-9*cos(x)^2+4*cos(x)^3), x, -2, x-2*atan(2*cos(x)*sin(x)/(1-cos(x)+2*cos(x)^2))],
424+
# Problem (3.4)
425+
[3/(5+4*sin(x)), x, 2, x+2*atan(cos(x)/(2+sin(x)))],
426+
# Problem (3.6)
427+
[2/(1+cos(x)^2), x, 3, x*sqrt(2)-atan(cos(x)*sin(x)/(1+cos(x)^2+sqrt(2)))*sqrt(2)],
428+
# Problem (3.8)
429+
[1/(p+q*cos(x)+r*sin(x)), x, 3, 2*atan((r+(p-q)*tan(1/2*x))/sqrt(p^2-q^2-r^2))/sqrt(p^2-q^2-r^2), SI.NotImplementedError],
430+
431+
# Waldek Hebisch - email May 2013
432+
433+
# Problem #1
434+
[(1-x^3+x^4-x^5+x^6)*exp(x), x, 25, 871*exp(x)-870*exp(x)*x+435*exp(x)*x^2-145*exp(x)*x^3+36*exp(x)*x^4-7*exp(x)*x^5+exp(x)*x^6],
435+
# Problem #2
436+
#[(2-x^2)*exp(x/(2+x^2))/(2*x+x^3), x, -5,Ei(x/(2+x^2))],
437+
#[(2+2*x+3*x^2-x^3+2*x^4)*exp(x/(2+x^2))/(2*x+x^3), x, -5, exp(x/(2+x^2))*(2+x^2)+Ei(x/(2+x^2))],
438+
# Problem #3
439+
#[(1+exp(x))*exp(x+exp(x))/(x+exp(x)), x, 2, Ei(exp(x)+x)],
440+
# Problem #4
441+
[(1-3*x-x^2+x^3)*exp(1/(-1+x^2))/(1-x-x^2+x^3), x, -6, exp(1/(-1+x^2))*(1+x)],
442+
# Problem #5
443+
[exp(1+1/log(x))*(-1+log(x)^2)/log(x)^2, x, 1, exp(1+1/log(x))*x],
444+
[exp(x+1/log(x))*(-1+(1+x)*log(x)^2)/log(x)^2, x, -2, exp(x+1/log(x))*x]
445+
=#
405446
]
406447

448+
407449
k = 0
408450
expected_exceptions = 0
409451
unexpected_exceptions = 0

test/test_stewart.out

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,10 @@ expected: log(1 + sin(x))
244244
∫1 / (1 - sin(x))dx = (2 + 2cos(x) - 2sin(x)) / (2 - 2sin(x))
245245
expected: cos(x) / (1 - sin(x))
246246
--- #82 -----------------------------------------------------------------
247-
∫tan(x)^2dx = (2sin(2x)) / (2 + 2cos(2x)) - x
247+
∫tan(x)^2dx = tan(x) - x
248248
expected: tan(x) - x
249249
--- #83 -----------------------------------------------------------------
250-
∫tan(x)^4dx = x + (-8sin(2x) - 8sin(4x) - (8//3)*sin(6x)) / (20 + 30cos(2x) + 12cos(4x) + 2cos(6x))
250+
∫tan(x)^4dx = x + (1//3)*(tan(x)^3) - tan(x)
251251
expected: x + (1//3)*(tan(x)^3) - tan(x)
252252
--- #84 -----------------------------------------------------------------
253253
∫sec(x)^4dx = (12sin(2x) + 8sin(4x) + (4//3)*sin(6x)) / (20 + 30cos(2x) + 12cos(4x) + 2cos(6x))
@@ -268,10 +268,10 @@ expected: (1//3)*(sec(x)^3)
268268
∫(sec(x)^3)*(tan(x)^3)dx = ((-168//5) - 56cos(2x) - (176//3)*cos(x) - 48cos(3x) - (16//3)*cos(7x) - (368//15)*cos(5x) - (8//3)*cos(8x) - 32cos(4x) - 12cos(6x) - (4//15)*cos(10x)) / (252 + 420cos(2x) + 20cos(8x) + 240cos(4x) + 90cos(6x) + 2cos(10x))
269269
expected: (1//5)*(sec(x)^5) - (1//3)*(sec(x)^3)
270270
--- #90 -----------------------------------------------------------------
271-
∫tan(x)^5dx = ((3//2)*cos(8x) + 2cos(4x) + 4cos(6x) - (7//2) - 4cos(2x)) / (70 + 112cos(2x) + 2cos(8x) + 56cos(4x) + 16cos(6x)) + (1//2)*log(1 + tan(x)^2)
271+
∫tan(x)^5dx = (1//4)*(tan(x)^4) + (1//2)*log(1 + tan(x)^2) - (1//2)*(tan(x)^2)
272272
expected: (1//4)*(tan(x)^4) - (1//2)*(tan(x)^2) - log(cos(x))
273273
--- #91 -----------------------------------------------------------------
274-
∫tan(x)^6dx = ((236//3)*sin(2x) + (56//3)*sin(8x) + (272//3)*sin(4x) + 54sin(6x) + (46//15)*sin(10x)) / (252 + 420cos(2x) + 20cos(8x) + 240cos(4x) + 90cos(6x) + 2cos(10x)) - x
274+
∫tan(x)^6dx = (1//5)*(tan(x)^5) + tan(x) - x - (1//3)*(tan(x)^3)
275275
expected: (1//5)*(tan(x)^5) + tan(x) - x - (1//3)*(tan(x)^3)
276276
--- #92 -----------------------------------------------------------------
277277
∫(tan(x)^5)*sec(x)dx = ((672//5) + 224cos(2x) + (776//3)*cos(x) + 4cos(9x) + 176cos(3x) + (76//3)*cos(7x) + (1232//15)*cos(5x) + (32//3)*cos(8x) + 128cos(4x) + 48cos(6x) + (16//15)*cos(10x)) / (252 + 420cos(2x) + 20cos(8x) + 240cos(4x) + 90cos(6x) + 2cos(10x))
@@ -740,10 +740,10 @@ expected: -log(1 + cot((1//2)*x))
740740
∫1 / (3sin(x) + 4cos(x))dx = (1//5)*log((-1//2) - tan((1//2)*x)) - (1//5)*log((1//4)*tan((1//2)*x) - (1//2))
741741
expected: (-1//5)*atanh((3//5)*cos(x) - (4//5)*sin(x))
742742
--- #247 -----------------------------------------------------------------
743-
∫1 / (sin(x) + tan(x))dx = ((1//2)*cos(2x) - (1//2)) / (6 + 2cos(2x) + 8cos(x)) + (1//2)*log(tan((1//2)*x))
743+
∫1 / (sin(x) + tan(x))dx = (1//2)*log(tan((1//2)*x)) - (1//4)*(tan((1//2)*x)^2)
744744
expected: (1//2)*cot(x)*csc(x) - (1//2)*(csc(x)^2) - (1//2)*atanh(cos(x))
745745
--- #248 -----------------------------------------------------------------
746-
∫1 / (2sin(x) + sin(2x))dx = ((1//4) - (1//4)*cos(2x)) / (6 + 2cos(2x) + 8cos(x)) + (1//4)*log(tan((1//2)*x))
746+
∫1 / (2sin(x) + sin(2x))dx = (1//8)*(tan((1//2)*x)^2) + (1//4)*log(tan((1//2)*x))
747747
expected: (1//8)*(tan((1//2)*x)^2) + (1//4)*log(tan((1//2)*x))
748748
--- #249 -----------------------------------------------------------------
749749
∫sec(x) / (1 + sin(x))dx = (1 + 2sin(x) - cos(2x)) / (6 + 8sin(x) - 2cos(2x)) + (1//2)*log(-1 - tan((1//2)*x)) - (1//2)*log(tan((1//2)*x) - 1)
@@ -860,7 +860,7 @@ expected: (1//6)*(x^2) + (1//3)*log(1 + x) + (1//3)*(x^3)*log(1 + x) - (1//9)*(x
860860
∫(x^5) / exp(x^3)dx = ((-1//3) - (1//3)*(x^3)) / exp(x^3)
861861
expected: ((-1//3)*(x^3)) / exp(x^3) + (-1//3) / exp(x^3)
862862
--- #287 -----------------------------------------------------------------
863-
∫tan(4x)^2dx = ((1//2)*sin(8x)) / (2 + 2cos(8x)) - x
863+
∫tan(4x)^2dx = (1//4)*tan(4x) - x
864864
expected: (1//4)*tan(4x) - x
865865
--- #288 -----------------------------------------------------------------
866866
∫1 / sqrt(12x + 9(x^2) - 5)dx = integrand contains unsupported function sqrt
@@ -1125,7 +1125,7 @@ expected: SymbolicIntegration.NotImplementedError
11251125
∫sin(x)^4dx = (3//8)*x + (1//32)*sin(4x) - (1//4)*sin(2x)
11261126
expected: (3//8)*x - (1//4)*(sin(x)^3)*cos(x) - (3//8)*cos(x)*sin(x)
11271127
--- #375 -----------------------------------------------------------------
1128-
∫tan(x)^3dx = (1 - cos(4x)) / (6 + 8cos(2x) + 2cos(4x)) - (1//2)*log(1 + tan(x)^2)
1128+
∫tan(x)^3dx = (1//2)*(tan(x)^2) - (1//2)*log(1 + tan(x)^2)
11291129
expected: (1//2)*(tan(x)^2) + log(cos(x))
11301130
--- #376 -----------------------------------------------------------------
11311131
∫(x^5)*sqrt(1 + x^2)dx = integrand contains unsupported function sqrt

0 commit comments

Comments
 (0)