Sorry I am new to coq. I'm wondering how to prove list concatenation is not commutative using coq?
Asked
Active
Viewed 165 times
-2
-
Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Sep 15 '21 at 06:58
2 Answers
0
You just need to exhibit a counterexample. For instance:
Require Import Coq.Lists.List.
Import ListNotations.
Theorem list_app_is_not_commutative :
~ (forall A (l1 l2 : list A), l1 ++ l2 = l2 ++ l1).
Proof.
intros H.
specialize (H bool [true] [false]).
simpl in H.
congruence.
Qed.

Arthur Azevedo De Amorim
- 23,012
- 3
- 33
- 39
-
or simply (see [here](https://coq.inria.fr/refman/proof-engine/tactics.html?highlight=discriminate#coq:tacn.discriminate)) `intros H; discriminate (H bool [true] [false]).` – Lolo Sep 08 '21 at 14:20
-
Thanks. I tried to use exist tactic following your logic but get stuck: Theorem list_app_is_not_commutative : ~ (exists A (l1 l2 : list A), l1 ++ l2 = l2 ++ l1). Proof. exists bool [true] [false]. The error message says "Not an inductive goal with 1 constructor." Why can't I use exist tactic here? – Serene M Sep 08 '21 at 14:30
-
`exists` should be on top of the negation. your goal should be `exists A (l1 l2 : list A), l1 ++ l2 <> l2 ++ l1` – Lolo Sep 08 '21 at 14:44
-
the `exists` tactic is fine but the `exists ` must be the top constructor of you goal otherwise it will fail with the error message you got. – Lolo Sep 08 '21 at 15:17
-
1If written in the following form `exists l1 l2, l1++ l2 <> l2 ++ l1`, then you unknowingly wrote two nested existential quantifications, the right way to provide witnesses is `exists [true]; exists [false].` treating each existential quantification separately. There is also a shorter way of writing it `exists [true], [false].` – Yves Sep 10 '21 at 06:32
0
Like this ?
From Coq Require Import List.
Import ListNotations.
Goal [true] ++ [false] <> [false] ++ [true].
Proof. easy. Qed.

kyo dralliam
- 1,197
- 5
- 6