4

I am learning propositional logic and the rules of inference. The Disjunctive Syllogism rule states that if we have in our premises (P or Q), and also (not P); then we can reach Q.

I can not for the life of me figure out how to do this in Coq. Let's say I have :

H : A \/ B
H0 : ~ A
______________________________________(1/1)

What tactic should I use to reach

H1 : B.

As an extra, I would be glad if someone could share with me the Coq tactic equivalents of basic inference rules, like modus tollens, or disjunctive introduction etc. Is there maybe a plugin I can use?

Arthur Azevedo De Amorim
  • 23,012
  • 3
  • 33
  • 39
mlg556
  • 419
  • 3
  • 13

2 Answers2

3

Coq does not have this tactic built-in, but fortunately you can define your own tactics. Notice that

destruct H as [H1 | H1]; [contradiction |].

puts H1 : B in the context, just as you asked. So you can create an alias for this combined tactic:

Ltac disj_syllogism AorB notA B :=
  destruct AorB as [? | B]; [contradiction |].

Now we can easily imitate the disjunctive syllogism rule like so:

Section Foo.
Context (A B : Prop) (H : A \/ B) (H0 : ~ A).
Goal True.
  disj_syllogism H H0 H1.
End Foo.

Let me show a couple less automated approaches:

Ltac disj_syllogism AorB notA B :=
  let A := fresh "A" in
  destruct AorB as [A | B]; [contradiction (notA A) |].

This approach does not ask Coq to find a contradiction, it provides it directly to the contradiction tactic (notA A term). Or we could have used an explicit term with the pose proof tactic:

Ltac disj_syllogism AorB notA B :=
  pose proof (match AorB with
              | or_introl a => False_ind _ (notA a)
              | or_intror b => b
              end) as B.

I hope this helps. I'm not sure if some extra explanation is needed -- feel free to ask for clarification and I'll update my answer.

Anton Trunov
  • 15,074
  • 2
  • 23
  • 43
  • Thank you very much. I had a feeling that it was doable with combining existent tactics, but I'm a begninner in Ltac. – mlg556 Oct 21 '18 at 16:02
  • Perhaps you could recommend some resources about Ltac ? I find the documentation quite scarce. For example I am also trying to make a tactic which takes two hypotheses H : P , H0 : Q in the context and produces H3 : P /\Q. – mlg556 Oct 21 '18 at 16:29
  • 1
    Both Software Foundations book and CPDT book by A. Chlipala have some material on tactics (especially CPDT). You could model that with e.g. `Ltac conj_intro_context A B AandB := pose proof (conj A B) as AandB.`. Here is how you use it: `conj_intro_context H H0 H3.` – Anton Trunov Oct 21 '18 at 16:34
  • 1
    Also I did not understand why I have to put B as an input to these tactics. Shouldn't they get AorB,notA ; and produce B ? – mlg556 Oct 21 '18 at 17:00
  • It is given only to have *explicit* naming. You are right, it's possible to delegate naming to Coq and omit `B` altogether. However, explicit naming is important because it makes proofs less brittle -- it's easier to change proofs in case of changes to the definitions, etc. For instance you can redefine disjunctive syllogism as `Ltac disj_syllogism AorB notA := destruct AorB; [contradiction |].`, letting Coq pick the name of the output hypothesis for you. – Anton Trunov Oct 21 '18 at 17:17
  • You could even skip `notA`, as `contradiction` would find it on its own. – Anton Trunov Oct 21 '18 at 17:18
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/182229/discussion-between-mlg556-and-anton-trunov). – mlg556 Oct 21 '18 at 18:48
0

I think you maybe have the wrong expectations on how Coq works? The general way of proving this is essentially a truth-table on the different possibilities:

Lemma it: forall a b, (a \/ b) /\ ~a -> b.
Proof.
  intuition.
  Show Proof.
Qed.

(fun (a b : Prop) (H : (a \/ b) /\ ~ a) =>
 and_ind
   (fun (H0 : a \/ b) (H1 : ~ a) =>
    or_ind (fun H2 : a => let H3 : False := H1 H2 in False_ind b H3)
      (fun H2 : b => H2) H0) H)

If you look at the resulting proof-term, you see the Coq is essentially taking apart the boolean the constructors. We can do this manually and get the same proof-term:

Lemma it: forall a b, (a \/ b) /\ ~a -> b.
Proof.
  intros a b H.
  induction H.
  induction H.
  contradict H. exact H0.
  exact H.
Qed.

Whereas e.g. modus ponens corresponds to an apply in Coq, I don't think this is "built in" in any direct way.

Afterwards, you can use this lemma (and I'm sure there's a corresponding version somewhere in the standard library) to derive your additional hypothesis through apply.

Volker Stolz
  • 7,274
  • 1
  • 32
  • 50
  • 1
    I think I was not clear enough, I am not looking for a proof for Disjunctive Syllogism, rather I am looking for a tactic that, when applied to (P or Q) and (not P), will give me Q as a premise. – mlg556 Oct 20 '18 at 23:50
  • I've revised my answer a bit. I do not think this tactics exists in the sense of a builtin tactics. – Volker Stolz Oct 21 '18 at 07:43