Files
agdaproofs/IntegersModNRing.agda
2019-01-04 20:45:34 +00:00

67 lines
3.9 KiB
Agda
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{-# OPTIONS --safe --warning=error #-}
open import LogicalFormulae
open import Orders
open import Groups
open import Naturals
open import PrimeNumbers
open import Rings
open import Setoids
open import IntegersModN
module IntegersModNRing where
modNTo : {n : } {pr : 0 <N n} (a : n n pr)
modNTo record { x = x ; xLess = xLess } = x
*nhelper : {n : } {pr : 0 <N n} (max : ) (a : n n pr) n n pr (max modNTo a) n n pr
*nhelper {zero} {()}
*nhelper {succ n} zero a b pr2 = record { x = 0 ; xLess = succIsPositive n }
*nhelper {succ n} (succ max) record { x = zero ; xLess = xLess } b ()
*nhelper {succ n} (succ max) record { x = (succ x) ; xLess = xLess } b pr2 = (*nhelper max record { x = x ; xLess = xLess2 } b (succInjective pr2)) +n b
where
xLess2 : x <N succ n
xLess2 = PartialOrder.transitive (TotalOrder.order TotalOrder) (a<SuccA x) xLess
_*n_ : {n : } {pr : 0 <N n} n n pr n n pr n n pr
_*n_ {0} {()}
_*n_ {succ n} {_} record { x = a ; xLess = aLess } b = *nhelper a record { x = a ; xLess = aLess } b refl
nIdent : (n : ) (pr : 0 <N n) n n pr
nIdent 0 ()
nIdent 1 pr = record { x = 0 ; xLess = pr }
nIdent (succ (succ n)) _ = record { x = 1 ; xLess = succPreservesInequality (succIsPositive n) }
nMult0Right : {n : } {pr : 0 <N n} (max : ) (a : n n pr) (modNTo a max) (a *n record { x = 0 ; xLess = pr }) record { x = 0 ; xLess = pr }
nMult0Right {0} {()}
nMult0Right {succ n} .zero record { x = zero ; xLess = xLess } refl = equalityZn _ _ refl
nMult0Right {succ n} {pr} (.succ x) record { x = (succ x) ; xLess = xLess } refl rewrite nMult0Right {succ n} {pr} x record { x = x ; xLess = PartialOrder.transitive (TotalOrder.order TotalOrder) (a<SuccA x) xLess } refl = equalityZn _ _ refl
nMultCommutative : {n : } {pr : 0 <N n} (a b : n n pr) (a *n b) (b *n a)
nMultCommutative {0} {()}
nMultCommutative {succ n} {pr} record { x = zero ; xLess = xLess } b with <NRefl pr xLess
... | refl rewrite nMult0Right (modNTo b) b refl = equalityZn _ _ refl
nMultCommutative {succ n} record { x = (succ x) ; xLess = xLess } b = {!!}
nMultIdent : {n : } {pr : 0 <N n} (a : n n pr) (nIdent n pr) *n a a
nMultIdent {zero} {()}
nMultIdent {succ zero} {pr} record { x = zero ; xLess = (le diff proof) } = equalityZn _ _ refl
nMultIdent {succ zero} {pr} record { x = (succ a) ; xLess = (le diff proof) } = exFalso f
where
f : False
f rewrite additionNIsCommutative diff (succ a) = naughtE (succInjective (equalityCommutative proof))
nMultIdent {succ (succ n)} {pr} record { x = a ; xLess = aLess } with orderIsTotal a (succ (succ n))
nMultIdent {succ (succ n)} {pr} record { x = a ; xLess = aLess } | inl (inl a<ssn) = equalityZn _ _ refl
nMultIdent {succ (succ n)} {pr} record { x = a ; xLess = aLess } | inl (inr ssn<a) = exFalso (PartialOrder.irreflexive (TotalOrder.order TotalOrder) (PartialOrder.transitive (TotalOrder.order TotalOrder) aLess ssn<a))
nMultIdent {succ (succ n)} {pr} record { x = .(succ (succ n)) ; xLess = aLess } | inr refl = exFalso (PartialOrder.irreflexive (TotalOrder.order TotalOrder) aLess)
nRing : (n : ) (pr : 0 <N n) Ring {_} (n n pr)
Ring.additiveGroup (nRing n 0<n) = AbelianGroup.grp (nGroup n 0<n)
Ring._*_ (nRing n 0<n) a b = a *n b
Ring.multWellDefined (nRing n 0<n) = reflGroupWellDefined
Ring.1R (nRing n pr) = nIdent n pr
Ring.groupIsAbelian (nRing n 0<n) = AbelianGroup.commutative (nGroup n 0<n)
Ring.multAssoc (nRing n 0<n) = {!!}
Ring.multCommutative (nRing n 0<n) {a} {b} = nMultCommutative a b
Ring.multDistributes (nRing n 0<n) = {!!}
Ring.multIdentIsIdent (nRing n 0<n) {a} = nMultIdent a