Skip to content

Commit 29a6295

Browse files
committed
Continuing #18564: more standard naming of lemmas of the form "length (foo l)".
1 parent 2243a9d commit 29a6295

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

theories/Lists/List.v

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -842,21 +842,21 @@ Section Elts.
842842
Lemma remove_remove_eq : forall l x, remove x (remove x l) = remove x l.
843843
Proof. intros l x; now rewrite (notin_remove _ _ (remove_In l x)). Qed.
844844

845-
Lemma remove_length_le : forall l x, length (remove x l) <= length l.
845+
Lemma length_remove_le : forall l x, length (remove x l) <= length l.
846846
Proof.
847847
intro l; induction l as [|y l IHl]; simpl; intros x; trivial.
848848
destruct (eq_dec x y); simpl.
849849
- rewrite IHl; constructor; reflexivity.
850850
- apply (proj1 (Nat.succ_le_mono _ _) (IHl x)).
851851
Qed.
852852

853-
Lemma remove_length_lt : forall l x, In x l -> length (remove x l) < length l.
853+
Lemma length_remove_lt : forall l x, In x l -> length (remove x l) < length l.
854854
Proof.
855855
intro l; induction l as [|y l IHl]; simpl; intros x Hin.
856856
- contradiction Hin.
857857
- destruct Hin as [-> | Hin].
858858
+ destruct (eq_dec x x); [|easy].
859-
apply Nat.lt_succ_r, remove_length_le.
859+
apply Nat.lt_succ_r, length_remove_le.
860860
+ specialize (IHl _ Hin); destruct (eq_dec x y); simpl; auto.
861861
now apply Nat.succ_lt_mono in IHl.
862862
Qed.
@@ -1730,20 +1730,20 @@ End Fold_Right_Recursor.
17301730
- cbn. rewrite IH. destruct (f x); reflexivity.
17311731
Qed.
17321732

1733-
Corollary filter_length f (l : list A) : length (filter f l) + length (filter (fun x => negb (f x)) l) = length l.
1733+
Corollary length_filter f (l : list A) : length (filter f l) + length (filter (fun x => negb (f x)) l) = length l.
17341734
Proof. symmetry. apply (partition_length f), partition_as_filter. Qed.
17351735

1736-
Corollary filter_length_le f (l : list A): length (filter f l) <= length l.
1737-
Proof. rewrite <- (filter_length f l). apply Nat.le_add_r. Qed.
1736+
Corollary length_filter_le f (l : list A): length (filter f l) <= length l.
1737+
Proof. rewrite <- (length_filter f l). apply Nat.le_add_r. Qed.
17381738

1739-
Lemma filter_length_forallb f (l : list A): length (filter f l) = length l -> forallb f l = true.
1739+
Lemma length_filter_forallb f (l : list A): length (filter f l) = length l -> forallb f l = true.
17401740
Proof.
17411741
intro H. induction l as [|x l IH]; [reflexivity |].
17421742
cbn in *. destruct (f x).
17431743
- apply IH. now injection H.
17441744
- exfalso. assert (length l < length (filter f l)) as E.
17451745
+ symmetry in H. apply Nat.eq_le_incl in H. exact H.
1746-
+ eapply Nat.le_ngt; [apply filter_length_le | exact E].
1746+
+ eapply Nat.le_ngt; [apply length_filter_le | exact E].
17471747
Qed.
17481748

17491749
(** Remove by filtering *)
@@ -2185,14 +2185,14 @@ Section Cutting.
21852185
Lemma firstn_O l: firstn 0 l = [].
21862186
Proof. now simpl. Qed.
21872187

2188-
Lemma firstn_le_length n: forall l:list A, length (firstn n l) <= n.
2188+
Lemma length_firstn_le n: forall l:list A, length (firstn n l) <= n.
21892189
Proof.
21902190
induction n as [|k iHk]; simpl; [auto | intro l; destruct l as [|x xs]; simpl].
21912191
- now apply Nat.le_0_l.
21922192
- now rewrite <- Nat.succ_le_mono.
21932193
Qed.
21942194

