3 module Logic.Theory.Arithmetic (
10 type PositiveOrNull (..),
11 type PositiveNonNull (..),
12 type NegativeOrNull (..),
13 type NegativeNonNull (..),
15 type Oppositeable (..),
22 import Data.Ord qualified as Ord
24 import Logic.Theory.Eq
25 import Logic.Theory.Ord
26 import Numeric.Natural (Natural)
27 import Prelude (Integer, maxBound)
28 import Prelude qualified
32 class Zeroable a where
34 default zero :: Prelude.Num a => Zero ::: a
35 zero = ZeroAxiom ... 0
37 instance Zeroable Integer
38 instance Zeroable Natural
40 newtype Succ n = SuccAxiom n
46 default one :: Prelude.Num a => One ::: a
47 one = SuccAxiom ZeroAxiom ... 1
49 instance Oneable Integer
50 instance Oneable Natural
52 class Signable a where
53 sign :: x ::: a -> Compare Zero x ::: Ord.Ordering
54 default sign :: Ord.Ord a => Prelude.Num a => x ::: a -> Compare Zero x ::: Ord.Ordering
55 sign = compare (ZeroAxiom ... 0)
56 instance Signable Natural
58 instance Signable Integer
60 newtype PositiveOrNull a x = PositiveOrNull (x ::: a / x >= Zero)
61 instance Axiom (PositiveOrNull a Zero)
62 instance Axiom (PositiveOrNull a (Opposite (Zero)))
63 instance Axiom (PositiveOrNull a (Succ n))
65 newtype PositiveNonNull a x = PositiveNonNull (x ::: a / x > Zero)
66 instance Axiom (PositiveNonNull a (Succ n))
68 newtype NegativeOrNull a x = NegativeOrNull (x ::: a / x <= Zero)
69 instance Axiom (NegativeOrNull a Zero)
70 instance Axiom (NegativeOrNull a (Opposite (Zero)))
71 instance Axiom (NegativeOrNull a (Opposite ((Succ n))))
73 newtype NegativeNonNull a x = NegativeNonNull (x ::: a / x < Zero)
74 instance Axiom (NegativeNonNull a (Succ n))
76 data Opposite n = OppositeAxiom
78 class Oppositeable a where
79 opposite :: x ::: a -> Opposite x ::: a
80 opposite (Named x) = OppositeAxiom ... x
82 instance Oppositeable Int
83 instance Oppositeable Integer
85 instance Axiom (Opposite (Opposite (x ::: Integer)) == x)
91 type AxiomUpperBound max i a = (i ::: a) < max -> (i ::: a) < ((i ::: a) + One)
92 instance Axiom (AxiomUpperBound IntMax i Int)
94 type AxiomNoUpperBound i a = (i ::: a) < Succ (i ::: a)
95 instance Axiom (AxiomNoUpperBound i Natural)
96 instance Axiom (AxiomNoUpperBound i Integer)
99 type role (+) nominal nominal
102 instance Axiom (Commutative (+) x y)
104 -- | `(+)` is associative
105 instance Axiom (Associative (+) x y z)