CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-mpmath

Python library for arbitrary-precision floating-point arithmetic

Pending
Overview
Eval results
Files

elliptic-modular-functions.mddocs/

Elliptic Functions and Modular Forms

Elliptic functions, modular forms, theta functions, and q-analog functions for advanced mathematical applications including algebraic geometry, number theory, and mathematical physics.

Capabilities

Elliptic Functions and Jacobi Functions

Jacobi elliptic functions and their variants.

def jacobi(kind, u, m):
    """
    Jacobi elliptic functions.
    
    Args:
        kind: Function type ('sn', 'cn', 'dn', 'ns', 'nc', 'nd', 'sc', 'cs', 'sd', 'ds', 'cd', 'dc')
        u: Argument
        m: Parameter (0 ≤ m ≤ 1)
        
    Returns:
        Specified Jacobi elliptic function
    """

def ellipfun(kind, u, m):
    """
    Jacobi elliptic function (alias for jacobi).
    
    Args:
        kind: Function type
        u: Argument  
        m: Parameter
        
    Returns:
        Jacobi elliptic function
    """

Modular Parameter Conversions

Functions for converting between different modular parameters.

def qfrom(m=None, k=None, tau=None):
    """
    Compute nome q from modular parameters.
    
    Args:
        m: Parameter m (alternative to k or tau)
        k: Modulus k (alternative to m or tau)
        tau: Half-period ratio τ (alternative to m or k)
        
    Returns:
        Nome q = exp(iπτ)
    """

def mfrom(q=None, k=None, tau=None):
    """
    Compute parameter m from other modular parameters.
    
    Args:
        q: Nome q (alternative to k or tau)
        k: Modulus k (alternative to q or tau)
        tau: Half-period ratio τ (alternative to q or k)
        
    Returns:
        Parameter m
    """

def kfrom(m=None, q=None, tau=None):
    """
    Compute modulus k from other modular parameters.
    
    Args:
        m: Parameter m (alternative to q or tau)
        q: Nome q (alternative to m or tau)
        tau: Half-period ratio τ (alternative to m or q)
        
    Returns:
        Modulus k
    """

def taufrom(m=None, k=None, q=None):
    """
    Compute half-period ratio τ from other modular parameters.
    
    Args:
        m: Parameter m (alternative to k or q)
        k: Modulus k (alternative to m or q)
        q: Nome q (alternative to m or k)
        
    Returns:
        Half-period ratio τ
    """

def qbarfrom(m=None, k=None, tau=None):
    """
    Compute complementary nome q' from modular parameters.
    
    Args:
        m: Parameter m (alternative to k or tau)
        k: Modulus k (alternative to m or tau)
        tau: Half-period ratio τ (alternative to m or k)
        
    Returns:
        Complementary nome q'
    """

Jacobi Theta Functions

Jacobi theta functions and their variants.

def jtheta(n, z, q, derivative=0):
    """
    Jacobi theta function θ_n(z,q).
    
    Args:
        n: Function index (1, 2, 3, or 4)
        z: Argument
        q: Nome parameter
        derivative: Derivative order (default 0)
        
    Returns:
        θ_n(z,q) or its derivative
    """

Modular Forms

Modular forms and related functions.

def kleinj(tau):
    """
    Klein j-invariant function.
    
    Args:
        tau: Modular parameter
        
    Returns:
        j(τ) - Klein j-invariant
    """

def eta(tau):
    """
    Dedekind eta function η(τ).
    
    Args:
        tau: Modular parameter (Im(τ) > 0)
        
    Returns:
        η(τ) = q^(1/24) ∏(1-q^n) where q = exp(2πiτ)
    """

Elliptic Integrals

Complete and incomplete elliptic integrals of the first, second, and third kind.

def ellipe(*args):
    """
    Complete or incomplete elliptic integral of the second kind E(m) or E(φ,m).
    
    Args:
        m: Parameter (when called with one argument)
        φ, m: Amplitude and parameter (when called with two arguments)
        
    Returns:
        Complete: E(m) = ∫₀^(π/2) √(1-m sin²θ) dθ
        Incomplete: E(φ,m) = ∫₀^φ √(1-m sin²θ) dθ
    """

def ellipf(phi, m):
    """
    Incomplete elliptic integral of the first kind F(φ,m).
    
    Args:
        phi: Amplitude
        m: Parameter
        
    Returns:
        F(φ,m) = ∫₀^φ dθ/√(1-m sin²θ)
    """

def ellippi(n, *args):
    """
    Complete or incomplete elliptic integral of the third kind Π(n,m) or Π(n,φ,m).
    
    Args:
        n: Characteristic
        m: Parameter (for complete integral)
        φ, m: Amplitude and parameter (for incomplete integral)
        
    Returns:
        Complete: Π(n,m) = ∫₀^(π/2) dθ/((1-n sin²θ)√(1-m sin²θ))
        Incomplete: Π(n,φ,m) = ∫₀^φ dθ/((1-n sin²θ)√(1-m sin²θ))
    """

