Type: | Package |
Title: | The Field of Cyclotomic Numbers |
Version: | 1.3.0 |
Maintainer: | Stéphane Laurent <laurent_step@outlook.fr> |
Description: | The cyclotomic numbers are complex numbers that can be thought of as the rational numbers extended with the roots of unity. They are represented exactly, enabling exact computations. They contain the Gaussian rationals (complex numbers with rational real and imaginary parts) as well as the square roots of all rational numbers. They also contain the sine and cosine of all rational multiples of pi. The algorithms implemented in this package are taken from the 'Haskell' package 'cyclotomic', whose algorithms are adapted from code by Martin Schoenert and Thomas Breuer in the 'GAP' project (https://www.gap-system.org/). Cyclotomic numbers have applications in number theory, algebraic geometry, algebraic number theory, coding theory, and in the theory of graphs and combinatorics. They have connections to the theory of modular functions and modular curves. |
License: | GPL-3 |
URL: | https://github.com/stla/cyclotomic |
BugReports: | https://github.com/stla/cyclotomic/issues |
Imports: | intmap, gmp, maybe, memoise, methods, numbers, VeryLargeIntegers |
Encoding: | UTF-8 |
RoxygenNote: | 7.2.3 |
Collate: | 'Cyclotomic.R' 'arithmetic.R' 'conjugate.R' 'imports.R' 'is.R' 'maputils.R' 'mkCyclotomic.R' 'polar.R' 'rational.R' 'showCyclotomic.R' 'sqrt.R' 'trigonometry.R' 'zzz.R' |
Suggests: | testthat (≥ 3.0.0) |
Config/testthat/edition: | 3 |
NeedsCompilation: | no |
Packaged: | 2023-11-02 18:31:27 UTC; SDL96354 |
Author: | Stéphane Laurent [aut, cre], Scott N. Walck [cph] (author of the Haskell library 'cyclotomic') |
Repository: | CRAN |
Date/Publication: | 2023-11-02 20:20:06 UTC |
Coercion to a 'cyclotomic' object
Description
Coercion to a 'cyclotomic' object
Usage
## S4 method for signature 'character'
as.cyclotomic(x)
## S4 method for signature 'cyclotomic'
as.cyclotomic(x)
## S4 method for signature 'numeric'
as.cyclotomic(x)
## S4 method for signature 'bigz'
as.cyclotomic(x)
## S4 method for signature 'bigq'
as.cyclotomic(x)
Arguments
x |
a |
Value
A cyclotomic
object.
Examples
as.cyclotomic(2)
as.cyclotomic("1/3")
Convert cyclotomic number to complex number
Description
Convert a cyclotomic number to a complex number.
Usage
asComplex(cyc)
Arguments
cyc |
a cyclotomic number |
Value
A complex number (generally inexact).
Examples
asComplex(zeta(4))
Conjugate cyclotomic number
Description
Complex conjugate of a cyclotomic number.
Usage
conjugate(cyc)
Arguments
cyc |
a cyclotomic number |
Value
A cyclotomic number, the complex conjugate of cyc
.
Examples
conjugate(zeta(4)) # should be -zeta(4)
Square root as a cyclotomic number
Description
Square root of an integer or a rational number as a cyclotomic number. This is slow.
Usage
cycSqrt(x)
Arguments
x |
an integer, a gmp rational number ( |
Value
The square root of x
as a cyclotomic number.
Examples
cycSqrt(2)
phi <- (1 + cycSqrt(5)) / 2 # the golden ratio
phi^2 - phi # should be 1
Extract value from a 'Just' value
Description
The from_just
function is imported from the
maybe package.
Follow the link to its documentation:
from_just
.
It has been imported for convenient use of the maybeRational
function, which possibly returns a 'Just' value.
Unary operators for cyclotomic objects
Description
Unary operators for cyclotomic objects.
Usage
## S4 method for signature 'cyclotomic,missing'
e1 + e2
## S4 method for signature 'cyclotomic,missing'
e1 - e2
Arguments
e1 |
object of class |
e2 |
nothing |
Value
A cyclotomic
object.
Imaginary part of cyclotomic number.
Description
The imaginary part of a cyclotomic number.
Usage
imaginaryPart(cyc)
Arguments
cyc |
a cyclotomic number |
Value
A cyclotomic number.
Examples
imaginaryPart(zeta(9))
Is the cyclotomic a Gaussian rational?
Description
Checks whether a cyclotomic number is a Gaussian rational number.
Usage
isGaussianRational(cyc)
Arguments
cyc |
a cyclotomic number |
Value
A Boolean value.
Is the cyclotomic a rational number?
Description
Checks whether a cyclotomic number is a rational number.
Usage
isRational(cyc)
Arguments
cyc |
a cyclotomic number |
Value
A Boolean value.
See Also
Is the cyclotomic a real number?
Description
Checks whether a cyclotomic number is a real number.
Usage
isReal(cyc)
Arguments
cyc |
a cyclotomic number |
Value
A Boolean value.
Cyclotomic as exact rational number if possible
Description
Cyclotomic number as exact rational number if possible.
Usage
maybeRational(cyc)
Arguments
cyc |
a cyclotomic number |
Value
A maybe
value, just
a rational number if cyc
is a rational number, nothing
otherwise.
See Also
Examples
maybeRational(zeta(4))
maybeRational(cosDeg(60)) # use `from_just` to get the value
Polar complex number with rational magnitude and angle
Description
Complex number in polar form with rational magnitude and rational angle as a cyclotomic number.
Usage
polarDeg(r, theta)
polarRev(r, theta)
Arguments
r |
magnitude, an integer number, a gmp rational number, or a
fraction given as a character string (e.g. |
theta |
angle, an integer number, a gmp rational number, or a
fraction given as a character string (e.g. |
Value
A cyclotomic number.
Examples
polarDeg(1, 90) # should be zeta(4)
polarRev(1, "1/4") # should be zeta(4) as well
Roots of quadratic polynomial
Description
Roots of a polynomial of degree 2 as cyclotomic numbers.
Usage
quadraticRoots(a, b, c)
Arguments
a , b , c |
the coefficients of the polynomial |
Value
A list of two cyclotomic numbers, the roots of the polynomial ax2 + bx +c.
Examples
library(cyclotomic)
quadraticRoots(a = 1, b = 2, c = -1)
Real part of cyclotomic number.
Description
The real part of a cyclotomic number.
Usage
realPart(cyc)
Arguments
cyc |
a cyclotomic number |
Value
A cyclotomic number.
Examples
realPart(zeta(9))
Cosine and sine of a rational number
Description
Cosine and sine of a rational angle as a cyclotomic number.
Usage
cosDeg(theta)
sinDeg(theta)
cosRev(theta)
sinRev(theta)
Arguments
theta |
an integer number, a gmp rational number, or a
fraction given as a character string (e.g. |
Details
The function cosDeg
, resp. sinDeg
, returns the cosine,
resp. the sine, of its argument assumed to be given in degrees.
The function cosRev
, resp. sinRev
, returns the cosine,
resp. the sine, of its argument assumed to be given in revolutions.
Value
A cyclotomic number.
Examples
cosDeg(60)
cosDeg("2/3")^2 + sinDeg("2/3")^2 == 1
The primitive n-th root of unity.
Description
For example, 'zeta(4) = i' is the primitive 4th root of unity, and 'zeta(5) = exp(2*pi*i/5)' is the primitive 5th root of unity. In general, 'zeta(n) = exp(2*pi*i/n)'.
Usage
zeta(n)
Arguments
n |
a positive integer |
Value
A cyclotomic number.
Examples
zeta(4)