[Merged by Bors] - feat(Data/Real): representation of reals from [0, 1] in positional system#26021
[Merged by Bors] - feat(Data/Real): representation of reals from [0, 1] in positional system#26021vasnesterov wants to merge 24 commits intoleanprover-community:masterfrom
[0, 1] in positional system#26021Conversation
PR summary e0f13842c2Import changes for modified filesNo significant changes to the import graph Import changes for all files
|
|
I am not a maintainer, but I wonder that if we add positional system of real to mathlib, it is preferred to add the more general version, which includes
|
There was a problem hiding this comment.
Maybe you can take advantage of the API developed in the PRs mentioned in #Is there code for X?>Base n expansion of real numbers? (sorry, results there are not really easy to use)
Co-authored-by: Junyan Xu <[email protected]>
| · rw [inv_pow] | ||
|
|
||
| /-- The number `0.d₀d₁d₂...` in the system with base `b`. -/ | ||
| noncomputable def ofDigits {b : ℕ} (digits : ℕ → Fin b) : ℝ := |
There was a problem hiding this comment.
I'll try and write something longer later, but for reviewers who didn't see my Zulip message, I'd be inclined to either make digits:
- PNat-indexed, so that the
$n$ th digit represents$b^{-n}$ - Int-indexed, so that the
$n$ th digit represents$b^{n}$
There was a problem hiding this comment.
The Int-indexed version would be able to represent all nonnegative reals, but if we want to use LaurentSeries, we have to let the
There was a problem hiding this comment.
Is using LaurentSeries meaningful here? Does the multiplication do anything sensible?
There was a problem hiding this comment.
I'm pointing at LaurentSeries as a way to include the condition that the expansions should start with ...000 (for negative reals they start with ...(b-1)(b-1)(b-1)); The multiplication of course doesn't match. In this case we could also consider including the condition directly so as not to worry about the sign, since it's not hard to state.
There was a problem hiding this comment.
My take on these ideas:
-
Regarding Int: I think that digits in [0,1] is a fine place to start. The behaviour of reals is different when expanding after the decimal point (you can go on forever) and before (you can't) and rather than trying to unify these things in a clever way, which gets messed up because of minus signs, with this hack involving (b-1) digits (which I think is daft, to be honest), I think we should just stick to [0,1]. It's simple, and it's missing from mathlib. The moment we allow Int-valued things we open up a can of worms. I think there is an argument for allowing Int, demanding finite support to the left of the decimal point and then mapping to NNReal but this feels like a different project which could easily coexist with this one. The relevant map from Nat to Int would be the constructor, which is nice.
-
Regarding PNat; I do think that this suggestion has some merit but the proof of the pudding will be in the eating. It would be a nice exercise to translate this PR into PNat language and to see if it makes it better or worse. One thing which might be missing is the analogue of
Finset.range nas a functionPNat -> Finset (PNat)plus all the API needed to make it painless. This is worth an experiment but my experience with cyclotomic fields was that Mathlib wasn't quite ready for it yet.
I think we want both, so that we can state the theorem that these are the same. |
|
This might also be an argument for why we want the Int-indexed version, since that largely lets us follow the standard informal proof. |
|
I think we should have both versions: one for |
[0, 1] in positional system
|
This PR/issue depends on:
|
|
Coming here from triage: what's the status of this PR? Is this waiting on the author to refactor the PR, waiting on review, or something else? |
Ruben-VandeVelde
left a comment
There was a problem hiding this comment.
Thanks - a few comments to match mathlib style more closely below.
|
This pull request has conflicts, please merge |
|
This job finally got to the top of the pile -- sorry it took so long. Right now there is a trivial conflict and also a complaint that this file is no longer allowed to live in |
kbuzzard
left a comment
There was a problem hiding this comment.
Sorry, I only made it half way through this and now I need to pause for a bit, so I thought I'd submit my half-review just to prove that I am actually looking at the PR now! Apologies for the delay.
kbuzzard
left a comment
There was a problem hiding this comment.
It wouldn't surprise me if some expert could golf these proofs a lot, but I don't really have the time or the energy to take this any further; I think the proofs are fine as they are (I suggested some more golfs and name changes).
In my mind this is ready for merge modulo the question of whether PNat would be a better indexing set. My gut feeling is that it would make the proofs even worse but do you think that actually this would be a an effective change?
|
@kbuzzard Please, respond to my comment above. |
grunweg
left a comment
There was a problem hiding this comment.
I'm not Kevin, but here's my take on the style questions you raised.
|
@vasnesterov Could you say something regarding the suggestion to use |
|
I agree with @kbuzzard above that it makes sense, but would be painful due to the lack of |
|
OK, based on #PR reviews > representation of reals in [0, 1] in positional system @ 💬 from Kevin, let's merge. Thanks! |
…system (#26021) * Introduce `ofDigits {b : ℕ} (digits : ℕ → Fin b) : ℝ`, representing a real number of the form `0.d₀d₁d₂...` (where `dᵢ = digits i`) as an infinite sum. * Prove that this sum converges to a number in the interval `[0, 1]`. * Prove `ofDigits_close_of_common_prefix`: if the first `n` digits of two numbers are equal, then their difference is bounded by `b⁻ⁿ`. * Introduce `Real.digits`, which converts a real number into its sequence of digits. * Prove that `ofDigits (toDigits x b) = x`. Zulip threads: - [Zulip thread where this was proposed](https://leanprover.zulipchat.com/#narrow/stream/217875-Is-there-code-for-X.3F/topic/Base.20n.20expansion.20of.20real.20numbers.3F/near/502937293) - [#PR reviews > representation of reals in [0, 1] in positional system](https://leanprover.zulipchat.com/#narrow/channel/144837-PR-reviews/topic/representation.20of.20reals.20in.20.5B0.2C.201.5D.20in.20positional.20system/with/537704930)
|
Pull request successfully merged into master. Build succeeded: |
[0, 1] in positional system[0, 1] in positional system
| namespace Real | ||
|
|
||
| /-- `ofDigits` takes a sequence of digits `(d₀, d₁, ...)` in base `b` and returns the | ||
| real numnber `0.d₀d₁d₂... = ∑ᵢ(dᵢ/bⁱ)`. This auxiliary definition `ofDigitsTerm` sends the |
There was a problem hiding this comment.
This is a typo, I think? There is a missing +1 here. I'd suggest writing this as
…system (leanprover-community#26021) * Introduce `ofDigits {b : ℕ} (digits : ℕ → Fin b) : ℝ`, representing a real number of the form `0.d₀d₁d₂...` (where `dᵢ = digits i`) as an infinite sum. * Prove that this sum converges to a number in the interval `[0, 1]`. * Prove `ofDigits_close_of_common_prefix`: if the first `n` digits of two numbers are equal, then their difference is bounded by `b⁻ⁿ`. * Introduce `Real.digits`, which converts a real number into its sequence of digits. * Prove that `ofDigits (toDigits x b) = x`. Zulip threads: - [Zulip thread where this was proposed](https://leanprover.zulipchat.com/#narrow/stream/217875-Is-there-code-for-X.3F/topic/Base.20n.20expansion.20of.20real.20numbers.3F/near/502937293) - [#PR reviews > representation of reals in &leanprover-community#91;0, 1&leanprover-community#93; in positional system](https://leanprover.zulipchat.com/#narrow/channel/144837-PR-reviews/topic/representation.20of.20reals.20in.20.5B0.2C.201.5D.20in.20positional.20system/with/537704930)
…system (leanprover-community#26021) * Introduce `ofDigits {b : ℕ} (digits : ℕ → Fin b) : ℝ`, representing a real number of the form `0.d₀d₁d₂...` (where `dᵢ = digits i`) as an infinite sum. * Prove that this sum converges to a number in the interval `[0, 1]`. * Prove `ofDigits_close_of_common_prefix`: if the first `n` digits of two numbers are equal, then their difference is bounded by `b⁻ⁿ`. * Introduce `Real.digits`, which converts a real number into its sequence of digits. * Prove that `ofDigits (toDigits x b) = x`. Zulip threads: - [Zulip thread where this was proposed](https://leanprover.zulipchat.com/#narrow/stream/217875-Is-there-code-for-X.3F/topic/Base.20n.20expansion.20of.20real.20numbers.3F/near/502937293) - [#PR reviews > representation of reals in &leanprover-community#91;0, 1&leanprover-community#93; in positional system](https://leanprover.zulipchat.com/#narrow/channel/144837-PR-reviews/topic/representation.20of.20reals.20in.20.5B0.2C.201.5D.20in.20positional.20system/with/537704930)
ofDigits {b : ℕ} (digits : ℕ → Fin b) : ℝ, representing a real number of the form0.d₀d₁d₂...(wheredᵢ = digits i) as an infinite sum.[0, 1].ofDigits_close_of_common_prefix: if the firstndigits of two numbers are equal, then their difference is bounded byb⁻ⁿ.Real.digits, which converts a real number into its sequence of digits.ofDigits (toDigits x b) = x.Zulip threads:
⌊n * x⌋₊ / n = ⌊x⌋₊#26004