proofcoqtransitivity

Using coq, trying to prove a simple lemma on trees


Trying to prove correctness of a insertion function of elements into a bst I got stuck trying to prove a seemingly trivial lemma. My attempt so far:

Inductive tree : Set :=
| leaf : tree
| node : tree -> nat -> tree -> tree.    

Fixpoint In (n : nat) (T : tree) {struct T} : Prop :=
  match T with
  | leaf => False
  | node l v r => In n l \/ v = n \/ In n r
  end.

(* all_lte is the proposition that all nodes in tree t 
   have value at most n *)  
Definition all_lte (n : nat) (t : tree) : Prop :=
  forall x, In x t -> (x <= n).

Lemma all_lte_trans: forall n m t, n <= m /\ all_lte n t -> all_lte m t.
Proof.
intros.
destruct H.
unfold all_lte in H0.
unfold all_lte.
intros.

Clearly if everything in the tree is smaller than n and n <= m everything is smaller than m, but I cannot seem to make coq believe me. How do I continue?


Solution

  • You have to use the le_trans theorem :

    le_trans: forall n m p : nat, n <= m -> m <= p -> n <= p
    

    that comes from Le package. It meas that you have to import Le or more generally Arith with :

    Require Import Arith.
    

    at the beginning of your file. Then, you can do :

    eapply le_trans.
    eapply H0; trivial.
    trivial.