1
1
# ########################## Utility functions #########################
2
2
3
- # beautify convers floats to integers/rational numbers with small
3
+ # beautify converts floats to integers/rational numbers with small
4
4
# denominators if possible
5
5
function beautify (eq)
6
6
if is_add (eq)
@@ -47,22 +47,22 @@ function split_terms(eq, x)
47
47
end
48
48
end
49
49
50
- # is_holonomic checks whether y is a holonomic function, i.e.,
50
+ # is_holonomic checks whether y is a holonomic function, i.e.,
51
51
# is closed under differentiation w.r.t. x
52
- #
52
+ #
53
53
# For our purpose, we define a holonomic function as one composed
54
54
# of the positive powers of x, sin, cos, exp, sinh, and cosh
55
- #
55
+ #
56
56
# Args:
57
57
# y: the expression to check for holonomy
58
58
# x: independent variable
59
- #
59
+ #
60
60
# Returns:
61
61
# true if y is holonomic
62
62
function is_holonomic (y, x)
63
63
y = value (y)
64
64
65
- # technically, polynomials are not holonomic, but
65
+ # technically, polynomials are not holonomic, but
66
66
# practically we can include them
67
67
if is_polynomial (y, x)
68
68
return true
@@ -90,8 +90,8 @@ function is_holonomic(y, x)
90
90
return false
91
91
end
92
92
93
- # blender generates a list of ansatzes based on repetative
94
- # differentiation. It works for holonomic functions, which
93
+ # blender generates a list of ansatzes based on repetitive
94
+ # differentiation. It works for holonomic functions, which
95
95
# are closed under differentiation.
96
96
function blender (y, x; n = 3 )
97
97
basis = value (y)
@@ -111,7 +111,7 @@ function blender(y, x; n = 3)
111
111
return split_terms (basis, x)
112
112
end
113
113
114
- # subs_symbols returns a dictionary of the symbolic constants
114
+ # subs_symbols returns a dictionary of the symbolic constants
115
115
# in the expression and random real value assignments.
116
116
#
117
117
# Args:
@@ -138,8 +138,8 @@ function subs_symbols(eq, x; include_x = false, radius = 5.0, as_complex = true)
138
138
return S
139
139
end
140
140
141
- # atomize splits terms into a part dependent on x and a part
142
- # constant w.r.t. variables in xs.
141
+ # atomize splits terms into a part dependent on x and a part
142
+ # constant w.r.t. variables in xs.
143
143
#
144
144
# For example, `atomize(a*sin(b*x), x)` is `(a, sin(b*x))`)
145
145
function atomize (eq, xs... )
@@ -165,7 +165,7 @@ function atomize(eq, xs...)
165
165
end
166
166
end
167
167
168
- # apply_coefs generates the final integral based on the list
168
+ # apply_coefs generates the final integral based on the list
169
169
# of coefficients (q) and a list of ansatzes (ker).
170
170
function apply_coefs (q, ker)
171
171
s = 0
@@ -201,11 +201,11 @@ complex_from_num(x) = Complex(value(real(x)), value(imag(x)))
201
201
# ########################## Symbolic Integration #############################
202
202
203
203
# integrate_symbolic is the main entry point for symbolic integration.
204
- #
204
+ #
205
205
# Argu:
206
206
# eq: the expression to integrate
207
207
# x: independent variable
208
- #
208
+ #
209
209
# Returns:
210
210
# the integral or nothing if no solution
211
211
function integrate_symbolic (eq, x; plan = default_plan ())
@@ -226,10 +226,10 @@ struct Problem
226
226
x:: Expression # independent variable
227
227
coef:: Expression # coefficient of the integrand
228
228
ker:: Array{Expression} # the pruned list of the basis expressions (kernel)
229
- plan:: NumericalPlan # the numerial plan, containing various parameters
229
+ plan:: NumericalPlan # the numerical plan, containing various parameters
230
230
end
231
231
232
- # Constructor to create a Problem for integrand eq
232
+ # Constructor to create a Problem for integrand eq
233
233
function Problem (eq, x; plan = default_plan ())
234
234
eq = expand (eq)
235
235
coef, eq = atomize (eq, x)
@@ -314,14 +314,14 @@ subs_symbols(prob::Problem) = subs_symbols(prob.eq, prob.x)
314
314
abstract type IntegrationAlgorithm end
315
315
316
316
struct SymbolicIntegrator <: IntegrationAlgorithm
317
- eqs:: Vector{Equation} # list of equations of the form Σ θ[i]*frag[i] ~ 0
317
+ eqs:: Vector{Equation} # list of equations of the form Σ θ[i]*frag[i] ~ 0
318
318
vars:: Vector{Expression} # list of dummy variables (θ[1], θ[2], ...)
319
319
frags:: Dict # Dict of fragments of form frag => expression in θs
320
320
end
321
321
322
322
@variables θ[1 : 30 ]
323
323
324
- # Constructor creating a SymbolicIntegrator algorithm
324
+ # Constructor creating a SymbolicIntegrator algorithm
325
325
# from an integration Problem
326
326
function SymbolicIntegrator (prob:: Problem )
327
327
frags = Dict ()
@@ -355,16 +355,16 @@ function solver(prob::Problem, alg::SymbolicIntegrator)
355
355
sol = apply_coefs (q, prob. ker)
356
356
return sol
357
357
catch e
358
- # println(e)
358
+ # println(e)
359
359
end
360
360
361
361
return nothing
362
362
end
363
363
364
364
# If the linear system generated by the SymbolicIntegrator solver is
365
- # under-determined, make_square uses semi-numerical methods to
365
+ # under-determined, make_square uses semi-numerical methods to
366
366
# generate a full-rank linear system.
367
- #
367
+ #
368
368
# The output is another SymbolicIntegrator or nothing if unsuccessful.
369
369
function make_square (prob:: Problem , alg:: SymbolicIntegrator )
370
370
n = length (alg. vars)
@@ -390,10 +390,10 @@ function make_square(prob::Problem, alg::SymbolicIntegrator)
390
390
end
391
391
392
392
struct NumericIntegrator
393
- A:: AbstractMatrix # training dataset as a normalized linear system
393
+ A:: AbstractMatrix # training dataset as a normalized linear system
394
394
X:: AbstractVector # vector of test points
395
395
V:: AbstractMatrix # verification dataset
396
- basis:: Vector{Expression} # expand basis
396
+ basis:: Vector{Expression} # expand basis
397
397
end
398
398
399
399
# Constructor to create a NumericIntegrator algorithm from prob
0 commit comments