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

Very strange behavior of QQ -> RealField() conversion. #393

Closed
jonhanke opened this issue Jun 28, 2007 · 2 comments
Closed

Very strange behavior of QQ -> RealField() conversion. #393

jonhanke opened this issue Jun 28, 2007 · 2 comments

Comments

@jonhanke
Copy link

There is something very wrong with this behavior of this code, which tries to convert 1/2 to a 2x2 matrix. The problem seems not to be in the matrix code, but since it's hard to reproduce it appears in that form.

Component: basic arithmetic

Keywords: real, rational, coerce

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

@jonhanke
Copy link
Author

comment:1

Attachment: sage_errors__matrix_test.py.gz

Here is the output of the attached routine, which essentially does the same thing 3 times and gets 3 different answers!

jonhanke@[~/Documents/sage-2.6/devel/sage-qfdevel/sage/quadratic_forms]: sage -br

----------------------------------------------------------
sage: Building and installing modified SAGE library files.

running install
running build
running build_py
copying sage/quadratic_forms/sage_errors__matrix_test.py -> build/lib.macosx-10.3-i386-2.5/sage/quadratic_forms
running build_ext
running build_scripts
running install_lib
copying build/lib.macosx-10.3-i386-2.5/sage/quadratic_forms/sage_errors__matrix_test.py -> /Users/jonhanke/Documents/sage-2.6/local/lib/python2.5/site-packag

sage: MatrixTest()
False
[0.000000000000000 0.000000000000000]
[0.000000000000000 0.000000000000000]
[0.500000000000000 0.000000000000000]
[0.000000000000000 0.500000000000000]

m1 is 
[0.000000000000000 0.000000000000000]
[0.000000000000000 0.000000000000000]

m2 is 
[0.000000000000000 0.000000000000000]
[0.000000000000000 0.000000000000000]
False


m1 is 
[0.500000000000000 0.000000000000000]
[0.000000000000000 0.500000000000000]

m2 is 
[0.500000000000000 0.000000000000000]
[0.000000000000000 0.500000000000000]
False

@williamstein williamstein added this to the sage-2.8.2 milestone Aug 18, 2007
@mwhansen
Copy link
Contributor

comment:3

This is just due to the difference between SAGE and Python. When run from the command line or in a .sage file, SAGE will preprocess the file and change 1/2 to Integer(1)/Integer(2) to (correctly) form the rational 1/2. When included or run form a .py file, it will remain as 1/2 which Python evaluates to 0.

There is also a typo in the second section of the attached file (m1 is printed twice).

tobiasdiez pushed a commit to tobiasdiez/sage that referenced this issue Feb 22, 2024
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

3 participants