Commit 519b15aa authored by Tim Steenvoorden's avatar Tim Steenvoorden
Browse files

implement Lattice for Int and Nat

parent 9e792843
definition module Data.Int
from Algebra.Order import class Eq, class Ord
from Algebra.Enum import class Enum
from Algebra.Group import class Semigroup, class Monoid, class Group
from Algebra.Ring import class Semiring, class Ring, class Domain
from Algebra.Enum import class Enum
from Algebra.Lattice import class MeetSemilattice, class JoinSemilattice, class UpperBounded, class LowerBounded
/// # Definition
......@@ -23,6 +24,11 @@ instance Semiring Int
// instance Ring Int
instance Domain Int
instance MeetSemilattice Int
instance JoinSemilattice Int
instance UpperBounded Int
instance LowerBounded Int
/// # Helpers
inc :: !Int -> Int
......
......@@ -3,9 +3,10 @@ implementation module Data.Int
import Control.Function
import Algebra.Order
import Algebra.Enum
import Algebra.Group
import Algebra.Ring
import Algebra.Enum
import Algebra.Lattice
import Clean.Prim
......@@ -62,6 +63,7 @@ instance Monoid Int where
instance Group Int where
(-) x y = prim_subInt x y
inverse x = prim_negInt x
instance Semiring Int where
......@@ -86,6 +88,18 @@ instance Domain Int where
lcm 0 _ = 0
lcm x y = abs ((x `quot` gcd x y) * y)
instance MeetSemilattice Int where
(/\) x y = prim_minInt x y
instance JoinSemilattice Int where
(\/) x y = prim_maxInt x y
instance UpperBounded Int where
top = undefined
instance LowerBounded Int where
bottom = undefined
/// # Helpers
inc :: !Int -> Int
......
......@@ -2,7 +2,8 @@ definition module Data.Nat
from Algebra.Order import class Eq, class Ord
from Algebra.Group import class Semigroup, class Monoid
from Algebra.Ring import class Semiring
from Algebra.Ring import class Semiring, class Domain
from Algebra.Lattice import class MeetSemilattice, class JoinSemilattice, class UpperBounded, class LowerBounded
/// # Definition
......@@ -20,6 +21,11 @@ instance Semigroup Nat
instance Monoid Nat
instance Semiring Nat
instance MeetSemilattice Nat
instance JoinSemilattice Nat
instance UpperBounded Nat
instance LowerBounded Nat
/// # Special Algebra
(.-) infixl 6 :: !Nat !Nat -> Nat
......@@ -7,6 +7,7 @@ import Control.Function
import Algebra.Order
import Algebra.Group
import Algebra.Ring
import Algebra.Lattice
import Clean.Prim
......@@ -17,7 +18,7 @@ import Clean.Prim
//TODO rewrite in inlined ABC (?)
nat :: !Int -> Nat
nat n
| prim_ltInt n 0 = abort "Data.Nat.nat: negative integer"
| n < 0 = prim_abort "Data.Nat.nat: negative integer"
| otherwise = n
int :: !Nat -> Int
......@@ -48,10 +49,25 @@ instance Semiring Nat where
unity = prim_oneInt
/// ## Lattice
instance MeetSemilattice Nat where
(/\) x y = prim_minInt x y
instance JoinSemilattice Nat where
(\/) x y = prim_maxInt x y
instance UpperBounded Nat where
top = prim_upperInt
instance LowerBounded Nat where
bottom = prim_zeroInt
/// # Special Algebra
//TODO rewrite in inlined ABC (?)
(.-) infixl 6 :: !Nat !Nat -> Nat
(.-) n m
| prim_ltInt m n = prim_subInt n m
| otherwise = 0
| m < n = prim_subInt n m
| otherwise = prim_zeroInt
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment