canon-0.1.0.3: Massive Number Arithmetic

Math.NumberTheory.Canon

Description

A Canon is an exponentation-based representation for arbitrarily massive numbers, including prime towers.

Synopsis

# Documentation

data Canon Source #

Canon: GADT for either Bare (Integer) or some variation of a canonical form (see CanonValueType).

Instances

 Source # Methodssucc :: Canon -> Canon #pred :: Canon -> Canon #toEnum :: Int -> Canon #enumFrom :: Canon -> [Canon] #enumFromThen :: Canon -> Canon -> [Canon] #enumFromTo :: Canon -> Canon -> [Canon] #enumFromThenTo :: Canon -> Canon -> Canon -> [Canon] # Source # Instances for Canon Methods(==) :: Canon -> Canon -> Bool #(/=) :: Canon -> Canon -> Bool # Source # Methods(/) :: Canon -> Canon -> Canon #recip :: Canon -> Canon # Source # Methodsquot :: Canon -> Canon -> Canon #rem :: Canon -> Canon -> Canon #div :: Canon -> Canon -> Canon #mod :: Canon -> Canon -> Canon #quotRem :: Canon -> Canon -> (Canon, Canon) #divMod :: Canon -> Canon -> (Canon, Canon) # Source # Methods(+) :: Canon -> Canon -> Canon #(-) :: Canon -> Canon -> Canon #(*) :: Canon -> Canon -> Canon #abs :: Canon -> Canon # Source # Methods(<) :: Canon -> Canon -> Bool #(<=) :: Canon -> Canon -> Bool #(>) :: Canon -> Canon -> Bool #(>=) :: Canon -> Canon -> Bool #max :: Canon -> Canon -> Canon #min :: Canon -> Canon -> Canon # Source # Methods Source # MethodsshowsPrec :: Int -> Canon -> ShowS #show :: Canon -> String #showList :: [Canon] -> ShowS # Source # Instance of CanonConv class Methods

Create a Canon from an Integer. This may involve expensive factorization.

BareStatus: A "Bare Simplified" number means a prime number, +/-1 or 0. The code must set the flag properly A "Bare NotSimplified" number is an Integer that has not been checked (to see if it can be factored).

Constructors

 Simplified NotSimplified

Instances

 Source # Methods Source # Methods Source # MethodsshowList :: [BareStatus] -> ShowS #

CanonValueType: 3 possibilities for this GADT (integral, non-integral rational, irrational). Imaginary/complex numbers are not supported

Constructors

 IntegralC NonIntRationalC IrrationalC

Instances

 Source # Methods Source # Methods Source # MethodsshowList :: [CanonValueType] -> ShowS #

cMult :: Canon -> Canon -> CycloMap -> (Canon, CycloMap) Source #

Multiply Function: Generally speaking, this will be much cheaper than addition/subtraction which requires factoring. You are usually just merging lists of prime, exponent pairs and adding exponents where common primes are found. This notion is the crux of the library.

Note: This can be used instead of the * operator if you want to maintain a CycloMap for performance reasons.

cDiv :: Canon -> Canon -> CycloMap -> (Canon, CycloMap) Source #

Div function : Multiply by the reciprocal.

cAdd :: Canon -> Canon -> CycloMap -> (Canon, CycloMap) Source #

Addition and subtraction is generally much more expensive because it requires refactorization. There is logic to look for algebraic forms which can greatly reduce simplify factorization. Note: This can be used instead of the +/- operators if you want to maintain a CycloMap for performance reasons.

cSubtract :: Canon -> Canon -> CycloMap -> (Canon, CycloMap) Source #

Addition and subtraction is generally much more expensive because it requires refactorization. There is logic to look for algebraic forms which can greatly reduce simplify factorization. Note: This can be used instead of the +/- operators if you want to maintain a CycloMap for performance reasons.

cExp :: Canon -> Canon -> Bool -> CycloMap -> (Canon, CycloMap) Source #

Exponentiation: This does allow for negative exponentiation if the Bool flag is True. Note: This can be used instead of the exponentiation operator if you want to maintain a CycloMap for performance reasons.

Compute reciprocal (by negating exponents).

GCD and LCM functions for Canon

GCD and LCM functions for Canon

