Skip to content

Commit 0b3deee

Browse files
proux01yosakaon
authored andcommitted
Add a parser/printer for extended-real integer constants (math-comp#1704)
1 parent bd1f384 commit 0b3deee

4 files changed

Lines changed: 74 additions & 8 deletions

File tree

CHANGELOG_UNRELEASED.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@
2525
- in `uniform_structure.v`:
2626
+ lemma `continuous_injective_withinNx`
2727

28+
- in `constructive_ereal.v`:
29+
+ variants `Ione`, `Idummy_placeholder`
30+
+ inductives `Inatmul`, `IEFin`
31+
+ definition `parse`, `print`
32+
+ number notations in scopes `ereal_dual_scope` and `ereal_scope`
33+
+ notation `- 1` in scopes `ereal_dual_scope` and `ereal_scope`
34+
2835
### Changed
2936

3037
- in `lebesgue_stieltjes_measure.v` specialized from `numFieldType` to `realFieldType`:

reals/constructive_ereal.v

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ From mathcomp Require Import mathcomp_extra interval_inference.
3131
(* | `\bar R` |==| coproduct of `R` and $\{+\infty, -\infty\}$| *)
3232
(* | | | notation for `extended (R:Type)` | *)
3333
(* | `r%:E` |==| injects real numbers into `\bar R` | *)
34+
(* | - x |==| opposite of x : \bar R | *)
35+
(* | 0, 1, -1 |==| 0%R, 1%R%:E, - 1%R%:E | *)
36+
(* | <number> |==| <number>%:R%:E with <number> a sequence | *)
37+
(* | | | of digits | *)
38+
(* | -<number> |==| - <number>%:R%:E with <number> a sequence | *)
39+
(* | | | of digits | *)
3440
(* | `+%E, -%E, *%E` |==| addition/opposite/multiplication for | *)
3541
(* | | | extended reals | *)
3642
(* | `x^-1`, `x / y` |==| inverse and division for extended reals | *)
@@ -59,6 +65,12 @@ From mathcomp Require Import mathcomp_extra interval_inference.
5965
(* \bar R == coproduct of R and {+oo, -oo}; *)
6066
(* notation for extended (R:Type) *)
6167
(* r%:E == injects real numbers into \bar R *)
68+
(* - x == opposite of x : \bar R *)
69+
(* 0, 1, -1 == 0%R, 1%R%:E, - 1%R%:E *)
70+
(* <number> == <number>%:R%:E with <number> a sequence *)
71+
(* of digits *)
72+
(* -<number> == - <number>%:R%:E with <number> a sequence *)
73+
(* of digits *)
6274
(* +%E, -%E, *%E == addition/opposite/multiplication for extended *)
6375
(* reals *)
6476
(* x^-1, x / y == inverse and division for extended reals *)
@@ -582,6 +594,53 @@ Notation "x ^+ n" := (expe x%E n) : ereal_scope.
582594
Notation "x *+ n" := (ednatmul x%dE n) : ereal_dual_scope.
583595
Notation "x *+ n" := (enatmul x%E n) : ereal_scope.
584596

597+
(**md Notation for constant numerals. This has been introduced so
598+
that, e.g., in the scope `ereal_scope`, `-<n>` is correctly parsed
599+
without requiring one writes `- <n>%:E`. See the Rocq reference manual
600+
for the `Number Notation` command
601+
and [PR #1704](https://github.com/math-comp/analysis/pull/1704)
602+
for more explanations. *)
603+
Variant Ione := IOne : Ione.
604+
Inductive Inatmul := INatmul : Ione -> nat -> Inatmul.
605+
Inductive IEFin := IEFinP : Inatmul -> IEFin | IEFinN : IEFin -> IEFin.
606+
Variant Idummy_placeholder :=.
607+
608+
Definition parse (x : Number.int) : IEFin :=
609+
match x with
610+
| Number.IntDecimal (Decimal.Pos u) => IEFinP (INatmul IOne (Nat.of_uint u))
611+
| Number.IntDecimal (Decimal.Neg u) =>
612+
IEFinN (IEFinP (INatmul IOne (Nat.of_uint u)))
613+
| Number.IntHexadecimal (Hexadecimal.Pos u) =>
614+
IEFinP (INatmul IOne (Nat.of_hex_uint u))
615+
| Number.IntHexadecimal (Hexadecimal.Neg u) =>
616+
IEFinN (IEFinP (INatmul IOne (Nat.of_hex_uint u)))
617+
end.
618+
619+
Definition print (x : IEFin) : option Number.int :=
620+
match x with
621+
| IEFinP (INatmul IOne n) =>
622+
Some (Number.IntDecimal (Decimal.Pos (Nat.to_uint n)))
623+
| IEFinN (IEFinP (INatmul IOne n)) =>
624+
Some (Number.IntDecimal (Decimal.Neg (Nat.to_uint n)))
625+
| _ => None
626+
end.
627+
628+
Arguments GRing.one {_}.
629+
#[warnings="-via-type-remapping,-via-type-mismatch"]
630+
Number Notation Idummy_placeholder parse print (via IEFin
631+
mapping [[EFin] => IEFinP, [oppe] => IEFinN,
632+
[GRing.natmul] => INatmul, [GRing.one] => IOne])
633+
: ereal_scope.
634+
#[warnings="-via-type-remapping,-via-type-mismatch"]
635+
Number Notation Idummy_placeholder parse print (via IEFin
636+
mapping [[EFin] => IEFinP, [oppe] => IEFinN,
637+
[GRing.natmul] => INatmul, [GRing.one] => IOne])
638+
: ereal_dual_scope.
639+
Arguments GRing.one : clear implicits.
640+
641+
Notation "- 1" := (oppe 1 : dual_extended _) : ereal_dual_scope.
642+
Notation "- 1" := (oppe 1) : ereal_scope.
643+
585644
Notation "\- f" := (fun x => - f x)%dE : ereal_dual_scope.
586645
Notation "\- f" := (fun x => - f x)%E : ereal_scope.
587646
Notation "f \+ g" := (fun x => f x + g x)%dE : ereal_dual_scope.
@@ -684,10 +743,10 @@ Proof. by rewrite lee_fin ler0N1. Qed.
684743
Lemma lte0N1 : 0 < (-1)%:E :> \bar R = false.
685744
Proof. by rewrite lte_fin ltr0N1. Qed.
686745

687-
Lemma lteN10 : - 1%E < 0 :> \bar R.
746+
Lemma lteN10 : -1 < 0 :> \bar R.
688747
Proof. by rewrite lte_fin ltrN10. Qed.
689748

690-
Lemma leeN10 : - 1%E <= 0 :> \bar R.
749+
Lemma leeN10 : -1 <= 0 :> \bar R.
691750
Proof. by rewrite lee_fin lerN10. Qed.
692751

693752
Lemma lte0n n : (0 < n%:R%:E :> \bar R) = (0 < n)%N.
@@ -1273,13 +1332,13 @@ Proof. by move=> rreal; rewrite muleC real_mulrNy. Qed.
12731332

12741333
Definition real_mulr_infty := (real_mulry, real_mulyr, real_mulrNy, real_mulNyr).
12751334

1276-
Lemma mulN1e x : (- 1%E) * x = - x.
1335+
Lemma mulN1e x : -1 * x = - x.
12771336
Proof.
12781337
by case: x => [r| |]/=;
12791338
rewrite /mule ?mulN1r// eqe oppr_eq0 oner_eq0/= lte_fin oppr_gt0 ltr10.
12801339
Qed.
12811340

1282-
Lemma muleN1 x : x * (- 1%E) = - x. Proof. by rewrite muleC mulN1e. Qed.
1341+
Lemma muleN1 x : x * -1 = - x. Proof. by rewrite muleC mulN1e. Qed.
12831342

12841343
Lemma mule_neq0 x y : x != 0 -> y != 0 -> x * y != 0.
12851344
Proof.
@@ -2311,7 +2370,7 @@ Qed.
23112370
Lemma iter_mule n x y : iter n ( *%E x) y = x ^+ n * y.
23122371
Proof. by elim: n => [|n ih]; rewrite ?mul1e// [LHS]/= ih expeS muleA. Qed.
23132372

2314-
HB.instance Definition _ := Monoid.isComLaw.Build (\bar R) 1%E mule
2373+
HB.instance Definition _ := Monoid.isComLaw.Build (\bar R) 1 mule
23152374
muleA muleC mul1e.
23162375

23172376
Lemma muleCA : left_commutative ( *%E : \bar R -> \bar R -> \bar R ).

theories/ftc.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ apply: cvg_at_right_left_dnbhs.
9999
by rewrite -EFinD addrAC subrr add0r.
100100
have nice_E y : nicely_shrinking y (E y).
101101
split=> [n|]; first exact: measurable_itv.
102-
exists (2, fun n => PosNum (d_gt0 n)); split => //= [n z|n].
102+
exists (2%R, fun n => PosNum (d_gt0 n)); split => //= [n z|n].
103103
rewrite /E/= in_itv/= /ball/= ltr_distlC => /andP[yz ->].
104104
by rewrite (lt_le_trans _ yz)// ltrBlDr ltrDl.
105105
rewrite (lebesgue_measure_ball _ (ltW _))// -/mu muE -EFinM lee_fin.
@@ -153,7 +153,7 @@ apply: cvg_at_right_left_dnbhs.
153153
by rewrite ltrDl Nd_gt0 -EFinD opprD addrA subrr add0r.
154154
have nice_E y : nicely_shrinking y (E y).
155155
split=> [n|]; first exact: measurable_itv.
156-
exists (2, (fun n => PosNum (Nd_gt0 n))); split => //=.
156+
exists (2%R, (fun n => PosNum (Nd_gt0 n))); split => //=.
157157
by rewrite -oppr0; exact: cvgN.
158158
move=> n z.
159159
rewrite /E/= in_itv/= /ball/= => /andP[yz zy].

theories/kernel.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1666,7 +1666,7 @@ HB.instance Definition _ :=
16661666

16671667
Let measure_uub : measure_fam_uub kernel_snd.
16681668
Proof.
1669-
exists 2 => /= -[x y].
1669+
exists 2%R => /= -[x y].
16701670
rewrite /kernel_snd/= (@le_lt_trans _ _ 1%:E) ?lte1n//.
16711671
exact: sprob_kernel_le1.
16721672
Qed.

0 commit comments

Comments
 (0)