Reformulate case-using functions
clayrat opened this issue · comments
If we define bipMinus
as
bipMinusHelp : Bim -> Bip
bipMinusHelp (BimP c) = c
bipMinusHelp _ = U
bipMinus : (a, b: Bip) -> Bip
bipMinus a b = bipMinusHelp (bimMinus a b)
then the proof of subSuccR
simplifies a lot, since now we can use rewrite
:
subSuccR : (p, q: Bip) -> bipMinus p (bipSucc q) = bipPred (bipMinus p q)
subSuccR p q = rewrite subMaskSuccR p q in
rewrite subMaskCarrySpec p q in
aux (bimMinus p q)
where
aux : (m : Bim) -> bipMinusHelp (bimPred m) = bipPred (bipMinusHelp m)
aux BimO = Refl
aux (BimP U ) = Refl
aux (BimP (O _)) = Refl
aux (BimP (I _)) = Refl
aux BimM = Refl
So I propose to redefine all case
-using functions (bipMinus
, bipMin
, bipMax
, bipSqrtRemStep
etc) to this form, at least until idris-lang/Idris-dev#4001 is fixed.
Another inconvenience is that we can't put these helpers under where
, as there currently is no way to refer to them (see idris-lang/Idris-dev#3991).
Another approach might be using with
blocks:
bipMinus : (a, b: Bip) -> Bip
bipMinus a b with (bimMinus a b)
bipMinus a b | BimP c = c
bipMinus a b | _ = U
As these automatically get elaborated into helper functions, it also allows rewrite
s to work, but we can't proceed with aux
for the same reason - with
blocks can't be referred to.
My preference is for using top-level helper functions instead of where
or with
, but since you're writing 99% of the proofs at the moment I think you should choose ultimately whatever style suits you best whilst we work around idris-lang/Idris-dev#4001. In any case, a top-level helper function is what I used in my Bin
proof.
What I'm saying is that top-level helpers is apparently the only way forward for now, where
/with
is unusable due to idris-lang/Idris-dev#3991