Le 20/09/2015 17:11, William Stein a écrit :
On Sun, Sep 20, 2015 at 8:02 AM, Thierry Dumont
<tdum...@math.univ-lyon1.fr> wrote:
Le 20/09/2015 16:26, Volker Braun a écrit :

Why change the default? Global state is always a liability; Just don't
do it. Make the field a parameter to your code:

def frobnicate(x,y, field=None)
      if field is None:
          from sage.structure.element import get_coercion_model
          field = get_coercion_model().common_parent(x, y)
      x, y = field(x), field(y)
      ...

frobnicate(1, 2, field=RealField(100))

--
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
<mailto:sage-devel+unsubscr...@googlegroups.com>.
To post to this group, send email to sage-devel@googlegroups.com
<mailto:sage-devel@googlegroups.com>.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.


Ok...
The origin of the discussion was: I have a code, translated from C, where a
I want to be able to increase the precision  of the float constants (there
are many of them -about 400!-), as the problem is ill conditioned.... David
Roe proposed to patch the parser.

Without changing the default precision, and using your solution, we revert
to something where we must "declare" the float values:
x=field(137.8)
in place of
x=137.8
My principal motivation was lazyness :-)
But ok, I understand your argument; and also, patching the parser is not
very smart programing...


Just type

     RealNumber = RealField(300)

and now every single real literal will be a 300-bit float.    Your
problem is solved.  All the pre-parser does is replace real literals
with RealNumber('literal'), e.g.,


Aaaahhhhh, yes!
Nice,
Thanks!
yours
t.
    sage: preparse('3.14')
    "RealNumber('3.14')"

You can thus trivially re-interpret all real literals in Sage programs
(or worksheets) in absolutely any way you want by redefining
RealNumber.  This only impacts that one scope and session too, so it
won't mess up the library in any way (which a priori any change to the
pre-parser itself could).

Similar remarks apply for integer literals.

    sage: preparse('389')
    'Integer(389)'

<dream>I wish I was writing this remark in the README.md of a
pip-hosted package called sage-preparser, which is an also popular
IPython extension...</dream>

[1] 
https://cloud.sagemath.com/projects/4a5f0542-5873-4eed-a85c-a18c706e8bcd/files/support/2015-09-20-080623-real_precision.sagews

William


t.



--
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 http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.




--
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 http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

<<attachment: tdumont.vcf>>

Reply via email to