On Wed, Mar 28, 2018 at 11:01 PM, saad khalid <saad1...@gmail.com> wrote:
> On Wednesday, March 28, 2018 at 1:52:17 AM UTC-5, Simon King wrote:
>>
>> Hi Andrey and Saad,
>>
>> On 2018-03-28, Andrey Novoseltsev <novo...@gmail.com> wrote:
>> > On Tuesday, 27 March 2018 18:03:48 UTC-6, saad khalid wrote:
>> >>
>> >> Why not assume by default that when someone enters a floating point
>> >> number, they intend it as a member of QQ, at least in this case.
>> >>
>> >
>> > It may be an interesting option to have similar to "automatic_names".
>>
>> +1
>>
>> I certainly oppose for it being the default, as when I type in a float
>> I *want* a float (actually an element of RR).
>>
>> Cheers,
>> Simon
>>
>
> Yes, I definitely agree with that. Do others also feel this would be
> apropriate? How could we go about implementing this?

It's surprisingly easy to implement this, due to how Robert Bradshaw
rewrote this part of the Sage preparser.    If you define this
function in a notebook or command line sage session:

def RealNumber(s):
    if '.' not in s:
        return QQ(s)
    a = s.split('.')
    return ZZ(a[0]) + ZZ(a[1])/10^len(a[1])

then all real number literals will be interpreted as exact rationals!

sage: 3.45
69/20

sage: matrix(2, [1.5,2.5, 7, 8.333])
[ 3/2  5/2]
[ 7     8333/1000]

sage: 3.5*x^2 - x*1.23445 + 2/3
7/2*x^2 - 24689/20000*x + 2/3

You can similarly change the interpretation of integer literals by
defining "Integer".

https://cocalc.com/share/4a5f0542-5873-4eed-a85c-a18c706e8bcd/support/2018-03-29-103001-RealNumber.ipynb?viewer=share


>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-devel+unsubscr...@googlegroups.com.
> To post to this group, send email to sage-devel@googlegroups.com.
> Visit this group at https://groups.google.com/group/sage-devel.
> For more options, visit https://groups.google.com/d/optout.



-- 
William (http://wstein.org)

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to