Mod function

Check if a Canon is an odd Integer. Note: Return False if the Canon is not integral. See CanonValueType for possible cases.

Totient functions

cPhi :: Canon -> CycloMap -> (Canon, CycloMap) Source #

Totient functions

Compute log as a Rational number.

Compute log as a Double.

Functions to check if a canon is negative/positive

Functions to check if a canon is negative/positive

Functions to check if a Canon is Integral, (Ir)Rational, Simplified or a prime tower

Functions to check if a Canon is Integral, (Ir)Rational, Simplified or a prime tower

Functions to check if a Canon is Integral, (Ir)Rational, Simplified or a prime tower

Force the expression to be simplified. This could potentially be very expensive.

Functions to check if a Canon is Integral, (Ir)Rational, Simplified or a prime tower

Determines the depth/height of maximum prime tower in the Canon.

cSplit :: Canon -> (Canon, Canon) Source #

Split a Canon into the numerator and denominator.

cNumerator and cDenominator are for processing "rational" canon reps.

cNumerator and cDenominator are for processing "rational" canon reps.

Checks if the Canon is Canonical, a more complex expression.

Checks if the Canon just a Bare Integer.

Returns the status for Bare numbers.

Return the CanonValueType (Integral, etc).

Functions to check if a Canon is Integral, (Ir)Rational, Simplified or a prime tower

This is used for tetration, etc. It defaults to zero for non-integral reps.

Tetration function

Pentation Function

Hexation Function

cHyperOp :: Integer -> Canon -> Integer -> CycloMap -> (Canon, CycloMap) Source #

Generalized Hyperoperation Function (https:/en.wikipedia.orgwiki/Hyperoperation)

(>^) :: CanonRoot a b c => a -> b -> c infixr 9 Source #

Root operator

(<^) :: CanonExpnt a b c => a -> b -> c infixr 9 Source #

Exponentiation operator

(<^>) :: Canon -> Integer -> Canon infixr 9 Source #

The thinking around the hyperoperators is that they should look progressively scarier :)

(<<^>>) :: Canon -> Integer -> Canon infixr 9 Source #

The thinking around the hyperoperators is that they should look progressively scarier :)

(<<<^>>>) :: Canon -> Integer -> Canon infixr 9 Source #

The thinking around the hyperoperators is that they should look progressively scarier :)

type CanonElement = (Canon, Canon) Source #

This element is a base, exponent pair. The base is an integer and is generally prime or 0, -1. The exponent is also a Canon (allowing for arbitrary nesting) A Canon conceptually consists of a list of these elements. The first member of the pair will be a Canon raised to the first power. By doing this, we're allow for further generality in the definition of a Canon.

Return the base b from a Canon Element (equivalent to b^e)

Return the exponent e from a Canon Element (equivalent to b^e)

getBases :: Canon -> [Canon] Source #

Return the list of bases from a Canon (conceptually of the form [b^e])>

Return the list of exponents from a Canon (conceptually of the form [b^e]).

Return the list of CanonElements from a Canon (conceptually of the form [b^e]).

Divisor functions should be called with integral Canons. Restricted to positive divisors. Returns Either String Canon

Divisor functions should be called with integral Canons. Restricted to positive divisors. Returns Either String Canon

Efficiently compute all of the divisors based on the canonical representation. | Returns Either an error message or a list of Canons.

Compute the nth divisor of a Canon. It operates on the absolute value of the Canon and is zero based. Note: This is deterministic but it's not ordered by the value of the divisor.

Consider this to be the inverse of the cNthDivisor function. This function ignores signs but both parameters must be integral.

data CycloMap Source #

CycloMap is a newtype hiding the details of a map of CR_ to pairs of integers and corresponding cyclotomic polynomials.

Instances

 Source # Methods Source # MethodsshowList :: [CycloMap] -> ShowS #

fromCycloMap :: CycloMap -> CycloMapInternal Source #

Unwrap the CycloMap newtype.

cmLookup :: CR_ -> CycloMap -> Maybe CycloPair Source #

showCyclo :: CR_ -> CycloMap -> [Char] Source #

This will display the cyclotomic polynomials for a CR.

This is an initial map with the cyclotomic polynomials for 1 and 2.