Skip to content

Commit 47d1155

Browse files
author
Gregory Malecha
committed
Remove ListNth's and Show's dependence on omega.
1 parent e04ba49 commit 47d1155

File tree

3 files changed

+36
-28
lines changed

3 files changed

+36
-28
lines changed

theories/Data/ListNth.v

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
Require Import Coq.Lists.List.
2-
Require Import Coq.omega.Omega.
32

43
Set Implicit Arguments.
54
Set Strict Implicit.
@@ -11,16 +10,19 @@ Section parametric.
1110
n < length A ->
1211
nth_error (A ++ B) n = nth_error A n.
1312
Proof.
14-
induction A; destruct n; simpl; intros; try omega; auto.
15-
eapply IHA. omega.
13+
induction A; destruct n; simpl; intros; auto.
14+
{ inversion H. }
15+
{ inversion H. }
16+
{ eapply IHA. apply Lt.lt_S_n; assumption. }
1617
Qed.
1718

1819
Lemma nth_error_app_R : forall (A B : list T) n,
1920
length A <= n ->
2021
nth_error (A ++ B) n = nth_error B (n - length A).
2122
Proof.
22-
induction A; destruct n; simpl; intros; try omega; auto.
23-
apply IHA. omega.
23+
induction A; destruct n; simpl; intros; auto.
24+
+ inversion H.
25+
+ apply IHA. apply Le.le_S_n; assumption.
2426
Qed.
2527

2628
Lemma nth_error_weaken : forall ls' (ls : list T) n v,
@@ -41,32 +43,36 @@ Section parametric.
4143
nth_error ls n = None.
4244
Proof.
4345
clear. induction ls; destruct n; simpl; intros; auto.
44-
exfalso; omega. rewrite IHls; auto. omega.
46+
+ inversion H.
47+
+ apply IHls. apply Le.le_S_n; assumption.
4548
Qed.
4649

