forked from tabtab777/Coq
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoqUtil.v
More file actions
69 lines (59 loc) · 2.07 KB
/
CoqUtil.v
File metadata and controls
69 lines (59 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
Require Import Notations.
Require Import Coq.Lists.List.
Require Import Coq.Arith.Le.
Require Import Coq.Numbers.Natural.Peano.NPeano.
Require Import Coq.Arith.Compare_dec.
Require Import Coq.omega.Omega.
Require Import Bool.Sumbool.
Require Import Bool.Bool.
Require Import Coq.Logic.ConstructiveEpsilon.
Require Import Coq.ZArith.ZArith.
Import ListNotations.
Notation "'existsT' x .. y , p" :=
(sigT (fun x => .. (sigT (fun y => p)) ..))
(at level 200, x binder, right associativity,
format "'[' 'existsT' '/ ' x .. y , '/ ' p ']'") : type_scope.
(* Custom Induction on Natural *)
Definition nat_rect_custom (P : nat -> Type) (f1 : P 0%nat) (f2 : P 1%nat)
(f3 : forall n, P n -> P (S (S n))) : forall n, P n.
refine (fix F n :=
match n with
| O => f1
| S O => f2
| S (S m) => f3 m _
end).
auto.
Defined.
Check nat_rect_custom.
Theorem nat_lemma : forall n : nat, n = 0%nat \/ n = 1%nat \/ exists m : nat, n = S (S m).
Proof.
induction n using nat_rect_custom. auto. auto.
right. right. exists n. auto.
Qed.
Inductive custom_list {A : Type} : list A -> Type :=
| nil_list : custom_list []
| cons l1 x l2 : custom_list l1 -> custom_list l2 -> custom_list (l1 ++ [x] ++ l2).
Check custom_list_rect.
Definition list_rect_custom (A : Type) (P : list A -> Type) (f1 : P [])
(fn : forall x l1 l2, P l1 -> P l2 -> P (l1 ++ [x] ++ l2)) :
forall l, P l.
refine (fix F l :=
match l with
| [] => _
| (x :: l) => _
end). auto.
pose proof (fn x nil l f1). apply X. auto.
Defined.
Theorem list_lemma : forall (A : Type) (l : list A), l = [] \/ exists f x g, l = f ++ [x] ++ g.
Proof.
induction l using list_rect_custom.
auto. right.
exists l1, x, l2. auto.
Qed.
Definition induction_list_append_rev (A : Type) (P : list A -> Type)
(H1 : P []) (Hn : forall (x : A) (l : list A), P l -> P (l ++ [x])) : forall l : list A, P l.
refine (fix F l :=
match l with
| [] => H1
| h :: t => _
end).