Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multivariate Taylor expansion with HypergeometricFunctions #336

Open
Li-shiyue opened this issue Oct 3, 2023 · 6 comments
Open

Multivariate Taylor expansion with HypergeometricFunctions #336

Li-shiyue opened this issue Oct 3, 2023 · 6 comments

Comments

@Li-shiyue
Copy link

using TaylorSeries
using HypergeometricFunctions
function bbb(params)
x,y = params
return _₁F₁(2,3,x+0.5*y-1)
end
x, y = set_variables("x y", order=8)
bbb([x,y])
ERROR: MethodError: no method matching AbstractFloat(::TaylorN{Float64})

Closest candidates are:
(::Type{T})(::T) where T<:Number
@ Core boot.jl:792
(::Type{T})(::AbstractChar) where T<:Union{AbstractChar, Number}
@ Base char.jl:50
(::Type{T})(::Base.TwicePrecision) where T<:Number
@ Base twiceprecision.jl:266
...

Can anybody tell me how to solve it?

@lbenet
Copy link
Member

lbenet commented Oct 3, 2023

This one is more complicated. So I'll explain you where I am.

julia> using TaylorSeries, HypergeometricFunctions

julia> x, y = set_variables("x y", order=8);

julia> Base.float(t::HomogeneousPolynomial) = HomogeneousPolynomial(float.(t.coeffs))

julia> Base.float(t::TaylorN) = TaylorN(float.(t.coeffs), t.order)

julia> TaylorSeries.TaylorN{T}(a::S) where {T,S} = (R=promote_type(T,S); TaylorN(R(a), get_order()))

julia> Base.eps(::Type{TaylorN{T}}) where {T} = eps(one(T))

julia> Base.eps(a::TaylorN) = eps(constant_term(a))

julia> _₁F₁(2,3,x+0.5*y-1)
 0.5284822353142297 + 0.32120558828564066 x + 0.16060279414282033 y + 0.11392894125311108 x² + 0.11392894125613448 x y + 0.02848223531327777 y² + 0.029278774897663628 x³ + 0.0439181620949485 x² y + 0.02195908104747425 x y² + 0.0036598468622079535 y³ + 0.005941825591207862 x⁴ + 0.01188368338042503 x³ y + 0.008912756962586393 x² y² + 0.0029709208451062577 x y³ + 0.00037136409945049136 y⁴ + 0.0010004169168939174 x⁵ + 0.002497931469181667 x⁴ y + 0.0024982484957348523 x³ y² + 0.0012491242478674261 x² y³ + 0.00031226124780728244 x y⁴ + 3.126302865293492e-5 y⁵ + 6.657557616881685e-5 x⁶ + 0.0003943810321619436 x⁵ y + 0.0005199235472231411 x⁴ y² + 0.0003170265531848421 x³ y³ + 0.00012617656816756717 x² y⁴ + 2.3222195020789684e-5 x y⁵ + 1.0402433776377632e-6 y⁶ + 0.00295215126325725 x⁷ + 0.0015420171546910721 x⁶ y - 0.0016231759523063917 x⁵ y² + 0.0007304291785378762 x⁴ y³ + 0.0006695600803263865 x³ y⁴ + 5.072424850957474e-5 x² y⁵ + 9.891228459367074e-5 x y⁶ + 2.3063681744197264e-5 y⁷ - 0.08602832547223875 x⁸ - 0.0389562228553534 x⁷ y + 0.17790008437278051 x⁶ y² + 0.11816720932790531 x⁵ y³ + 0.01753030028490903 x⁴ y⁴ + 0.00941442052337707 x³ y⁵ + 0.002597081523690227 x² y⁶ - 0.0018159280966427757 x y⁷ - 0.0003360481463759326 y⁸ + 𝒪(‖x‖⁹)

Please check if this should be the expected output.

@Li-shiyue
Copy link
Author

It doesn't work
function tele_gf111(params,t,z)
a,b = params
pfq1 = HypergeometricFunctions.pFq((1+a,), (b,),t*(z-1))
pfq2 = HypergeometricFunctions.pFq((a+b,), (b,), t*(z-1))
return pfq1+pfq2
end
x, y = set_variables("x y",order=8)
Base.float(t::HomogeneousPolynomial) = HomogeneousPolynomial(float.(t.coeffs))
Base.float(t::TaylorN) = TaylorN(float.(t.coeffs), t.order)
TaylorSeries.TaylorN{T}(a::S) where {T,S} = (R=promote_type(T,S); TaylorN(R(a), get_order()))
Base.eps(::Type{TaylorN{T}}) where {T} = eps(one(T))
Base.eps(a::TaylorN) = eps(constant_term(a))
@time taylor_cof = tele_gf111([2,2],x,y)
ERROR: MethodError: no method matching iterate(::Type{HypergeometricFunctions.ℕ})

