2020-06-16 22:09:31 +03:00
|
|
|
||| Until Idris2 starts supporting the 'syntax' keyword, here's a
|
|
|
|
||| poor-man's equational reasoning
|
2020-05-18 15:59:07 +03:00
|
|
|
module Syntax.PreorderReasoning
|
|
|
|
|
2023-02-17 20:47:54 +03:00
|
|
|
infixl 0 ~~,~=
|
2020-06-16 22:09:31 +03:00
|
|
|
prefix 1 |~
|
2022-03-22 23:58:36 +03:00
|
|
|
infix 1 ...,..<,..>,.=.,.=<,.=>
|
2020-05-18 15:59:07 +03:00
|
|
|
|
2020-06-16 22:09:31 +03:00
|
|
|
|||Slightly nicer syntax for justifying equations:
|
|
|
|
|||```
|
|
|
|
||| |~ a
|
|
|
|
||| ~~ b ...( justification )
|
|
|
|
|||```
|
|
|
|
|||and we can think of the `...( justification )` as ASCII art for a thought bubble.
|
|
|
|
public export
|
2020-10-07 19:44:18 +03:00
|
|
|
data Step : a -> b -> Type where
|
|
|
|
(...) : (0 y : a) -> (0 step : x ~=~ y) -> Step x y
|
2020-05-18 15:59:07 +03:00
|
|
|
|
2020-06-16 22:09:31 +03:00
|
|
|
public export
|
|
|
|
data FastDerivation : (x : a) -> (y : b) -> Type where
|
2020-10-07 19:44:18 +03:00
|
|
|
(|~) : (0 x : a) -> FastDerivation x x
|
2021-02-09 17:18:41 +03:00
|
|
|
(~~) : FastDerivation x y -> (step : Step y z) -> FastDerivation x z
|
2021-01-16 10:03:45 +03:00
|
|
|
|
|
|
|
public export
|
2023-06-30 18:05:24 +03:00
|
|
|
Calc : {0 x : a} -> {0 y : b} -> (0 der : FastDerivation x y) -> x ~=~ y
|
|
|
|
Calc der = irrelevantEq $ Calc' der
|
|
|
|
where
|
|
|
|
Calc' : {0 x : c} -> {0 y : d} -> FastDerivation x y -> x ~=~ y
|
|
|
|
Calc' (|~ x) = Refl
|
|
|
|
Calc' ((~~) der (_ ...(Refl))) = Calc' der
|
2020-05-18 15:59:07 +03:00
|
|
|
|
2020-06-16 22:09:31 +03:00
|
|
|
{- -- requires import Data.Nat
|
|
|
|
0
|
2020-05-18 15:59:07 +03:00
|
|
|
example : (x : Nat) -> (x + 1) + 0 = 1 + x
|
2021-01-16 10:03:45 +03:00
|
|
|
example x =
|
|
|
|
Calc $
|
2020-06-16 22:09:31 +03:00
|
|
|
|~ (x + 1) + 0
|
|
|
|
~~ x+1 ...( plusZeroRightNeutral $ x + 1 )
|
|
|
|
~~ 1+x ...( plusCommutative x 1 )
|
|
|
|
-}
|
2022-03-22 23:58:36 +03:00
|
|
|
|
|
|
|
-- Smart constructors
|
|
|
|
public export
|
2023-06-30 18:05:24 +03:00
|
|
|
(..<) : (0 y : a) -> {0 x : b} -> (0 step : y ~=~ x) -> Step x y
|
|
|
|
(y ..<(prf)) {x} = (y ...(sym prf))
|
2022-03-22 23:58:36 +03:00
|
|
|
|
|
|
|
public export
|
|
|
|
(..>) : (0 y : a) -> (0 step : x ~=~ y) -> Step x y
|
|
|
|
(..>) = (...)
|
2023-02-17 20:47:54 +03:00
|
|
|
|
|
|
|
||| Use a judgemental equality but is not trivial to the reader.
|
|
|
|
public export
|
2023-06-30 18:05:24 +03:00
|
|
|
(~=) : FastDerivation x y -> (0 z : dom) -> {auto 0 xEqy : y = z} -> FastDerivation x z
|
2023-02-17 20:47:54 +03:00
|
|
|
(~=) der y {xEqy = Refl} = der ~~ y ... Refl
|