Python interface (pycalcium / pyca)

Calcium includes a simple Python interface (pycalcium, or pyca for short) implemented using ctypes.

Introduction

Setup and usage

Make sure the Calcium library and its dependencies are built and in the path of the system’s dynamic library loader. Then make sure that <calcium_source_dir>/pycalcium is in the Python path, for example by adding it to PYTHONPATH, adding it to sys.path, or simply starting Python inside the pycalcium directory.

Import the module and run a calculation:

>>> import pyca
>>> pyca.ca(1) / 3
0.333333 {1/3}
>>> pyca.exp(pyca.pi * pyca.i / 2)
1.00000*I {a where a = I [a^2+1=0]}

If you don’t mind polluting the global namespace, import everything:

>>> from pyca import *
>>> exp(pi*i/2) + ca(1)/3
0.333333 + 1.00000*I {(3*a+1)/3 where a = I [a^2+1=0]}

Current limitations

  • Leaks memory (for example, when printing).

  • Because ctypes is used, this is not as efficient as a Cython wrapper. This interface should be used for testing and not for absolute performance.

  • Does not wrap various functions.

API documentation

Functions are available both as regular functions and as methods on the ca class.

pyca.fmpz_to_python_int(xref)[source]
pyca.fmpq_set_python(cref, x)[source]
class pyca.fexpr_struct[source]

Low-level wrapper for qqbar_struct, for internal use by ctypes.

__init__(*args, **kwargs)

Initialize self. See help(type(self)) for accurate signature.

alloc

Structure/Union member

data

Structure/Union member

class pyca.qqbar_struct[source]

Low-level wrapper for qqbar_struct, for internal use by ctypes.

__init__(*args, **kwargs)

Initialize self. See help(type(self)) for accurate signature.

enclosure

Structure/Union member

poly

Structure/Union member

class pyca.ca_struct[source]

Low-level wrapper for ca_struct, for internal use by ctypes.

__init__(*args, **kwargs)

Initialize self. See help(type(self)) for accurate signature.

data

Structure/Union member

class pyca.ca_ctx_struct[source]

Low-level wrapper for ca_ctx_struct, for internal use by ctypes.

__init__(*args, **kwargs)

Initialize self. See help(type(self)) for accurate signature.

content

Structure/Union member

class pyca.ca_mat_struct[source]

Low-level wrapper for ca_mat_struct, for internal use by ctypes.

__init__(*args, **kwargs)

Initialize self. See help(type(self)) for accurate signature.

c

Structure/Union member

entries

Structure/Union member

r

Structure/Union member

rows

Structure/Union member

class pyca.ca_vec_struct[source]

Low-level wrapper for ca_vec_struct, for internal use by ctypes.

__init__(*args, **kwargs)

Initialize self. See help(type(self)) for accurate signature.

alloc

Structure/Union member

entries

Structure/Union member

length

Structure/Union member

class pyca.ca_poly_struct[source]

Low-level wrapper for ca_poly_struct, for internal use by ctypes.

__init__(*args, **kwargs)

Initialize self. See help(type(self)) for accurate signature.

alloc

Structure/Union member

coeffs

Structure/Union member

length

Structure/Union member

class pyca.ca_poly_vec_struct[source]

Low-level wrapper for ca_poly_vec_struct, for internal use by ctypes.

__init__(*args, **kwargs)

Initialize self. See help(type(self)) for accurate signature.

alloc

Structure/Union member

entries

Structure/Union member

length

Structure/Union member

class pyca.fexpr(val=0)[source]
static inject(vars=False)[source]

Inject all builtin symbol names into the calling namespace. For interactive use only!

>>> fexpr.inject()
>>> n = fexpr("n")
>>> Sum(Sin(Pi*n/3)/Factorial(n), For(n,0,Infinity))
Sum(Div(Sin(Div(Mul(Pi, n), 3)), Factorial(n)), For(n, 0, Infinity))
builtins()[source]
__init__(val=0)[source]

Initialize self. See help(type(self)) for accurate signature.

static from_param(arg)[source]
latex()[source]
nwords()[source]
size_bytes()[source]
allocated_bytes()[source]
num_leaves()[source]
depth()[source]
is_atom()[source]
is_atom_integer()[source]
is_symbol()[source]
head()[source]
nargs()[source]
args()[source]
contains(x)[source]

Check if x appears exactly as a subexpression in self.

>>> f = fexpr("f"); x = fexpr("x"); y = fexpr("y")
>>> (f(x+1).contains(f), f(x+1).contains(x), f(x+1).contains(y))
(True, True, False)
>>> (f(x+1).contains(1), f(x+1).contains(2))
(True, False)
>>> (f(x+1).contains(x+1), f(x+1).contains(f(x+1)))
(True, True)
replace(old, new=None)[source]

Replace subexpression.

>>> f = fexpr("f"); x = fexpr("x"); y = fexpr("y")
>>> f(x+1, x-1).replace(x, y)
f(Add(y, 1), Sub(y, 1))
>>> f(x+1, x-1).replace(x+1, y-1)
f(Sub(y, 1), Sub(x, 1))
>>> f(x+1, x-1).replace(f, f+1)
Add(f, 1)(Add(x, 1), Sub(x, 1))
>>> f(x+1, x-1).replace(x+2, y)
f(Add(x, 1), Sub(x, 1))
__bool__()[source]
expanded_normal_form()[source]

Converts this expression to expanded normal form as a formal rational function of its non-arithmetic subexpressions.

>>> x = fexpr("x"); y = fexpr("y")
>>> (x / x**2).expanded_normal_form()
Div(1, x)
>>> (((x ** 0) + 3) ** 5).expanded_normal_form()
1024
>>> ((x+y+1)**3 - (y+1)**3 - (x+y)**3 - (x+1)**3).expanded_normal_form()
Add(Mul(-1, Pow(x, 3)), Mul(6, x, y), Mul(-1, Pow(y, 3)), -1)
>>> (1/((1/y + 1/x))).expanded_normal_form()
Div(Mul(x, y), Add(x, y))
>>> (((x+y)**5 * (x-y)) / (x**2 - y**2)).expanded_normal_form()
Add(Pow(x, 4), Mul(4, Pow(x, 3), y), Mul(6, Pow(x, 2), Pow(y, 2)), Mul(4, x, Pow(y, 3)), Pow(y, 4))
>>> (1 / (x - x)).expanded_normal_form()
Traceback (most recent call last):
  ...
ValueError: expanded_normal_form: overflow, formal division by zero or unsupported expression
nstr(n=16)[source]

Evaluates this expression numerically using Arb, returning a decimal string correct within 1 ulp in the last output digit. Attempts to obtain n digits (but the actual output accuracy may be lower).

>>> Exp = fexpr("Exp"); Exp(1).nstr()
'2.718281828459045'
>>> Pi = fexpr("Pi"); Pi.nstr(30)
'3.14159265358979323846264338328'
>>> Log = fexpr("Log"); Log(-2).nstr()
'0.6931471805599453 + 3.141592653589793*I'
>>> Im = fexpr("Im")
>>> Im(Log(2)).nstr()   # exact zero
'0'

Here the imaginary part is zero, but Arb is not able to compute so exactly. The output 0e-N indicates only that the absolute value is bounded by 1e-N:

>>> Exp(Log(-2)).nstr()
'-2.000000000000000 + 0e-22*I'
>>> Im(Exp(Log(-2))).nstr()
'0e-731'

The algorithm fails if the expression or any subexpression is not a finite complex number:

>>> Log(0).nstr()
Traceback (most recent call last):
  ...
ValueError: nstr: unable to evaluate to a number

Expressions must be constant:

>>> fexpr("x").nstr()
Traceback (most recent call last):
  ...
ValueError: nstr: unable to evaluate to a number
class pyca.qqbar(val=0)[source]

Wrapper around the qqbar type, representing an algebraic number.

>>> (qqbar(2).sqrt() / qqbar(-2).sqrt()) ** 2
-1.00000 (deg 1)
>>> qqbar(0.5) == qqbar(1) / 2
True
>>> qqbar(0.1) == qqbar(1) / 10
False
>>> qqbar(3+4j)
3.00000 + 4.00000*I (deg 2)
>>> qqbar(3+4j).root(5)
1.35607 + 0.254419*I (deg 10)
>>> qqbar(3+4j).root(5) ** 5
3.00000 + 4.00000*I (deg 2)

The constructor can evaluate fexpr symbolic expressions provided that the expressions are constant and composed strictly of algebraic-valued basic operations applied to algebraic numbers.

>>> fexpr.inject()
>>> qqbar(Pow(0, 0))
1.00000 (deg 1)
>>> qqbar(Sqrt(2) * Abs(1+1j) + (+Re(3-4j)) + (-Im(5+6j)))
-1.00000 (deg 1)
>>> qqbar((Floor(Sqrt(1000)) + Ceil(Sqrt(1000)) + Sign(1+1j) / Sign(1-1j) + Csgn(1j) + Conjugate(1j)) ** Div(-1, 3))
0.250000 (deg 1)
>>> [qqbar(RootOfUnity(3)), qqbar(RootOfUnity(3,2))]
[-0.500000 + 0.866025*I (deg 2), -0.500000 - 0.866025*I (deg 2)]
>>> qqbar(Decimal("0.125")) == qqbar(125)/1000
True
>>> qqbar(Decimal("-2.7e5")) == -270000
True
__init__(val=0)[source]

Initialize self. See help(type(self)) for accurate signature.

static from_param(arg)[source]
__bool__()[source]
re()[source]
im()[source]
conj()[source]
conjugate()
floor()[source]
ceil()[source]
sgn()[source]

The sign of this algebraic number.

>>> qqbar(-3).sgn()
-1.00000 (deg 1)
>>> qqbar(2+3j).sgn()
0.554700 + 0.832050*I (deg 4)
>>> qqbar(0).sgn()
0 (deg 1)
sign()

The sign of this algebraic number.

>>> qqbar(-3).sgn()
-1.00000 (deg 1)
>>> qqbar(2+3j).sgn()
0.554700 + 0.832050*I (deg 4)
>>> qqbar(0).sgn()
0 (deg 1)
sqrt()[source]

Principal square root of this algebraic number.

>>> qqbar(-1).sqrt()
1.00000*I (deg 2)
>>> qqbar(-1).sqrt().sqrt()
0.707107 + 0.707107*I (deg 4)
root(n)[source]

Principal nth root of this algebraic number.

>>> qqbar(3).root(1)
3.00000 (deg 1)
>>> qqbar(3).root(2)
1.73205 (deg 2)
>>> qqbar(3).root(3)
1.44225 (deg 3)
static polynomial_roots(coeffs)[source]

Returns the roots of the polynomial defined by coeffs as a list. Roots are sorted in a fixed, canonical order.

At present, the implementation only allows integers (not algebraic numbers) as coefficients.

>>> qqbar.polynomial_roots([])
[]
>>> qqbar.polynomial_roots([0])
[]
>>> qqbar.polynomial_roots([1,2])
[-0.500000 (deg 1)]
>>> qqbar.polynomial_roots([3,2,1])
[-1.00000 + 1.41421*I (deg 2), -1.00000 - 1.41421*I (deg 2)]
>>> qqbar.polynomial_roots([1,2,1])
[-1.00000 (deg 1), -1.00000 (deg 1)]
conjugates()[source]

Returns the algebraic conjugates of this algebraic number. The output is a list, with elements sorted in a fixed, canonical order.

>>> qqbar(0).conjugates()
[0 (deg 1)]
>>> ((qqbar(5).sqrt()+1)/2).conjugates()
[1.61803 (deg 2), -0.618034 (deg 2)]
>>> qqbar(2+3j).conjugates()
[2.00000 + 3.00000*I (deg 2), 2.00000 - 3.00000*I (deg 2)]
>>> qqbar.polynomial_roots([4,3,2,1])[0].conjugates()
[-1.65063 (deg 3), -0.174685 + 1.54687*I (deg 3), -0.174685 - 1.54687*I (deg 3)]
>>> qqbar.polynomial_roots([-35,0,315,0,-693,0,429])[0].conjugates()
[0.949108 (deg 6), 0.741531 (deg 6), 0.405845 (deg 6), -0.405845 (deg 6), -0.741531 (deg 6), -0.949108 (deg 6)]
minpoly()[source]

Returns the minimal polynomial of self over the integers as a list of Python integers specifying the coefficients.

>>> qqbar(0).minpoly()
[0, 1]
>>> (qqbar(2) / 3).minpoly()
[-2, 3]
>>> qqbar(2).sqrt().minpoly()
[-2, 0, 1]
>>> ((qqbar(2).sqrt() + 1).root(3) + 1).minpoly()
[2, -12, 21, -22, 15, -6, 1]
>>> qqbar(0.5).minpoly()
[-1, 2]
>>> qqbar(0.1).minpoly()
[-3602879701896397, 36028797018963968]
>>> (qqbar(1) / 10).minpoly()
[-1, 10]
is_real()[source]

Check if this algebraic number is a real number.

>>> qqbar(2).sqrt().is_real()
True
>>> qqbar(-2).sqrt().is_real()
False
is_rational()[source]

Check if this algebraic number is a rational number.

>>> (qqbar(-5) / 7).is_rational()
True
>>> (qqbar(-5) / 7).sqrt().is_rational()
False
is_integer()[source]

Check if this algebraic number is an integer.

>>> qqbar(3).is_integer()
True
>>> (qqbar(3) / 5).is_integer()
False
degree()[source]

The degree of this algebraic number (the degree of the minimal polynomial).

>>> qqbar(5).degree()
1
>>> qqbar(5).sqrt().degree()
2
p()[source]

Assuming that self is a rational number, returns the numerator as a Python integer.

>>> (qqbar(-2)/3).p()
-2
>>> qqbar(-1).sqrt().p()
Traceback (most recent call last):
  ...
