[sage-support] numeric approximations for symbolic expressions
How do I get a numeric approximation for symbolic expressions that have variables? I want to leave the variables alone, but get numeric approximations for all constants. For example, here's how it works in mathematica: In[1]:= a:=1+Sqrt[2]*x In[2]:= a Out[2]= 1 + Sqrt[2] x In[3]:= N[a] Out[3]= 1. + 1.41421 x However, the corresponding thing does not work in Sage: sage: a=1+sqrt(2)*x sage: a sqrt(2)*x + 1 sage: n(a) --- TypeError Traceback (most recent call last) /home/grout/ in () /home/grout/downloads/sage-3.1.3.alpha1/local/lib/python2.5/site-packages/sage/misc/functional.py in numerical_approx(x, prec, digits) /home/grout/sage/local/lib/python2.5/site-packages/sage/calculus/calculus.py in numerical_approx(self, prec, digits) 1300 except TypeError: 1301 # try to return a complex result -> 1302 approx = self._complex_mpfr_field_(ComplexField(prec)) 1303 1304 return approx /home/grout/sage/local/lib/python2.5/site-packages/sage/calculus/calculus.py in _complex_mpfr_field_(self, field) 4852 0 4853 """ -> 4854 return self._convert(field) 4855 4856 def _complex_double_(self, field): /home/grout/sage/local/lib/python2.5/site-packages/sage/calculus/calculus.py in _convert(self, typ) 4786 raise 4787 else: -> 4788 return typ(g) 4789 return self._operator(*fops) 4790 /home/grout/downloads/sage-3.1.3.alpha1/local/lib/python2.5/site-packages/sage/rings/complex_field.py in __call__(self, x, im) /home/grout/sage/local/lib/python2.5/site-packages/sage/calculus/calculus.py in _complex_mpfr_field_(self, field) 4852 0 4853 """ -> 4854 return self._convert(field) 4855 4856 def _complex_double_(self, field): /home/grout/sage/local/lib/python2.5/site-packages/sage/calculus/calculus.py in _convert(self, typ) 4780 """ 4781 try: -> 4782 fops = [typ(op) for op in self._operands] 4783 except TypeError: 4784 g = self.simplify() /home/grout/downloads/sage-3.1.3.alpha1/local/lib/python2.5/site-packages/sage/rings/complex_field.py in __call__(self, x, im) /home/grout/sage/local/lib/python2.5/site-packages/sage/calculus/calculus.py in _complex_mpfr_field_(self, field) 4852 0 4853 """ -> 4854 return self._convert(field) 4855 4856 def _complex_double_(self, field): /home/grout/sage/local/lib/python2.5/site-packages/sage/calculus/calculus.py in _convert(self, typ) 4780 """ 4781 try: -> 4782 fops = [typ(op) for op in self._operands] 4783 except TypeError: 4784 g = self.simplify() /home/grout/downloads/sage-3.1.3.alpha1/local/lib/python2.5/site-packages/sage/rings/complex_field.py in __call__(self, x, im) /home/grout/sage/local/lib/python2.5/site-packages/sage/calculus/calculus.py in _complex_mpfr_field_(self, field) 1453 1454 def _complex_mpfr_field_(self, field): -> 1455 raise TypeError 1456 1457 def _complex_double_(self, C): TypeError: This came up today when I was trying to convince the class that a rather complicated looking taylor polynomial was really just a nice polynomial, even though the coefficients looked really complicated. Thanks, Jason --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: numeric approximations for symbolic expressions
On Fri, Oct 10, 2008 at 7:11 AM, Jason Grout <[EMAIL PROTECTED]> wrote: > > How do I get a numeric approximation for symbolic expressions that have > variables? I want to leave the variables alone, but get numeric > approximations for all constants. For example, here's how it works in > mathematica: > > In[1]:= a:=1+Sqrt[2]*x > > In[2]:= a > > Out[2]= 1 + Sqrt[2] x > > In[3]:= N[a] > > Out[3]= 1. + 1.41421 x > > > However, the corresponding thing does not work in Sage: > > sage: a=1+sqrt(2)*x > sage: a > sqrt(2)*x + 1 > sage: n(a) > --- > TypeError Traceback (most recent call last) For polynomials, do this: sage: f = 1 + sqrt(2)*x sage: f.polynomial(RDF) 1.41421356237*x + 1.0 --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Cython editor
> Do you have these changes posted somewhere? I'd like to try it out, if > possible. er, no, but here are a few hints. First try sage -grep "def" | grep "def " >~/.sage/sage_doc so you have a file in your .sage folder containing all the lines in SAGE's code containing the word "def " (i don't know why sage -grep "def " with a space does not work, the second grep is here to fix the problem). then in tools/external tools i add a script "quick sage documentation" whose input is "current selection" and output "bottom pannel", and which contains: -- #!/usr/bin/env python from sys import stdin from commands import getoutput name= stdin.read() cmd= "cat /home/my_home_folder_here/.sage/sage_doc | grep \"def " + name + "\"" s= getoutput(cmd) print s -- so if i select MatrixSpace and run that tool, the bottom panel displays matrix/matrix_space.py:def MatrixSpace(base_ring, nrows, ncols=None, sparse=False): You may want to script to have "current word" as its input but careful, underscores are understood as word separators. In order to get the full documentation, i've added the following script, whose execution is pretty slow but it works: the bottom panel displays the whole thing. So in tools/external tools, add a script "full sage doc" with the same input and output containing --- #!/usr/bin/env python from sys import stdin word= stdin.read() from commands import getoutput cmd= "echo " + word + "? | sage" print getoutput(cmd) --- so it just runs "echo MatrixSpace? | sage" when MatrixSpace is selected, and prints it in the bottom panel. i'll write again about the completion trick (i've tried to play with it recently and it doesn't work anymore!) --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Cython editor
alright, here's how you do the completion with gedit. It's not that it stopped working, it's just a bug i hadn't noticed before. There a quite a few flaws -- help appreciated if you know a way to improve on this ! so currently: -- only the last word on the line can be completed (true, it's usually the one you're typing!) -- annoyingly, after the completion gedit goes to the next line (get used to pressing backspace right after the hotkey for completion !) -- discovered recently: it doesn't work on the first line of the document !! so in tools/external tools, create a script with input= current line, output= insert at cursor position (note: current line really returns the current paragraph... and something buggy on the first line). the code is: - #!/usr/bin/env python #find the last word: from sys import stdin s= stdin.read() word= s.split()[-1] #read the doc file: from commands import getoutput docfile= "/home/pedro/.sage/sage_doc" cmd= "cat " + docfile + " | grep \"def " + word + "\"" poss= getoutput(cmd).split("\n") #complete: import re regexp= re.compile("def (" + word + ".*)\(") choices= [ regexp.search(s) for s in poss] choices= filter(lambda x: x is not None, choices) choices= [x.groups()[0] for x in choices] if len(choices) > 0: def gcd(s,t): i= 0 m=min(len(s), len(t)) while i len(word): print common[len(word) - len(common):], - if you want to display all possibilities for completion, choose a second hotkey close to the previous one (eg i use F3 and shift + F3) and create another script with input= current line, output=bottom panel, and code: #!/usr/bin/env python #!/usr/bin/env python #find the last word: from sys import stdin s= stdin.read() word= s.split()[-1] #read the doc file: from commands import getoutput docfile= "/home/pedro/.sage/sage_doc" cmd= "cat " + docfile + " | grep \"def " + word + "\"" poss= getoutput(cmd).split("\n") #complete: import re regexp= re.compile("def (" + word + ".*)\(") choices= [ regexp.search(s) for s in poss] choices= filter(lambda x: x is not None, choices) choices= [x.groups()[0] for x in choices] for choice in choices: print choice - if there were a massive popular demand (say five people), i could turn this into a proper gedit plugin rather than a trick using external tools. Let me know what you think ! pierre On Oct 10, 11:18 am, Pierre <[EMAIL PROTECTED]> wrote: > > Do you have these changes posted somewhere? I'd like to try it out, if > > possible. > > er, no, but here are a few hints. First try > > sage -grep "def" | grep "def " >~/.sage/sage_doc > > so you have a file in your .sage folder containing all the lines in > SAGE's code containing the word "def " (i don't know why sage -grep > "def " with a space does not work, the second grep is here to fix the > problem). > > then in tools/external tools i add a script "quick sage > documentation" whose input is "current selection" and output "bottom > pannel", and which contains: > > -- > #!/usr/bin/env python > > from sys import stdin > from commands import getoutput > name= stdin.read() > cmd= "cat /home/my_home_folder_here/.sage/sage_doc | grep \"def " + > name + "\"" > > s= getoutput(cmd) > print s > -- > > so if i select MatrixSpace and run that tool, the bottom panel > displays > > matrix/matrix_space.py:def MatrixSpace(base_ring, nrows, ncols=None, > sparse=False): > > You may want to script to have "current word" as its input but > careful, underscores are understood as word separators. > > In order to get the full documentation, i've added the following > script, whose execution is pretty slow but it works: the bottom panel > displays the whole thing. So in tools/external tools, add a script > "full sage doc" with the same input and output containing > --- > #!/usr/bin/env python > from sys import stdin > word= stdin.read() > from commands import getoutput > cmd= "echo " + word + "? | sage" > print getoutput(cmd) > --- > so it just runs "echo MatrixSpace? | sage" when MatrixSpace is > selected, and prints it in the bottom panel. > > i'll write again about the completion trick (i've tried to play with > it recently and it doesn't work anymore!) --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: numeric approximations for symbolic expressions
William Stein wrote: > On Fri, Oct 10, 2008 at 7:11 AM, Jason Grout > <[EMAIL PROTECTED]> wrote: >> How do I get a numeric approximation for symbolic expressions that have >> variables? I want to leave the variables alone, but get numeric >> approximations for all constants. For example, here's how it works in >> mathematica: >> >> In[1]:= a:=1+Sqrt[2]*x >> >> In[2]:= a >> >> Out[2]= 1 + Sqrt[2] x >> >> In[3]:= N[a] >> >> Out[3]= 1. + 1.41421 x >> >> >> However, the corresponding thing does not work in Sage: >> >> sage: a=1+sqrt(2)*x >> sage: a >> sqrt(2)*x + 1 >> sage: n(a) >> --- >> TypeError Traceback (most recent call last) > > For polynomials, do this: > > sage: f = 1 + sqrt(2)*x > sage: f.polynomial(RDF) > 1.41421356237*x + 1.0 Aah, thanks. I guess I also now see the f.series command, which does what I originally wanted as well (lets me specify the ring for the coefficients to the series approximation). The general request still stands, though: is there a way to numerically approximate all the constants in a symbolic expression, but keep the variables as variables? Thanks, Jason --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: numeric approximations for symbolic expressions
On Fri, 10 Oct 2008 10:35:16 -0500 Jason Grout <[EMAIL PROTECTED]> wrote: > The general request still stands, though: is there a way to > numerically approximate all the constants in a symbolic expression, > but keep the variables as variables? The pynac based symbolics code does the following: sage: x,y,z = var("x y z", ns=1) sage: t = 1 + sqrt(2)*x + sin(x) sage: t.n() sin(x) + (1.4142135623730951)*x + 1.0 This is with the bundle at #3872 and patches at #4244 applied, and the package at #4243. Cheers, Burcin --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: numeric approximations for symbolic expressions
Burcin Erocal wrote: > On Fri, 10 Oct 2008 10:35:16 -0500 > Jason Grout <[EMAIL PROTECTED]> wrote: > >> The general request still stands, though: is there a way to >> numerically approximate all the constants in a symbolic expression, >> but keep the variables as variables? > > The pynac based symbolics code does the following: > > sage: x,y,z = var("x y z", ns=1) > sage: t = 1 + sqrt(2)*x + sin(x) > sage: t.n() > sin(x) + (1.4142135623730951)*x + 1.0 > > This is with the bundle at #3872 and patches at #4244 applied, and the > package at #4243. Nice. That's exactly what I was wanting. Chalk me up as one more person eager to get this in shape and into Sage. Thanks, Jason --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: numeric approximations for symbolic expressions
On Oct 10, 10:02 am, Jason Grout <[EMAIL PROTECTED]> wrote: > Burcin Erocal wrote: > > On Fri, 10 Oct 2008 10:35:16 -0500 > > Jason Grout <[EMAIL PROTECTED]> wrote: > > >> The general request still stands, though: is there a way to > >> numerically approximate all the constants in a symbolic expression, > >> but keep the variables as variables? > > > The pynac based symbolics code does the following: > > > sage: x,y,z = var("x y z", ns=1) > > sage: t = 1 + sqrt(2)*x + sin(x) > > sage: t.n() > > sin(x) + (1.4142135623730951)*x + 1.0 > > > This is with the bundle at #3872 and patches at #4244 applied, and the > > package at #4243. > > Nice. That's exactly what I was wanting. Chalk me up as one more > person eager to get this in shape and into Sage. Yep, it is certainly the highest priority ticket for 3.2 and 3.1.3 has unfortunately delayed longer than planned. I plan to do 3.1.3.rc0 tonight and unless something major happens it should be very close to final. Then we can open 3.2 during the coding sprint at SD 10 here at Loria. > Thanks, > > Jason Cheers, Michael --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] math range error on sqrt()
Hi, I'm working with a biologist on some data, and having trouble getting SAGE to solve quadratic polynomials with complicated coefficients. Using solve() returns nothing even when there is a solution, perhaps because sqrt() returns a "math range error". Does anyone have any advice on how to get around this? thanks john perry --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: math range error on sqrt()
Hi John, On Fri, Oct 10, 2008 at 10:36 PM, john_perry_usm <[EMAIL PROTECTED]> wrote: > I'm working with a biologist on some data, and having trouble getting > SAGE to solve quadratic polynomials with complicated coefficients. > Using solve() returns nothing even when there is a solution, perhaps > because sqrt() returns a "math range error". > > Does anyone have any advice on how to get around this? Are you able to post a snippet of code to reproduce the problem? That would help a lot in trying to figure out what is going on. --Mike --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: jsMath issue and solution with error code -7
Thanks! On Aug 24, 8:46 am, "Philippe Saade" <[EMAIL PROTECTED]> wrote: > Hi, > > i post this here for future newbies who might encounter the same problem... > > ** on Linux/Ubuntu 8.04, under Firefox 2 or 3, with all TexFonts > installed, i kept having this error message : > > It looks like jsMath failed to set up properly (error code -7) > > for a single > sage : show(x^2) > > command. > > My solution was to : > > * mkdir -p /home/foobar/.fonts (for user foobar) > * download on of the zip file here > :http://www.math.union.edu/~dpvc/jsMath/download/jsMath-fonts.html > (the TeX-fonts-15.zip looks not too dark.) > * unzip the .zip > * restart firefox > * (adjust scale size in the options of jsMaths control panel to suit my taste) > > Philippe --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: jsMath issue and solution with error code -7
Doug Bradshaw wrote: > Thanks! > > On Aug 24, 8:46 am, "Philippe Saade" <[EMAIL PROTECTED]> wrote: >> Hi, >> >> i post this here for future newbies who might encounter the same problem... >> >> ** on Linux/Ubuntu 8.04, under Firefox 2 or 3, with all TexFonts >> installed, i kept having this error message : >> >> It looks like jsMath failed to set up properly (error code -7) >> >> for a single >> sage : show(x^2) >> >> command. >> >> My solution was to : >> >> * mkdir -p /home/foobar/.fonts (for user foobar) >> * download on of the zip file here >> :http://www.math.union.edu/~dpvc/jsMath/download/jsMath-fonts.html >> (the TeX-fonts-15.zip looks not too dark.) >> * unzip the .zip >> * restart firefox >> * (adjust scale size in the options of jsMaths control panel to suit my >> taste) >> We really ought to include these fonts with Sage and have the error message say: "Here are some fonts. Install them. If you want darker or lighter variations, go here (link to the website)" Jason --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: jsMath issue and solution with error code -7
On Oct 10, 1:55 pm, Jason Grout <[EMAIL PROTECTED]> wrote: > We really ought to include these fonts with Sage and have the error > message say: "Here are some fonts. Install them. If you want darker or > lighter variations, go here (link to the website)" #1608 :) > Jason Cheers, Michael --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: math range error on sqrt()
Sure. This fails in exactly the fashion I mean: sage: round(sqrt(1)) I made this example up, but it gives you an idea of what I'm working with. On Oct 10, 3:38 pm, "Mike Hansen" <[EMAIL PROTECTED]> wrote: > Hi John, > > On Fri, Oct 10, 2008 at 10:36 PM, john_perry_usm <[EMAIL PROTECTED]> wrote: > > I'm working with a biologist on some data, and having trouble getting > > SAGE to solve quadratic polynomials with complicated coefficients. > > Using solve() returns nothing even when there is a solution, perhaps > > because sqrt() returns a "math range error". > > > Does anyone have any advice on how to get around this? > > Are you able to post a snippet of code to reproduce the problem? That > would help a lot in trying to figure out what is going on. > > --Mike --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: numeric approximations for symbolic expressions
Burcin Erocal wrote: > On Fri, 10 Oct 2008 10:35:16 -0500 > Jason Grout <[EMAIL PROTECTED]> wrote: > >> The general request still stands, though: is there a way to >> numerically approximate all the constants in a symbolic expression, >> but keep the variables as variables? > > The pynac based symbolics code does the following: > > sage: x,y,z = var("x y z", ns=1) > sage: t = 1 + sqrt(2)*x + sin(x) > sage: t.n() > sin(x) + (1.4142135623730951)*x + 1.0 > > This is with the bundle at #3872 and patches at #4244 applied, and the > package at #4243. Is there any chance this could be merged into 3.1.3 to get wider testing? That is, if it's a purely optional framework. Barring that, is there a chance we could get a single huge patch that consolidates all of this, or even just a single patch that contains the changes in the bundle? Thanks, Jason --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: math range error on sqrt()
Try adding another 1. Apparently I copied & pasted the wrong one. On Oct 10, 6:01 pm, Marshall Hampton <[EMAIL PROTECTED]> wrote: > I just get: > 1.05409255339e+154 > when I input your example. > > -M. Hampton > > On Oct 10, 5:24 pm, john_perry_usm <[EMAIL PROTECTED]> wrote: > > > Sure. This fails in exactly the fashion I mean: > > sage: > > round(sqrt(1)) > > > I made this example up, but it gives you an idea of what I'm working > > with. > > > On Oct 10, 3:38 pm, "Mike Hansen" <[EMAIL PROTECTED]> wrote: > > > > Hi John, > > > > On Fri, Oct 10, 2008 at 10:36 PM, john_perry_usm <[EMAIL PROTECTED]> > > > wrote: > > > > I'm working with a biologist on some data, and having trouble getting > > > > SAGE to solve quadratic polynomials with complicated coefficients. > > > > Using solve() returns nothing even when there is a solution, perhaps > > > > because sqrt() returns a "math range error". > > > > > Does anyone have any advice on how to get around this? > > > > Are you able to post a snippet of code to reproduce the problem? That > > > would help a lot in trying to figure out what is going on. > > > > --Mike --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: numeric approximations for symbolic expressions
On Oct 10, 3:48 pm, Jason Grout <[EMAIL PROTECTED]> wrote: > Is there any chance this could be merged into 3.1.3 to get wider > testing? That is, if it's a purely optional framework. Barring that, > is there a chance we could get a single huge patch that consolidates all > of this, or even just a single patch that contains the changes in the > bundle? Nope, I don't see this happening until I a) valgrind the new doctests b) build it on Cygwin, Solaris, Linux/Itanium and G4/G5 on OSX 10.4 and 10.5 and have all doctests pass and the doctests pass. ghmm has taught me that just because it mostly works and there is only a couple allegedly easy bugs to fix a patch like that can still hold up a release for an extended amount of time (2 weeks in 3.1.2 in my guesstimation). And those bugs in ghmm on Itanium are still not fixed, but we did disable doctests globally in those two files in order to make the doctests pass. 3.1.3 is supposed to be out soon, i.e. before the SD 10 coding sprint, and I am not willing to take the risk of pynac's integration bundle. > Thanks, > > Jason Cheers, Michael --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: math range error on sqrt()
I just get: 1.05409255339e+154 when I input your example. -M. Hampton On Oct 10, 5:24 pm, john_perry_usm <[EMAIL PROTECTED]> wrote: > Sure. This fails in exactly the fashion I mean: > sage: > round(sqrt(1)) > > I made this example up, but it gives you an idea of what I'm working > with. > > On Oct 10, 3:38 pm, "Mike Hansen" <[EMAIL PROTECTED]> wrote: > > > Hi John, > > > On Fri, Oct 10, 2008 at 10:36 PM, john_perry_usm <[EMAIL PROTECTED]> wrote: > > > I'm working with a biologist on some data, and having trouble getting > > > SAGE to solve quadratic polynomials with complicated coefficients. > > > Using solve() returns nothing even when there is a solution, perhaps > > > because sqrt() returns a "math range error". > > > > Does anyone have any advice on how to get around this? > > > Are you able to post a snippet of code to reproduce the problem? That > > would help a lot in trying to figure out what is going on. > > > --Mike --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: math range error on sqrt()
On Oct 10, 4:04 pm, john_perry_usm <[EMAIL PROTECTED]> wrote: > Try adding another 1. Apparently I copied & pasted the wrong one. > I can reproduce it on a 64 bit box: sage: round(sqrt(1 )) 1.05409255339e+154 sage: round(sqrt(1 1)) --- OverflowError Traceback (most recent call last) /scratch/mabshoff/release-cycle/sage-3.1.3.rc0/ in () /scratch/mabshoff/release-cycle/sage-3.1.3.rc0/local/lib/python2.5/ site-packages/sage/misc/functional.pyc in round(x, ndigits) 845 else: 846 try: return x.round() --> 847 except AttributeError: return RealDoubleElement(__builtin__.round(x, 0)) 848 849 def quotient(x, y, *args, **kwds): /scratch/mabshoff/release-cycle/sage-3.1.3.rc0/local/lib/python2.5/ site-packages/sage/calculus/calculus.pyc in __float__(self) 6201 f = self._operands[0] 6202 g = self._operands[1] -> 6203 return float(f._approx_(float(g))) 6204 6205 def _fast_float_(self, *vars): /scratch/mabshoff/release-cycle/sage-3.1.3.rc0/local/lib/python2.5/ site-packages/sage/calculus/calculus.pyc in _approx_(self, x) 7978 7979 def _approx_(self, x): -> 7980 return math.sqrt(x) 7981 7982 sqrt = Function_sqrt() OverflowError: math range error The issue seems to be that RealDoubleElement() cannot deal with a value that large since it overflows the range that float provides. Cheers, Michael --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Problem w/ min or me?
Given the following input; sage: var('x') sage: var('y') sage: e1 = (y + x + 2) sage: e2 = (y - x^2 + 2*x + 3) sage: e3 = (y + x + 42) sage: e4 = min(e1, e2, e3) sage: e4(-10, -10) I get the result -18. (the value of e1(-10, -10) I would expect to get -127 (the value of e2(-10,-10) I want the smallest value selected from the 3 equations at the specified point. Am I using the wrong sort of min function? What should be using? If it is the wrong min - What is the min I am using used for? mcdewey --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Problem w/ min or me?
I am using version; 'SAGE Version 3.1.2, Release Date: 2008-09-19' mcdewey --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Problem w/ min or me?
mcdewey wrote: > Given the following input; > sage: var('x') > sage: var('y') > sage: e1 = (y + x + 2) > sage: e2 = (y - x^2 + 2*x + 3) > sage: e3 = (y + x + 42) > sage: e4 = min(e1, e2, e3) > sage: e4(-10, -10) > > I get the result -18. (the value of e1(-10, -10) > > I would expect to get -127 (the value of e2(-10,-10) > typing sage: e4 y+x+4 shows the problem. min is a builtin python function and isn't smart about symbolic functions; it just returns the first thing when it comes to symbolic expressions: sage: var("x,y") sage: min(x,y) x sage: min(y,x) y > I want the smallest value selected from the 3 equations at the > specified point. I would do this like: sage: min(f(-10,-10) for f in [e1,e2,e3]) -127 In other words, evaluate the functions before calling min. Jason --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Problem w/ min or me?
> min is a builtin python function and isn't smart > about symbolic functions; it just returns the first thing when it comes > to symbolic expressions: > ... > I would do this like: > > sage: min(f(-10,-10) for f in [e1,e2,e3]) > -127 > > In other words, evaluate the functions before calling min. > > Jason Thanks - that explains the problem but doesn't quite get where I wanted to go. Is there a version of min that understands symbolic functions? I would like to be able to send the resulting equation to plot3d. Mcdewey --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Problem w/ min or me?
mcdewey wrote: >> min is a builtin python function and isn't smart >> about symbolic functions; it just returns the first thing when it comes >> to symbolic expressions: >> > ... >> I would do this like: >> >> sage: min(f(-10,-10) for f in [e1,e2,e3]) >> -127 >> >> In other words, evaluate the functions before calling min. >> >> Jason > > Thanks - that explains the problem but doesn't quite get where I > wanted to go. > Is there a version of min that understands symbolic functions? > I would like to be able to send the resulting equation to plot3d. You could define a function that calls the min: def mymin(x,y): return min(f(-10,-10) for f in [e1,e2,e3]) Then plot mymin. Jason --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] making an animation of an @interact
(this might be mainly directed towards schilly): Is there an easy way to make an animation of an @interact as a slider goes through its values? Something like schilly's Taylor Series interact at http://wiki.sagemath.org/interact/calculus. Thanks, Jason --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Sage doctest randomness
On Oct 10, 5:45 pm, [EMAIL PROTECTED] wrote: > Ryan Hinton wrote: > > Jason, > > > I saw a suggestion recently on the sage list to set the random seed at > > the beginning of each doctest so previously "random" outputs could be > > tested. I'm writing some 'pick a random member from this (very large) > > set' routines, so I could use this functionality. Is it in yet? How > > can I set the random seed (inside my doctest)? > > > Thanks! > > I think Carl Witty wrote this functionality (I've CCd him). I think it > is in now, but he knows the details of how to use it. Quick summary: The random seed is automatically set at the beginning of each docstring. If you're using the standard Sage random number routines (like ZZ.random_element(), or the combinatorics random elements, etc.), then you shouldn't have to do anything to make your doctest repeatable. If you do want to set a random seed inside your docstring (or at the Sage command line), use sage: set_random_seed(0) (or pick another number instead of the 0). For more details, there's about 400 lines of documentation at the top of sage/misc/randstate.pyx; I don't want to repeat it all here :) Carl --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: Sage doctest randomness
Ryan Hinton wrote: > Jason, > > I saw a suggestion recently on the sage list to set the random seed at > the beginning of each doctest so previously "random" outputs could be > tested. I'm writing some 'pick a random member from this (very large) > set' routines, so I could use this functionality. Is it in yet? How > can I set the random seed (inside my doctest)? > > Thanks! > I think Carl Witty wrote this functionality (I've CCd him). I think it is in now, but he knows the details of how to use it. I'm also forwarding this to sage-support, since it's an answer I'm sure more people would like to hear. Thanks, Jason --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---