I'm trying to prove following statement with the interactive proof assistant:
total
concatAssoc : (x : List a) -> (y : List a) -> (z : List a) -> (x ++ y) ++ z = x ++ (y ++ z)
concatAssoc = ?h
I understand how it can be proven without elaborator reflection:
concatAssoc [] _ _ = Refl
concatAssoc (_ :: x) y z = cong $ concatAssoc x y z
However, I'm just curious why I have an issue with proving this statement interactively in REPL. Here is what I did:
:elab h
x <- gensym "x"
_base <- gensym "_base"
intro'
intro x
repeatUntilFail intro'
induction (Var x)
search
compute
attack
intro'
intro'
intro _base
rewriteWith (Var _base)
reflexivity
solve
:qed
Here's what I got:
...
-Main.h> solve
h: No more goals.
-Main.h> :qed
Proof completed!
Main.h = %runElab (do x <- gensym "x"
_base <- gensym "_base"
intro'
intro x
repeatUntilFail intro'
induction (Var x)
search
compute
attack
intro'
intro'
intro _base
rewriteWith (Var _base)
reflexivity
solve)
After that I substituted the function body with this proof:
import Pruviloj.Core
import Pruviloj.Induction
import Language.Reflection.Elab
total
concatAssoc : (x : List a) -> (y : List a) -> (z : List a) -> (x ++ y) ++ z = x ++ (y ++ z)
concatAssoc = %runElab (do x <- gensym "x"
_base <- gensym "_base"
intro'
intro x
repeatUntilFail intro'
induction (Var x)
search
compute
attack
intro'
intro'
intro _base
rewriteWith (Var _base)
reflexivity
solve)
However, when I tried to compile it, I got following error:
>idris 1.idr -p contrib -p pruviloj -X ElabReflection
Type checking .\1.idr
1.idr:9:16-23:34:
|
9 | concatAssoc = %runElab (do x <- gensym "x"
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ...
When checking right hand side of concatAssoc with expected type
(x : List a) -> (y : List a) -> (z : List a) -> (x ++ y) ++ z = x ++ y ++ z
Can't find a value of type
(x ++ []) ++ z = x ++ z
Holes: Main.concatAssoc
So my question is why the same proof works in REPL, but fails if written in a file?
There seem to be an issue with the way REPL treats implicits in the :elab
mode.
Idris> :l ElabDoesNotWork.idr
Holes: Main.h
*ElabDoesNotWork> :elab h
---------- Goal: ----------
{hole_0} : (a : Type) -> (x : List a) -> (y : List a) -> (z : List a) -> (x ++ y) ++ z = x ++ y ++ z
-Main.h>
Here REPL kind of asks us to do intro
on (a : Type)
, but when compiling the module the type variable is implicit and we don't have to introduce it.
The workaround here is to remove the offending intro
:
import Pruviloj.Core
import Pruviloj.Induction
concatAssoc : (xs, ys, zs : List a) -> (xs ++ ys) ++ zs = xs ++ (ys ++ zs)
concatAssoc = %runElab (do intro `{{xs}}
intro `{{ys}}
intro `{{zs}}
induction (Var `{{xs}})
compute
reflexivity
compute
attack
intro `{{x}}
intro `{{xs'}}
intro `{{IH}}
rewriteWith (Var `{{IH}})
reflexivity
solve)