coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Pierre Courtieu <pierre.courtieu AT gmail.com>
- To: coq-club AT inria.fr
- Subject: Re: [Coq-Club] Simplifying pattern matching
- Date: Tue, 16 Aug 2022 11:50:22 +0200
- Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=pierre.courtieu AT gmail.com; spf=Pass smtp.mailfrom=pierre.courtieu AT gmail.com; spf=None smtp.helo=postmaster AT mail-qk1-f182.google.com
- Ironport-data: A9a23:IUZd16k2+IRz44P2k9PGzGXo5gy7IERdPkR7XQ2eYbSJt1+Wr1Gzt xIYDDqEP/uLY2T8eNknaIu1p0sGsZeDzdNhGlQ6rihgFFtH+JHPbTi7BhepbnnKdqUvb2o+s p5AMoGYRCwQZiWBzvt4GuG59RGQ7YnRGvykTrSs1hlZHWeIcg944f5Ys7N/09UAbeSRWVvX4 4ui+pOHYTdJ5hYtWo4qw/LbwP9QlK+q0N8olgRWiSdj4TcyP1FMZH4uDfnZw0nQGuG4LcbmL wr394xVy0uCl/sb5nxJpZ6gGqECaua60QFjERO6UYD66vRJjnRaPqrWqJPwZG8P4whlkeydx /1AsJ/oaF90YZSdo9UAFD5FOn4lLJRZreqvzXiX6aR/zmXDenrohuxtVQQ4ZN1CvOlwBm5K+ LoTLzVlghKr3brnhuLmDLM23IJ6fJOD0IA34hmMyRnBDPs8W52FSKLX/8NZ0SoYicVHHPKYb M0cAdZqREiQM00SYQdHYH44tNu1tFbTUjgAlAnLr7UssnP/lhZ37qe4ZbI5ffTTHZkP9qqCn UrN+H28CRUHPvSE2D+d+zStgPXOlGX1Quov+KaQ8/drhBiKxTVWBkRGDx20pv62jkP4UNVaQ 6AJxsYwhaU39xSKFoSiZkyDkWPDmQM1BIFBKvJvvWlh1ZHoywqeA2EFSBtIZ9onqNI6SFQWO rmhz4OB6dtH4O39dJ6NyluHhWjtZnVNfAfucQdBHFRVuYCyyG0mpkuXFo4LLUKjsjHi9djNL 92iqSE/g/AKjpdO2fz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8r2j/t2165vTVhCUlPll4eiYslLa2CxOVXbBVqaYbSLITqYpqO/Kai4SLBWkKBVr0jq4 WfdQxKlZG7Z0WC5DUPKU6kEliyQMR1AtZvodx9sDTKmV9f6clihN9QxizQqwLoyj3eMNGgGM DE6fVkey9/YpS5enPh7HHRMq3R/KuzR0T6Y4vPCJ9AdtuZxHiV5ispV5X07z/1e6yQOF5kX0 GPC68VjpV2riLzF0j18TB9HsSpGnqqOtERmfLzar9xOACaeuh0K6mqUBlIBoN4vWbiN8+hAj 9PIkqz0MjJL9dnZqNAdC8bjI8WCKHM9MBDtFVY87SMARD+vcHjc3glTyaHIsHKSqZc+p97nn 59cEtezu3Q6E/obDgJuG9lQef+fuxsrlLeaiIgD4n/s9HHs
- Ironport-sdr: DLAtcc7TYjaAhNYfxAIL1SNB81z+Ha4pQ/RenlNb1DJ8J3RcNWBEf0GkqUJ2UCp/6LMuVG7yZD eeOMPxwEZGTi29pQLpzKrSx6xQcalGnvuY2gcR7qm3wFDnx8idwA6uwH48XnQkZo6TTtSvXENi zNzPwN2IKculSAJaXNAgusrWJBdqWRGsWmLo5t3nlZ5zhhwmbfqiisONTn4pkrfU8VYJzY5sU6 kUaYa2qBST5K2oJKhATmpYga4Njmy5GDsItJGCUqkwHoucpd3ArsBw7aQv36q6lpBQrbX+hSM8 3vvaKUl8zIeZlgDO3wP5PS2k
You are right but in coq there is a difference between what the user writes and what coq stores: pattern matching are always compiled into non ambiguous ones (what you call "all different constructor and free variables") because that it is the only form that the calculus of constructions supports. So if you look at terms (*), not user written pre-terms, pattern matching are *always* in this particular form. That said most of the time in proofs we prefer remembering the user written pattern matching.
P.
(*) preferably with "Set Printing All" because the default term printer tends to de-compile on the fly to make things readable.
Le mar. 16 août 2022 à 11:24, Vedran Čačić <veky AT math.hr> a écrit :
Well, it is possible that _I_ misunderstood the OP's question. If Form's are actually all the different constructors of a type of h, and all x are actually free variables, and *there is no last case (with Value_others, which you conveniently disregarded;)*, then yes, the equivalence holds. But as soon as any of these assumptions are not met, a counterexample exists.My remark was that you _can_ save the equivalence, by convertingy1 if P1y2 if P2...yl if Ply0 otherwisenot into (as OP suggested)(P1 /\ y1) \/ (P2 /\ y2) \/ ... \/ (Pl /\ yl) \/ y0but into (more complicated but models what Coq actually does better)(P1 /\ y1) \/ (~P1 /\ P2 /\ y2) \/ (~P1 /\ ~P2 /\ P3 /\ y3) \/ ... \/ (~P1 /\ ~P2 /\ ... /\ ~Pl /\ y0).I hope it is clearer now. Yes, if Pi are actually disjoint (different constructors are an important special case, of course), and there is no "else branch", these are the same, but in general, they are not.čet, 4. kol 2022. u 09:12 mukesh tiwari <mukeshtiwari.iiitm AT gmail.com> napisao je:Hi Vedran,
Sorry, I did not get "so each case should have conjoined the negations
of previous ones if you really want equivalence", so could you please
explain? The equivalence holds [1], unless I have misunderstood
Wendlasida's question.
Best,
Mukesh
[1] https://gist.github.com/mukeshtiwari/c2afb95b5f3db39b5cb75e5b4a44e363
Inductive Constructors : Type :=
| First (n : nat)
| Second (n m : nat)
| Third (n m p : nat).
(* The proof can definitely be shorten using Ltac *)
Lemma ex_rewrite :
forall (h : Constructors) opt,
opt = match h with
| First n => n
| Second n m => m
| Third n m p => p
end <->
(exists n, h = First n /\ opt = n) \/
(exists n m, h = Second n m /\ opt = m) \/
(exists n m p, h = Third n m p /\ opt = p).
Proof.
destruct h;
intros ?; split;
intro H.
+ left. eauto.
+ destruct H as [[w [Ha Hb]] | [[w [Ha [Hb Hc]]] |
[w H]]].
++ inversion Ha; subst;
auto.
++ congruence.
++ destruct H as (m & p & Hf & Hw).
congruence.
+ right; left.
eauto.
+ destruct H as [[w [Ha Hb]] | [[w [Ha [Hb Hc]]] |
[w H]]].
++ congruence.
++ inversion Hb; subst; reflexivity.
++ destruct H as (mt & p & Hf & Hw).
congruence.
+ right; right.
eauto.
+ destruct H as [[w [Ha Hb]] | [[w [Ha [Hb Hc]]] |
[w H]]].
++ congruence.
++ congruence.
++ destruct H as (mt & pt & Hf & Hw).
inversion Hf; subst.
reflexivity.
Qed.
On Wed, Aug 3, 2022 at 5:29 PM Vedran Čačić <veky AT math.hr> wrote:
>
> Of course, the lemma can't be <->: patterns are matched from top to bottom, so each case should have conjoined the negations of previous ones if you really want equivalence. However, the -> direction, which OP was interested in, holds.
>
> ~Veky
>
> On Sat, Jul 30, 2022, 15:37 mukesh tiwari <mukeshtiwari.iiitm AT gmail.com> wrote:
>>
>> Hi Wendlasida,
>>
>>
>> I am not sure that it’s the best way but one way to do is to define a lemma:
>>
>> Lemma ex_rewrite : forall opt h,
>> (opt = match h with
>> | Form_1 x => Value_1
>> | Form_2 x1 x2 => Value_2
>> ...
>> | Form_n x1... xn => Value_n
>> | _ => Value_others ) <->
>> (exists x, h = Form_1 x /\ opt = Value_1) \/ (exists x1 x2, h = Form_2 x1 x2 /\ opt = Value_1) ... (exists x1 ... xn, h = Form_n x1 xn /\ opt = Value_n) \/ (opt = Value_others).
>>
>> You prove it once and use it everywhere. (However, if h appears in somewhere in your proof, then ‘destruct h’ (or case h which you are already doing) would give you all the constructors and you can discharge them accordingly, so I am not sure if the above is going add any value).
>>
>> Best,
>> Mukesh
>>
>>
>>
>> On Sat, 30 Jul 2022 at 11:26, Wendlasida Ouedraogo <ouedraogo.tertius AT gmail.com> wrote:
>>>
>>> Dear All,
>>> I am currently working on programs that perform a lot of pattern matchings. I am looking for a tactic or an existing library that can help me to transform an hypothesis like:
>>>
>>>> opt = match h with
>>>> | Form_1 x => Value_1
>>>> | Form_2 x1 x2 => Value_2
>>>> ...
>>>> | Form_n x1... xn => Value_n
>>>> | _ => Value_others
>>>
>>>
>>> into
>>>
>>>> (exists x, h = Form_1 x /\ opt = Value_1) \/ (exists x1 x2, h = Form_2 x1 x2 /\ opt = Value_1) ... (exists x1 ... xn, h = Form_n x1 xn /\ opt = Value_n) \/ (opt = Value_others)
>>>
>>>
>>> Is there a tactic that can perform such transformation? I usually perform this transformation using the "assert" and "case" tactics that lead to long proofs or a high number of subgoals. Any ideas?
>>>
>>> --
>>> Cordialement,
>>> M. Wendlasida Tertius OUEDRAOGO
>>> Mobile : 0751061208
--Vedran Čačić
- Re: [Coq-Club] Simplifying pattern matching, Vedran Čačić, 07/31/2022
- Re: [Coq-Club] Simplifying pattern matching, mukesh tiwari, 08/04/2022
- Re: [Coq-Club] Simplifying pattern matching, Vedran Čačić, 08/04/2022
- Re: [Coq-Club] Simplifying pattern matching, Pierre Courtieu, 08/16/2022
- Re: [Coq-Club] Simplifying pattern matching, Vedran Čačić, 08/19/2022
- Re: [Coq-Club] Simplifying pattern matching, Pierre Courtieu, 08/19/2022
- Re: [Coq-Club] Simplifying pattern matching, Vedran Čačić, 08/19/2022
- Re: [Coq-Club] Simplifying pattern matching, Pierre Courtieu, 08/16/2022
- Re: [Coq-Club] Simplifying pattern matching, Pierre Courtieu, 08/05/2022
- Re: [Coq-Club] Simplifying pattern matching, mukesh tiwari, 08/05/2022
- Re: [Coq-Club] Simplifying pattern matching, Vedran Čačić, 08/04/2022
- <Possible follow-up(s)>
- Re: [Coq-Club] Simplifying pattern matching, Wendlasida Ouedraogo, 08/01/2022
- Re: [Coq-Club] Simplifying pattern matching, mukesh tiwari, 08/04/2022
Archive powered by MHonArc 2.6.19+.