Skip to content
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

Refactor numerical_approx() #13055

Closed
sagetrac-dsm mannequin opened this issue May 29, 2012 · 28 comments
Closed

Refactor numerical_approx() #13055

sagetrac-dsm mannequin opened this issue May 29, 2012 · 28 comments

Comments

@sagetrac-dsm
Copy link
Mannequin

sagetrac-dsm mannequin commented May 29, 2012

Drop the _numerical_approx method, instead use numerical_approx. Move the generic implementation to a new Cython file. Also put the conversion of decimal digits to bits in one place.

Finally, the documentation of numerical_approx should be made more clear and consistent.

CC: @benjaminfjones

Component: basic arithmetic

Keywords: numerical_approx, sd40.5, days74

Author: Jeroen Demeyer

Branch: fd79227

Reviewer: Marc Mezzarobba

Issue created by migration from https://trac.sagemath.org/ticket/13055

@sagetrac-dsm sagetrac-dsm mannequin added this to the sage-5.11 milestone May 29, 2012
@sagetrac-dsm sagetrac-dsm mannequin assigned burcin May 29, 2012
@sagetrac-dsm

This comment has been minimized.

@sagetrac-dsm
Copy link
Mannequin Author

sagetrac-dsm mannequin commented May 29, 2012

Changed keywords from numerical_approx to numerical_approx, sd40.5

@jdemeyer jdemeyer modified the milestones: sage-5.11, sage-5.12 Aug 13, 2013
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@jdemeyer

This comment has been minimized.

@jdemeyer
Copy link

comment:7

I doubt that this is a bug. How would you guess the default precision for the .n() method?

@jdemeyer jdemeyer changed the title loss of precision via SR Better default precision for .n() method Nov 27, 2014
@jdemeyer

This comment has been minimized.

@jdemeyer jdemeyer removed this from the sage-6.4 milestone Nov 27, 2014
@kcrisman
Copy link
Member

kcrisman commented Dec 4, 2014

comment:11

Hmm, I'm not sure this is wontfix, though. I'm sympathetic to your argument, but Doug's point that

sage: sin(1.2345678901234567890)
0.9440057250452665781
sage: sin(1.2345678901234567890).n()
0.944005725045267

seems good; you shouldn't lose precision, should you? (Forget about hold!)

@jdemeyer
Copy link

jdemeyer commented Dec 4, 2014

comment:12

Losing precision is a feature of the .n() method, that's what it does. The x.n() method asks for a numerical approximation of x to a precision of 53 bits. This is easily explained. I also like the fact that neither the implementation nor the user should need to worry about what x is, the output is a real/complex number with 53 bits of precision.

If you think that .n() is wrong, what should (2/3).n() return then? The only possible answer which doesn't lose precision is the rational 2/3.

@jdemeyer
Copy link

jdemeyer commented Dec 4, 2014

comment:13

About hold=True, that even doesn't seem to work with real numbers:

sage: gamma(1.2345678901234567890, hold=True)
0.9097200568693150729

@kcrisman
Copy link
Member

kcrisman commented Dec 4, 2014

comment:14

About hold=True, that even doesn't seem to work with real numbers:

Exactly, which is why I didn't use that example.

Okay, I don't have that much invested in this. But then

sage: x = 1.2340000000000000000000001
sage: x.n?
Docstring:
   Return a numerical approximation of x with at least prec bits of
   precision.

   EXAMPLES:

      sage: (2/3).n()
      0.666666666666667
      sage: pi.n(digits=10)
      3.141592654
      sage: pi.n(prec=20)   # 20 bits
      3.1416

   TESTS:

   Check that http://trac.sagemath.org/14778 is fixed:

      sage: (0).n(algorithm='foo')
      0.000000000000000

should really be improved, and possibly the documentation for other versions of .numerical_approx as well. Those are practically stubs!

@kcrisman kcrisman added this to the sage-6.5 milestone Dec 4, 2014
@jdemeyer
Copy link

jdemeyer commented Mar 9, 2015

comment:17

One other detail which is wrong in the "at least" in "at least prec bits of precision". Certainly for the global numerical_approx() function, it's exactly prec bits.

@jdemeyer
Copy link

jdemeyer commented Jun 1, 2016

Changed keywords from numerical_approx, sd40.5 to numerical_approx, sd40.5, days74

@jdemeyer jdemeyer modified the milestones: sage-6.5, sage-7.3 Jun 1, 2016
@jdemeyer

This comment has been minimized.

@jdemeyer
Copy link

jdemeyer commented Jun 1, 2016

Author: Jeroen Demeyer

@jdemeyer

This comment has been minimized.

@jdemeyer

This comment has been minimized.

@jdemeyer jdemeyer changed the title Document default precision for .n() method Refactor numerical_approx() Jun 1, 2016
@jdemeyer
Copy link

jdemeyer commented Jun 1, 2016

@jdemeyer
Copy link

jdemeyer commented Jun 1, 2016

Commit: fafdb9c

@jdemeyer
Copy link

jdemeyer commented Jun 1, 2016

New commits:

fafdb9cImprove numerical_approx

@mezzarobba
Copy link
Member

comment:24

Most of the changes look good to me, but I don't like the new description of RealLiteral.numerical_approx(): as far as I understand “real literals” are exact decimal numbers, so converting one to a RealField element with d·log₁₀ 2 bits of precision doesn't really “change its precision” to d decimal digits.

And—just wondering, I have nothing against that choice—is there a reason why you didn't put the generic implementation directly in Element (and put code to convert non-Elements to Elements before calling it when necessary)?

@jdemeyer
Copy link

jdemeyer commented Jun 2, 2016

comment:25

Replying to @mezzarobba:

is there a reason why you didn't put the generic implementation directly in Element (and put code to convert non-Elements to Elements before calling it when necessary)?

Because of the "put code to convert non-Elements to Elements before calling it" part. I don't know how to do that in general.

@jdemeyer
Copy link

jdemeyer commented Aug 1, 2016

comment:26

ping

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 2, 2016

Changed commit from fafdb9c to fd79227

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 2, 2016

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

fd79227Improve numerical_approx

@mezzarobba
Copy link
Member

Reviewer: Marc Mezzarobba

@mezzarobba
Copy link
Member

comment:28

I still disagree about the docstring of RealLiteral.numerical_approx(), but let's not again delay the ticket by two months...

@vbraun
Copy link
Member

vbraun commented Aug 7, 2016

Changed branch from u/jdemeyer/document_default_precision_for__n___method to fd79227

@fchapoton
Copy link
Contributor

Changed commit from fd79227 to none

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants