[Agda] Reasoning with Pattern Match with Default Cases

Ulf Norell ulf.norell at gmail.com
Thu Nov 12 16:07:37 CET 2015


The best you can do, in my experience, is not use default cases in
functions you want to prove lots of properties about. That doesn't mean you
should spell out all the cases, though. Instead you can define a view for
the particular set of patterns you are interested in. In your case

data Ty : Set where
  int bool : Ty
  _=>_ : Ty → Ty → Ty

data BoolView : Ty → Set where
  bool : BoolView bool
  other : ∀ {τ} → BoolView τ

boolView : ∀ τ → BoolView τ
boolView bool = bool
boolView τ = other

f : Ty → Nat
f τ  with boolView τ
f .bool | bool  = 0
f τ     | other = 0

lemma : (τ : Ty) -> f τ ≡ 0
lemma τ  with boolView τ
lemma .bool | bool  = refl
lemma τ     | other = refl

/ Ulf

On Thu, Nov 12, 2015 at 3:05 PM, Marco Vassena <vassena at chalmers.se> wrote:

> Suppose I have defined a function by pattern match.
> In the function I am interested in one specific case, therefore I
> explicitly
> match that one, while all the others are implicitly covered:
>
> f : Ty -> ℕ
> f Bool = 0
> f τ = 0
>
> Now I want to prove something about this function, however the
> proof cannot be as concise as the definition of f:
>
> lemma : (τ : Ty) -> f τ ≡ 0
> lemma Bool = refl
> lemma τ = {! refl !}  -- f τ != zero
>
> I have to explicitly go through all the other cases, otherwise f τ won't
> reduce:
>
> lemma : (τ : Ty) -> f τ ≡ 0
> lemma Bool = refl
> lemma Int = refl
> lemma (τ => τ₁) = refl
> ...
>
> As you can imagine this can be very repetitive and annoying if the proofs
> are more involved
> and there are many values that fall in the "default" case.
>
> Do you know if it is possible to abstract over this pattern when reasoning
> about
> functions defined by pattern matching with a default case?
>
> All the best,
> Marco
> _______________________________________________
> Agda mailing list
> Agda at lists.chalmers.se
> https://lists.chalmers.se/mailman/listinfo/agda
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.chalmers.se/pipermail/agda/attachments/20151112/3cf532f2/attachment.html


More information about the Agda mailing list