Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] [Coq-club] return annotation on a match clause leads to missing information

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] [Coq-club] return annotation on a match clause leads to missing information


Chronological Thread 
  • From: Ralf Jung <jung AT mpi-sws.org>
  • To: coq-club AT inria.fr, Merlin Göttlinger <megoettlinger AT gmail.com>
  • Subject: Re: [Coq-Club] [Coq-club] return annotation on a match clause leads to missing information
  • Date: Tue, 30 Jan 2018 15:18:35 +0100
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=jung AT mpi-sws.org; spf=Pass smtp.mailfrom=jung AT mpi-sws.org; spf=None smtp.helo=postmaster AT juno.mpi-klsb.mpg.de
  • Ironport-phdr: 9a23:/dajHh/MtAAQI/9uRHKM819IXTAuvvDOBiVQ1KB41eMcTK2v8tzYMVDF4r011RmVBdyds6oMotGVmpioYXYH75eFvSJKW713fDhBt/8rmRc9CtWOE0zxIa2iRSU7GMNfSA0tpCnjYgBaF8nkelLdvGC54yIMFRXjLwp1Ifn+FpLPg8it2O2+54Dfbx9UiDahfLh/MAi4oQLNu8cMnIBsMLwxyhzHontJf+RZ22ZlLk+Nkhj/+8m94odt/zxftPw9+cFAV776f7kjQrxDEDsmKWE169b1uhTFUACC+2ETUmQSkhpPHgjF8BT3VYr/vyfmquZw3jSRMMvrRr42RDui9b9mRgL2hicJNzA382/ZhcJ/g61ZvB2vqAdyw5LXbYyPKPZyYq3QcNEcSGFcXshRTStBAoakYoUTFeUBOehYpJT5qVsTqxu+ChSnCeTtyj9VgH/20rY30+E5EQHHxQAgBNwPsG/OoNXyLqcSXvm4wa/VxjvNaPNW3C3y6InOch05rvGMXK5wccrMyUY0DQ/KklKQqYnjMjiI1eoNq3CW4/duWO+rkWIrtgV8riKsy8otkIXEiZ4ZxkjZ+Sh3xIs5P8C0RUphbdK5E5ZduDuWOotqTs4kXmpmojw1yqcctp6+ZCUKyIooxxrYa/GfcYiI/xTjVOGLLTd9nHJleauzhxW28Ui70eLwTMy00E5FriZfj9bDqGgB1x3V6seZVvtw5lqt1DiL2gzJ9+1JJVo4mKnaJpI7zbM8ioIfsUHZES/3nEX2grWWdkIh+uWw6eTnf7PmppCHOo9xkgH+M70imtexAOQjKAQOWHKb+euk2L354UL5WKlKjuExkqTBrJ/aIt0bqrelDA9Rz4Ys8A2yDyym0dQdhXkINkhJeBOBj4jzOlHBOur0DfmlgwfkrDA+zPffe7blH5/lL37Zkb6nc6w5o2tR0g4yy+dweY5IDrAHL//pEhv0udPfAwMlNw2yzOv9INp434IaH2mIB/nKHrnVtAqy7+Yha8uRYoBd7DTgLfcN4ubvyGQmghkaZ6b/jshfU2yxAvkzexbRWnHrmNpUST5b7Dp7d/TjjRi5aRAWYn+zW6wm4TRiU9CjFYaGXZ+2xrub03XiR8EEViV9ElmJVEzQWcCcQf5VM3CXOs4kiSMfE7+7RN15jEz8hErB07Nia9Hs1GgYuJbkjoIn5fDVklc37T0xDMCG2SeIV24ykm5aHzI=

Hi Merlin,

`Program` usually does some magic to be able to provide the "context" you are
missing here inside the `match`. However, this magic cannot be used together
with `return` clauses, which explains the behavior you are seeing.

To get the missing context when using `return`, you can do the necessary magic
yourself. For example, you can look at the term that is generated by
`Program`
in your example that works (`Print rule_transform'.`). I can't compile your
code as there's lots of missing context, but this shows the principle:

Program Definition test_0 (n: nat) :=
match n with
| O => true
| S _ => false
end.

Print test_0.

test_0 =
λ (n : nat) (program_branch_0 := λ _ : 0 = n, true)
(program_branch_1 := λ (wildcard' : nat) (_ : S wildcard' = n), false),
match n as n' return (n' = n → bool) with
| 0 => program_branch_0
| S wildcard' => program_branch_1 wildcard'
end eq_refl
: nat → bool

So, the "magic" consists of match returning a function from an equality proof
relating the original discriminee (n) to the result of the match in the return
type (n').

The following proof term should help understanding what is going on:

Definition foo (n: nat) (H: forall m, n <> S m) : n = 0 :=
match n as n' return n = n' -> n = 0 with
| O => fun (EQ: n = 0) => EQ
| S n' => fun (EQ: n = S n') =>
(* match on something of type False *)
match H _ EQ with end
end eq_refl.

As you can see, both match arms actually produce a *function*, with the
function's argument being an equality proof reflecting the match arm we are
in.
This equality proof is provided on the outside by just eq_refl, because the
entire match has the type `n = n -> n = 0`.

Kind regards,
Ralf

On 30.01.2018 13:58, Merlin Göttlinger wrote:
> Hi,
>
> it took me quite a while to figure out why my Program Fixpoint (and refine
> with
> Fix as well) generates missing contextual witnesses in the proof obligations
> making the goal unprovable. I had that happening previously when the
> recursive
> calls were made inside a higher order function (which did no longer seem to
> be
> unfolded when a measure function was involved) but that could be resolved by
> specialising that higher order function to pass the necessary proof along as
> well. But here the recursive call is "direct" and not nested in some other
> fuzz
> that could confuse Coq.
>
> Self contained example showing this
> behaviour: 
> https://gist.github.com/mgttlinger/ea0654dcf71b8937a7c67231e0c625f9
>
> Can someone explain why this is happening?
>
> Cheers,
> Merlin



Archive powered by MHonArc 2.6.18.

Top of Page