oalg-base-1.1.4.0: Algebraic structures on oriented entities and limits as a tool kit to solve algebraic problems.
Copyright(c) Erich Gut
LicenseBSD3
Maintainerzerich.gut@gmail.com
Safe HaskellSafe-Inferred
LanguageHaskell2010

OAlg.Structure.Number.Definition

Description

definition of numbers as ordered Semiring with infinitely many elements.

Synopsis

Number

class (Semiring r, Commutative r, Ord r) => Number r where Source #

ordered commutative semi ring where + and * respect the given ordering.

Definitions

  1. A number x is called positive if 0 < x and negative if x < 0.
  2. A number structure is called positive if it contains no negative elements.

Properties

  1. 1 is positive.
  2. For all x < y and z holds: x + z < y + z
  3. For all 0 < x, 0 < y holds: 0 < x * y.
  4. For all x holds: x == signum x * abs x.
  5. For all x holds: floor x + fraction x == x.

Note

  1. A not positive structure of numbers contain always also the additive inverse of 1 which is negative.
  2. Structures of numbers have infinitely many values, because from the properties above follows that 0 < 1 < 2 < .. < ntimes n 1 < ntimes (n + 1) 1 < .. for all 0 <= n.

Minimal complete definition

minusOne, zFloorFraction

Methods

minusOne :: Maybe r Source #

the additive inverse of 1 - if it exists - and will be denoted by -1 (see the note above).

signum :: r -> r Source #

sign of a number.

Property For all x holds: if 0 < x then signum x == 1 and if x == 0 then signum x == 0 and if x < 0 then signum x == -1 (for -1 see minusOne).

Note The default implementation is:

signum x = case rZero compare x of
             GT -> rOne
             EQ -> rZero
             LT -> e where Just e = minusOne

abs :: r -> r Source #

absolute value of a number.

Definition The absolute value of a x is defined by abs x = signum x * x (which serves as the default implementation).

Properties For all x holds:

  1. 0 <= abs x.
  2. if 0 <= x then abs x == x.

floor :: r -> r Source #

floor of a value of a number.

Properties

  1. floor 0 == 0.
  2. For all x holds: floor (x + 1) = floor x + 1.

fraction :: r -> r Source #

fractional part of a number.

Property For all x holds: 0 <= fraction x < 1.

zFloorFraction :: r -> (Z, r) Source #

simultaneous evaluation of floor - represented as an integer - and its fraction.

Properties For all x holds:

  1. floor x == ntimes (prj $ fst $ zFloorFraction $ x) (signum x).
  2. fraction x == snd . zFloorFraction.

Note This properties are used for the default implementation of floor and fraction.

zFloor :: Number r => r -> Z Source #

floor to Z.

digital represenation of numbers

toDigits :: (Number r, KnownNat b, 2 <= b) => r -> Digits b r Source #

the digital representation of x in the base b.

Let Digits s xs ys = toDigits r then

  • s is the signum x.
  • xs is the digital representation of abs (floor x) .
  • ys is the - possibly infinite - digital representation of abs (fraction x) in the base b.

Examples

>>> toDigits (1/3) :: Digits 10 Q
Digits 1 [] [3,3,3..]
>>> toDigits (-4/3) :: Digits 3 Q
Digits (-1) [1] [1]

Note To get the first n digits of the fractional part ys for the digital representation of x use toDigitsFinite n x.

data Digits (b :: Nat) r where Source #

digital representation of numbers for the given base b.

Note

  1. dgsFlr is a finite list
  2. dgsFrc maybe a infinite list and as such valid could end up in an infinite proposition!

Constructors

Digits 

Fields

  • :: 2 <= b
     
  • => { dgsSig :: r

    the signum.

  •    , dgsFlr :: [N]

    the digital representation of the floor part

  •    , dgsFrc :: [N]

    the digital representation of the fractional part

  •    } -> Digits b r
     

Instances

Instances details
Show r => Show (Digits b r) Source # 
Instance details

Defined in OAlg.Structure.Number.Definition

Methods

showsPrec :: Int -> Digits b r -> ShowS #

show :: Digits b r -> String #

showList :: [Digits b r] -> ShowS #

Eq r => Eq (Digits b r) Source # 
Instance details

Defined in OAlg.Structure.Number.Definition

Methods

(==) :: Digits b r -> Digits b r -> Bool #

(/=) :: Digits b r -> Digits b r -> Bool #

Ord r => Ord (Digits b r) Source # 
Instance details

Defined in OAlg.Structure.Number.Definition

Methods

compare :: Digits b r -> Digits b r -> Ordering #

(<) :: Digits b r -> Digits b r -> Bool #

(<=) :: Digits b r -> Digits b r -> Bool #

(>) :: Digits b r -> Digits b r -> Bool #

(>=) :: Digits b r -> Digits b r -> Bool #

