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

Make sin(0), log(1) and similar expressions return Sage integers, not Python ints #10133

Closed
kcrisman opened this issue Oct 15, 2010 · 17 comments
Closed

Comments

@kcrisman
Copy link
Member

From this thread:

> > sage: type(log(1))
> > <type 'int'>
> > sage: log(1).n()
> > ---------------------------------------------------------------------------
> > AttributeError: 'int' object has no attribute 'n'
> > sage: Integer(log(1)).n()
> > 0.000000000000000
> > sage: a = Integer(1)
> > sage: a.log()
> > 0
> > sage: type(a.log())
> > <type 'int'>
> > sage: from sage.functions.log import function_log
> > sage: function_log(Integer(1))
> > 0
> > sage: type(function_log(Integer(1)))
> > <type 'int'>
> 
> > Is there any way to get around this in the code, or are we pretty much
> > stuck with this because of how GinacFunctions work?  I'm not 100% sure
> > this is a bug in log; maybe instead we should extend int so that
> 
> This is a bug in the log() function, and any other function which
> returns exact values like 0 or 1. We already work around most cases,
> see lines 720-722 and 736-761 of sage/symbolic/function.pyx.
> 
> The correct fix is to change the corresponding pynac functions to
> coerce the exact value to the parent of the argument before returning
> it. For example, all the lines "return _ex1;" or "return _ex0;" in
> 
> http://pynac.sagemath.org/hg/file/b233d9dadcfa/ginac/inifcns_trans.cpp
> 
> has to be changed this way.
> 

Yup, I see what you are talking about - e.g. 

if (x.is_equal(_ex1))  // log(1) -> 0
     return _ex0;

Although it might be nice to stay relatively close to Ginac and fix such things on the Sage level if that's not really bad.

This ticket's goal is to implement one of these solutions (that is, catch this in function.pyx or in Pynac).

We might as well also deal with sin(0), tan(0), sin(pi) from #10972 here as well, otherwise that really wasn't a duplicate.

Depends on #17130

CC: @eviatarbach

Component: symbolics

Keywords: type coercion symbolic

Author: Jeroen Demeyer

Branch: c8c26e1

Reviewer: Ralf Stephan

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

@kcrisman
Copy link
Member Author

kcrisman commented Jun 1, 2011

comment:1

#10972 was closed as a duplicate. Ironic that I reported both, though in my defense, that ticket does list a few specific functions beyond log for which that happens, and it was 8 months ago :)

@sagetrac-dsm
Copy link
Mannequin

sagetrac-dsm mannequin commented Feb 13, 2012

comment:2

ping. I just noticed this in a different context.

@kcrisman

This comment has been minimized.

@kcrisman
Copy link
Member Author

comment:4

See also this sage-devel thread.

@kcrisman
Copy link
Member Author

comment:5

See also this sage-devel thread, where it seems that the consensus is that such things should give Sage Integers, though at #10972 Burcin seems to suggest that symbolic expressions are appropriate.

@kcrisman
Copy link
Member Author

Changed keywords from none to type coercion symbolic

@kcrisman kcrisman changed the title Make sure log(1) returns an Integer, not an int Make sin(0), log(1), cos(0), and similar expressions return Sage integers, not symbolic expressions or Python ints Oct 31, 2012
@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
Copy link

Dependencies: #17130

@jdemeyer
Copy link

Author: Jeroen Demeyer

@jdemeyer
Copy link

Branch: u/jdemeyer/ticket/10133

@jdemeyer
Copy link

Commit: c8c26e1

@jdemeyer
Copy link

New commits:

6d10729Simplify numerical evaluation of BuiltinFunctions
b6e1ed4Merge remote-tracking branches 'origin/u/jdemeyer/ticket/17131' and 'origin/u/jdemeyer/ticket/17133' into ticket/17130
382f97aMerge branch 'u/jdemeyer/ticket/17130' of trac.sagemath.org:sage into 6.5beta1
726598917130: reviewer's patch: fix typo
c47dbd4Fix Trac #17328 again in a better way
a486db2Call the factorial() method of an Integer
c8c26e1Convert Ginac function results to the correct parent

@jdemeyer jdemeyer changed the title Make sin(0), log(1), cos(0), and similar expressions return Sage integers, not symbolic expressions or Python ints Make sin(0), log(1) and similar expressions return Sage integers, not Python ints Nov 26, 2014
@rwst
Copy link

rwst commented Dec 5, 2014

comment:15

Looks good and passes make ptestlong.

@rwst
Copy link

rwst commented Dec 5, 2014

Reviewer: Ralf Stephan

@vbraun
Copy link
Member

vbraun commented Dec 12, 2014

Changed branch from u/jdemeyer/ticket/10133 to c8c26e1

@rwst
Copy link

rwst commented Aug 29, 2015

comment:17

Actually this should have been fixed in Pynac. Now, accidentally the recent patches dealing with pynac/pynac#7 automatically produce this behaviour. Which will be Pynac-0.4.4. The wrapper from this ticket should then be removed.

@rwst
Copy link

rwst commented Aug 29, 2015

Changed commit from c8c26e1 to none

@fchapoton

This comment has been minimized.

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

6 participants