Skip to content

Commit d3807d3

Browse files
authored
Merge pull request #19 from coq-community/fix-arith-deprec
fix Arith-related deprecations, notably for even-odd
2 parents 70e4104 + 25a17fc commit d3807d3

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

theories/Q_denumerable.v

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121

2222
(** We start by some general notions for expressing the bijection *)
2323

24-
Definition identity (A:Type) := fun a:A=> a.
25-
Definition compose (A B C:Type) (g:B->C) (f:A->B) := fun a:A=>g(f a).
24+
Definition identity (A:Type) := fun (a:A) => a.
25+
Definition compose (A B C:Type) (g:B->C) (f:A->B) := fun (a:A) => g(f a).
2626

2727
Section Denumerability.
2828

2929
(** What it means to have the same cardinality *)
3030
Definition same_cardinality (A:Type) (B:Type) :=
3131
{f:A->B & { g:B->A |
32-
(forall b,(compose _ _ _ f g) b= (identity B) b) /\
32+
(forall b,(compose _ _ _ f g) b = (identity B) b) /\
3333
forall a,(compose _ _ _ g f) a = (identity A) a}}.
3434

3535
(** What it means to be a denumerable *)
@@ -58,10 +58,8 @@ Defined.
5858

5959
End Denumerability.
6060

61-
6261
(** We first prove that [Z] is denumerable *)
6362

64-
From Coq Require Div2.
6563
From Coq Require Import ZArith.
6664
From Coq Require Import Lia.
6765

@@ -73,11 +71,12 @@ Definition Z_to_nat_i (z:Z) :nat :=
7371
| Zneg p => pred (Nat.double (nat_of_P p))
7472
end.
7573

76-
(** Some lemmas about parity. They could be added to [Arith.Div2] *)
77-
Lemma odd_pred2n: forall n : nat, Even.odd n -> {p : nat | n = pred (Nat.double p)}.
74+
(** Some lemmas about parity. *)
75+
Lemma odd_pred2n: forall n : nat, Nat.Odd_alt n -> {p : nat | n = pred (Nat.double p)}.
7876
Proof.
7977
intros n H_odd;
80-
rewrite (Div2.odd_double _ H_odd);
78+
apply Nat.Odd_alt_Odd in H_odd;
79+
rewrite (Nat.Odd_double _ H_odd);
8180
exists (S (Nat.div2 n));
8281
generalize (Nat.div2 n);
8382
clear n H_odd; intros n;
@@ -86,12 +85,19 @@ Proof.
8685
reflexivity.
8786
Defined.
8887

88+
Lemma even_2n : forall n : nat, Nat.Even_alt n -> {p : nat | n = Nat.double p}.
89+
Proof.
90+
intros n H_even; exists (Nat.div2 n).
91+
apply Nat.Even_alt_Even in H_even.
92+
apply Nat.Even_double; assumption.
93+
Defined.
94+
8995
Lemma even_odd_exists_dec : forall n, {p : nat | n = Nat.double p} + {p : nat | n = pred (Nat.double p)}.
9096
Proof.
9197
intro n;
92-
destruct (Even.even_odd_dec n) as [H_parity|H_parity];
93-
[ left; apply (Div2.even_2n _ H_parity)
94-
| right; apply (odd_pred2n _ H_parity)].
98+
destruct (Nat.Even_Odd_dec n) as [H_parity|H_parity];
99+
[ left; apply Nat.Even_alt_Even in H_parity; apply (even_2n _ H_parity)
100+
| right; apply Nat.Odd_alt_Odd in H_parity; apply (odd_pred2n _ H_parity)].
95101
Defined.
96102

97103
(** An injection from [nat] to [Z] *)
@@ -106,17 +112,20 @@ Proof.
106112
unfold Nat.double; intros m n; lia.
107113
Defined.
108114

109-
Lemma parity_mismatch_not_eq:forall m n, Even.even m -> Even.odd n -> ~m=n.
115+
Lemma parity_mismatch_not_eq:forall m n, Nat.Even_alt m -> Nat.Odd_alt n -> m <> n.
110116
Proof.
111-
intros m n H_even H_odd H_eq; subst m;
112-
apply (Even.not_even_and_odd n); trivial.
117+
intros m n H_even H_odd H_eq; subst m.
118+
apply Nat.Even_alt_Even in H_even.
119+
apply Nat.Odd_alt_Odd in H_odd.
120+
apply (Nat.Even_Odd_False n); trivial.
113121
Defined.
114122

115-
Lemma even_double:forall n, Even.even (Nat.double n).
123+
Lemma even_double : forall n, Nat.Even_alt (Nat.double n).
116124
Proof.
117125
intro n;
118126
unfold Nat.double;
119-
replace (n + n) with (2*n); auto with arith; lia.
127+
replace (n + n) with (2*n);
128+
[apply Nat.Even_alt_Even; exists n; reflexivity | lia].
120129
Defined.
121130

122131
Lemma double_S_neq_pred:forall m n, ~Nat.double (S m) = pred (Nat.double n).

0 commit comments

Comments
 (0)