2195-
Lemma firstn_length_le: forall l:list A, forall n:nat,
2195+
Lemma length_firstn_eq: forall l:list A, forall n:nat,
21962196
n <= length l -> length (firstn n l) = n.
21972197
Proof. intro l; induction l as [|x xs Hrec].
21982198
- simpl. intros n H. apply Nat.le_0_r in H. now subst.
@@ -3670,7 +3670,7 @@ Section Repeat.
36703670
| S k => x::(repeat x k)
36713671
end.
36723672

3673-
Theorem repeat_length x n:
3673+
Theorem length_repeat x n:
36743674
length (repeat x n) = n.
36753675
Proof.
36763676
induction n as [| k Hrec]; simpl; rewrite ?Hrec; reflexivity.
@@ -3701,7 +3701,7 @@ Section Repeat.
37013701
repeat x n = l1 ++ l2 -> repeat x (length l1) = l1 /\ repeat x (length l2) = l2.
37023702
Proof.
37033703
revert n; induction l1 as [|a l1 IHl1]; simpl; intros n Hr; subst.
3704-
- repeat split; now rewrite repeat_length.
3704+
- repeat split; now rewrite length_repeat.
37053705
- destruct n; inversion Hr as [ [Heq Hr0] ]; subst.
37063706
now apply IHl1 in Hr0 as [-> ->].
37073707
Qed.
@@ -3799,7 +3799,7 @@ Section Repeat.
37993799
Proof.
38003800
intro Hnm. rewrite (nth_error_nth' _ a).
38013801
- now rewrite nth_repeat.
3802-
- now rewrite repeat_length.
3802+
- now rewrite length_repeat.
38033803
Qed.
38043804

38053805
End Repeat.
@@ -3854,7 +3854,7 @@ Proof.
38543854
rewrite flat_map_concat_map, length_concat, map_map. reflexivity.
38553855
Qed.
38563856

3857-
Corollary flat_map_constant_length A B c (f: A -> list B) l:
3857+
Corollary length_flat_map_constant A B c (f: A -> list B) l:
38583858
(forall x, In x l -> length (f x) = c) -> length (flat_map f l) = (length l) * c.
38593859
Proof.
38603860
intro H. rewrite length_flat_map.
@@ -3867,7 +3867,7 @@ Lemma length_list_power (A B:Type)(l:list A) (l':list B):
38673867
length (list_power l l') = (length l')^(length l).
38683868
Proof.
38693869
induction l as [ | a m IH ]; [reflexivity|].
3870-
cbn. rewrite flat_map_constant_length with (c := length l').
3870+
cbn. rewrite length_flat_map_constant with (c := length l').
38713871
- rewrite IH. apply Nat.mul_comm.
38723872
- intros x H. apply length_map.
38733873
Qed.
@@ -4013,6 +4013,15 @@ Notation concat_length := length_concat (only parsing).
40134013
Notation flat_map_length := length_flat_map (only parsing).
40144014
#[deprecated(since = "8.20", note = "Use length_list_power instead.")]
40154015
Notation list_power_length := length_list_power (only parsing).
4016+
Notation remove_length_le := length_remove_le (only parsing).
4017+
Notation remove_length_lt := length_remove_lt (only parsing).
4018+
Notation filter_length := length_filter (only parsing).
4019+
Notation filter_length_le := length_filter_le (only parsing).
4020+
Notation filter_length_forallb := length_filter_forallb (only parsing).
4021+
Notation firstn_le_length := length_firstn_le (only parsing).
4022+
Notation firstn_length_le := length_firstn_eq (only parsing).
4023+
Notation repeat_length := length_repeat (only parsing).
4024+
Notation flat_map_constant_length := length_flat_map_constant (only parsing).
40164025
(* end hide *)
40174026

40184027

theories/Strings/PString.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Lemma sub_length_spec (s : string) (off len : int) :
124124
Proof.
125125
intros Hoff Hlen.
126126
pose proof (length_spec (sub s off len)) as Hs.
127-
rewrite sub_spec, List.firstn_length_le in Hs; [lia|].
127+
rewrite sub_spec, List.length_firstn_eq in Hs; [lia|].
128128
rewrite List.length_skipn, <-length_spec. lia.
129129
Qed.
130130

0 commit comments

Comments
 (0)