Closest candidates are:
iterate(::Union{LinRange, StepRangeLen})
@ Base range.jl:880
iterate(::Union{LinRange, StepRangeLen}, ::Integer)
@ Base range.jl:880
iterate(::T) where T<:Union{Base.KeySet{<:Any, <:Dict}, Base.ValueIterator{<:Dict}}
@ Base dict.jl:698
...

@lbenet
Copy link
Member

lbenet commented Oct 3, 2023

One single hint: copy-pasting my code above, and including the following, shows the problem:

julia> a = 2
2

julia> b = 2
2

julia> pfq1 = HypergeometricFunctions.pFq((1+a,), (b,),x*(y-1))
ERROR: AssertionError: !(iszero(constant_term(b)))
Stacktrace:
  [1] /(a::TaylorN{Float64}, b::TaylorN{Float64})
    @ TaylorSeries ~/.julia/dev/TaylorSeries/src/arithmetic.jl:662

You cannot divide two TaylorN objects, when the denominator contains a zero constant term.

@Li-shiyue
Copy link
Author

function tele_gf111(params,t,z)
a,b = params
pfq1 = HypergeometricFunctions.pFq((1+a,), (a,),t+b*(z-1))
pfq2 = HypergeometricFunctions.pFq((a+b,), (a,), t+b*(z-1))
return pfq1+pfq2
end
x, y = set_variables("x y",order=8)
Base.float(t::HomogeneousPolynomial) = HomogeneousPolynomial(float.(t.coeffs))
Base.float(t::TaylorN) = TaylorN(float.(t.coeffs), t.order)
TaylorSeries.TaylorN{T}(a::S) where {T,S} = (R=promote_type(T,S); TaylorN(R(a), get_order()))
Base.eps(::Type{TaylorN{T}}) where {T} = eps(one(T))
Base.eps(a::TaylorN) = eps(constant_term(a))
@time taylor_cof = tele_gf111([21,4],x,y)

This works fine for me,!!!!!

However,here is a little change,When I seperate TaylorN,so I define:
function tele_gf111(params,t,z)
a,b = params
pfq1 = HypergeometricFunctions.pFq((1+a,), (a,),t+b*(z-1))
pfq2 = HypergeometricFunctions.pFq((a+t,), (a,), t+b*(z-1))
return pfq1+pfq2
end
or
function tele_gf111(params,t,z)
a,b = params
pfq1 = HypergeometricFunctions.pFq((1+a,), (a,),t+b*(z-1))
pfq2 = HypergeometricFunctions.pFq((t+z-1,), (a,), t+b*(z-1))
return pfq1+pfq2
end
Then I get error:
ERROR: MethodError: no method matching iterate(::Type{HypergeometricFunctions.ℕ₀})

Closest candidates are:
iterate(!Matched::Union{LinRange, StepRangeLen})
@ Base range.jl:880
iterate(!Matched::Union{LinRange, StepRangeLen}, !Matched::Integer)
@ Base range.jl:880
iterate(!Matched::T) where T<:Union{Base.KeySet{<:Any, <:Dict}, Base.ValueIterator{<:Dict}}
@ Base dict.jl:698
...
I am interesting about get the Series when TaylorN is seperated

@lbenet lbenet mentioned this issue Oct 4, 2023
@lbenet lbenet reopened this Oct 4, 2023
@Li-shiyue
Copy link
Author

I divide two TaylorN while the denominator doesn't contain a zero constant term.but get the error,I don't know how to solve it
x, y = set_variables("x y", order=8)
Base.float(t::HomogeneousPolynomial) = HomogeneousPolynomial(float.(t.coeffs))
Base.float(t::TaylorN) = TaylorN(float.(t.coeffs), t.order)
TaylorSeries.TaylorN{T}(a::S) where {T,S} = (R=promote_type(T,S); TaylorN(R(a), get_order()))
Base.eps(::Type{TaylorN{T}}) where {T} = eps(one(T))
Base.eps(a::TaylorN) = eps(constant_term(a))
HypergeometricFunctions.pFq((x,),(2,),x+y)pFq((2,),(4,),x+0.5y)
ERROR: MethodError: no method matching iterate(::Type{HypergeometricFunctions.ℕ₀})

Closest candidates are:
iterate(!Matched::Union{LinRange, StepRangeLen})
@ Base range.jl:880
iterate(!Matched::Union{LinRange, StepRangeLen}, !Matched::Integer)
@ Base range.jl:880
iterate(!Matched::T) where T<:Union{Base.KeySet{<:Any, <:Dict}, Base.ValueIterator{<:Dict}}
@ Base dict.jl:698
...

@Li-shiyue
Copy link
Author

Is there anyone to help? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants