Coq: Is it possible to prove that if two records are different, then one of their fields is different?

Say you have an entry:

Record Example := {
  fieldA : nat;
  fieldB : nat
}.

Can we prove:

Lemma record_difference : forall (e1 e2 : Example),
  e1 <> e2 ->
    (fieldA e1 <> fieldA e2)
    \/
    (fieldB e1 <> fieldB e2).

If so, how?

On the one hand, this looks plausible, since it is Recordabsolutely determined by their fields. On the other hand, not knowing what made it e1different from e2first of all, how should we decide which side of the disjunction to prove?


As a comparison, we note that if there is only one field in the record, we can prove the corresponding lemma:

Record SmallExample := {
   field : nat
}.

Lemma record_dif_small : forall (e1 e2 : SmallExample),
  e1 <> e2 -> field e1 <> field e2.
Proof.
  unfold not; intros; apply H.
  destruct e1; destruct e2; simpl in H0.
  f_equal; auto.
Qed.
+4
source share
1 answer

On the other hand, not knowing what made it e1different from e2first of all, how should we decide which side of the disjunction to prove?

: , . , , fieldA e1 = fieldA e2.

Require Import Coq.Arith.PeanoNat.

Record Example := {
  fieldA : nat;
  fieldB : nat
}.

Lemma record_difference : forall (e1 e2 : Example),
  e1 <> e2 ->
    (fieldA e1 <> fieldA e2)
    \/
    (fieldB e1 <> fieldB e2).
Proof.
intros [n1 m1] [n2 m2] He1e2; simpl.
destruct (Nat.eq_dec n1 n2) as [en|nen]; try now left.
right. intros em. congruence.
Qed.

Nat.eq_dec - , , :

Nat.eq_dec : forall n m, {n = m} + {n <> m}.

{P} + {~ P} , P ~ P , , .

, , . , , intros em .

n1, m1, n2, m2 : nat
He1e2 : {| fieldA := n1; fieldB := m1 |} <> {| fieldA := n2; fieldB := m2 |}
en : n1 = n2
em : m1 = m2
============================
False

en em , , He1e2. congruence Coq .

, . :

forall (A B : Type) (p1 p2 : A * B),
  p1 = p2 <-> fst p1 = fst p2 /\ snd p1 = snd p2.

forall (A B : Type) (p1 p2 : A * B),
  p1 <> p2 <-> ~ (fst p1 = fst p2 /\ snd p1 = snd p2).

. ~ P \/ ~ Q; , Coq.

+4

Source: https://habr.com/ru/post/1687255/


All Articles