【University of Science and Technology of China-Formalization】Part B: Predicate Logic

In this section, we will learn how to use Coq to prove predicate logic theorems. In Coq, we can declare set variables like propositional variables: 

Variables AB: Set.

Before we declare that A and B are set variables. Next, we declare some predicate variables P and Q on set A:

Variables P Q: A -> Prop.

You can think of P and Q as functions that get elements from A and return a Prop. If we have a set of elements, such as a: A, we can use P(a) to represent
that the proposition P is satisfied. Using the same method, we can declare attributes related to several elements. For example, we can introduce the relationship R in the following way to connect A and B:

Variable R : A -> B -> Prop.

Here R ab expresses the relationship between a and b. You can think of R as a function with two parameters.

 

Universal Quantification (Universal Quantification)

In Coq, the keyword forall is used to represent universal quantification. We can write forall x: A, P x to indicate that all elements of A satisfy the proposition P, forall x: A, P x -> Q x means that any element of A satisfies the proposition P and satisfies the proposition Q.

Variables A: Set.
Variables P Q: A -> Prop.
Theorem example4 :
        (forall x: A, P x -> Q x) -> (forall x: A, P x) -> forall x: A, Q x.
    Proof.
        intros H1 H2 a.
        apply H1.
        apply H2.
    Qed.

We can regard this example as a syllogism, with the major premise that "all A satisfies the property P also satisfies Q", the minor premise is "all A satisfies the property P", and the conclusion is "all A satisfies Q".

We use a few steps to prove this. In the first step, we use strategy introduction. After this step, we get a premise "a: A" and two hypotheses H1 and H2. The introduction of a strategy introduces a hypothesis a: A. In this hypothesis, every occurrence of x in all targets is replaced with a, so our target becomes Q.

We have hypothesis H1: for all x: A, P x -> Q x, we want to prove Q a, we can use the application H1 to instantiate the hypothesis H1 to P a -> Q a, which will eliminate the implication, we just need Prove P a.

We do the elimination in the last step. If we know H: forall x: A, P, and we want to prove P, where x is replaced by A, we use H2 to prove P. 

Exercise 3: Try to prove the following predicate logic proposition:

       ∀x.(~P(x) /\ Q(x)) -> ∀x.(P(x) -> Q(x))  

Exercise 4: Try to prove the following predicate logic proposition:

       ∀x.(P(x) -> Q(x)) -> ∀x.~Q(x) -> ∀x.~P(x)    

Exercise 5: Try to prove the following predicate logic proposition:

       ∀x.(P(x) /\ Q(x)) <-> (∀x.P(x) /\ ∀x.Q(x))

Existential Quantification

In Coq, the keyword exists is used to indicate existence quantification. We can write exists x: A, P x  to indicate that an element x of A satisfies the proposition P.

Theorem example5 :
        (exists x: A, P x) -> (forall x: A, P x -> Q x) -> exists x: A, Q x.
    Proof.
        intros H1 H2.
        destruct H1 as [a p].
        exists a.
        apply H2.
        apply p.
    Qed.

After introducing the two hypotheses H1 and H2 into the context, we need to deal with the symbols that exist in the hypotheses and goals. The strategy of existence quantification is similar to the strategy of connection quantification. The expression proving existence exists x: Q x, we can assume that the value of x satisfies the existence and replaces all x in Q. In this theorem, we assume that H1: exists x: A, P x, which can be disassembled into two hypotheses: a: A and P: a.

 

Strategy existence replaces all "x" in the target with "a", which is the elimination of existence. 

The last application operation is the same as example 4.  

 

 

Exercise 6: Try to prove the following predicate logic proposition:

       ∃x.(~P(x) \/ Q(x)) -> ∃x.(~(P(x) /\ ~Q(x)))   

Exercise 7: Try to prove the following predicate logic proposition:

       ∃x.(~P(x) /\ ~Q(x)) -> ∃x.~(P(x) /\ Q(x))    

Exercise 8: Try to prove the following predicate logic proposition:

       ∃x.(P(x) \/ Q(x)) <-> (∃x.P(x) \/ ∃x.Q(x))

 #中科大软院-hbj formalized course notes-Welcome to leave a message and exchange private messages

 

 

 

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/weixin_41950078/article/details/109655738