-
Notifications
You must be signed in to change notification settings - Fork 297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement computable real numbers #1038
Comments
That sounds like a cool idea! We do accept pull requests if you feel like working on it. |
Exact real number computation is a subtle topic, and I think that choosing the correct approach will depend on your application. There's a huge gap between "computable in principle" and "computable in practice." Are you really going after kernel computation? Even simple rational arithmetic can be slow: I'm not sure how familiar you are, but there's a good amount written about this in Coq, surrounding the CoRN (Computational Real Numbers) library. https://arxiv.org/pdf/0805.2438.pdf http://users-cs.au.dk/spitters/calculemus.pdf http://corn.cs.ru.nl/ |
We know a whole bunch about sin and cos and tan, and it would not surprise me if one could prove in Lean, without too much trouble, that |
Actually, I'm not sure what do I want. Ideally, I want some framework where a) one can build “approximators” for various real numbers with sane (though probably computationally inefficient) defaults; E.g., a straightforward lemma lemma approx_plus : approximates f x → approximates g y → approximates (λ r, f (r / 2) + g (r / 2)) y is very inefficient, if one of the numbers is actually a rational number. So, it would be nice to have lemma approx_plus_param (c : rat) (hc : 0 < c < 1) : approximates f x → approximates g y → approximates (λ r, f (c * r) + g ((1 - c) * r)) y In order to actually compute something in a reasonable time, one would need to use particular instances here and there. As for π, it would be nice to have something more effective, e.g., based on one of those formulas Re @robertylewis : I have quite some math background, but about zero experience in this particular area. I'll look more carefully at CoRN, then come back here. |
I think that mathlib computable reals should be modeled after some framework for exact real computation in a conventional programming language e.g. C. This way, it stays as close to practical computation as possible. I think that at this point we've decided not to pursue "naively computable" things, since they don't come with many benefits. Instead we have the "purely mathematical" version (where noncomputable things are okay if they make proofs easier) and the "ruthlessly practical computational" version which is used for VM computation, with a proven relation to the mathematical version. From my point of view the Leibniz formula for pi is on the "purely mathematical" side. It's useful to know abstractly that this sequence converges, but it's not a reasonable method for actually calculating pi. On a computational type, there is no problem with having separate functions I've done some research on this topic before, and a popular method seems to be functions that take Another aspect of these computable reals that is sometimes important is the ability to memoize previous values, since subcomputations tend to use them over and over. We still need to work on the lean side a bit to support memoization for functions (there is a current PR for lean 3.5c about interior mutability that should help here). |
By
you mean for example some interval arithmetic library, rather than |
Interval arithmetic is another direction we could go, and probably more practical too, but no, I actually mean a library for so called "exact real arithmetic", which entails the manipulation of functions as data to perform operations on cauchy sequence representations like I indicated above. For example: |
The basics of interval arithmetic are about to hit mathlib in #16761. |
Let me close this issue. |
Hi,
I'd like to have real numbers that can be used for in-kernel computations. I mean, it would be nice to have, e.g., a function
pi.approx : ℚ₊ → ℚ
with a proof|pi.approx r - pi| ≤ r
.The main issue is that this function cannot be implemented as
approx : ℝ → ℚ₊ → ℚ
. I can think about two (not mutually exclusive) approaches.Define new
with a (strong) setoid structure, then migrate some (or most) theorems to deal with this setoid.
Define
then prove lemmas like
The text was updated successfully, but these errors were encountered: