Skip to content

Commit de34d8c

Browse files
symbolic tests added
1 parent 1dd6117 commit de34d8c

File tree

3 files changed

+86
-42
lines changed

3 files changed

+86
-42
lines changed

src/integral.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function integrate_sum(eq, x; bypass = false, kwargs...)
109109
ε₀ = max(ε₀, ε)
110110
end
111111

112-
if !isequal(unsolved, 0) && isempty(const_params(unsolved, x))
112+
if !isequal(unsolved, 0) && isempty(sym_consts(unsolved, x))
113113
eq = factor_rational(simplify_trigs(unsolved))
114114

115115
if !isequal(eq, unsolved)

src/symbolic.jl

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,26 @@
1-
function extract_real(y)
2-
if istree(y)
3-
if is_add(y)
4-
return sum(extract_real(t) for t in args(y))
5-
elseif is_mul(y)
6-
return prod(extract_real(t) for t in args(y))
7-
elseif is_div(y)
8-
return extract_real(numer(y)) / extract_real(denom(y))
9-
elseif is_pow(y)
10-
q = args(p)[1]
11-
k = args(p)[2]
12-
return extract_real(q) ^ k
13-
else
14-
return y
15-
end
16-
else
17-
return real(y)
18-
end
19-
end
20-
21-
22-
function beautify(coef)
23-
if is_add(coef)
24-
return sum(beautify(t) for t in args(coef))
25-
elseif is_mul(coef)
26-
return prod(beautify(t) for t in args(coef))
27-
elseif is_pow(coef)
28-
p = args(coef)[1]
29-
k = args(coef)[2]
1+
"""
2+
Convers floats to integers/rational numbers with small denominators
3+
if possible
4+
"""
5+
function beautify(eq)
6+
if is_add(eq)
7+
return sum(beautify(t) for t in args(eq))
8+
elseif is_mul(eq)
9+
return prod(beautify(t) for t in args(eq))
10+
elseif is_pow(eq)
11+
p = args(eq)[1]
12+
k = args(eq)[2]
3013
return beautify(p) ^ k
31-
elseif is_div(coef)
32-
return beautify(numer(coef)) / beautify(denom(coef))
33-
elseif is_number(coef)
34-
return nice_parameter(coef)
14+
elseif is_div(eq)
15+
return beautify(numer(eq)) / beautify(denom(eq))
16+
elseif is_number(eq)
17+
return nice_parameter(eq)
3518
else
36-
return coef
19+
return eq
3720
end
3821
end
3922

23+
4024
###################################################################
4125

4226
"""

test/runtests.jl

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ include("axiom.jl")
1111

1212
##############################################################################
1313

14-
@variables x β
14+
@variables x a b β
1515

1616
"""
1717
a list of basic standard integral tests
@@ -205,17 +205,77 @@ basic_integrals = [
205205
1 / log(x) - 1 / log(x)^2,
206206
]
207207

208-
function test_integrals(subs=nothing, rng=nothing; kw...)
208+
209+
sym_integrals = [
210+
# Basic Forms
211+
a*x^2,
212+
a / x,
213+
1 / (a*x + 5),
214+
1 / (x + a)^2,
215+
(x + a)^3,
216+
x * (x - a)^4,
217+
1 / (a + x^2),
218+
sqrt(x - a),
219+
1 / sqrt(a*x - 1),
220+
x * sqrt(a*x + b),
221+
log(a*x),
222+
x * log(a*x),
223+
x^2 * log(a*x),
224+
log(a*x) / x,
225+
log(x^2 - a*x + b),
226+
log(a*x)^2,
227+
x^2 * log(a*x+b)^2,
228+
exp(a*x),
229+
x * exp(a*x),
230+
x^2 * exp(a*x),
231+
x * exp(a*x^2),
232+
sin(a*x),
233+
sin(a*x)^2,
234+
cos(a*x + b)^2,
235+
sin(a*x) * cos(a*x),
236+
sin(a*x) * cos(b*x),
237+
tan(a*x),
238+
sec(a*x),
239+
x * cos(a*x),
240+
x^2 * cos(a*x),
241+
sin(a*x)^2 * cos(b*x)^3,
242+
exp(a*x) * sin(b*x),
243+
x * exp(a*x) * sin(a*x),
244+
x * exp(a*x) * cos(b*x),
245+
cosh(a*x),
246+
exp(a*x) * cosh(b*x),
247+
cos(a*x) * cosh(b*x),
248+
sec(a*x)^2 * tan(a*x),
249+
exp(a*x) / (1 + exp(a*x)),
250+
cos(exp(a*x)) * sin(exp(a*x)) * exp(a*x),
251+
1 / (x * log(a*x)),
252+
log(log(a*x)) / x,
253+
sin(log(a*x)),
254+
x / (exp(a*x) - b),
255+
exp(a*x) * exp(exp(a*x)),
256+
log(cos(a*x)) * tan(a*x),
257+
1 / (x^3 + a),
258+
exp(a*x+b) / x,
259+
sin(x + a) / (x + a),
260+
cos(a*x) / x,
261+
x / log(a*x^2),
262+
# bypass = true
263+
β, # turn of bypass = true
264+
exp(a*x) / x - exp(a*x) / x^2,
265+
cos(a*x) / x - sin(a*x) / x^2,
266+
]
267+
268+
269+
function test_integrals(basis=true, subs=nothing; kw...)
209270
args = isempty(kw) ? Dict() : Dict(kw)
210271
args[:detailed] = false
211272
misses = []
212273
k = 1
274+
275+
integrals = basis ? basic_integrals : sym_integrals
276+
args[:symbolic] = !basis
213277

214-
for (i, eq) in enumerate(basic_integrals)
215-
if rng != nothing && !(i in rng)
216-
continue
217-
end
218-
278+
for (i, eq) in enumerate(integrals)
219279
if isequal(eq, β)
220280
printstyled("**** bypass on ****\n"; color = :red)
221281
bypass = true

0 commit comments

Comments
 (0)