Q-Functions and Quantum Analogs

Q-analog functions for quantum mathematics and combinatorics.

def qp(a, q, n):
    """
    q-Pochhammer symbol (a;q)_n.
    
    Args:
        a: Base parameter
        q: q-parameter
        n: Count (can be infinity)
        
    Returns:
        (a;q)_n = ∏(1-aq^k) for k=0 to n-1
    """

def qhyper(a_s, b_s, q, z, **kwargs):
    """
    Basic hypergeometric function.
    
    Args:
        a_s: List of numerator parameters
        b_s: List of denominator parameters
        q: q-parameter
        z: Argument
        **kwargs: Additional options
        
    Returns:
        Basic hypergeometric series
    """

def qgamma(z, q):
    """
    q-gamma function Γ_q(z).
    
    Args:
        z: Argument
        q: q-parameter
        
    Returns:
        q-gamma function
    """

def qfac(n, q):
    """
    q-factorial [n]_q!.
    
    Args:
        n: Non-negative integer
        q: q-parameter
        
    Returns:
        [n]_q! = [1]_q[2]_q...[n]_q where [k]_q = (1-q^k)/(1-q)
    """

Usage Examples

import mpmath
from mpmath import mp

# Set precision
mp.dps = 25

# Jacobi elliptic functions
m = 0.5  # Parameter
u = 1.0  # Argument

sn_val = mp.jacobi('sn', u, m)
cn_val = mp.jacobi('cn', u, m)
dn_val = mp.jacobi('dn', u, m)

print(f"sn({u}, {m}) = {sn_val}")
print(f"cn({u}, {m}) = {cn_val}")
print(f"dn({u}, {m}) = {dn_val}")

# Verify fundamental identity: sn² + cn² = 1
identity = sn_val**2 + cn_val**2
print(f"sn² + cn² = {identity}")  # Should be 1

# Modular parameter conversions
k = 0.5  # Modulus
m_from_k = mp.mfrom(k=k)
q_from_k = mp.qfrom(k=k)
tau_from_k = mp.taufrom(k=k)

print(f"From k={k}:")
print(f"  m = {m_from_k}")
print(f"  q = {q_from_k}")
print(f"  τ = {tau_from_k}")

# Theta functions
tau = 1j  # Pure imaginary for convergence
z = 0.5
q = mp.exp(mp.j * mp.pi * tau)

theta1 = mp.jtheta(1, z, q)
theta2 = mp.jtheta(2, z, q)
theta3 = mp.jtheta(3, z, q)
theta4 = mp.jtheta(4, z, q)

print(f"θ₁({z}, q) = {theta1}")
print(f"θ₂({z}, q) = {theta2}")
print(f"θ₃({z}, q) = {theta3}")
print(f"θ₄({z}, q) = {theta4}")

# Dedekind eta function
eta_val = mp.eta(tau)
print(f"η({tau}) = {eta_val}")

# Klein j-invariant
j_val = mp.kleinj(tau)
print(f"j({tau}) = {j_val}")

# Q-functions
q = 0.5
n = 5

# q-factorial
qfac_val = mp.qfac(n, q)
print(f"[{n}]_q! = {qfac_val}")

# q-Pochhammer symbol
a = 2
qpoch_val = mp.qp(a, q, n)
print(f"({a};{q})_{n} = {qpoch_val}")

# q-gamma function
z = 3
qgamma_val = mp.qgamma(z, q)
print(f"Γ_q({z}) = {qgamma_val}")

# Complete elliptic integrals (for comparison)
K_val = mp.ellipk(m)
E_val = mp.ellipe(m)
print(f"K({m}) = {K_val}")
print(f"E({m}) = {E_val}")

# Relationship between Jacobi functions and elliptic integrals
# sn(K(m), m) should equal 1
sn_at_K = mp.jacobi('sn', K_val, m)
print(f"sn(K({m}), {m}) = {sn_at_K}")  # Should be close to 1

# Advanced: Basic hypergeometric series
a_list = [0.5]
b_list = [2]
z = 0.3
qhyper_val = mp.qhyper(a_list, b_list, q, z)
print(f"₁φ₁(0.5; 2; {q}, {z}) = {qhyper_val}")

Applications and Context

These functions are fundamental in:

  • Algebraic Geometry: Elliptic curves and modular forms
  • Number Theory: L-functions and modular equations
  • Mathematical Physics: Exactly solvable models and conformal field theory
  • Combinatorics: Partition functions and q-analogs
  • Complex Analysis: Doubly periodic functions and uniformization

The modular parameter conversions allow seamless translation between different conventions used in various mathematical contexts, while the q-analog functions provide discrete analogs of classical special functions that arise naturally in quantum mathematics and combinatorics.

Install with Tessl CLI

npx tessl i tessl/pypi-mpmath

docs

core-arithmetic.md

elementary-functions.md

elliptic-modular-functions.md

index.md

linear-algebra.md

mathematical-constants.md

numerical-calculus.md

pattern-recognition.md

signal-processing.md

special-functions.md

visualization.md

tile.json