Code Monkey home page Code Monkey logo

theta.jl's Introduction

Theta.jl

Documentation Build Status Code Coverage
Build Status Coverage Status codecov

Theta.jl is a Julia package for computing the Riemann theta function and its derivatives.

For more information, refer to our preprint.

Installation

Download Julia 1.4. Start Julia and run

import Pkg
Pkg.add("Theta")

Examples

First load the package in Julia.

using Theta

We start with a matrix M in the Siegel upper-half space.

M = [0.794612+1.9986im 0.815524+1.95836im 0.190195+1.21249im 0.647434+1.66208im 0.820857+1.68942im; 
0.0948191+1.95836im 0.808422+2.66492im 0.857778+1.14274im 0.754323+1.72747im 0.74972+1.95821im; 
0.177874+1.21249im 0.420423+1.14274im 0.445617+1.44248im 0.732018+0.966489im 0.564779+1.57559im; 
0.440969+1.66208im 0.562332+1.72747im 0.292166+0.966489im 0.433763+1.91571im 0.805161+1.46982im; 
0.471487+1.68942im 0.0946854+1.95821im 0.837648+1.57559im 0.311332+1.46982im 0.521253+2.29221im];      

We construct a RiemannMatrix using M.

R = RiemannMatrix(M);

We can then compute the theta function on inputs z and M as follows.

z = [0.30657351+0.34017115im; 0.71945631+0.87045964im; 0.19963849+0.71709398im; 0.64390182+0.97413482im; 0.02747232+0.59071266im];
theta(z, R)

We can also compute first derivatives of theta functions by specifying the direction using the optional argument derivs. The following code computes the partial derivative of the theta function with respect to the first coordinate of z.

theta(z, R, derivs=[[1,0,0,0,0]])

We specify higher order derivatives by adding more elements into the input to derivs, where each element specifies the direction of the derivative. For instance, to compute the partial derivative of the theta function with respect to the first, second and fifth coordinates of z, we run

theta(z, R, derivs=[[1,0,0,0,0], [0,1,0,0,0], [0,0,0,0,1]])

We can compute theta functions with characteristics using the optional argument char.

theta(z, R, char=[[0,1,0,1,1],[0,1,1,0,0]])

We can also compute derivatives of theta functions with characteristics.

theta(z, R, derivs=[[1,0,0,0,0]], char=[[0,1,0,1,1],[0,1,1,0,0]])

theta.jl's People

Contributors

chualynn avatar irojkov-ph avatar juliatagbot avatar vchuravy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

theta.jl's Issues

error theta in 1 dimension

I get (version julia-1.9.0-win64) :

julia> theta([0], RiemannMatrix([im]))
ERROR: MethodError: no method matching +(::Float64, ::Vector{Float64})
For element-wise addition, use broadcasting with dot syntax: scalar .+ array

Closest candidates are:
+(::Any, ::Any, ::Any, ::Any...)
@ Base operators.jl:578
+(::T, ::T) where T<:Union{Float16, Float32, Float64}
@ Base float.jl:408
+(::Union{Float16, Float32, Float64}, ::BigFloat)
@ Base mpfr.jl:423
...

Stacktrace:
[1] (::Theta.var"#9#12"{RiemannMatrix, Vector{Float64}, Vector{Any}, Matrix{Float64}, Matrix{Float64}, Int64})(p::Vector{Float64})
@ Theta .\none:0
[2] iterate
@ .\generator.jl:47 [inlined]
[3] collect(itr::Base.Generator{Vector{Vector{Float64}}, Theta.var"#9#12"{RiemannMatrix, Vector{Float64}, Vector{Any}, Matrix{Float64}, Matrix{Float64}, Int64}})
@ Base .\array.jl:782
[4] oscillatory_part(R::RiemannMatrix, x::Vector{Float64}, y0::Matrix{Float64}, shift_n::Vector{Float64}, derivs::Vector{Any})
@ Theta xxx.julia\packages\Theta\2Upgk\src\eval_theta.jl:61
[5] theta(z::Vector{Int64}, R::RiemannMatrix; char::Vector{Any}, derivs::Vector{Any}, derivs_t::Vector{Any})
@ Theta xxx.julia\packages\Theta\2Upgk\src\eval_theta.jl:46
[6] theta(z::Vector{Int64}, R::RiemannMatrix)
@ Theta xxx.julia\packages\Theta\2Upgk\src\eval_theta.jl:20
[7] top-level scope
@ REPL[2]:1

Wrong result theta

Wrong :

julia> theta([0,0], RiemannMatrix([im/5 0;0 im/5]))
1.000000602807001 + 0.0im

Right :

julia> theta([0,0], RiemannMatrix([5im 0;0 5im]))
1.000000602807001 + 0.0im

My julia Version : julia-1.9.0-win64

Allowing scalar input (Jacobi theta)

Let me say first that your package saved my life ๐Ÿ˜‰ I might have a suggestion for an enhancement though.

I needed the Jacobi theta function, of which Riemann theta is a generalization. While wrapping variables into arrays works perfectly fine, it would be nice to have a dedicated method for scalar inputs in order to avoid allocating temporary 1-element arrays.

I can imagine it could be too difficult due to how your implementation relies on inputs being arrays or it could bring negligible benefits in comparison with evaluation of the function itself. In such a case, a simple wrapper would be still very convenient.

EDIT

I was a bit fast with this one... I don't know what exactly happened, but a combination of kernel restarts and updates broke something and now I can't wrap scalars any more. Boiling your example down to single numbers results in:

M = hcat(0.794612+1.9986im)
R = RiemannMatrix(M)
z = [0.30657351+0.34017115im]
theta(z, RiemannMatrix(M))
MethodError: no method matching +(::Float64, ::Array{Float64,1})
For element-wise addition, use broadcasting with dot syntax: scalar .+ array
Closest candidates are:
  +(::Any, ::Any, ::Any, ::Any...) at operators.jl:538
  +(::Float64, ::Float64) at float.jl:401
  +(::AbstractFloat, ::Bool) at bool.jl:106
  ...

Here's my environment:

Pkg.status()
Status `~/.julia/environments/v1.5/Project.toml`
  [7073ff75] IJulia v1.23.2
  [76087f3c] NLopt v0.5.1
  [91a5bcdd] Plots v1.10.6
  [d330b81b] PyPlot v2.9.0
  [42bdb5c4] Theta v0.1.2

Any help appreciated!

Disagrees with Mathematica

Hello,

I was very excited to find this package since I need to compute Riemann Theta functions in Julia. However, the theta function exported by this package seems to disagree with the SiegelTheta function in Mathematica on a simple test case. The Mathematica code
SiegelTheta[{{I/2, -1/2}, {-1/2, I/2}}, {0.5, 0.5}] gives 2.21457*10^-11 - 9.61931*10^-24 I. This makes sense, as one can prove this value is exactly 0. However, I find that theta([0.5, 0.5], RiemannMatrix([[1im/2, -1/2] [-1/2, 1im/2]])) evaluates to 0.9925441784910575 - 5.823949418449035e-35im in Julia 1.7. Am I misunderstanding something? Thanks very much for your help!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.