Skip to content

Commit

Permalink
Use TaylorDiff
Browse files Browse the repository at this point in the history
  • Loading branch information
SouthEndMusic committed Jul 22, 2024
1 parent 8026cde commit b60c6a4
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 242 deletions.
28 changes: 13 additions & 15 deletions GaussTuranExampleTemp/example.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using Optim
using TaylorDiff
using PreallocationTools
using Integrals
using DoubleFloats

include("high_order_derivatives.jl")

# This fix is needed to avoid crashing: https://github.com/JuliaLang/julia/pull/54201
include("linear_algebra_fix.jl")

FT = Double64
FT = Float64 # Double64
n = 5
s = 1
a = FT(0.0)
Expand All @@ -17,7 +16,7 @@ b = FT(1.0)
"""
Example functions ϕⱼ from [1]
"""
function f(x::T, j::Int)::T where {T<:Number}
function f(x::T, j::Int)::T where {T <: Number}
pow = if j % 2 == 0
j / 2 - 1
else
Expand All @@ -26,10 +25,8 @@ function f(x::T, j::Int)::T where {T<:Number}
x^pow
end

deriv! = @generate_derivs(2)
I = Integrals.GaussTuran(
f,
deriv!,
a,
b,
n,
Expand All @@ -39,25 +36,26 @@ I = Integrals.GaussTuran(
g_tol = FT(1e-250),
show_trace = true,
show_every = 100,
iterations = 10_000,
),
iterations = 10_000
)
)

# Integration error |I(fⱼ) - ₐ∫ᵇfⱼ(x)dx| first N functions fⱼ
max_int_error_upper =
maximum(abs(I(x -> f(x, j)) - I.cache.rhs_upper[j]) for j = 1:I.cache.N)
max_int_error_upper = maximum(abs(I(x -> f(x, j)) - I.cache.rhs_upper[j])
for j in 1:(I.cache.N))
@show max_int_error_upper
# max_int_error_upper = 3.0814879110195774e-32
# max_int_error_upper = 2.220446049250313e-16

# Integration error |I(fⱼ) - ₐ∫ᵇfⱼ(x)dx| last n functions fⱼ
max_int_error_lower = maximum(
abs(I(x -> f(x, j)) - I.cache.rhs_lower[j-I.cache.N]) for
j = (I.cache.N+1):(I.cache.N+I.cache.n)
abs(I(x -> f(x, j)) - I.cache.rhs_lower[j - I.cache.N])
for
j in (I.cache.N + 1):(I.cache.N + I.cache.n)
)
@show max_int_error_lower
# max_int_error_lower = 2.8858134286698342e-30
# max_int_error_lower = 2.0211055051788662e-12

# Example with eˣ
exp_error = abs(I(Base.exp) - (Base.exp(1) - 1))
@show exp_error;
# exp_error = -6.436621416953051e-18
# exp_error = 1.5543122344752192e-15
57 changes: 0 additions & 57 deletions GaussTuranExampleTemp/high_order_derivatives.jl

This file was deleted.

Loading

0 comments on commit b60c6a4

Please sign in to comment.