4750
Lemma nth_error_length : forall (ls ls' : list T) n,
4851
nth_error (ls ++ ls') (n + length ls) = nth_error ls' n.
4952
Proof.
5053
induction ls; simpl; intros.
5154
rewrite Plus.plus_0_r. auto.
52-
cutrewrite (n + S (length ls) = S n + length ls); [ | omega ]. simpl. auto.
55+
rewrite <- Plus.plus_Snm_nSm.
56+
simpl. eapply IHls.
5357
Qed.
5458

5559
Theorem nth_error_length_ge : forall T (ls : list T) n,
5660
nth_error ls n = None -> length ls <= n.
5761
Proof.
58-
induction ls; destruct n; simpl in *; auto; simpl in *; try omega.
59-
inversion 1. intro. apply IHls in H. omega.
62+
induction ls; destruct n; simpl in *; auto; simpl in *.
63+
+ intro. apply Le.le_0_n.
64+
+ inversion 1.
65+
+ intros. eapply Le.le_n_S. auto.
6066
Qed.
6167

6268
Lemma nth_error_length_lt : forall {T} (ls : list T) n val,
6369
nth_error ls n = Some val -> n < length ls.
6470
Proof.
6571
induction ls; destruct n; simpl; intros; auto.
66-
{ inversion H. }
67-
{ inversion H. }
68-
{ omega. }
69-
{ apply Lt.lt_n_S. eauto. }
72+
+ inversion H.
73+
+ inversion H.
74+
+ apply Lt.lt_0_Sn.
75+
+ apply Lt.lt_n_S. eauto.
7076
Qed.
7177

7278

theories/Data/Positive.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Require Import BinPos.
1+
Require Import Coq.PArith.BinPos.
22
Require Import ExtLib.Core.RelDec.
33

44
Set Implicit Arguments.
@@ -54,4 +54,4 @@ Proof.
5454
intuition; [ apply Pos.le_ge | apply Pos.ge_le ]; auto.
5555
Qed.
5656

57-
Export BinPos.
57+
Export Coq.PArith.BinPos.

theories/Programming/Show.v

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Require Import Coq.Strings.String.
22
Require Import Coq.Program.Wf.
3-
Require Import Omega.
4-
3+
Require Import Coq.PArith.BinPos.
4+
Require Import Coq.ZArith.ZArith.
55
Require Import ExtLib.Structures.Monoid.
66
Require Import ExtLib.Structures.Reducible.
77
Require Import ExtLib.Programming.Injection.
@@ -13,7 +13,7 @@ Require Import ExtLib.Core.RelDec.
1313
Set Implicit Arguments.
1414
Set Strict Implicit.
1515

16-
Definition showM : Type :=
16+
Definition showM : Type :=
1717
forall m, Injection ascii m -> Monoid m -> m.
1818

1919
Class ShowScheme (T : Type) : Type :=
@@ -28,7 +28,7 @@ Global Instance ShowScheme_string : ShowScheme string :=
2828

2929
Global Instance ShowScheme_string_compose : ShowScheme (string -> string) :=
3030
{ show_mon := Monoid_compose string
31-
; show_inj := String
31+
; show_inj := String
3232
}.
3333

3434
Definition runShow {T} {M : ShowScheme T} (m : showM) : T :=
@@ -39,7 +39,7 @@ Class Show T := show : T -> showM.
3939
Definition to_string {T} {M : Show T} (v : T) : string :=
4040
runShow (show v) ""%string.
4141

42-
Definition empty : showM :=
42+
Definition empty : showM :=
4343
fun _ _ m => monoid_unit m.
4444
Definition cat (a b : showM) : showM :=
4545
fun _ i m => monoid_plus m (a _ i m) (b _ i m).
@@ -63,7 +63,7 @@ End ShowNotation.
6363

6464
Definition indent (indent : showM) (v : showM) : showM :=
6565
let nl := Ascii.ascii_of_nat 10 in
66-
fun _ inj mon =>
66+
fun _ inj mon =>
6767
v _ (fun a => if eq_dec a nl
6868
then monoid_plus mon (inj a) (indent _ inj mon)
6969
else inj a) mon.
@@ -91,15 +91,17 @@ Program Fixpoint nat_show (n:nat) {measure n} : showM :=
9191
(@nat_show n' _) << (inject (Char.digit2ascii (n - 10 * n'))).
9292
Next Obligation.
9393
assert (NPeano.div n 10 < n) ; eauto.
94-
eapply NPeano.Nat.div_lt ; omega.
94+
eapply NPeano.Nat.div_lt.
95+
inversion H; apply Lt.lt_O_Sn.
96+
repeat constructor.
9597
Defined.
9698
Global Instance nat_Show : Show nat := { show := nat_show }.
9799

98-
Global Instance Show_pos : Show positive :=
100+
Global Instance Show_positive : Show positive :=
99101
fun x => nat_show (Pos.to_nat x).
100102

101103
Global Instance Show_Z : Show Z :=
102-
fun x =>
104+
fun x =>
103105
match x with
104106
| Z0 => "0"%char
105107
| Zpos p => show p
@@ -120,7 +122,7 @@ Section sepBy.
120122
Context {F : Foldable T showM}.
121123

122124
Definition sepBy (sep : showM) (ls : T) : showM :=
123-
match
125+
match
124126
fold (fun s acc =>
125127
match acc with
126128
| None => Some s
@@ -138,7 +140,7 @@ Section sepBy_f.
138140
Variable (f : E -> showM).
139141

140142
Definition sepBy_f (sep : showM) (ls : T) : showM :=
141-
match
143+
match
142144
fold (fun s acc =>
143145
match acc with
144146
| None => Some (f s)
@@ -148,7 +150,7 @@ Section sepBy_f.
148150
| None => empty
149151
| Some s => s
150152
end.
151-
End sepBy_f.
153+
End sepBy_f.
152154

153155
Definition wrap (before after : showM) (x : showM) : showM :=
154156
before << x << after.
@@ -192,5 +194,5 @@ Fixpoint iter_show (ss : list showM) : showM :=
192194
(*
193195
Examples:
194196
Eval compute in (runShow (show (42,"foo"%string)) : string).
195-
Eval compute in (runShow (show (inl true : bool+string))
197+
Eval compute in (runShow (show (inl true : bool+string))
196198
*)

0 commit comments

Comments
 (0)