nat pair and its notation. Be care for to the format to match
1 2 3 4
Inductive natprod : Type := | pair (n1 n2 : nat).
Notation"( x , y )" := (pair x y).
Note that pattern-matching on a pair (with parentheses: [(x, y)]) is not to be confused with the "multiple pattern" syntax (with no parentheses: [x, y]) that we have seen previously.
Consider whether match the param can be sustituted into the definition.
The easiest situation as app's def is:
1 2 3 4 5 6 7
app = fix app (l1 l2 : natlist) {struct l1} : natlist := match l1 with | [ ] => l2 | h :: t => h :: app t l2 end : natlist -> natlist -> natlist
1 2 3
Theorem nil_app : forall l : natlist, [] ++ l = l. Proof. reflexivity. Qed.
Sometimes helpful to perform case analysis.
1 2 3 4 5 6 7 8
Theorem tl_length_pred : forall l:natlist, pred (length l) = length (tl l). Proof. intros l. destruct l as [| n l']. - (* l = nil *) reflexivity. - (* l = cons n l' *) reflexivity. Qed.
Induction on Lists
Just like Induction on nat is usually from O, Lists usually from nil.
Search
What if you forget the theorem name but only knows its basic form.
(** Or say you've forgotten the name of the theorem showing that plus is commutative. You can use a pattern to search for all theorems involving the equality of two additions. *)
Search (_ + _ = _ + _).
(** You'll see a lot of results there, nearly all of them from the standard library. To restrict the results, you can search inside a particular module: *)
Search (_ + _ = _ + _) inside Induction.
More useful param with search pattern.
1
Search (?x + ?y = ?y + ?x).
List Exercises
Refer to my github repo.
Like plus_n_Sm , lemma leb_n_Sn might be helpful in the next exercise.
Leave the bag_count_sum (3 stars) and rev_injective (4 stars).
About if else, we could use [destruct] tactics to analysis different cases like this.
1 2 3 4 5 6 7 8 9 10 11 12 13
Theorem bag_count_sum : forall(b1 b2: bag) (n : nat), count n (sum b1 b2) = (count n b1) + (count n b2). Proof. intros. induction b1. - simpl. reflexivity. - simpl. rewrite -> IHb1. (* use case_eqn or destruct *) destruct (n0 =? n) as []eqn:?. (* case_eq (n0 =? n). *) + simpl. reflexivity. + reflexivity. Qed.