-
Notifications
You must be signed in to change notification settings - Fork 393
[ contrib ] Arithmetic on Fin #830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Pretty sure these are the more convenient isos: public export
pad : (n : Nat) -> Fin m -> Fin (n + m)
pad Z k = k
pad (S n) k = FS (pad n k)
public export
sum : {a : Nat} -> Either (Fin a) (Fin b) -> Fin (a + b)
sum (Left x) = weakenN b x
sum (Right x) = pad a x
public export
mus : {a : Nat} -> Fin (a + b) -> Either (Fin a) (Fin b)
mus {a = Z} k = Right k
mus {a = S n} FZ = Left FZ
mus {a = S n} (FS l) = mapFst FS (mus l)
public export
prod : {b : Nat} -> Fin a -> Fin b -> Fin (a * b)
prod FZ y = weakenN (mult (pred a) b) y
prod (FS x) y = pad b (prod x y)
public export
dorp : Fin (a * b) -> (Fin a, Fin b)
dorp = ? {- ...divmod... -} |
I agree with you and I rewrote correctness proofs of split functions as an inverse of appropriate functions. However, I couldn't manage to call them as you suggest because there could be two different pairs of notions for sum and product for
These sums and products have different properties. What I was originally talked about is the index-sum and index-product (this is what you name When I was at first trying to express properties of my split functions through sum and product of (+) : {...} -> Fin a -> Fin b -> Fin (a + b)
(*) : {...} -> Fin a -> Fin b -> Fin (a * b) it would lead to the following: Thus, I refined the signatures of number-sum and number-product to (+) : {...} -> Fin (S a) -> Fin (S b) -> Fin (S $ a + b)
(*) : {...} -> Fin (S a) -> Fin (S b) -> Fin (S $ a * b) With these signatures, examples from above would be nicer: Well, the question is the following. Actually, the original split functions and their properties now are expressed without number-sum and number-product. But the functions the these operations, and some properties of them are still in this PR. I feel myself that they can be useful sometime, but I'm not sure. So, should they leave or should I remove them? |
Rebased over changes of #857. |
I rebased again and added documentation comments to main functions. |
Also, not commented out function was uncommented.
This was fairly painful but I think the proof have cleaner types and are more maintainable now. Additionally I have renamed a lot of variables and definitions to have a more uniform |
Data.Fin.Extra
Some zeroes in signatures, one simpler implementation and formatting.
Some zeroes in signatures, one simpler implementation and formatting.
There are three more or less separate changes (that correspond to separate commits):
Data.Fin.Extra
module's sectioning -- or else it becomes a mess;Data.Fin.Extra
contains a function proving properties of relation betweenfinToNat
andweaken
, I propose similar functions forfinToNat
regarding toweakenN
andshift
;Fin
:Fin
of sum to (type) sum ofFin
s:Fin (a+b) -> Either (Fin a) (Fin b)
;Fin
of product to (type) product ofFin
s:Fin (a*b) -> (Fin a, Fin b)
.