ValueError: self must be a rational number
q()[source]

Assuming that self is a rational number, returns the denominator as a Python integer.

>>> (qqbar(-2)/3).q()
3
>>> qqbar(-1).sqrt().q()
Traceback (most recent call last):
  ...
ValueError: self must be a rational number
fexpr(formula=True, root_index=False, serialized=False, gaussians=True, quadratics=True, cyclotomics=True, cubics=True, quartics=True, quintics=True, depression=True, deflation=True, separation=True)[source]
fexpr_repr()[source]
class pyca.ca_ctx(**kwargs)[source]

Python class wrapping the ca_ctx_t context object. Currently only supports a global instance.

__init__(**kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

static from_param(arg)[source]
class pyca.ca(val=0, context=None)[source]

Python class wrapping the ca_t type for numbers.

Examples:

>>> ca(1)
1
>>> ca()
0
>>> ca(0)
0
>>> ca(-5)
-5
>>> ca(2.25)
2.25000 {9/4}
>>> ca(1) / 3
0.333333 {1/3}
>>> (-1) ** ca(0.5)
1.00000*I {a where a = I [a^2+1=0]}
>>> ca(1-2j)
1.00000 - 2.00000*I {-2*a+1 where a = I [a^2+1=0]}
>>> ca(0.1)           # be careful with float input!
0.100000 {3602879701896397/36028797018963968}
>>> ca(float("inf"))
+Infinity
>>> ca(float("nan"))
Unknown
>>> 3 < pi < ca(22)/7
True
>>> ca(qqbar(200).sqrt())
14.1421 {10*a where a = 1.41421 [a^2-2=0]}
__init__(val=0, context=None)[source]

Initialize self. See help(type(self)) for accurate signature.

static from_param(arg)[source]
static inf()[source]

The special value positive infinity.

Examples:

>>> inf == ca.inf()    # alias for the method
True
>>> inf
+Infinity
>>> -inf
-Infinity
>>> abs(-inf)
+Infinity
>>> inf + inf
+Infinity
>>> (-inf) + (-inf)
-Infinity
>>> -inf * inf
-Infinity
>>> inf / inf
Undefined
>>> 1 / inf
0
>>> re(inf)
Undefined
>>> im(inf)
Undefined
>>> sign(inf)
1
>>> sign((1+i)*inf) == (1+i)/sqrt(2)
True
static uinf()[source]

The special value unsigned infinity.

Examples:

>>> uinf == ca.uinf()    # alias for the method
True
>>> uinf
UnsignedInfinity
>>> abs(uinf)
+Infinity
>>> -3 * uinf
UnsignedInfinity
>>> 1/uinf
0
>>> sign(uinf)
Undefined
>>> uinf * uinf
UnsignedInfinity
>>> uinf / uinf
Undefined
>>> uinf + uinf
Undefined
>>> re(uinf)
Undefined
>>> im(uinf)
Undefined
static undefined()[source]

The special value undefined.

Examples:

>>> undefined == ca.undefined()    # alias for the method
True
>>> undefined
Undefined
>>> undefined == undefined
True
>>> undefined * 0
Undefined
static unknown()[source]

The special meta-value unknown. This meta-value is not comparable.

Examples:

>>> unknown == unknown
Traceback (most recent call last):
  ...
NotImplementedError: unable to decide predicate: equal
>>> unknown == 0
Traceback (most recent call last):
  ...
NotImplementedError: unable to decide predicate: equal
>>> unknown == undefined
Traceback (most recent call last):
  ...
NotImplementedError: unable to decide predicate: equal
>>> unknown + unknown
Unknown
>>> unknown + 3
Unknown
>>> unknown + undefined
Undefined
static pi()[source]

The constant pi.

Examples:

>>> pi == ca.pi()    # alias for the method
True
>>> pi
3.14159 {a where a = 3.14159 [Pi]}
>>> sin(pi/6)
0.500000 {1/2}
>>> (pi - 3) ** 3
0.00283872 {a^3-9*a^2+27*a-27 where a = 3.14159 [Pi]}
static euler()[source]

Euler’s constant (gamma).

Examples:

>>> euler == ca.euler()    # alias for the method
True
>>> euler
0.577216 {a where a = 0.577216 [Euler]}
>>> exp(euler)
1.78107 {a where a = 1.78107 [Exp(0.577216 {b})], b = 0.577216 [Euler]}
static i()[source]

The imaginary unit.

Examples:

>>> i == ca.i()    # alias for the method
True
>>> i == I == j    # extra aliases for convenience
True
>>> i
1.00000*I {a where a = I [a^2+1=0]}
>>> i**2
-1
>>> i**3
-1.00000*I {-a where a = I [a^2+1=0]}
>>> abs(i)
1
>>> sign(i)
1.00000*I {a where a = I [a^2+1=0]}
>>> abs(sqrt(1+i) / sqrt(1-i))
1
>>> re(i), im(i)
(0, 1)
__bool__()[source]
static operands_with_same_context(a, b)[source]
pow_arithmetic(n)[source]
nstr(n=16, parts=False)[source]

Evaluates this expression numerically using Arb, returning a decimal string correct within 1 ulp in the last output digit. Attempts to obtain n digits (but the actual output accuracy may be lower).

Examples:

>>> ca(0).nstr()
'0'
>>> pi.nstr(30)
'3.14159265358979323846264338328'

By default, the result is considered accurate when the larger of the real and imaginary parts is known to n digits. If parts is set, the algorithm will attempt to compute both real and imaginary parts accurately. It will, in particular, attempt to recognize when a real or imaginary part is exactly zero:

>>> (log(1+i) + log(1-i)).nstr()
'0.6931471805599453 + 0e-25*I'
>>> (log(1+i) + log(1-i)).nstr(parts=True)
'0.6931471805599453'

An exception is raised if the numerical evaluation code fails to produce a finite enclosure:

>>> (1 / ca(0)).nstr()
Traceback (most recent call last):
  ...
ValueError: nstr: unable to evaluate to a number
rewrite_cnf(deep=True)[source]
re()[source]

Real part.

Examples:

>>> re(2+3j) == ca(2+3j).re()
True
>>> re(2+3*i)
2
im()[source]

Imaginary part.

Examples:

>>> im(2+3j) == ca(2+3j).im()    # alias for the method
True
>>> im(2+3*i)
3
conj()[source]

Complex conjugate.

Examples:

>>> conj(1j) == conjugate(1j) == ca(1j).conj() == ca(1j).conjugate()    # alias for the method
True
>>> conj(2+i)
2.00000 - 1.00000*I {-a+2 where a = I [a^2+1=0]}
>>> conj(pi)
3.14159 {a where a = 3.14159 [Pi]}
conjugate()

Complex conjugate.

Examples:

>>> conj(1j) == conjugate(1j) == ca(1j).conj() == ca(1j).conjugate()    # alias for the method
True
>>> conj(2+i)
2.00000 - 1.00000*I {-a+2 where a = I [a^2+1=0]}
>>> conj(pi)
3.14159 {a where a = 3.14159 [Pi]}
floor()[source]

Floor function.

Examples:

>>> floor(3) == ca(3).floor()    # alias for the method
True
>>> floor(pi)
3
>>> floor(-pi)
-4
ceil()[source]

Ceiling function.

Examples:

>>> ceil(3) == ca(3).ceil()    # alias for the method
True
>>> ceil(pi)
4
>>> ceil(-pi)
-3
sgn()[source]

Sign function.

Examples:

>>> sgn(2) == sign(2) == ca(2).sgn()    # aliases for the method
True
>>> sign(0)
0
>>> sign(sqrt(2))
1
>>> sign(-sqrt(2))
-1
>>> sign(-sqrt(-2))
-1.00000*I {-a where a = I [a^2+1=0]}
sign()

Sign function.

Examples:

>>> sgn(2) == sign(2) == ca(2).sgn()    # aliases for the method
True
>>> sign(0)
0
>>> sign(sqrt(2))
1
>>> sign(-sqrt(2))
-1
>>> sign(-sqrt(-2))
-1.00000*I {-a where a = I [a^2+1=0]}
csgn()[source]

Real-valued complex extension of real sign function.

Examples:

>>> csgn(3)
1
>>> csgn(3*i)
1
>>> csgn(-3*i)
-1
>>> csgn(-3)
-1
>>> csgn(0)
0
>>> csgn(1+i)
1
>>> csgn((1+i)*inf)
1
>>> csgn(-i*inf)
-1
>>> csgn(uinf)
Undefined
arg()[source]

Complex argument (phase).

Examples:

>>> arg(2) == arg(0) == ca(0).arg() == 0
True
>>> arg(-10)
-3.14159 {-a where a = 3.14159 [Pi]}
>>> arg(sqrt(-3))
1.57080 {(a)/2 where a = 3.14159 [Pi]}
>>> arg(-sqrt(sqrt(-3)))
-2.35619 {(-3*a)/4 where a = 3.14159 [Pi]}
sqrt()[source]

Principal square root.

Examples:

>>> sqrt(2) == ca(2).sqrt()    # alias for the method
True
>>> sqrt(0)
0
>>> sqrt(1)
1
>>> sqrt(2)
1.41421 {a where a = 1.41421 [a^2-2=0]}
>>> sqrt(-1)
1.00000*I {a where a = I [a^2+1=0]}
>>> sqrt(inf)
+Infinity
>>> sqrt(-inf)
+I * Infinity
>>> sqrt(uinf)
UnsignedInfinity
>>> sqrt(undefined)
Undefined
>>> sqrt(unknown)
Unknown
log()[source]

Natural logarithm.

Examples:

>>> log(2) == ca(2).log()    # alias for the method
True
>>> log(1)
0
>>> log(exp(2))
2
>>> log(2)
0.693147 {a where a = 0.693147 [Log(2)]}
>>> log(4) == 2*log(2)
True
>>> log(1+sqrt(2)) / log(3+2*sqrt(2))
0.500000 {1/2}
>>> log(ca(10)**(10**30)) / log(10)
1.00000e+30 {1000000000000000000000000000000}
>>> log(-1)
3.14159*I {a*b where a = 3.14159 [Pi], b = I [b^2+1=0]}
>>> log(i)
1.57080*I {(a*b)/2 where a = 3.14159 [Pi], b = I [b^2+1=0]}
>>> log(0)
-Infinity
>>> log(inf)
+Infinity
>>> log(-inf)
+Infinity
>>> log(uinf)
+Infinity
>>> log(undefined)
Undefined
>>> log(unknown)
Unknown
exp()[source]

Exponential function.

Examples:

>>> exp(0)
1
>>> exp(1)
2.71828 {a where a = 2.71828 [Exp(1)]}
>>> exp(-1)
0.367879 {a where a = 0.367879 [Exp(-1)]}
>>> exp(-1) * exp(1)
1
>>> exp(7*pi*i/2)
-1.00000*I {-a where a = I [a^2+1=0]}
>>> exp(inf)
+Infinity
>>> exp(-inf)
0
>>> exp(uinf)
Undefined
>>> exp(undefined)
Undefined
>>> exp(unknown)
Unknown
sin(form=None)[source]

Sine function.

Examples:

>>> sin(0)
0
>>> sin(pi)
0
>>> sin(pi/2)
1
>>> sin(pi/6)
0.500000 {1/2}
>>> sin(sqrt(2))**2 + cos(sqrt(2))**2
1
>>> sin(3 + pi) + sin(3)
0
>>> sin(1, form="exponential")
0.841471 - 0e-24*I {(-a^2*b+b)/(2*a) where a = 0.540302 + 0.841471*I [Exp(1.00000*I {b})], b = I [b^2+1=0]}
>>> sin(1, form="direct")
0.841471 {a where a = 0.841471 [Sin(1)]}
>>> sin(1, form="tangent")
0.841471 {(2*a)/(a^2+1) where a = 0.546302 [Tan(0.500000 {1/2})]}
>>> sin(inf)
Undefined
>>> sin(i * inf)
+I * Infinity
>>> sin(-i * inf)
-I * Infinity
cos(form=None)[source]

Cosine function.

Examples:

>>> cos(0)
1
>>> cos(pi)
-1
>>> cos(pi/2)
0
>>> cos(pi/3)
0.500000 {1/2}
>>> cos(pi/6)**2
0.750000 {3/4}
>>> cos(1)**2 + sin(1)**2
1
>>> cos(1, form="exponential")
0.540302 - 0e-24*I {(a^2+1)/(2*a) where a = 0.540302 + 0.841471*I [Exp(1.00000*I {b})], b = I [b^2+1=0]}
>>> cos(1, form="direct")
0.540302 {a where a = 0.540302 [Cos(1)]}
>>> cos(1, form="tangent")
0.540302 {(-a^2+1)/(a^2+1) where a = 0.546302 [Tan(0.500000 {1/2})]}
>>> cos(i * inf)
+Infinity
>>> cos(-i * inf)
+Infinity
>>> cos(inf)
Undefined
tan(form=None)[source]

Tangent function.

Examples:

>>> tan(0)
0
>>> tan(pi)
0
>>> tan(pi/2)
UnsignedInfinity
>>> tan(pi/4)
1
>>> tan(3*pi/4)
-1
>>> tan(pi/3)**2
3
>>> tan(1 + pi) - tan(1)
0
>>> tan(1, form="direct")
1.55741 {a where a = 1.55741 [Tan(1)]}
>>> tan(1, form="sine_cosine")
1.55741 {(b)/(a) where a = 0.540302 [Cos(1)], b = 0.841471 [Sin(1)]}
>>> tan(1, form="exponential")
1.55741 + 0e-23*I {(-a^2*b+b)/(a^2+1) where a = 0.540302 + 0.841471*I [Exp(1.00000*I {b})], b = I [b^2+1=0]}
>>> tan(inf)
Undefined
>>> tan(i * inf)
1.00000*I {a where a = I [a^2+1=0]}
>>> tan(-i * inf)
-1.00000*I {-a where a = I [a^2+1=0]}
atan(form=None)[source]

Inverse tangent function.

Examples:

>>> atan(0)
0
>>> atan(1)
0.785398 {(a)/4 where a = 3.14159 [Pi]}
>>> atan(1-sqrt(2))
-0.392699 {(-a)/8 where a = 3.14159 [Pi]}
>>> atan(inf)
1.57080 {(a)/2 where a = 3.14159 [Pi]}
>>> atan(-inf)
-1.57080 {(-a)/2 where a = 3.14159 [Pi]}
>>> atan(i*inf)
1.57080 {(a)/2 where a = 3.14159 [Pi]}
>>> atan(-i*inf)
-1.57080 {(-a)/2 where a = 3.14159 [Pi]}
>>> atan((1+i)*inf)
1.57080 {(a)/2 where a = 3.14159 [Pi]}
>>> atan(tan(23*pi/27)) == -4*pi/27
True
>>> atan(2, form="direct")
1.10715 {a where a = 1.10715 [Atan(2)]}
>>> atan(2, form="logarithm")
1.10715 - 0e-24*I {(a*b)/2 where a = 0e-24 - 2.21430*I [Log(-0.600000 - 0.800000*I {(-4*b-3)/5})], b = I [b^2+1=0]}
asin(form=None)[source]

Inverse sine function.

Examples:

>>> asin(0)
0
>>> asin(1)
1.57080 {(a)/2 where a = 3.14159 [Pi]}
>>> asin(-1)
-1.57080 {(-a)/2 where a = 3.14159 [Pi]}
>>> asin(sqrt(2)/2)
0.785398 {(a)/4 where a = 3.14159 [Pi]}
>>> asin(i)
0.881374*I {-a*c where a = -0.881374 [Log(0.414214 {b-1})], b = 1.41421 [b^2-2=0], c = I [c^2+1=0]}
>>> sin(asin(sqrt(2)-1)) == sqrt(2)-1
True
>>> asin(sin(sqrt(2)-1)) == sqrt(2)-1
True
>>> asin(sqrt(2)-1, form="logarithm")
0.427079 + 0e-24*I {-a*d where a = 0e-24 + 0.427079*I [Log(0.910180 + 0.414214*I {b+c*d-d})], b = 0.910180 [Sqrt(0.828427 {2*c-2})], c = 1.41421 [c^2-2=0], d = I [d^2+1=0]}
>>> asin(sqrt(2)-1, form="direct")
0.427079 {a where a = 0.427079 [Asin(0.414214 {b-1})], b = 1.41421 [b^2-2=0]}
>>> asin(inf)
-I * Infinity
>>> asin(-inf)
+I * Infinity
>>> asin(inf*i)
+I * Infinity
>>> asin(-inf*i)
-I * Infinity
>>> asin(uinf)
UnsignedInfinity
>>> asin(undefined)
Undefined
acos(form=None)[source]

Inverse cosine function.

Examples:

>>> acos(0)
1.57080 {(a)/2 where a = 3.14159 [Pi]}
>>> acos(1)
0
>>> acos(-1)
3.14159 {a where a = 3.14159 [Pi]}
>>> acos(sqrt(2)/2)
0.785398 {(a)/4 where a = 3.14159 [Pi]}
>>> acos(i)
1.57080 - 0.881374*I {(2*a*d+b)/2 where a = -0.881374 [Log(0.414214 {c-1})], b = 3.14159 [Pi], c = 1.41421 [c^2-2=0], d = I [d^2+1=0]}
>>> cos(acos(sqrt(2) - 1)) == sqrt(2) - 1
True
>>> acos(inf)
+I * Infinity
>>> acos(-inf)
-I * Infinity
>>> acos(inf*i)
-I * Infinity
>>> acos(-inf*i)
+I * Infinity
>>> acos(uinf)
UnsignedInfinity
>>> acos(undefined)
Undefined
erf()[source]

Error function.

Examples:

>>> erf(0)
0
>>> erf(1)
0.842701 {a where a = 0.842701 [Erf(1)]}
>>> erf(inf)
1
>>> erf(-inf)
-1
>>> erf(i*inf)
+I * Infinity
>>> erf(-i*inf)
-I * Infinity
>>> erf(uinf)
Undefined
erfc()[source]

Complementary error function.

Examples:

>>> erfc(inf)
0
>>> erfc(-inf)
2
>>> erfc(1000)
1.86004e-434298 {a where a = 1.86004e-434298 [Erfc(1000)]}
>>> erfc(i*inf)
-I * Infinity
>>> erfc(-i*inf)
+I * Infinity
>>> erfc(sqrt(2)) + erf(sqrt(2))
1
>>> erfc(uinf)
Undefined
erfi()[source]

Imaginary error function.

Examples:

>>> erfi(0)
0
>>> erfi(1)
1.65043 {a where a = 1.65043 [Erfi(1)]}
>>> erfi(inf)
+Infinity
>>> erfi(-inf)
-Infinity
>>> erfi(i*inf)
1.00000*I {a where a = I [a^2+1=0]}
>>> erfi(-i*inf)
-1.00000*I {-a where a = I [a^2+1=0]}
>>> erf(2)**2 + erfi(i*2)**2
0
gamma()[source]

Gamma function.

Examples:

>>> [gamma(n) for n in range(1,11)]
[1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880]
>>> gamma(0)
UnsignedInfinity
>>> 1 / gamma(0)
0
>>> gamma(0.5)
1.77245 {a where a = 1.77245 [Sqrt(3.14159 {b})], b = 3.14159 [Pi]}
>>> gamma(0.5)**2 == pi
True
>>> pi * gamma(pi) / gamma(pi+1)
1
class pyca.ca_mat(*args, context=None)[source]

Python class wrapping the ca_mat_t type for matrices.

Examples:

>>> ca_mat(2,3)
ca_mat of size 2 x 3
[0, 0, 0]
[0, 0, 0]
>>> ca_mat([[1,2],[3,4],[5,6]])
ca_mat of size 3 x 2
[1, 2]
[3, 4]
[5, 6]
>>> ca_mat(2, 5, range(10))
ca_mat of size 2 x 5
[0, 1, 2, 3, 4]
[5, 6, 7, 8, 9]
>>> ca_mat([[1,-2],[2,1]]) * ca_mat([[1,pi],[1,2]])
ca_mat of size 2 x 2
[-1, -0.858407 {a-4 where a = 3.14159 [Pi]}]
[ 3, 8.28319 {2*a+2 where a = 3.14159 [Pi]}]

A nontrivial calculation:

>>> H = ca_mat([[ca(1)/(i+j+1) for i in range(5)] for j in range(5)])
>>> H
ca_mat of size 5 x 5
[             1, 0.500000 {1/2}, 0.333333 {1/3}, 0.250000 {1/4}, 0.200000 {1/5}]
[0.500000 {1/2}, 0.333333 {1/3}, 0.250000 {1/4}, 0.200000 {1/5}, 0.166667 {1/6}]
[0.333333 {1/3}, 0.250000 {1/4}, 0.200000 {1/5}, 0.166667 {1/6}, 0.142857 {1/7}]
[0.250000 {1/4}, 0.200000 {1/5}, 0.166667 {1/6}, 0.142857 {1/7}, 0.125000 {1/8}]
[0.200000 {1/5}, 0.166667 {1/6}, 0.142857 {1/7}, 0.125000 {1/8}, 0.111111 {1/9}]
>>> H.trace()
1.78730 {563/315}
>>> sum(c*multiplicity for (c, multiplicity) in H.eigenvalues())
1.78730 {563/315}
>>> H.det()
3.74930e-12 {1/266716800000}
>>> prod(c**multiplicity for (c, multiplicity) in H.eigenvalues())
3.74930e-12 {1/266716800000}
__init__(*args, context=None)[source]

Initialize self. See help(type(self)) for accurate signature.

static from_param(arg)[source]
__bool__()[source]
static operands_with_same_context(a, b)[source]
nrows()[source]
ncols()[source]
entries()[source]
table()[source]
tolist()
trace()[source]

The trace of this matrix.

Examples:

>>> ca_mat([[1,2],[3,pi]]).trace()
4.14159 {a+1 where a = 3.14159 [Pi]}
det(algorithm=None)[source]

The determinant of this matrix.

Examples:

>>> ca_mat([[1,1-i*pi],[1+i*pi,1]]).det()
-9.86960 {-a^2 where a = 3.14159 [Pi], b = I [b^2+1=0]}
conjugate()[source]

Entrywise complex conjugate.

>>> ca_mat([[5,1-i]]).conjugate()
ca_mat of size 1 x 2
[5, 1.00000 + 1.00000*I {a+1 where a = I [a^2+1=0]}]
conj()

Entrywise complex conjugate.

>>> ca_mat([[5,1-i]]).conjugate()
ca_mat of size 1 x 2
[5, 1.00000 + 1.00000*I {a+1 where a = I [a^2+1=0]}]
transpose()[source]

Matrix transpose.

>>> ca_mat([[5,1-i]]).transpose()
ca_mat of size 2 x 1
[                                               5]
[1.00000 - 1.00000*I {-a+1 where a = I [a^2+1=0]}]
conjugate_transpose()[source]

Conjugate matrix transpose.

>>> ca_mat([[5,1-i]]).conjugate_transpose()
ca_mat of size 2 x 1
[                                              5]
[1.00000 + 1.00000*I {a+1 where a = I [a^2+1=0]}]
conj_transpose()

Conjugate matrix transpose.

>>> ca_mat([[5,1-i]]).conjugate_transpose()
ca_mat of size 2 x 1
[                                              5]
[1.00000 + 1.00000*I {a+1 where a = I [a^2+1=0]}]
charpoly()[source]

Characteristic polynomial of this matrix.

>>> ca_mat([[5,pi],[1,-1]]).charpoly()
ca_poly of length 3
[-8.14159 {-a-5 where a = 3.14159 [Pi]}, -4, 1]
eigenvalues()[source]

Eigenvalues of this matrix. Returns a list of (value, multiplicity) pairs.

>>> ca_mat(4, 4, range(16)).eigenvalues()
[(32.4642 {a+15 where a = 17.4642 [a^2-305=0]}, 1), (-2.46425 {-a+15 where a = 17.4642 [a^2-305=0]}, 1), (0, 2)]
>>> ca_mat([[1,pi],[-pi,1]]).eigenvalues()[0]
(1.00000 + 3.14159*I {a*b+1 where a = 3.14159 [Pi], b = I [b^2+1=0]}, 1)
rref()[source]

Reduced row echelon form.

>>> ca_mat([[1,2,3],[4,5,6],[7,8,9]]).rref()
ca_mat of size 3 x 3
[1, 0, -1]
[0, 1,  2]
[0, 0,  0]
>>> ca_mat([[1,pi,2,pi],[1/pi,3,1/(pi+1),4],[1,1,1,1]]).rref()
ca_mat of size 3 x 4
[1, 0, 0, 0.401081 {(a^3-a^2-2*a)/(3*a^2+3*a-2) where a = 3.14159 [Pi]}]
[0, 1, 0,  1.35134 {(4*a^2+4*a-2)/(3*a^2+3*a-2) where a = 3.14159 [Pi]}]
[0, 0, 1,     -0.752416 {(-a^3+a)/(3*a^2+3*a-2) where a = 3.14159 [Pi]}]
>>> ca_mat([[1, 0, 0], [0, 1-exp(ca(2)**-10000), 0]]).rref()
Traceback (most recent call last):
  ...
NotImplementedError: failed to compute rref
rank()[source]

Rank of this matrix.

>>> ca_mat([[1,2,3],[4,5,6],[7,8,9]]).rank()
2
>>> ca_mat([[1, 0, 0], [0, 1-exp(ca(2)**-10000), 0]]).rank()
Traceback (most recent call last):
  ...
NotImplementedError: failed to compute rank
inv()[source]

Matrix inverse.

>>> ca_mat([[1,1],[0,1/pi]]).inv()
ca_mat of size 2 x 2
[1, -3.14159 {-a where a = 3.14159 [Pi]}]
[0,   3.14159 {a where a = 3.14159 [Pi]}]
>>> ca_mat([[1, 1], [2, 2]]).inv()
Traceback (most recent call last):
  ...
ZeroDivisionError: singular matrix
>>> ca_mat([[1, 0], [0, 1-exp(ca(2)**-10000)]]).inv()
Traceback (most recent call last):
  ...
NotImplementedError: failed to prove matrix singular or nonsingular
solve(other, algorithm=None)[source]

Solve linear system (with a nonsingular matrix).

>>> ca_mat([[1,2],[3,4]]).solve(ca_mat([[5],[6]]))
ca_mat of size 2 x 1
[           -4]
[4.50000 {9/2}]
>>> ca_mat([[1,1],[2,2]]).solve(ca_mat([[5],[6]]))
Traceback (most recent call last):
  ...
ZeroDivisionError: singular matrix
>>> ca_mat([[1, 0], [0, 1-exp(ca(2)**-10000)]]).solve(ca_mat([[5],[6]]))
Traceback (most recent call last):
  ...
NotImplementedError: failed to prove matrix singular or nonsingular
right_kernel()[source]

Returns a basis of the right kernel (nullspace) of self.

>>> A = ca_mat([[3,4,6],[5,6,7]])
>>> X = A.right_kernel()
>>> X
ca_mat of size 3 x 1
[              4]
[-4.50000 {-9/2}]
[              1]
>>> A * X
ca_mat of size 2 x 1
[0]
[0]
diagonalization()[source]

Matrix diagonalization: given a square matrix self, returns a diagonal matrix D and an invertible matrix P such that self equals \(PDP^{-1}\). Raises ValueError if self is not diagonalizable.

>>> A = ca_mat([[1,2],[3,4]])
>>> D, P = A.diagonalization()
>>> D
ca_mat of size 2 x 2
[5.37228 {(a+5)/2 where a = 5.74456 [a^2-33=0]},                                                 0]
[                                             0, -0.372281 {(-a+5)/2 where a = 5.74456 [a^2-33=0]}]
>>> P * D * P.inv()
ca_mat of size 2 x 2
[1, 2]
[3, 4]

A diagonalizable matrix without distinct eigenvalues:

>>> A = ca_mat([[-1,3,-1],[-3,5,-1],[-3,3,1]])
>>> D, P = A.diagonalization()
>>> D
ca_mat of size 3 x 3
[1, 0, 0]
[0, 2, 0]
[0, 0, 2]
>>> P
ca_mat of size 3 x 3
[1, 1, -0.333333 {-1/3}]
[1, 1,                0]
[1, 0,                1]
>>> P * D * P.inv() == A
True
log()[source]

Matrix logarithm.

>>> ca_mat([[4,2],[2,4]]).log().det() == log(2)*(log(2)+log(3))
True
>>> ca_mat([[1,1],[0,1]]).log()
ca_mat of size 2 x 2
[0, 1]
[0, 0]
>>> ca_mat([[0,1],[0,0]]).log()
Traceback (most recent call last):
  ...
ZeroDivisionError: singular matrix
>>> ca_mat([[0,0,1],[0,1,0],[1,0,0]]).log() / (pi*I)
ca_mat of size 3 x 3
[  0.500000 {1/2}, 0, -0.500000 {-1/2}]
[               0, 0,                0]
[-0.500000 {-1/2}, 0,   0.500000 {1/2}]
>>> ca_mat([[0,0,1],[0,1,0],[1,0,0]]).log().exp()
ca_mat of size 3 x 3
[0, 0, 1]
[0, 1, 0]
[1, 0, 0]
exp()[source]

Matrix exponential.

>>> ca_mat([[1,2],[0,3]]).exp()
ca_mat of size 2 x 2
[2.71828 {a where a = 2.71828 [Exp(1)]}, 17.3673 {b^3-b where a = 20.0855 [Exp(3)], b = 2.71828 [Exp(1)]}]
[                                     0,                           20.0855 {a where a = 20.0855 [Exp(3)]}]
>>> ca_mat([[1,2],[3,4]]).exp()[0,0]
51.9690 {(-a*c+11*a+b*c+11*b)/22 where a = 215.354 [Exp(5.37228 {(c+5)/2})], b = 0.689160 [Exp(-0.372281 {(-c+5)/2})], c = 5.74456 [c^2-33=0]}
>>> ca_mat([[0,0,1],[1,0,0],[0,1,0]]).exp().det()
1
>>> ca_mat([[0,1,0,0,0],[0,0,2,0,0],[0,0,0,3,0],[0,0,0,0,4],[0,0,0,0,0]]).exp()
ca_mat of size 5 x 5
[1, 1, 1, 1, 1]
[0, 1, 2, 3, 4]
[0, 0, 1, 3, 6]
[0, 0, 0, 1, 4]
[0, 0, 0, 0, 1]

This example currently fails (due to failure to compute the exact Jordan decomposition internally):

>>> ca_mat([[0,0,1],[0,2,0],[-1,0,0]]).log().exp()
Traceback (most recent call last):
  ...
NotImplementedError: unable to compute matrix exponential
jordan_form(transform=False)[source]

Jordan decomposiion: given a square matrix self, returns a block diagonal matrix J composed of Jordan blocks and optionally an invertible matrix P such that self equals \(PJP^{-1}\).

>>> A = ca_mat([[20,77,59,40], [0,-2,-3,-2], [-10,-35,-23,-15], [2,7,3,1]])
>>> J, P = A.jordan_form(transform=True)
>>> P * J * P.inv()
ca_mat of size 4 x 4
[ 20,  77,  59,  40]
[  0,  -2,  -3,  -2]
[-10, -35, -23, -15]
[  2,   7,   3,   1]
>>> A = ca_mat([[log(2), log(3)], [log(4), log(5)]])
>>> J, P = A.jordan_form(transform=True)
>>> J[0,0]
2.46769 {(a+b+e)/2 where a = 2.63279 [Sqrt(6.93159 {b^2-2*b*e+8*d*e+e^2})], b = 1.60944 [Log(5)], c = 1.38629 [Log(4)], d = 1.09861 [Log(3)], e = 0.693147 [Log(2)]}
>>> P * J * P.inv() == A
True
class pyca.ca_vec(n=0, context=None)[source]

Python class wrapping the ca_vec_t type for vectors.

__init__(n=0, context=None)[source]

Initialize self. See help(type(self)) for accurate signature.

static from_param(arg)[source]
class pyca.ca_poly_vec(n=0, context=None)[source]
__init__(n=0, context=None)[source]

Initialize self. See help(type(self)) for accurate signature.

static from_param(arg)[source]
class pyca.ca_poly(val=0, context=None)[source]

Python class wrapping the ca_poly_t type for polynomials.

__init__(val=0, context=None)[source]

Initialize self. See help(type(self)) for accurate signature.

static from_param(arg)[source]
__bool__()[source]
static operands_with_same_context(a, b)[source]
mul_series(other, n)[source]
div_series(other, n)[source]
inv_series(n)[source]

Power series inverse truncated to length n.

Examples:

>>> ca_poly([1,2,3]).inv_series(10)
ca_poly of length 10
[1, -2, 1, 4, -11, 10, 13, -56, 73, 22]
>>> ca_poly([sqrt(2), 1, 2]).inv_series(5).inv_series(5)
ca_poly of length 3
[1.41421 {a where a = 1.41421 [a^2-2=0]}, 1, 2]
>>> ca_poly([]).inv_series(3)
ca_poly of length 3
[UnsignedInfinity, Undefined, Undefined]
>>> ca_poly([0,1,2]).inv_series(3)
ca_poly of length 3
[UnsignedInfinity, Undefined, Undefined]
>>> ca_poly([inf,1,2]).inv_series(3)
ca_poly of length 3
[Undefined, Undefined, Undefined]
log_series(n)[source]

Power series logarithm truncated to length n.

Examples:

>>> ca_poly([1,1]).log_series(4)
ca_poly of length 4
[0, 1, -0.500000 {-1/2}, 0.333333 {1/3}]
>>> ca_poly([2,1]).log_series(4)
ca_poly of length 4
[0.693147 {a where a = 0.693147 [Log(2)]}, 0.500000 {1/2}, -0.125000 {-1/8}, 0.0416667 {1/24}]
>>> ca_poly([-2,2,3]).log_series(5).exp_series(5)
ca_poly of length 3
[-2, 2, 3]
>>> ca_poly([0,1]).log_series(3)
ca_poly of length 3
[-Infinity, Undefined, Undefined]
>>> ca_poly([inf,1]).log_series(3)
ca_poly of length 3
[Undefined, Undefined, Undefined]
exp_series(n)[source]

Power series exponential truncated to length n.

Examples:

>>> ca_poly([0,1]).exp_series(4)
ca_poly of length 4
[1, 1, 0.500000 {1/2}, 0.166667 {1/6}]
>>> ca_poly([1,-0.5]).exp_series(2)
ca_poly of length 2
[2.71828 {a where a = 2.71828 [Exp(1)]}, -1.35914 {(-a)/2 where a = 2.71828 [Exp(1)]}]
>>> ca_poly([inf]).exp_series(3)
ca_poly of length 3
[Undefined, Undefined, Undefined]
>>> ca_poly([unknown]).exp_series(3)
ca_poly of length 3
[Unknown, Unknown, Unknown]
atan_series(n)[source]

Power series inverse tangent truncated to length n.

>>> ca_poly([0,1]).atan_series(6)
ca_poly of length 6
[0, 1, 0, -0.333333 {-1/3}, 0, 0.200000 {1/5}]
>>> ca_poly([1,1]).atan_series(4)
ca_poly of length 4
[0.785398 {(a)/4 where a = 3.14159 [Pi]}, 0.500000 {1/2}, -0.250000 {-1/4}, 0.0833333 {1/12}]
>>> f = ca_poly([2,3,4])
>>> 2*f.atan_series(5) - ((2*f).div_series(1-f**2, 5)).atan_series(5) == pi
True
>>> ca_poly([0]).atan_series(3)
ca_poly of length 0
[]
>>> ca_poly([i,1]).atan_series(3)
ca_poly of length 3
[+I * Infinity, Undefined, Undefined]
>>> ca_poly([-i,1]).atan_series(3)
ca_poly of length 3
[-I * Infinity, Undefined, Undefined]
>>> ca_poly([unknown,1]).atan_series(3)
ca_poly of length 3
[Unknown, Unknown, Unknown]
gcd(other)[source]

Polynomial GCD.

Examples:

>>> x = ca_poly([0,1]); (x+1).gcd(x-1)
ca_poly of length 1
[1]
>>> x = ca_poly([0,1]); (x**2 + pi**2).gcd(x+i*pi)
ca_poly of length 2
[3.14159*I {a*b where a = 3.14159 [Pi], b = I [b^2+1=0]}, 1]
roots()[source]

Roots of this polynomial. Returns a list of (root, multiplicity) pairs.

>>> ca_poly([2,11,20,12]).roots()
[(-0.666667 {-2/3}, 1), (-0.500000 {-1/2}, 2)]
factor_squarefree()[source]

Squarefree factorization of this polynomial Returns (lc, L) where L is a list of (factor, multiplicity) pairs.

>>> ca_poly([9,6,7,-28,12]).factor_squarefree()
(12, [(ca_poly of length 3
[0.333333 {1/3}, 0.666667 {2/3}, 1], 1), (ca_poly of length 2
[-1.50000 {-3/2}, 1], 2)])
squarefree_part()[source]

Squarefree part of this polynomial.

>>> ca_poly([9,6,7,-28,12]).squarefree_part()
ca_poly of length 4
[-0.500000 {-1/2}, -0.666667 {-2/3}, -0.833333 {-5/6}, 1]
integral()[source]

Integral of this polynomial.

>>> ca_poly([1,1,1,1]).integral()
ca_poly of length 5
[0, 1, 0.500000 {1/2}, 0.333333 {1/3}, 0.250000 {1/4}]
derivative()[source]

Derivative of this polynomial.

>>> ca_poly([1,1,1,1]).derivative()
ca_poly of length 3
[1, 2, 3]
monic()[source]

Make this polynomial monic.

>>> ca_poly([1,2,3]).monic()
ca_poly of length 3
[0.333333 {1/3}, 0.666667 {2/3}, 1]
>>> ca_poly().monic()
Traceback (most recent call last):
  ...
ValueError: failed to make monic
is_proper()[source]

Checks if this polynomial definitely has finite coefficients and that the leading coefficient is provably nonzero.

>>> ca_poly([]).is_proper()
True
>>> ca_poly([1,2,3]).is_proper()
True
>>> ca_poly([1,2,1-exp(ca(2)**-10000)]).is_proper()
False
>>> ca_poly([inf]).is_proper()
False
degree()[source]

Degree of this polynomial.

>>> ca_poly([1,2,3]).degree()
2
>>> ca_poly().degree()
-1
>>> ca_poly([1,2,1-exp(ca(2)**-10000)]).degree()
Traceback (most recent call last):
  ...
NotImplementedError: unable to determine degree
pyca.re(x)[source]
pyca.im(x)[source]
pyca.sgn(x)[source]
pyca.sign(x)[source]
pyca.csgn(x)[source]
pyca.arg(x)[source]
pyca.floor(x)[source]
pyca.ceil(x)[source]
pyca.conj(x)[source]
pyca.conjugate(x)[source]
pyca.sqrt(x)[source]
pyca.log(x)[source]
pyca.exp(x)[source]
pyca.erf(x)[source]
pyca.erfc(x)[source]
pyca.erfi(x)[source]
pyca.gamma(x)[source]
pyca.fac(x)[source]

Alias for gamma(x+1).

Examples:

>>> fac(10)
3.62880e+6 {3628800}
pyca.cos(x, form=None)[source]
pyca.sin(x, form=None)[source]
pyca.tan(x, form=None)[source]
pyca.atan(x, form=None)[source]
pyca.asin(x, form=None)[source]
pyca.acos(x, form=None)[source]
pyca.cosh(x)[source]

The hyperbolic cosine function is not yet implemented in Calcium. This placeholder function evaluates the hyperbolic cosine function using exponentials.

Examples:

>>> cosh(1)
1.54308 {(a^2+1)/(2*a) where a = 2.71828 [Exp(1)]}
pyca.sinh(x)[source]

The hyperbolic sine function is not yet implemented in Calcium. This placeholder function evaluates the hyperbolic sine function using exponentials.

Examples:

>>> sinh(1)
1.17520 {(a^2-1)/(2*a) where a = 2.71828 [Exp(1)]}
pyca.tanh(x)[source]

The hyperbolic tangent function is not yet implemented in Calcium. This placeholder function evaluates the hyperbolic tangent function using exponentials.

Examples:

>>> tanh(1)
0.761594 {(a^2-1)/(a^2+1) where a = 2.71828 [Exp(1)]}
pyca.prod(s)[source]
pyca.gd(x)[source]
pyca.test_floor_ceil()[source]
pyca.test_power_identities()[source]
pyca.test_log()[source]
pyca.test_exp()[source]
pyca.test_erf()[source]
pyca.test_gudermannian()[source]
pyca.test_gamma()[source]
pyca.test_conversions()[source]
pyca.test_notebook_examples()[source]
pyca.test_qqbar_misc()[source]
pyca.test_context_switch()[source]
pyca.test_improved_zero_recognition()[source]
pyca.test_trigonometric()[source]
pyca.test_comparisons()[source]
pyca.test_xfail()[source]
pyca.test_latex()[source]
pyca.latex_test_report()[source]