coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Maximilian Wuttke <mwuttke97 AT posteo.de>
- To: coq-club AT inria.fr
- Subject: Re: [Coq-Club] Not enough information to resolve this refine goal
- Date: Wed, 30 Sep 2020 21:19:17 +0200
- Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=mwuttke97 AT posteo.de; spf=Pass smtp.mailfrom=mwuttke97 AT posteo.de; spf=None smtp.helo=postmaster AT mout02.posteo.de
- Ironport-phdr: 9a23:wUqSaBKkO3sWIDkYEdmcpTZWNBhigK39O0sv0rFitYgeLP3xwZ3uMQTl6Ol3ixeRBMOHsq0C0LCd6vq8EUU7or+5+EgYd5JNUxJXwe43pCcHRPC/NEvgMfTxZDY7FskRHHVs/nW8LFQHUJ2mPw6arXK99yMdFQviPgRpOOv1BpTSj8Oq3Oyu5pHfeQpFiCe/bL9oIhi6swrdutQIjYZtN6081gbHrnxUdupM2GhmP0iTnxHy5sex+J5s7SFdsO8/+sBDTKv3Yb02QaRXAzo6PW814tbrtQTYQguU+nQcSGQWnQFWDAXD8Rr3Q43+sir+tup6xSmaIcj7Rq06VDi+86tmTgLjhSEaPDA77W7XkNR9gr9FrhKvpxJxwIDab4+aO/V8YqzTcsgXRXZDU8tLSyBNHo2xYokJAuEcPehYtY79p14WoBW5HwatC+LvyjpJhn/y3K01yeIhGhzG0ww9A9IOrHfUo8voP6oVVOC0wrTIzSnfb/NVxzjw7IrFfws5ofGLRrJwbdTeyU41GwzYkFqdsIroNC6a2eoRqWaU9fZgVf6xhG49rQF8ujahy8cjhITIhI8Y11LJ+ypnzIg6K9O0VlN2bMO6HJdMqiyXN4R7Tt0mTmxruCs21L0LtJCmcSUWzJkqxB7RZvOBfoOV7BzjU+ORLi15hHJjYL+wmxay8Uyhyu3kTMa01ExFojBDktbSqnAA0QHY5MufSvZl40us2jaC2xrS5+xGO0w5m6vWJ4Qgz7MxjpYeskDOEjXrlEj5jaKabFso9va05+j9f7nrqIOQOolpgQ/kKKsugNawAeEgPwgOQWeb/eO82aXm/U3+XbVKkuE6nrfDvJDCIsQbvbK5DBFS0oo59hmwES+q0NUenXYZMFJIYA+LgovpNl3UIf31D+2zjlqtnTtxxv3LP6XtApDXIXjClLfhc6x960lZyAcryNBe6Y9UCq0dIPLwRED8sN7VAwQhMwyz2ObnFMty1oQEVW2SHKCVKLnSvkOQ5uIzP+mMY5cYtyr6K/g8/vLhkXs5mUIGcqSyxpsWaHW4Hux8LEmDYHrshM0BEWYQsQYkQuzqkg7KbTkGbHGrGqk4+zsTCYS8DI6FSJr+rqaG2XKeF41XY2FCC1mKWUj1a5mHVr9YbT2PPtNin21bfaCmUJMs0leiuVmpmPJcMuPI93hA5trY399v6riLzE1gxXlPF82Yllq1YSRshGpRHm0u27tjrEs7xlrRifEl0cwdLsRa4rZyail/NZPYyLUqWdX1Rx6ZJJGRT026T9LgDTxjFotgke9LWF50HpCZtj6G2iOrB7EPkLnSXc4s9bnA0n+3K8svkns=
Note that even defining `fromList` this way is somewhat complicated. One
possible implementation:
```
Fixpoint fromList (l : list A) : 1 <= length l -> nonEmpty A.
Proof.
destruct l as [ | x l'].
- intros H. exfalso. cbn in H. abstract omega.
- destruct l' as [ | y l''] eqn:E.
+ intros _. exact (singleton x).
+ intros H. refine (consNE x (fromList l' _)).
abstract (subst; cbn in *; omega).
Defined.
```
Note that this is structurally recursive over the list. In the second
case, we have to make another case distinction on whether the rest of
the list is empty. Note that in the last case, we make recursive use of
`fromList l' _`, not `fromList (cons y l'') _`.
Note that `1 <= length l` is introduced *after* the case distinction on
`l`. This makes sure that `l` is also modified after the case
distinction. This pattern is called the 'convoy pattern', see [1].
[1]: <http://adam.chlipala.net/cpdt/cpdt.pdf>.
On 30/09/2020 20:52, jonikelee AT gmail.com wrote:
> That fixpoint fromList is not going to be structurally recursive as it
> is defined, even if you do solve its remaining subgoals. I would
> suggest this alternative:
>
> Fixpoint fromList (l : list A)(lgt0 : length l > 0) :nonEmpty A.
>
> If you still really need to have a single arg version of fromList that
> takes a sigma type, my suggestion is to define it in terms of the above
> alternative.
>
> On Wed, 30 Sep 2020 13:21:49 -0500
> Agnishom Chattopadhyay <agnishom AT cmi.ac.in> wrote:
>
>> I am trying to write a function whose argument type is a sigma type.
>> Here are some details.
>>
>> Inductive nonEmpty (A : Type) : Type :=
>> | singleton : A -> nonEmpty A
>> | consNE : A -> nonEmpty A -> nonEmpty A.
>>
>> Arguments singleton {A}.
>> Arguments consNE {A}.
>>
>> Section NonEmpty.
>>
>> Variable A : Type.
>>
>> Fixpoint toList (l : nonEmpty A) :=
>> match l with
>> | singleton x => (cons x nil)
>> | consNE x xs => (cons x (toList xs))
>> end.
>>
>> Fixpoint fromList (l : {l : list A | length l > 0}) : nonEmpty A.
>> refine (match (proj1_sig l) with
>> | nil => _
>> | (cons x nil) => singleton x
>> | (cons x xs) => consNE x (fromList (exist (fun xs =>
>> length xs
>>> 0) xs _))
>> end).
>>
>> Now, how do I solve these goals? For the first one, I want to show a
>> contradiction, saying that (proj1_sig l) couldn't have been nil,
>> given that we know that length ((proj1_sig l)) > 0. However, the
>> equation (proj1_sig l) = nil is not present in the context. It is
>> very similar in the case of the other hole as well.
>>
>> --Agnishom
>
- [Coq-Club] Not enough information to resolve this refine goal, Agnishom Chattopadhyay, 09/30/2020
- Re: [Coq-Club] Not enough information to resolve this refine goal, jonikelee AT gmail.com, 09/30/2020
- Re: [Coq-Club] Not enough information to resolve this refine goal, Maximilian Wuttke, 09/30/2020
- Re: [Coq-Club] Not enough information to resolve this refine goal, Maximilian Wuttke, 09/30/2020
- Re: [Coq-Club] Not enough information to resolve this refine goal, Agnishom Chattopadhyay, 09/30/2020
- Re: [Coq-Club] Not enough information to resolve this refine goal, Maximilian Wuttke, 09/30/2020
- Re: [Coq-Club] Not enough information to resolve this refine goal, Agnishom Chattopadhyay, 09/30/2020
- Re: [Coq-Club] Not enough information to resolve this refine goal, Maximilian Wuttke, 09/30/2020
- Re: [Coq-Club] Not enough information to resolve this refine goal, Maximilian Wuttke, 09/30/2020
- Re: [Coq-Club] Not enough information to resolve this refine goal, Maximilian Wuttke, 09/30/2020
- Re: [Coq-Club] Not enough information to resolve this refine goal, jonikelee AT gmail.com, 09/30/2020
Archive powered by MHonArc 2.6.19+.