English 中文(简体)
Showing (head . init ) = head in Agda
原标题:

I m trying to prove a simple lemma in Agda, which I think is true.

If a vector has more than two elements, taking its head following taking the init is the same as taking its head immediately.

I have formulated it as follows:

lem-headInit : ∀{l} (xs : Vec ℕ (suc (suc l)))
                    -> head (init xs) ≡ head xs
lem-headInit (x ∷ xs) = ?

Which gives me;

.l : ℕ
x  : ℕ
xs : Vec ℕ (suc .l)
------------------------------
Goal: head (init (x ∷ xs) | (initLast (x ∷ xs) | initLast xs)) ≡ x

as a response.

I do not entirely understand how to read the (init (x ∷ xs) | (initLast (x ∷ xs) | initLast xs)) component. I suppose my questions are; is it possible, how and what does that term mean.

Many thanks.

最佳回答

I do not entirely understand how to read the (init (x ∷ xs) | (initLast (x ∷ xs) | initLast xs)) component. I suppose my questions are; is it possible, how and what does that term mean.

This tells you that the value init (x ∷ xs) depends on the value of everything to the right of the |. When you prove something about in a function in Agda your proof will have to have the structure of the original definition.

In this case you have to case on the result of initLast because the definition of initLast does this before producing any results.

init : ∀ {a n} {A : Set a} → Vec A (1 + n) → Vec A n
init xs         with initLast xs
                --  ⇧  The first thing this definition does is case on this value
init .(ys ∷ʳ y) | (ys , y , refl) = ys

So here is how we write the lemma.

module inithead where

open import Data.Nat
open import Data.Product
open import Data.Vec
open import Relation.Binary.PropositionalEquality

lem-headInit : {A : Set} {n : ℕ} (xs : Vec A (2 + n))
             → head (init xs) ≡ head xs

lem-headInit (x ∷ xs) with initLast xs
lem-headInit (x ∷ .(ys ∷ʳ y)) | ys , y , refl = refl

I took the liberty of generalizing your lemma to Vec A since the lemma doesn t depend on the contents of the vector.

问题回答

Ok. I ve got this one by cheating and I m hoping somebody has a better solution. I threw away all the extra information you get from init being defined in terms of initLast and created my own naive version.

initLazy : ∀{A l} → Vec A (suc l) → Vec A l
initLazy (x ∷ []) = []
initLazy (x ∷ (y ∷ ys)) = x ∷ (initLazy (y ∷ ys))

Now the lemma is trivial.

Any other offers?





相关问题
How do I reason about conditionals in Coq?

I m working through the ListSet module from the Coq standard library. I m unsure how to reason about conditionals in a proof. For instance, I am having trouble with the following proof. Definitions ...

Z3: Extracting existential model-values

I m playing around with Z3 s QBVF solver, and wondering if it s possible to extract values from an existential assertion. To wit, let s say I have the following: (assert (exists ((x (_ BitVec 16))) (...

Tautology Checker for GNU Prolog [closed]

I am looking for open-source implementations of tautology checkers written in GNU Prolog (implementation for SWI-Prolog is acceptable as well, but GNU Prolog is preferred). I d like to feed program ...

Has anyone tried proving Z3 with Z3 itself?

Has anyone tried proving Z3 with Z3 itself? Is it even possible, to prove that Z3 is correct, using Z3? More theoretical, is it possible to prove that tool X is correct, using X itself?

How to proceed with this Coq Proof?

I m having a problem with my Coq proof and was hoping for some help and guidance. I have part of my definition below: Inductive Architecture : Set := | Create_Architecture (Arch_Name: string)(...

Searching through a list recursively in Coq

Im trying to search for an object in a list, and then perhaps return true if it is found; false otherwise. However, what I have tried to come up with is incorrect. I would really appreciate some ...

Pattern matching not specialising types

I m playing around in Coq, trying to create a sorted list. I just wanted a function that takes a list [1,2,3,2,4] and would return something like Sorted [1,2,3,4] - i.e. taking out the bad parts, but ...

Showing (head . init ) = head in Agda

I m trying to prove a simple lemma in Agda, which I think is true. If a vector has more than two elements, taking its head following taking the init is the same as taking its head immediately. I ...

热门标签