max :: Digits b r -> Digits b r -> Digits b r #

min :: Digits b r -> Digits b r -> Digits b r #

Validable r => Validable (Digits b r) Source # 
Instance details

Defined in OAlg.Structure.Number.Definition

Methods

valid :: Digits b r -> Statement Source #

(KnownNat b, Entity r) => Entity (Digits b r) Source # 
Instance details

Defined in OAlg.Structure.Number.Definition

toDigitsFinite :: (Number r, KnownNat b, 2 <= b) => N -> r -> Digits b r Source #

toDigitsFinite n is like toDigits but the fractional part is limited to the length of n and is given by dgsFrcTake n . toDigits.

fromDigits :: (Number r, Acyclic r, KnownNat b) => N -> Digits b r -> r Source #

fromDigits n dgs@(Digits s xs ys) is given by s * (xm * b^m + .. + xi * b^i + .. + x0 * b^0 + y1 * r^1 + .. + yj * r^j + .. + yn * r^n where b = dgsBase dgs, xs = [xm..xi..x0], ys = [y1,y2..yj..yn..] and r = invert b.

Property Let 1 < b and dgs = Digits s xs ys where s is either 1 or -1 and 0 <= xi < b for all i and 0 <= yj < b for all j then for all n holds: toDigits b n (fromDigits b n dgs) == dgs.

Note

  1. All the elements of the above formula are lifted to the type r via \x -> ntimes x rOne.
  2. Because the type r is acyclic, the expression invert b - which is actually invert (ntimes b rOne) - is regular.
  3. If b is not bigger then 1 then an exception Undefined will be thrown.

dgsBase :: KnownNat b => Digits b r -> N Source #

the base of a digit, i.e. the corresponding natural number of the type literal b.

dgsProxy :: Digits b r -> Proxy b Source #

the proxy with the same type b.

dgsFrcTake :: N -> Digits b r -> Digits b r Source #

limits the fractional part dgsFrc to the length of n.

Integral

class Number a => Integral a where Source #

discrete numbers.

Property For all x holds: fraction x == 0.

Minimal complete definition

divMod

Methods

divMod :: a -> a -> (a, a) Source #

div :: a -> a -> a Source #

mod :: a -> a -> a Source #

Instances

Instances details
Integral N Source # 
Instance details

Defined in OAlg.Structure.Number.Definition

Methods

divMod :: N -> N -> (N, N) Source #

div :: N -> N -> N Source #

mod :: N -> N -> N Source #

Integral Z Source # 
Instance details

Defined in OAlg.Structure.Number.Definition

Methods

divMod :: Z -> Z -> (Z, Z) Source #

div :: Z -> Z -> Z Source #

mod :: Z -> Z -> Z Source #

primes :: [N] Source #

the list of prime numbers.

Acyclic

class (Distributive a, Abelian a, Invertible a) => Acyclic a where Source #

distributive structure with entities scaleable by Q.

Property For every 0 < n and point p holds: ntimes n (one p) is invertible.

Note

  1. The cyclic rings Mod n for 2 <= n are not scaleable by Q, because 1 /= 0 and ntimes n 1 == 0!
  2. If for every point p holds that zero (p:>p) == one p then the structure is scaleable by Q (e.g. Orientation p).

Minimal complete definition

Nothing

Methods

qtimes :: Q -> a -> a Source #

qtimes q a == ztimes z a * invert (ntimes n (one (start a))). where z = numerator q and n = denominator q.

Instances

Instances details
Acyclic Q Source # 
Instance details

Defined in OAlg.Structure.Number.Definition

Methods

qtimes :: Q -> Q -> Q Source #

Acyclic () Source # 
Instance details

Defined in OAlg.Structure.Number.Definition

Methods

qtimes :: Q -> () -> () Source #

Fractional

type Fractional r = (Number r, Abelian r, Acyclic r) Source #

continuous numbers, i.e acyclic and negateable numbers. They induce a sub Q-vectorial structures of the real numbers.

Note We will distinguish here instances of Fractional and the mathematical entities of real numbers!

Measurable

class (Entity a, Number r) => Measurable a r where Source #

measurable entities.

Methods

dist :: a -> a -> r Source #

distance of two points.

Properties Let a r be Measurable, then holds:

  1. For all x and y in a holds: 0 <= dist x y
  2. For all x and y in a holds: dist x y == 0 if and only if x == y.
  3. For all x and y in a holds: dist x y == dist y x.
  4. For all x, y and z in a holds: dist x z <= dist x y + dist y z

Instances

Instances details
Measurable N Z Source # 
Instance details

Defined in OAlg.Structure.Number.Definition

Methods

dist :: N -> N -> Z Source #

(Number r, Abelian r) => Measurable r r Source # 
Instance details

Defined in OAlg.Structure.Number.Definition

Methods

dist :: r -> r -> r Source #