Exact values

Exact always means one number, exactly. Symbolic means the formula, a function of q.

CallWhat it isNumber?Arithmetic?
q6j(Exact(), js...)the value at q = 1yesyes
q6j(Exact(k), js...)the value at level kyesyes
q6j(Symbolic(), js...)the formulathrough f(q)no

Zero and equal mean different things on the two sides. For Exact(k) they mean at this level, and for Symbolic() at every q. A 6j symbol can vanish at a level and not vanish as a formula: no admissible label with spins up to 3 is zero at every q, while 119 of them are zero at level 10.

A number at q = 1

Exact() is a sign and a rational under a root, with its own arithmetic.

using QRecoupling
r = q3j(Exact(), 1//2, 1//2, 0, 1//2, -1//2, 0)
(q6j(Exact(), 1, 1, 1, 1, 1, 1), r, r^2)
(1//6, √(1//2), 1//2)

Adding values with unlike roots stays exact, as a sum of square roots with rational coefficients. Each sum has one such form, so == and iszero are proofs, which is what an identity or a contraction over products of symbols needs. /, inv and integer powers stay exact too, and float gives a number. sqrt and half-integer powers such as x^(1//2) are exact when the value is rational, such as a square. Other roots would be nested roots, which these values do not keep, and they say so.

s = fsymbol(Exact(), 1, 1, 1, 1, 1, 2) + fsymbol(Exact(), 1, 1, 1, 1, 1, 1)
(s, s^2, s * inv(s), float(s))
(1//2 + √15/6, 2//3 + √15/6, 1//1, 1.145497224367903)

The formula at every q

Symbolic() writes the formula in quantum integers [n] and never expands it. It holds no number. Evaluate it with c(q) at any q that At takes. An exact 1 gives the exact value at q = 1, while c(1.0) gives a float.

c = q6j(Symbolic(), 1, 1, 1, 1, 1, 1)
(c, c(1), c(1.0), c(0.8), c(0.8 + 0.2im))
(([5] − 1)/[4]!, 1//6, 0.16666666666666666, 0.17048258800366134, 0.17155707666100636 - 0.012310567538924705im)

A formula has no float of its own, since that needs a value of q, and no sums. Products, quotients, powers and roots of a formula that is one product of q-integers stay formulas, such as sqrt(qdim(Symbolic(), 1)), which is √([3]). It knows its rule but not its labels, so it does not move to a level: use q6j(Exact(k), js...), which applies the level's fusion rules.

== means equal at every q, for two formulas and for a formula and a number, which is a constant function. [6] and [3]! are both 6 at q = 1, and neither of them is 6.

(qint(Symbolic(), 6), qfact(Symbolic(), 3), qint(Symbolic(), 6) == qfact(Symbolic(), 3), qint(Symbolic(), 6) == 6, qint(Symbolic(), 6)(1) == 6)
([6], [3]!, false, false, true)

Nothing is expanded to decide this. Clearing denominators gives an integer polynomial in q, and a nonzero one cannot vanish at an integer larger than the sum of its coefficients. So the test reads that polynomial at one such integer, through its residues at word primes, and stops at the first nonzero residue. A vanishing sum is shown as 0. A value can vanish at q = 1 without vanishing elsewhere, and then its form is not 0 while v == 0 is true.

A level

Exact(k) is the same value at q = e^{iπ/(k+2)}. The labels fold to n ≤ (k+2)/2, the relations among the q-integers simplify the form up to k + 2 = 1100, and zeros are found and proved.

v = q6j(Exact(10), 1, 1, 1, 1, 1, 1)
([5] − 1)/[4]!   (k = 10)
(q6j(Exact(3), 1, 1, 1, 1, 1, 1), q6j(Exact(10), 1, 3//2, 3//2, 2, 3//2, 3//2))
(−1/[2]²   (k = 3), 0   (k = 10))

Two equal values can print differently, so == decides equality and the text does not. Nothing is expanded to do it. == compares the squares of the two values at places, primes where q is a root of unity, reading each from the rule's factorials. One different residue settles it, in about 5 µs at spins 100, k = 401. Equal squares need more places, as many as the norm of the difference allows, about 6.5 ms at that size, and the certified number then gives the sign.

Arithmetic with *, +, -, / and ^ is exact at a level, needs no backend, and gives a value that prints in the basis [1], …, [d].

a = q6j(Exact(12), 1, 1, 1, 1, 1, 1)
(a^2, a * inv(a) == 1)
(10[5] − 33[3] + 52   (k = 12), true)

sqrt and half-integer powers are exact for a form that is one product of q-integers, such as a quantum dimension, and for a rational value. The root of a product is again a form, and so are products, quotients and powers of such forms, so nothing is expanded: sqrt(qint(Exact(1098), 550)) is √([550]) in a few microseconds. A sum is held in the basis above, where a root is not read off, so take the root of each symbol: write sqrt(f) * sqrt(g) for sqrt(f * g).

d = qdim(Exact(12), 1)
(sqrt(d), d^(3//2), sqrt(d) * sqrt(qdim(Exact(12), 2)))
(√([3])   (k = 12), [3] √([3])   (k = 12), √([3][5])   (k = 12))

A form holds its rule, which is all that ==, iszero and float read, so it costs about 0.15 µs at any size. What it prints is written the first time it is shown, about 490 µs at spins 100, k = 401.

Use Level(k) for numbers. It costs about 1 µs at that size, and is accurate to about 10⁻¹⁶ in the median. float(v) rounds from more digits than Level(k) keeps: it takes under a microsecond on a typical form, and about 260 µs at that size, where the sum cancels heavily. numeric_value(v; bits) gives more digits.

(Float64(v), numeric_value(v; bits = 128))
(0.15470053837925152, 0.1547005383792515290182975610039149112949)

Powers of q

qcg and q3j carry powers of q, printed in front and on each term. At a level they reduce by q^h = −1, and the value is complex.

qcg(Exact(9), 3//2, 1//2, 1, 0, 3//2, 1//2)
q²(q⁶ + [2]) √(1/([3][5]))   (k = 9, q = e^{iπ/11})

== and iszero decide these forms like any other. They have no arithmetic at a level.

Radicals

With Nemo loaded, radical rewrites a level value in nested square roots.

using Nemo  # optional backend for nested radicals
radical(v)
(2√3 − 3)/3
no_surd = radical(q6j(Exact(5), 1, 1, 1, 1, 1, 1))
no_surd
no radical form: v² has degree 3 over ℚ at level 5, and only a power of two is a tower of square roots
  (`v.x_value` gives (P, R), which is then the value's only closed form)
  ≈ 0.08814600002041936

A radical exists only when the square of the value has degree a power of two over ℚ, which is rare beyond small levels. radical returns a RadExpr when it succeeds, otherwise a NoRadical with a reason:

kindMeaning
:noneNo expression in real nested square roots exists
:untriedThe degree budget prevented the search
:longThe expression exceeds an explicitly requested length budget
:failedThe descent could not finish its required sign checks

Here “radical” means nested square roots, not arbitrary nth roots. The default degree_limit is 32; maxlen=0 imposes no expression-length cap. Increasing the degree limit can be very expensive in both time and memory.

Polynomials in x

With Nemo loaded, xform writes a level value as P(x)√R(x) with x = 2cos(π/(k+2)), over one integer denominator. QRecoupling.xpolynomial and QRecoupling.radicand give the coefficients as vectors, lowest degree first. The polynomials are reduced below the degree of the number field, so they hold only at that level, and a long one prints as a summary. Expanding costs more as the level grows.

xform(q6j(Exact(10), 1, 1, 1, 1, 1, 1))
(2x² − 7)/3   (k = 10, x = 2cos(π/12))

On a generic form, xform expands the expression in x = q + q⁻¹. Both carry out the sum, which grows quickly with the spins and is not needed to read a value or to decide one.

s = q6j(Symbolic(), 1, 1, 1, 1, 1, 1)
g = xform(s)       # (x² − 3)/(x⁴ − 3x² + 2)
(x² − 3)/(x⁴ − 3x² + 2)   (x = q + q⁻¹)

Symbolic() writes the formula without carrying out the sum, and xform expands it. Radicals are displayed as products of ψ factors.

Generic square roots specify an algebraic expression. To evaluate with the package's numerical branch convention, use s(q) or a level target on the original symbolic value.

API reference

QRecoupling.QForm — Type
QForm

A value written in q-integers, as returned by Symbolic() and Exact(k).

A generic form, from Symbolic(), is a function of q and has no value of its own. f(q) evaluates it at any q that At takes, and f(1) gives its value at q = 1 exactly. == and iszero mean at every q, decided exactly, whether the other side is a form or a number. float, numeric_value and sums need a value of q, and say so.

Products, quotients, powers and roots of forms that are one product of q-integers are forms again, generic or at a level, and expand nothing.

A form at a level is one number, complex when it carries powers of q. float and numeric_value approximate it; == and iszero decide equality and vanishing exactly. Unweighted level forms support exact arithmetic. Arithmetic on forms carrying powers of q is not yet supported.

A form holds its rule, which is short and is all that deciding and evaluating read. What it prints is written from the rule the first time it is shown, so a form costs no more than its rule until then.

source
QRecoupling.xform — Function
xform(f::QForm) -> XValue or LevelXValue

An Exact(k) form written out in x = 2cos(π/(k+2)) as a LevelXValue, P(x)√R(x) over one integer denominator. A Symbolic() form is the formula expanded in x = q + 1/q, as √(∏_{e ∈ rad} ψ_e(x)) · num(x)/den(x). It needs Nemo, and may be expensive at large labels.

source
QRecoupling.LevelXValue — Type
LevelXValue

A value at a level written out in x = 2cos(π/(k+2)) as P(x)√R(x) over one integer denominator, from xform on an Exact(k) form. The polynomials are reduced below the degree of the number field, so they hold only at this level. QRecoupling.xpolynomial and QRecoupling.radicand give their coefficients, lowest degree first.

source
QRecoupling.ClassicalSum — Type
ClassicalSum

An exact sum of unlike square roots at q = 1, Σ cr √r with each r a square-free integer and each cr rational, such as 1//2 + √15/6. It is what adding two ClassicalResults gives when their roots differ, and it holds at least two roots: a sum that collapses to one root, or to zero, is a ClassicalResult again.

Square roots of distinct square-free integers are linearly independent over ℚ, so this form is unique. iszero and == compare coefficients and are proofs. +, -, *, /, inv and integer powers stay exact, and float gives a number.

source
QRecoupling.radical — Function
radical(v; kwargs...)

A value at a level in nested square roots, where they exist. It needs Nemo: load it with using Nemo.

source
radical(v::ExactX; maxlen = 0, degree_limit = 32) -> RadExpr or NoRadical

The value in real nested square roots, e.g. (√5 − 3)/2, or a NoRadical saying why there is none. No length limit by default (maxlen > 0 adds one); the descent is exponential in the value's degree, so past degree_limit it is not attempted and the number is given instead.

radical(q6j(Exact(3), 1, 1, 1, 1, 1, 1))    # (√5 − 3)/2, the Fibonacci level
radical(q6j(Exact(5), 1, 1, 1, 1, 1, 1))    # no radical form: v² has degree 3 over ℚ at level 5, …
radical(q6j(Exact(254), 45, 45, 45, 30, 30, 30))          # degree 64: not attempted, with the number
radical(q6j(Exact(254), 45, 45, 45, 30, 30, 30); degree_limit = 64)   # …and this is the long wait
source
radical(s::ExactXSum; maxlen = 0, degree_limit = 32) -> RadExpr or NoRadical

Term by term, added up; the first term without a radical form is the answer, with the sum's number.

source
QRecoupling.numeric_value — Function
numeric_value(v::ClassicalResult; bits=precision(BigFloat)) -> BigFloat

The classical exact value σ√r, rounded to bits bits.

source

The number a value denotes, correct to bits even when its coordinates cancel strongly.

source
numeric_value(v::ExactX; bits=precision(BigFloat)) -> BigFloat or nothing

Evaluate the selected real embedding with adaptive guard precision, then round to bits bits. Returns nothing if the working-precision budget is exhausted. The Horner mass is an error estimate, not an outward-rounded interval certificate. Negative radicands are rejected rather than clamped to zero.

source
numeric_value(s::ExactXSum) -> BigFloat or nothing

The number the sum denotes, each term certified as in numeric_value(::ExactX).

source