Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Nicola Botta
IdrisLibs2
Commits
be8971ff
Commit
be8971ff
authored
Dec 21, 2020
by
Nicola Botta
Browse files
Initial.
parent
66caaa2d
Changes
2
Hide whitespace changes
Inline
Side-by-side
BoundedNat/BoundedNat.lidr
0 → 100644
View file @
be8971ff
> module BoundedNat.BoundedNat
> import Sigma.Sigma
> %default total
> %access public export
> ||| Natural numbers bounded by LT
> LTB : Nat -> Type
> LTB b = Sigma Nat (\ n => LT n b)
> ||| Natural numbers bounded by LTE
> LTEB : Nat -> Type
> LTEB b = Sigma Nat (\ n => LTE n b)
BoundedNat/Operations.lidr
0 → 100644
View file @
be8971ff
> module BoundedNat.Operations
> import Data.Fin
> import Data.Vect
> import BoundedNat.BoundedNat
> import Fin.Properties
> import Nat.LTProperties
> import Sigma.Sigma
> import Pairs.Operations
> %default total
> %access public export
> ||| Mapping bounded |Nat|s to |Fin|s
> toFin : {b : Nat} -> LTB b -> Fin b
> toFin {b = Z} (MkSigma _ nLT0 ) = void (succNotLTEzero nLT0)
> toFin {b = S m} (MkSigma Z _ ) = FZ
> toFin {b = S m} (MkSigma (S n) (LTESucc prf)) = FS (toFin (MkSigma n prf))
> ||| Mapping |Fin|s to bounded |Nat|s
> fromFin : {b : Nat} -> Fin b -> LTB b
> fromFin k = MkSigma (finToNat k) (finToNatLemma k)
> |||
> toVect : {b : Nat} -> {A : Type} -> (LTB b -> A) -> Vect b A
> toVect {b = Z} _ = Nil
> toVect {b = S b'} {A} f = (f (MkSigma Z (ltZS b'))) :: toVect f' where
> f' : LTB b' -> A
> f' (MkSigma k q) = f (MkSigma (S k) (LTESucc q))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment