propositional_logic

Propositional Logic

Formal language

How to read props

Deduction rules

The meaning of a logical symbol is given by

Computational content

True (comp: trivial computation, logic: true)

False (comp: impossible computation, logic: false)

(comp: pair, logic: and)

(comp: variant, logic: or)

(comp: function, logic: implication)

Examples

Section PropositionalLogic.
Variables P Q R : Prop.

Theorem curry_uncurry : ((PQ) → R) ↔ (P → (QR)).
Proof.
  split.
  - intros f p q.
    apply f.
    split.
    + exact p.
    + exact q.
  - intros f [p q].
    apply f.
    + exact p.
    + exact q.
Qed.

Theorem and_uni : (PQR) ↔ (PQ) ∧ (PR).
Proof.
  split.
  - intros f.
    split.
    + intros p.
      apply f in p.
      destruct p as [q _].
      exact q.
    + intros p.
      apply f in p.
      destruct p as [_ r].
      exact r.
  - intros [f g] p.
    split.
    + apply f.
      exact p.
    + apply g.
      exact p.
Qed.

Theorem modus_tollens : (PQ) → ¬ Q → ¬ P.
Proof.
  intros f nq p.
  apply nq.
  apply f.
  exact p.
Qed.

Theorem resolution : (PQ) → (~ PR) → QR.
Proof.
  intros [p | q] [np | r].
  - contradiction.
  - right.
    exact r.
  - left.
    exact q.
  - left. (* right also works *)
    exact q. (* resp., exact r also works *)
Qed.
End PropositionalLogic.

Tells Coq to print implicit parentheses. Useful for learning precedence.
Set Printing Parentheses.
Section AndExamples.
Variables P Q R : Prop.

Theorem proj1 : PQP.
Proof.
  intros [p q].
  exact p.
Qed.

(*  is /\ *)
Theorem proj2 : PQQ.
Proof.
  intros [p q].
  exact q.
Qed.

Theorem and_comm :
  PQQP.
Proof.
  intros [p q].
  split.
  - exact q.
  - exact p.
Qed.

Theorem and_assoc :
  P ∧ (QR) → (PQ) ∧ R.
Proof.
  intros [p [q r]].
  split.
  - split.
    + exact p.
    + exact q.
  - exact r.
Qed.

Theorem and_addition :
  PPP.
Proof.
  intros p.
  split.
  - exact p.
  - exact p.
Qed.

End AndExamples.

Section OrExamples.
Variables P Q R : Prop.

Theorem or_comm :
  PQQP.
Proof.
  intros [p | q].
  - right.
    exact p.
  - left.
    exact q.
Qed.

Theorem or_assoc :
  P ∨ (QR) → (PQ) ∨ R.
Proof.
  intros [p | [q | r]].
  - left.
    left.
    exact p.
  - left.
    right.
    exact q.
  - right.
    exact r.
Qed.

Theorem noncontradiction :
  P → ¬ ¬ P.
Proof.
  intros p.
  intros np.
  contradiction.
Qed.

Theorem demorgan :
  ¬ (PQ) ↔ ¬ P ∧ ¬ Q.
Proof.
  split.
  - intros f.
    split.
    + intros p.
      apply f.
      left.
      exact p.
    + intros q.
      apply f.
      right.
      exact q.
  - intros [np nq] [p | q].
    + contradiction.
    + contradiction.
Qed.
End OrExamples.

Section IffExamples.
Variables P Q : Prop.

Theorem iff_refl :
  PP.
Proof.
  apply and_addition.
  intros p.
  exact p.
Qed.

Theorem iff_sym :
  (PQ) → (QP).
Proof.
  apply and_comm.
Qed.

End IffExamples.