[sage-support] Re: How to plot regions defined by inequalities in 3D?

2010-07-12 Thread Carl Witty
On Jul 12, 2:28 am, David Sanders  wrote:
> Hi,
>
> I have been playing around with the implicit_plot3d command, and it's
> very nice.
>
> Is there something similar to plot regions defined by inequalities in
> 3D, along the lines of the Mathematica
> RegionPlot3D command?  I see that there is an old discussion from 2
> years ago about this.
>
> It seems to me (in my ignorance) that the kind of algorithm required
> to do this should not be too different from that for implicit_plot3d
> with the region option. (Though implicit_plot3d draws surfaces,
> whereas region_plot3d would draw volumes. But apparently the marching
> cubes algorithm is used for both?)

I haven't looked at this stuff in more than a year, but I think this
is all accurate:

Our plotting framework doesn't really "understand" volumes, only
surfaces.  So it would be a major overhaul to produce a plot that
showed (via some sort of volumetric shading, say) the difference
between the "inside" and the "outside" of your region.

However, if you want to produce a plot of the surface of your region,
that's pretty easy.  If your region is defined by a single inequality
F(x,y,z)<0, then you can just implicit_plot3d F(x,y,z).  If your
region is defined as a boolean combination of inequalities, then
arrange all the inequalities to be of the form F(x,y,z) < 0, then drop
all the "< 0", replace "and" with "max_symbolic", replace "or" with
"min_symbolic", and replace "not F(x,y,z)" with "-F(x,y,z)".  Also,
when you plot, because of http://trac.sagemath.org/sage_trac/ticket/9483
you need to add "smooth=False".

Here's a complete example.  This forms the intersection between a cube
and the union of two cylinders.

sage: var('x,y,z')
(x, y, z)
sage: implicit_plot3d(max_symbolic(min_symbolic(x*x+y*y-1, x*x+z*z-2),
x-1.8, y-1.8, z-1.8, -x-1.8, -y-1.8, -z-1.8), (x, -2, 2), (y, -2, 2),
(z, -2, 2), smooth=False)

It would be great to put all of this into a region_plot3d command, but
as far as I know, Sage does not yet support symbolic conjunctions and
disjunctions ("and"s and "or"s); so it would be difficult to tell
region_plot3d about any region more complicated than a single
inequality.

Carl

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


[sage-support] Re: jmol problem

2009-04-04 Thread Carl Witty

On Apr 3, 10:14 pm, William Stein  wrote:
> 2009/4/3 Timothy Clemans :
>
>
>
> > I get the same. This historically has been a problem with the public
> > notebook(s).
>
> I 100% disagree.   This has *not* historically been a problem with the
> public notebooks. I have used them millions of times with numerous
> browsers from many places to draw 3d plots using jmol.
>
> I just did the same plot on another public notebook server (on the
> same machine) and it works fine:
>
>    http://demo2.sagenb.org/home/pub/3/
>
> There is a serious problem with the Linux install (or vmware virtual
> machine) that currently hosts sagenb.org, which manifest itself about
> 2 days ago -- for some reason the OS is randomly killing processes.
> This could be the result of some sort of attack, or just some other
> problem; I don't know.   That's probably what is responsible for your
> graph at sagenb.org to not work.  I'm actually very 
> surprisedhttp://sagenb.orgis working at all.

One reason for the OS to "randomly kill processes" is the Linux out-of-
memory killer (OOM killer for short).  Is there any chance that
sagenb.org is running out of RAM?  Are there any interesting messages
if you log in and type "dmesg"?

Actually, I just realized I could check this for myself, so I did... I
don't see anything about the OOM killer, but there is a recurring,
strange error message about "BUG: soft lockup - CPU#0 stuck for 11s!
[python:8525]".  I don't know what this means, or if it has anything
to do with this problem.

Carl
--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: Strange behavior on sagenb

2009-03-28 Thread Carl Witty

On Mar 28, 8:59 am, William Stein  wrote:
> I know of one place in sage where objects cache their hash for
> efficiency reasons (e.g., I think Sage matrices do). I hadn't thought
> about the fact that pickling, moving to an object to a platform where
> the hashes are different, and unpickling, would result in the subtle
> issue above, but that makes sense.   Here is an example:
>
> On a 32-bit platform do this:
>
> sage: a = matrix(ZZ,2,[1,-2,4,1993938292]); a.set_immutable(); b =
> {a:5}; save(b,'/Users/wstein/b.sobj')
>
> Then load b on a 64-bit platform (e.g. ,sage.math):
>
> sage: a = matrix(ZZ,2,[1,-2,4,1993938292]); a.set_immutable(); b =
> load('b.sobj'); b[a]
> boom! KeyError ...
> sage: sage: b.keys()[0] == a
> True
>
> The fix here is that right before pickling the cached hash of the
> matrix should be deleted.
>
> I don't know any other places in Sage that do the above.

This also happens (at least) in combinat/; see the __hash__
implementation in combinat/combinat.py

> This is now
>
>    http://trac.sagemath.org/sage_trac/ticket/5624

I've mentioned this on the ticket, as well.

Carl

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: python's list comprehension

2009-03-21 Thread Carl Witty

On Mar 20, 5:52 pm, Nils Bruin  wrote:
> sage: DB = CremonaDatabase()
> sage: L = [ N.str()+c[0] for N in (lambda l: xrange(l[0],l[1]))
> (DB.conductor_range()) for c in DB.allbsd(N).items() if
>                  round(RDF(c[1][4]))%81 == 0]
...
>  - the whole lambda expression to make the pair output by
> DB.conductor_range() into an iterable. Is there a syntactically more
> pleasing construct in python for that?
> (for instance variables local to expressions. In Magma speak: "[a..b]
> where (a,b)=DB.conductor_range()")

Note that you're skipping the last conductor in the database, I
think... DB.conductor_range? indicates that the returned values
represent an inclusive range, but range/xrange/etc. take their second
argument as an exclusive bound.  (This is easy to fix with the above
xrange expression, but I don't see how to fix it with the simple *args
syntax.)

Carl

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: Testing whether a function is always positive

2009-03-19 Thread Carl Witty

On Mar 19, 7:51 am, PaulBurk  wrote:
> Hi all,
>
> I'm working on a project, and my professor suggest I post a question
> here.
>
> I'm trying to use programs such as Mathematica, Maple and Sage to test
> whether a function is always positive.  Maple has an "is" command,
> which can be used to test some properties.  Sometimes it is
> sufficient, other times it fails.
>
> Does Sage have anything like an "is" command?  Is there any other way
> to test if a function is always positve/negative?

What sort of function?  With one argument or multiple arguments?  For
arbitrary functions (involving trig, exponents, etc.), I'm pretty sure
that it's provably impossible to always decide whether a function is
always positive, so the best any system can do is apply some
heuristics that work for some functions but not others.

For univariate or multivariate polynomials (with rational
coefficients), it's always possible in theory to determine whether a
function is positive everywhere, although I don't know of a method
that's usable in practice if there's more than a few variables.

Carl
--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: Images in TinyMCE

2009-03-17 Thread Carl Witty

On Mar 17, 4:54 pm, kcrisman  wrote:
> > TinyMCE doesn't upload files (at least, not with what we've done with
> > it).  You have to upload your files separately from TinyMCE.
>
> I see!  So if I use TinyMCE to put an image from the web in my
> notebook without putting it in Data, then presumably when I disconnect
> from the web, the image disappears?  This would sound more consistent,
> though it still doesn't explain why the URL file:///etc doesn't
> work...

It's probably a security feature in your web browser.  If remote web
pages could load file:/// URLs, then somebody could make a web page
that probes your hard drive and reports what it finds to the web
server.

Carl

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: public worksheet, and methods for exporting

2009-03-13 Thread Carl Witty

On Mar 13, 11:58 am, Pierre  wrote:
> >  Note that sagenb.org is not
> > designed to support classes as a class sage server; rather, it's
> > designed to give a person a way to try out Sage.
>
> Is there anything wrong with many people (that is, about 30) checking
> a public worksheet at the same time ? should we refrain from letting
> the students do that ?

Do you mean just looking at http://.../pub/nnn/, without doing "edit a
copy"?  I'm pretty sure that's fine.  The expensive part of editing a
worksheet is starting up a separate copy of Sage on the server; public
worksheets don't do that (which is why @interact doesn't work), so
viewing a public worksheet causes vastly less server load than editing
a worksheet.

(I hope this is correct... I'm not an expert on the notebook
internals.)

Carl

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: Cannot copy on OSX

2009-03-13 Thread Carl Witty

On Mar 13, 11:02 am, mabshoff  wrote:
> On Mar 13, 10:55 am, kcrisman  wrote:
> > Any ideas?
>
> The build box where that binary is being build had some changes to the
> file system layout, i.e. William might have build on an NFS mount
> instead of a local file system. I did a build on a local file system,
> so once I find some time I will get that binary uploaded to test if it
> makes a difference.

It looks like the build was done on a case-sensitive filesystem,
probably?

Carl

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: coercion bug?

2009-03-11 Thread Carl Witty

On Mar 11, 2:55 pm, Alex Raichev  wrote:
> > > Well, I think I can explain what's happening.  There's a coercion from
> > > arbitrary polynomials into the Symbolic Ring; this is useful, because
> > > it lets you deal with polynomials over the rationals, etc.
>
> Similarly, i think a coercion from QQbar and polynomials over QQbar to
> the Symbolic Ring would be useful.  At least it is in my work.  What
> do you all think?  As it stands Sage gives the error below.

What would you want to do with QQbar in the Symbolic Ring?  I don't
know how to pass an arbitrary element of QQbar to maxima (but I don't
know much about maxima); does maxima deal with arbitrary algebraic
numbers?

Carl

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: Maxima not able to multiply functions with complex numbers

2009-03-11 Thread Carl Witty

On Mar 11, 10:47 am, Mani chandra  wrote:
> Also I tried some basic stuff with "I" and it doesn't seem to be working.
>
> sage: exp(I).real
> 

Sage prefers methods to properties:

sage: exp(I).real()
cos(1)

Using

z = exp(I*r*cos(theta)).real()

makes your parametric_plot3d work, too.

Carl

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: coercion bug?

2009-03-10 Thread Carl Witty

On Mar 10, 6:47 pm, Alex Raichev  wrote:
> Does anyone know what's up with this weird error?  Sage can multiply a
> symbolic variable and a constant of a polynomial ring R but not a
> symbolic variable and an element of R.base_ring().
>
> Alex
>
> sage: var('t')
> t
> sage: K.= NumberField(t^2+2,'a')
> sage: R.= PolynomialRing(K)
> sage: t*R(a)
> a*t
> sage: t*a
> ---
> TypeError                                 Traceback (most recent call
> last)

Well, I think I can explain what's happening.  There's a coercion from
arbitrary polynomials into the Symbolic Ring; this is useful, because
it lets you deal with polynomials over the rationals, etc.  There's no
coercion from number fields into the Symbolic Ring, because the
Symbolic Ring can't do anything useful with them.

When you do t*R(a), that's exactly equivalent to var('a,t'); t*a.  The
fact that a is a number field generator is lost, and it just becomes a
symbolic variable.  (In particular, you'll notice that t*R(a)^2
doesn't reduce the a^2.)

Since t*R(a) is so useless, it would be better if it didn't work; I'm
not sure how hard it would be to change the coercion setup there,
though.

Carl
--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: Turning display of parents on and off

2009-03-06 Thread Carl Witty

On Mar 6, 3:02 pm, Alasdair  wrote:
> However, it doesn't work.  In console mode show_parent() should turn
> the display of parents on, and hide_parent() should turn it off.  It
> seems to work once - but not again.  That is, parent display can be
> turned on, and then off, but not on again - show_parent() has no
> effect after one "cycle". I'm not quite sure what's going on - my
> python knowledge is limited.  And sometimes when parent display is on,
> hide_parent() has no effect.
>
> Any ideas?

This is because .set_hook() pushes your function onto a list of
handlers; the first handler in the list that does not raise a TryNext
exception is used.  So you keep adding more and more copies of
repr_and_parent and repr_only onto the list.

Here's a variant that works for me (in limited testing).

import IPython
from IPython import ipapi
from IPython.genutils import Term
from pprint import PrettyPrinter

pformat = PrettyPrinter().pformat

_show_parent_mode = False

def _maybe_show_parent(self, arg):
if _show_parent_mode and hasattr(arg, 'parent'):
try:
print >>Term.cout, "%s\n\nParent: %s"%(repr(arg),repr
(arg.parent()))
return
except:
pass
raise ipapi.TryNext

ipapi.get().set_hook("result_display", _maybe_show_parent)

def show_parent():
global _show_parent_mode
_show_parent_mode = True

def hide_parent():
global _show_parent_mode
_show_parent_mode = False

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: Another variety() bug?

2009-03-03 Thread Carl Witty

On Mar 3, 3:02 pm, Alex Raichev  wrote:
> Maybe i'm beating a dead horse here, but i think the variety() command
> has another bug in it (different 
> fromhttp://trac.sagemath.org/sage_trac/ticket/4622
> ).  It crashes when working over number fields with the optional
> command 'ring=QQbar', possibly because it doesn't first embed the
> number field into QQbar.  Here are two examples.

I expect that fixing #5355 would fix this.

Carl

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: Hidden Issues in Optimization

2009-02-27 Thread Carl Witty

On Feb 27, 9:47 am, linuxgus  wrote:
> Can somebody shed some light on this and/or suggest alternative ways
> of doing this?

Well, when I try debugging this (that is, run your code, see it crash,
type: %debug to get into the debugger where I can run code), I see
that your function is returning a 150x1 array and it's being called in
a context that's expecting a scalar.

Carl

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: polynomial coercion bug?

2009-02-23 Thread Carl Witty

On Feb 23, 7:57 pm, Carl Witty  wrote:
> On Feb 23, 6:54 pm, Alex Raichev  wrote:
>
> > Carl, regarding the parenthetical remark of your first reply, are you
> > saying the coercion error for plain old monomials below is supposed to
> > happen?
>
> Well, I wouldn't say "supposed to happen" because I don't think this
> is the way it should stay long-term.  But yes, it's expected; that
> functionality is not yet implemented.

I've posted a wishlist request for coercions from number fields with
embedding into QQbar.

http://trac.sagemath.org/sage_trac/ticket/5355

Carl
--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: polynomial coercion bug?

2009-02-23 Thread Carl Witty

On Feb 23, 6:54 pm, Alex Raichev  wrote:
> Carl, regarding the parenthetical remark of your first reply, are you
> saying the coercion error for plain old monomials below is supposed to
> happen?

Well, I wouldn't say "supposed to happen" because I don't think this
is the way it should stay long-term.  But yes, it's expected; that
functionality is not yet implemented.

> If so, then what's the simplest way to take an element f of a
> polynomial ring R over a number field F and compute its embedded image
> in RR= R.change_ring(QQbar), supposing you have an embedding phi: F --> 
> QQbar?  Grab the coefficients of f, compute their images under phi,
>
> grab the monomials of f, redefine (not coerce) them in RR, and
> reassemble the pieces in RR?

Probably.  This was the shortest (probably not the clearest) way I
could quickly come up with to do the conversion.

sage: var('t')
t
sage: F. = NumberField(t^4+1)
sage: R. = F[]
sage: p = R.random_element()
sage: RR = R.change_ring(QQbar)
sage: phi = F.embeddings(QQbar)[0]
sage: gens = RR.gens()
sage: sum([phi(c) * prod([g^e for (g,e) in zip(gens, m.exponents()
[0])]) for (c,m) in p])
(-8.36396103067893? + 6.863961030678928?*I)*x*y + (-17.67731239591687?
- 10.86922437301290?*I)*y^2 + (-2.828427124746190? - 34.41421356237310?
*I)*x + (0.01611083391521890? + 0.1295048468845087?*I)*y -
11.07800623858925? - 4.978342947514801?*I

By the way, even if QQbar does get extended to support number fields
with embedding someday, it still won't handle the exact example in
your email because your number field doesn't have an embedding.

Carl
--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: polynomial coercion bug?

2009-02-19 Thread Carl Witty

On Feb 19, 10:16 pm, Carl Witty  wrote:
> There's a bug.  And, now that you've pointed out the bug, I figured
> out how to crash Sage with a segmentation fault; so it's a serious
> bug.  Thanks for reporting it!  This bug is now being tracked at
> http://trac.sagemath.org/sage_trac/ticket/5316

OK, I've posted a patch for the bug at that URL, and (assuming it gets
positively reviewed) the fix will be in Sage 3.3.

Carl



--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: polynomial coercion bug?

2009-02-19 Thread Carl Witty

On Feb 19, 7:59 pm, Alex Raichev  wrote:
> Hi all:
>
> I get an error when i try to coerce monomials of a multivariate
> polynomial ring over a number field to the corresponding polynomial
> ring over QQbar.  Shouldn't this work?  They're monomials; no
> coefficients.  Here's an example.
>
> Alex
>
> --
> | Sage Version 3.2.3, Release Date: 2009-01-05                       |
> | Type notebook() for the GUI, and license() for information.        |
> --
> sage: var('t')
> t
> sage: F= NumberField(t^2+1,'a')
> sage: R.= PolynomialRing(F,2,'xy')
> sage: print x.parent()
> Multivariate Polynomial Ring in x, y over Number Field in a with
> defining polynomial t^2 + 1
> sage: RR= R.change_ring(QQbar)
> sage: print RR(x).parent()
> ---
> TypeError                                 Traceback (most recent call
> last)

Yes, this should work.  (But currently only for NumberField(t^2+1,
'a'); that particular case is hardcoded into the QQbar coercion
mechanism, because QQbar was written before number fields had
embeddings, so it doesn't know which embedding to pick in general.)

There's a bug.  And, now that you've pointed out the bug, I figured
out how to crash Sage with a segmentation fault; so it's a serious
bug.  Thanks for reporting it!  This bug is now being tracked at
http://trac.sagemath.org/sage_trac/ticket/5316

Carl
--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: Using sage as default python distribution

2009-02-19 Thread Carl Witty

On Feb 19, 3:54 pm, Art  wrote:
> I would like to use the sage distribution as my default python
> distribution transparently. If I type python at the command line, I
> would like sage -python to be called and #/usr/bin/env python at the
> start of any script to call the sage python as well.
>
> How can I do this?
>
> Also, can I use easy_install with sage if an spkg doesn't exist? I
> have been downloading the source tarballs and doing sage -python setup
> install.

Try typing: sage -sh
This will put you "inside" the Sage environment, with all your paths,
environment variables, etc. set up to use Sage's python, libraries,
etc.

I think that easy_install will just work (and do what you want) in
that environment.

Carl
--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: Cannot pretty print in sage

2009-02-17 Thread Carl Witty

On Feb 17, 1:09 pm, Jason Grout  wrote:
> schmmd wrote:
> > I don't seem to be able to pretty print in sage.  I remember doing
> > this in class, but the pretty_print function gives the error "It looks
> > like jsMath failed to set up properly (error code -7).  I will try to
> > keep going, but it could get ugly." when I use it in the notebook
> > through vmware or the notebook on one of the public web servers.  Am I
> > doing anything wrong?  How can I, for example, print a matrix with
> > latex formatting?
>
> You are doing things correctly.  You just need to install some fonts.
> See http://wiki.sagemath.org/faq#IgetanerrorfromjsMathorthemathsymbolsdon...

Where does this error message come from?  How hard would it be to
change it to refer to
http://wiki.sagemath.org/faq#IgetanerrorfromjsMathorthemathsymbolsdon.27tlookrightwhendisplayinginthenotebook
?

(I think this might be worth doing even if it requires patching
jsMath.)

Carl
--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: Conjugates

2009-02-09 Thread Carl Witty

On Feb 8, 12:52 pm, William Stein  wrote:
> Since you're lucky and all conjugates are expressible in terms of
> radicals, the following
> easily gives all 8:
>
> sage: t = sqrt(2-sqrt(2)) + i*sqrt(sqrt(2)-1)
> sage: f = t.minpoly(); f
> x^8 - 12*x^6 + 6*x^4 - 12*x^2 + 1

Do you really need radicals, or do you just want exact results rather
than floating-point approximations?

If the latter, you can use:

sage: t = sqrt(2-sqrt(2)) + i*sqrt(sqrt(2)-1)
sage: f = t.minpoly(); f
x^8 - 12*x^6 + 6*x^4 - 12*x^2 + 1
sage: f.roots(ring=QQbar, multiplicities=False)

[-0.2939850909925362?,
 0.2939850909925362?,
 3.401533039052611?,
 -3.401533039052611?,
 0.7653668647301795? + 0.6435942529055826?*I,
 0.7653668647301795? - 0.6435942529055826?*I,
 -0.7653668647301795? + 0.6435942529055826?*I,
 -0.7653668647301795? - 0.6435942529055826?*I]

While elements of QQbar usually print as floating-point
approximations, operations with them are actually exact.

Carl

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: What is the difference between double and single quotes?

2009-02-03 Thread Carl Witty

On Feb 2, 10:38 pm, Andrey Novoseltsev  wrote:
> Hello,
>
> I was sure there is no difference in Python and Sage. However, when I
> try to return "I_0" in _latex_ function of my class, it typesets as
> I_0, because somehow it gets wrapped into \text{I\_0}. When I change
> the return value to 'I_0' everything works as expected. Why is it so
> and are there other differences?

I was also sure that there was no difference, so this doesn't make
sense to me.

Are you sure that's the only thing you changed?

Are you calling the _latex_ method directly to test this, or how are
you testing?

Carl
--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: How can I make a topographic map with Sage?

2009-01-29 Thread Carl Witty

On Jan 29, 5:32 pm, Sage  wrote:
> Is Sage suitable for topography? I have collected the data of a see,
> discreate data points. I need to make regressions on the data. Then, I
> think the contour plot creates the final topographic map. Or am I
> wrong? How are topographic maps dene in Sage? Can I give the data as
> an input and get the map back as an output?

Maybe the contour_plot function (type contour_plot? for documentation)
will be helpful?

Carl

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: functions in list comprehensions

2009-01-23 Thread Carl Witty

On Jan 23, 8:43 pm, kcrisman  wrote:
> But this whole thread was quite helpful to review the four (!)
> possibilities for doing evaluation: Maxima, ns, _fast_float_, and ring
> creation.  Thanks!

Well, if you're making that list, you should also include Python:

def f(x, y):
return x^2 + y^2 - 1

or, in a .py file (without the preparser):

def f(x, y):
return x**2 + y**2 - 1

Or for blazing speed, you should be able to put this in a notebook
cell (untested):

%cython
def f(int x, int y):
return x*x + y*y - 1

Carl

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: functions in list comprehensions

2009-01-23 Thread Carl Witty

On Jan 23, 2:18 pm, Robert Bradshaw 
wrote:
> One thought I had was that support for a wide variety of types could  
> be done by manipulating function pointers. This would make it easy to  
> give support for a wide variety of types without a lot of specialized  
> work.

Function pointers are far too slow; I'm going for speed.

Don't worry; a lot of the work in the new version is a generic type
support framework that indeed (hopefully) makes it easy to add more
types without too much work.

Carl

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: functions in list comprehensions

2009-01-23 Thread Carl Witty

On Jan 23, 1:43 pm, Robert Bradshaw 
wrote:
> > 3) I'm (still!) rewriting fast_float; one of the goals of the eventual
> > rewrite is to have a mode that uses Sage objects instead of floating-
> > point numbers (of course, this is much, much slower than the floating-
> > point mode, but it's still quite a bit faster than calling out to
> > maxima).  If I ever finish the rewrite, then perhaps symbolic
> > functions could use this mode automatically.
>
> How is this going? I hadn't heard any more on it, so I wondered if  
> you were still working on it.

I'm almost at feature parity with the original fast_float, at which
point I plan to submit it.  (Within the next month or so, if I manage
to keep working at it reasonably steadily.)

This version would have interpreters for C doubles (like the existing
fast_float), MPFR, and Python objects.  It's also significantly faster
than the existing fast_float interpreter.  It will not yet support the
extra features I was promising (conditionals, common subexpression
elimination); I also plan to eventually add special handling for a lot
more types.

Carl

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: functions in list comprehensions

2009-01-23 Thread Carl Witty

On Jan 23, 6:06 am, kcrisman  wrote:
> Concluding unscientific postscript:
>
> This brings up a question I have asked before, about when to use
> (e.g.) _fast_float_ or polynomial rings or whatever... Is there a
> heuristic for when this should be done in *ordinary* code, i.e. not
> intended for inclusion in Sage and maybe even written in five minutes
> for class?  It's clearly not always worth it or it would be
> ubiquitous, and I am puzzled as to why I needed it here (only 49
> points, right?).

There's actually a couple of questions here:  when is it worth it, and
when is it safe?

It looks like substitution for maxima-based symbolics is so
pathetically slow (calling into maxima) that _fast_float_ would always
be worth it.  But there's a good reason not to do it automatically,
anyway: it wouldn't be safe.

_fast_float_ is safe in your example, since you're doing arithmetic
with not-huge integers, and floating-point numbers can do arithmetic
with not-huge integers exactly.  But with a slight variant of your
problem that involved division or rational numbers, changing to
_fast_float_ could change the answers you get.  So, unfortunately, we
can't just automatically use it every time you do a symbolic function
call.

I wonder if the very-slow times here are a bug... it looks like
there's code in calculus.py that's supposed to be able to do this sort
of thing without calling out to maxima, so I'm not sure why it's using
maxima at all.  If that is a bug, and the bug were fixed, then it
might turn out that _fast_float_ is only worth it if you're evaluating
the function a dozen times, or a hundred times, or something.

> Let me put it a slightly more pungent way, with respect.  Suppose I am
> potential educational Sage user X, with not much time or programming
> experience but willing to try anything if it might help.  I try the
> thing in the first email, and it really bites.  Since I am only a
> potential Sage user, and I am not likely to email the support list
> (there are a lot of these, in my anecdotal experience), I just decide
> Sage isn't very useful for me and stick with my other options -
> whether those are Ms or just not using computers in class, which after
> all worked quite well for hundreds of years.  Will the pynac symbolics
> take away all my problems, or will I still have to add this
> (completely incomprehensible to my students) _fast_float_ thing, and
> only that if I am persistent enough to find it by searching this
> group, the wiki, or the documentation for quite a while (assuming I
> didn't know that I was looking for something like this ahead of time)?

It's clear that the present situation is not ideal.  I doubt if pynac
symbolics will fix all your problems (for instance, if your car makes
a funny noise whenever you go over 50mph, I don't think pynac
symbolics will help).  Since I don't know what all your problems are,
let me focus on occasionally very slow symbolic computations in Sage.

I can see a few possible solutions here:

1) try to educate users to avoid the symbolics subsystem (use
polynomial rings, etc., instead)

2) make symbolic computations avoid maxima more (switch to pynac, or
fix bugs in calculus.py, if indeed there's a bug there)

3) I'm (still!) rewriting fast_float; one of the goals of the eventual
rewrite is to have a mode that uses Sage objects instead of floating-
point numbers (of course, this is much, much slower than the floating-
point mode, but it's still quite a bit faster than calling out to
maxima).  If I ever finish the rewrite, then perhaps symbolic
functions could use this mode automatically.

4) try to educate users more about _fast_float_ (better documentation,
etc.)

I don't know; does this answer your question at all?

Carl
--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: Can you make @interact have a variable # of input boxes...

2009-01-22 Thread Carl Witty

On Jan 22, 10:55 am, kcrisman  wrote:
> Luiz said:
>
> This worked for me, but it is definitely hackish and cumbersome. You
> basically define the function in a string, exec the string to create
> the function, and then use the function interact, instead using the
> decoration @interact. (I've read it is frowned up, but...)
> # first cell
> fields = ['a','b','c','d','e']
> init_values = [10,15,31,14,-5, 6]
> fields_def = ','.join(['%s=%d' % t for t in zip(fields,init_values)])
> fdef= 'def _(' + fields_def + '):\n' \
>     + '\tprint sum([' + ','.join(fields) + '])\n'
> print fdef   # just to check
> # second cell
> exec(fdef)
> interact(_)

I think it would be not too difficult to change @interact so that the
following worked:

fields = {'a': 10, 'b': 15, 'c': 31, 'd': 14, 'e': -5}
@interact(fields)
def _(**kwargs):
sum = 0
for fld_name in fields.iterkeys():
sum += kwargs[fld_name]
print sum

(It would be even easier if we picked a different name for this
variant of @interact.)

Would that be enough to satisfy the original requirements?  (I haven't
read the original thread, just the above message.)

Can people think of a better name for this variant of @interact?

Carl

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: how to compute GCD of huge polynomial with degree 2^300

2009-01-22 Thread Carl Witty

On Jan 21, 1:39 am, William Stein  wrote:
> On Tue, Jan 20, 2009 at 9:59 PM, sea2...@gmail.com  wrote:
>
> > Hi,
> >  I want compute gcd(f,g), where f and g are polynomials and  their
> > degree are huge, e.g. deg(f) is about 2^300.
> >   I looked through  the Sage reference manual, and learned that NTL
> > is a library of fast arithmetic with polynomials. But is seems that
> > the degree of my polynomial is too large, can anyone help me? Thanks
>
> Are your polynomials very sparse or dense?  Just to store a degree
> 2^300 dense polynomial would take 2^300 memory locations, but modern
> computers have < 2^64 memory locations.   If the polynomial is very
> sparse, use symbolics:
>
> sage: var('x',ns=1)
> x
> sage: f = (x^(2^300)+x +1)
> sage: g = (x^(2^300) - x)
> sage: expand(f*g)
> x^4074071952668972172536891376818756322102936787331872501272280898708762599526673412366794752
> + 
> x^2037035976334486086268445688409378161051468393665936250636140449354381299763336706183397376
> - x^2 - x

Unfortunately, this seems not to work:
sage: gcd(f, g)
---
OverflowError Traceback (most recent call
last)
...
OverflowError: long int too large to convert to int

I'd be surprised if Sage had any code to do this straightforwardly; I
think you'll have to write your own code.

Just running the standard gcd algorithm won't work; it would take at
least 2^300 steps, which is a "longer than the life of the universe"
timeframe.

Perhaps some sort of multimodular algorithm could work, where you take
advantage of x^p=x (mod p) to bring the exponents down into a
reasonable range.  (I'm not sure how you recombine the outputs,
though, especially if you want a provably correct result.)

Carl
--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: number field question

2009-01-20 Thread Carl Witty

On Jan 19, 7:50 pm, William Stein  wrote:
> Any commutative algebra computer computation over QQbar can be reduced
> to a computation over a specific absolute number field, since there
> are only finitely many symbols in the input to the calculation.
> Singular, etc., fully supports doing commutative algebra over absolute
> number fields.  I think Singular doesn't explicitly support relative
> extensions, but might be able to do them anyways by just throwing in
> more variables.   So if you're asking whether computer algebra systems
> such as Singular, Macaulay 2, Magma, etc., implement commutative
> algebra over QQbar the answer is formally "yes", in that there is a
> direct translation of any problem over QQbar into a problem they are
> designed to solve.

I don't remember any features in Singular that would let you handle
relative extensions in any reasonable way; I think it only deals with
aboslute fields.

> Sage and probably the other systems are probably VERY awkward for
> actually doing computations over QQbar.  There's a lot of bookkeeping
> and stuff that one would have to do, and conceptually it would be
> painful.  Also, being able to do relative extensions is critical,
> since e.g., your coefficients could be the square roots of the primes
> up to 1000, and as an absolute field they would generate an extension
> of degre 2^168, which is too big.

Currently, QQbar always computes absolute fields internally; being
able to get elements of QQbar in terms of relative extensions would
require a major rewrite of QQbar, unless there's some sort of trick
I'm not thinking of.  Such a rewrite could be a good thing, but I
probably won't do it.  I'd be happy to answer questions, etc., if
somebody else wanted to try, though.

Carl

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: number field question

2009-01-20 Thread Carl Witty

On Jan 19, 4:46 pm, Alex Raichev  wrote:
> Hi everyone:
>
> I'm applying for a grant from the New Zealand government to fund some
> Sage development in the area of computational algebraic and analytic
> geometry.  For part of the application i need to report on the 'state
> of the field'.  Part of my response to this will be to mention that
> Sage doesn't have an implementation of factorization, ideal, and
> variety calculations over QQbar.  To double-check, is this true?

It's essentially true (although as William points out, it would be
straightforward to add some potentially inefficient code for these
tasks).

I have implemented one special case: if you have a zero-dimensional
ideal over the rationals, then you can compute its variety over QQbar:

sage: K. = PolynomialRing(QQ, 2, order='lex')
sage: I = Ideal([ x*y - 1, (x-2)^2 + (y-1)^2 - 1])
sage: I = Ideal(I.groebner_basis())
sage: I.variety(ring=QQbar)
[{y: 0.3194484597356763? - 1.633170240915238?*I, x:
0.11535382288068429? + 0.5897428050222055?*I}, {y: 0.3194484597356763?
+ 1.633170240915238?*I, x: 0.11535382288068429? - 0.5897428050222055?
*I}, {y: 0.3611030805286474?, x: 2.769292354238632?}, {y: 1, x: 1}]

> Related to that, do any major computer algebra systems (Singular
> included) have such implementations?

Mathematica supports algebraic numbers; I haven't checked whether they
support factorization, etc. with algebraic coefficients.

Carl
--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: Finding a duplicated vector in a list of vectors

2009-01-20 Thread Carl Witty

On Jan 19, 1:43 pm, slabbe  wrote:
> PROBLEM :
> In a list of vectors, I want to know if there is a pair of equal
> vectors.
>
> I have two solutions. The first to create an empty list L and append
> the vectors one per one. If a vector is already in L before adding it,
> then I found a pair of equal vectors. But looking if a vector belongs
> to a list is apparently very slow on my computer :

The problem is that you're working in the symbolic ring, which is very
slow.  Do you need to?  For instance, this particular example can be
handled much more quickly in QQbar, the field of algebraic numbers:

sage: v = vector((1, QQbar(0)))
sage: w = vector((1, QQbar(sqrt(2
sage: time w in [v,v,v,v]
CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
Wall time: 0.01 s
False

Carl Witty

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: question about visualization/animation of surfaces

2009-01-16 Thread Carl Witty

On Jan 15, 10:52 pm, "Justin C. Walker"  wrote:
> If the temp files are truly temp files (i.e., not of interest when the  
> process that creates them exits), then there are Python calls that  
> help: the temp files can be created and unlinked, so that at exit,  
> they vanish.  In fact, they are not visible in the file system at all.

This works for files which are meant to be written and read inside the
same process (some sort of manual swap file, say); but in our case the
goal is to send the file from the Sage process to the ffmpeg process,
and this technique doesn't work in that case.

Carl

--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: Arithmetic base(n)

2009-01-14 Thread Carl Witty

On Jan 14, 12:04 pm, Crissy Ruffo  wrote:
> I was looking into how SAGE handles arithmetic base(n).  Best I can
> tell, I use the function  Integer('string rep of number', base), but
> the answer returned is base(10), so I use the function .str(base) to
> convert it back to the desired base.  (thanks to the post by Ted
> Kosan  on converting Integers to base(n) strings) Does anyone know of
> something more direct?  

In general, this is the best approach I know of; but there are faster
ways of entering integers in the special cases of hexadecimal (prefix
with '0x') and octal (prefix with '0'):

sage: 0x10
16
sage: 010
8

> And if there is, does SAGE actually do the
> arithmetic base(10), but hide it from the user?

It doesn't really matter how Sage does the arithmetic, because you get
the same answer no matter what base you use; but the true answer to
your question is pretty complicated.  Different parts of Sage use
different techniques for arithmetic, but most of the arithmetic on
integers will be done internally in either base 4294967296 (2^32) or
base 18446744073709551616 (2^64), depending on what machine you're on.

Carl
--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: Problem Running with nohup on OSX.5

2009-01-09 Thread Carl Witty

On Jan 9, 1:53 pm, Tom  wrote:
> I'm having difficulty running Sage in the background on a Mac with OSX.
> 5 and getting the output saved in a file.  I tried a few permutations
> with different results so I expect I'm making a silly error.   Here's
> what I've seen.
> Since the program runs fine in some of the scenarios, I don't think
> the program (which I call "commands.sage") is the problem (I've made
> it simpler and simpler without any change in the results).  Any help
> would be appreciated.
>
> Thanks,
> Tom
>
> 0.  If I run Sage (from the command line) and type
>
> load "commands.sage"
>
> then the program runs fine.
>
> 1.  If I run
>
> nohup ./sage < commands.sage > results.txt &
>
> the file results.txt will just contain the initial startup messages
> from Sage, but nothing more.
>
> 2.  If I run
> ./sage < commands.sage > results.txt
>
> all the output is correctly written to results.txt.   The only problem
> is that I can't close the terminal session and let Sage run in the
> background.
>
> 3. If I run
>
> ./sage < commands.sage
>
> I get the initial startup message, but nothing else written to screen
> or any file.
>
> 4.  If I create a file "intro.sage" with the one line
>
> load "commands.sage"
>
> and then run
>
> ./sage < intro.sage
>
> then the program runs and the output is sent to the screen.
>
> 5.  If I run
>
> nohup ./sage < intro.sage > results.txt &
>
> the file results.txt will just contain the initial startup messages
> from Sage, but nothing more.

It seems to be working for me with:

  nohup ./sage mytest.sage < /dev/null > results.txt &

So I gave the command file as a command-line argument, instead of on
standard input; and I made sure to redirect standard input from /dev/
null.  I also had to avoid the name commands.sage, because that
conflicts with a module Commands that's part of Sage (via IPython).

Carl
--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: Interpolation

2009-01-08 Thread Carl Witty

On Jan 8, 11:17 am, Harald Schilly  wrote:
> On Jan 8, 5:16 pm, "William Stein"  wrote:
>
> > Since you're correcting me[...]  It's not at all clear
> > that this is a numerical problem.
>
> Yes, i am not sure either, but the subject-topic is interpolation and
> that's why i thought it is polynomial interpolation. There are of
> course other interpretations possible. Let's see if there will be some
> clearification ;)

The phrase "polynomial interpolation" is used to describe both the
inexact (floating-point) and exact (rationals, finite fields, etc.)
problem.  So Santanu definitely wants polynomial interpolation, but we
still don't know whether it's exact or inexact.

Carl
--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: Arbitrary precision in cython

2008-12-23 Thread Carl Witty

On Dec 23, 1:53 am, Paul Zimmermann  wrote:
>        Hi,
>
> as a followup on the "Arbitrary precision in cython" thread, I'd like to
> mention that one can directly use mpfr's implementation from within Sage:
>
> sage: RealField(150)(10).eint()
> 2492.2289762418777591384401439985248489896471
>
> It only works for real numbers, but has the advantage to guarantee correct
> rounding (for the 150-bit binary result; if you are using the decimal
> result above, you have to take into account the binary->decimal conversion
> error, which is at most 1/2 ulp).

Actually, Sage doesn't print the entire value for floating-point
numbers by default; it leaves a few digits off the end, so the
potential binary->decimal conversion error above is a lot more than
1/2 ulp.  To get the entire within-1/2-ulp decimal value, you can use:

sage: RealField(150)(10).eint().str(truncate=False)
'2492.2289762418777591384401439985248489896471010'

Carl
--~--~-~--~~~---~--~~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~--~~~~--~~--~--~---



[sage-support] Re: number field question

2008-12-03 Thread Carl Witty

On Nov 30, 1:27 pm, Alex Raichev <[EMAIL PROTECTED]> wrote:
> > It would be helpful if you could give a more concrete example, e.g., a 
> > session
> > where you have some elements, and finally want to do something with them.
>
> That's good idea, William.  Let me back up to and change my question
> to a more fundamental one.  How does one compute in QQbar with Sage?
> For example, how about factoring a polynomial, computing a radical
> ideal, or computing a variety (see below)?  I get the same error for
> all these: "no conversion of this ring to a Singular ring defined".
>
> Alex

None of these things are implemented for polynomials over QQbar; and
as far as I know there are no plans to implement them.

Simpler variants of a couple of your problems are implemented:

For univariate polynomials, you can find the roots with .roots
(ring=QQbar), and it's trivial to compute the factorization from
there.

You can compute the variety (over QQbar) of a zero-dimensional ideal
of polynomials with rational coefficients, using .variety(ring=QQbar).

It would be great to have more functionality implemented for
polynomials over QQbar; is that something you would be interested in
contributing?

Carl
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
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?hl=en
-~--~~~~--~~--~--~---



[sage-support] Re: number field question

2008-12-03 Thread Carl Witty

On Nov 27, 6:23 pm, Alex Raichev <[EMAIL PROTECTED]> wrote:
> Hi all:
>
> I have a list c of elements of QQbar and want to form the field
> generated by QQ and the elements of c.  What's the easiest way to do
> this?
>      I looked through section 29.1 Number Fields of the Sage reference
> manual, but couldn't find a simple solution using the functions
> mentioned there.

You want number_field_elements_from_algebraics(c) (or maybe
number_field_elements_from_algebraics(c, minimal=True), if you care
about getting the smallest possible number field).

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

2008-10-10 Thread Carl Witty

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: question about SAGE eigenvalues

2008-09-24 Thread Carl Witty

On Sep 23, 1:31 pm, Jason Grout <[EMAIL PROTECTED]> wrote:
> > OK, it is a feature.  To quote from
> >http://wiki.sagemath.org/sage-3.1.2(Release notes for 3.1.2):
>
> > The question marks at the end of the numbers in the previous example
> > mean that Sage is printing out an approximation of an exact value that
> > it uses. In particular, the question mark means that the last digit
> > can vary by plus or minus 1. In other words, 32.46424919657298? means
> > that the exact number is really between 32.46424919657297 and
> > 32.46424919657299. Sage knows what the exact number is and uses the
> > exact number in calculations.
>
> That last sentence is technically incorrect, I think (sorry; I wrote
> it).  It might be better to say, "Sage carries out the calculations
> using interval arithmetic and essentially uses infinite precision in
> these cases."
>
> Carl, is there some way to word things better?

I think the sentence from the release notes is fine.  Elements of
QQbar are exact algebraic numbers; the fact that QQbar uses interval
arithmetic internally is an implementation detail that shouldn't
matter to the user.  (It would be nice if users of QQbar had no reason
to even know about the interval arithmetic used internally.  For the
sake of efficiency, though, I don't always print the best possible
approximation to a number, so the intervals are somewhat exposed to
the user when they print QQbar elements.)

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: question about SAGE eigenvalues

2008-09-24 Thread Carl Witty

On Sep 23, 1:26 pm, Jason Grout <[EMAIL PROTECTED]> wrote:
> To me, it looks like it may be a bug:
>
> sage: A=matrix([[1,1],[2,3]])
> sage: e1,e2=A.eigenvalues()
> sage: e1.interval(ComplexIntervalField(53))
> 0.2679491924311228?
> sage: b=e1.interval(ComplexIntervalField(53))
> sage: b
> 0.2679491924311228?
> sage: b.str(style='brackets')
> '[0.26794919243112269 .. 0.26794919243112276]'
>
> The question mark notation indicates that this last interval (the "real"
> interval) should lie inside of
>
> [0.2679491924311227 .. 0.2679491924311229]
>
> But it doesn't seem to lie in that range.
>
> Carl, what do you think?

Yes, the above sure looks like a bug to me.

I'll try to look at it sometime this week (over the weekend, if not
sooner).

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: numerically solving a polynomial system of equations

2008-08-25 Thread Carl Witty

On Aug 24, 12:16 pm, Michael <[EMAIL PROTECTED]> wrote:
> I have a polynomial system of 50 equations in 50 unknowns. I would
> like
> to numerically solve this system (I'm interested in complex zeros).
> Seems to me that if I use sage's solve, it will sttempt to solve these
> algebraically.
>
> Are there any funcitons in sage for solving a polynomial or non-linear
> system
> numerically.

Other people have suggested phcpack, but not explained how to use it.

The following may or may not work for you (it depends on your
processor architecture and operating system); but if it does work,
it's actually quite easy.

First, install phc, by typing at the command line:

sage -i phc-2.3.39.p0

Then, from within Sage, you can do things like this:

sage: from sage.interfaces.phc import phc
sage: R2. = PolynomialRing(QQ,2)
sage: start_sys = [x^6-y^2,y^5-1]
sage: sol = phc.blackbox(start_sys, R2)
sage: len(sol.solutions())
30
sage: sol.solutions()[0] # display the first solution
[0.309016994374947 + 0.951056516295154*I,
 0.104528463267653 + 0.994521895368273*I]

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: Plotting and constant functions

2008-08-21 Thread Carl Witty

On Aug 21, 10:58 am, Mike Witt <[EMAIL PROTECTED]> wrote:
> This is an attempt to ask my previous question more clearly :-)
>
> I'm looking for a work-around for the situation where I would normally
> call parametric_plot (or plot, for that matter) with a function, and in
> some particular case that function turns out to evaluate to a constant.
>
> For example:
>
> sage: def f(a,b): return e^(a+b*I)
> :
...
> sage: parametric_plot([real(f(x,0)),imag(f(x,0))], -pi, pi)
>
>   Gives a page full of errors, which I interpret to mean that there
>   was a problem plotting because imag(f(x,0)) evaluates to a constant.

Here's one way to do what you want: on a symbolic value V, you can use
V.function(x) to make sure Sage treats it as a one-argument function
(even if V is a constant).

So the following three commands all work:

sage: parametric_plot([real(f(x,0)).function(x),imag(f(x,
0)).function(x)], -pi, pi)

sage: parametric_plot([real(f(x,1)).function(x),imag(f(x,
1)).function(x)], -pi, pi)

sage:
parametric_plot([real(f(x,-1)).function(x),imag(f(x,-1)).function(x)],
-pi, pi)

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: Debian Etch: Error trying to plot

2008-07-11 Thread Carl Witty

On Jul 10, 4:40 pm, Alejandro Jakubi <[EMAIL PROTECTED]> wrote:
> So, I was happy and issued a plot command in the console interface:
>
> sage: show(plot(cos,-5,5))
>
> I have got the plot displayed a window for the file tmp_1.png plus
> error messages about a missing font:
>
> ===
> numerix numpy 1.0.4
> matplotlib data path /usr/local/sage-3.0.2-debian32-intelx86-i686-
> Linux/local/lib/python2.5/site-packages/matplotlib/mpl-data
>         findfont failed Lucida Grande
>         findfont found Verdana, normal, normal 500, normal, 10.0
> findfont returning /usr/share/fonts/truetype/msttcorefonts/Verdana.ttf
>         findfont failed Lucida Grande
>         findfont found Verdana, normal, normal 500, normal, 10.0
> ...(last three lines repeated many times)
>
> ===
>
> Which, I guess, will be easy to solve.
>
> These missing font messages do not appear when this plot command is
> executed in the notebook interface.

These messages are because you're still in "matplotlib debugging
mode".  Just restart Sage and they'll go away.  Or type:
sage: matplotlib.verbose.set_level('silent')

They seem not to indicate a real problem.  (I get the same messages
when I turn on debugging.)

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: Debian Etch: Error trying to plot

2008-07-10 Thread Carl Witty

On Jul 7, 11:46 pm, Alejandro Jakubi <[EMAIL PROTECTED]> wrote:
...
> /usr/local/sage-3.0.2-debian32-intelx86-i686-Linux/local/lib/python2.5/
> site-packages/matplotlib/axis.py in ()
>      18 from transforms import Value, blend_xy_sep_transform,\
>      19      translation_transform, bbox_all, identity_transform
> ---> 20 from font_manager import FontProperties
>      21 from text import Text, TextWithDash, _process_text_args
>      22 from patches import bbox_artist
>
> /usr/local/sage-3.0.2-debian32-intelx86-i686-Linux/local/lib/python2.5/
> site-packages/matplotlib/font_manager.py in ()
>    1127         verbose.report("Using fontManager instance from %s" %
> _fmcache)
>    1128     except:
> -> 1129         _rebuild()
>    1130
>    1131     def findfont(prop, **kw):
>
...
> /usr/local/sage-3.0.2-debian32-intelx86-i686-Linux/local/lib/python2.5/
> site-packages/matplotlib/font_manager.py in createFontDict(fontfiles,
> fontext)
>     507             try:
>     508                 try:
> --> 509                     font = afm.AFM(fh)
>     510                 finally:
>     511                     fh.close()
...
> /usr/local/sage-3.0.2-debian32-intelx86-i686-Linux/local/lib/python2.5/
> site-packages/matplotlib/afm.py in _to_list_of_ints(s)
>      45 def _to_list_of_ints(s):
>      46     s = s.replace(',', ' ')
> ---> 47     return [_to_int(val) for val in s.split()]
>      48
>      49 def _to_list_of_floats(s):
>
> ValueError: invalid literal for int() with base 10: '-75.673'

It looks like matplotlib is trying to parse the AFM ("Adobe Font
Metrics") file for every font on your system, and one of them has a
floating-point number where matplotlib is expecting an integer.  This
would presumably be a bug either in that AFM file or in matplotlib (I
don't actually know whether floating-point numbers are allowed in AFM
files).

It does not occur when I do plotting on my Debian systems, so probably
it's some font that you have installed and I don't.

To track this down, type the following commands:

sage: import matplotlib
sage: matplotlib.verbose.set_level('debug')
sage: import matplotlib.font_manager

I think at this point you will get a bunch of debugging information,
followed by that same traceback.  If not, execute the following line
as well:

sage: matplotlib.font_manager._rebuild()

Now, look just above the beginning of the traceback, and you should
see a whole bunch of lines like this:
createFontDict: /usr/share/fonts/X11/Type1/lmvtlo10.afm
createFontDict: /usr/share/fonts/type1/gsfonts/b018015l.afm
createFontDict: /usr/share/fonts/X11/Type1/c0419bt_.afm

Look at the file specified in the last createFontDict line (for
instance, open it with a text editor; it's a simple text file) and see
if it has a '-75.673' in it.

If so, you've found the culprit.  The easy thing at this point is to
just work around the problem by uninstalling whatever package
installed that font.  The more difficult thing would be to figure out
whether floating-point numbers are actually allowed at that spot, and
report a bug either to matplotlib or to that font.

Let us know what you discover.

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: Efficient selection from a list: Is there a tric?

2008-07-03 Thread Carl Witty

On Jul 2, 10:09 pm, Rolandb <[EMAIL PROTECTED]> wrote:
> for a in range(1,5):
>  for b in range(1,5):
>   for c in range(1,5):
>    for d in range(1,5):
>     if a<>b<>c<>d:

By the way, the above line doesn't mean what you want.  It checks that
a<>b, that b<>c, and that c<>d, but it doesn't check any of a<>c,
a<>d, or b<>d.

>      print a,b,c,d

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: Displaying plot in frames

2008-06-10 Thread Carl Witty

On Jun 10, 11:28 am, Emerson <[EMAIL PROTECTED]> wrote:
> Hello everyone.
>
> I'm just wondering if there's a way of showing a SAGE plot in a window
> when running a code on the script (i.e., a python script ran with the
> sage environment from the command line). To make it more clear, I have
> the code bellow...
>
> #!/usr/bin/env sage
>
> import sys
> from sage.all import *
>
> g = 2
> t = .4
> var('n m')
> d2u = diff(1/(1 + (n * exp(-m/t))), m, 2)
> solns = solve([d2u == 0, m == g], m, n, solution_dict=True)
> ns = [[soln[n].n()] for soln in solns]
> n = ns.pop().pop()
> u = 1/(1 + (n * exp(-m/t)))
> p = plot([u], (-10, 10))
>
> ...and I want to display the plot "p" in a window/frame when i run my
> script from the command line (i.e., ./myScript.py). Any way to do
> that?

Well, I can tell you what sort of worked for me; but it's environment
specific.

The easy part: add a new line "p.show()" at the end of your script;
this should produce a plot and display it with your default image
viewer.

Unfortunately, in my environment, this displays the plot very briefly,
and then the plot disappears.  This is because the .show() command
creates a temporary file and sends it to my image viewer (Eye of
Gnome); then when Sage exits, it removes all its temporary files.  Eye
of Gnome notices that the file it was viewing went away, and stops
showing the file.

There's surely an easy fix or workaround for this, but I don't have
time to look into it; one easy but very unsatisfying workaround is to
add another line "sleep(100)" to your script, to let you view the
image for 100 seconds before it disappears.

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: simplifying exponents

2008-06-10 Thread Carl Witty

On Jun 10, 10:44 am, polo0691 <[EMAIL PROTECTED]> wrote:
> Thanks for creating sage! I can really see how useful sage could be
> for engineering purposes. I've been playing around with sage for a
> couple of days and I have had trouble with the following:
>
>   1) simplifying equations with exponents:
>
> sage: var('vgs vt n')
> (vgs, vt, n)
> sage: f = (vgs - vt)^n
> sage: f^(1/n)
> ((vgs - vt)^n)^(1/n)
> sage: f^(1/n).simplify()
> ((vgs - vt)^n)^(1/n)
>
>     It doesn't seem to easily simplify the exponent. I'm guessing it
> is a limitation of the CAS engine used. I also tried the same test
> case on YACAS and it didn't seem to want to simplify the exponent
> either.

I'm not surprised this doesn't simplify: there's no consistent
definition for exponentiation that lets you safely apply the
simplification you want.  To pick a simple case, over the reals,
squaring followed by square root gives the absolute value:

sage: ((-2)^2)^(1/2)
2

Then consider that Sage is assuming that vgs, vt, and n may be complex
numbers, and it gets very complicated.

Carl Witty

--~--~-~--~~~---~--~~
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: 3 == pi

2008-06-04 Thread Carl Witty

On Jun 4, 5:08 pm, Robert Bradshaw <[EMAIL PROTECTED]>
wrote:
> > In this thread:http://groups.google.com/group/sage-devel/
> > browse_thread/thread/bcdc671d2791056e/e086a9d59ff4b9ba
> > it seems that the consensus was to throw an error here; but nobody
> > ever implemented it (or even opened a trac ticket, as far as I know).
>
> Thanks for the reference. There's a trac ticket now:
>
> http://trac.sagemath.org/sage_trac/ticket/3369

I should have read the thread more closely; the whole discussion
started with trac #2781.  (I've added a pointer to #2781 from #3369
now.)

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: 3 == pi

2008-06-04 Thread Carl Witty

On Jun 4, 4:16 pm, Robert Bradshaw <[EMAIL PROTECTED]>
wrote:
> On Jun 4, 2008, at 2:46 PM, Jason Grout wrote:
>
> > Of course, bool(some equation) returning False does not necessarily  
> > mean
> > that the two expressions are not equal; it only means that we couldn't
> > prove them to be equal using some simple simplifications.
>
> >  From the docstring for _nonzero_ from equation.py (used to implement
> > bool()):
>
> > Return True if this (in)equality is definitely true.  Return False  
> > if it
> > is false or the algorithm for testing (in)equality is inconclusive.
>
> Should it throw an error in this case? (Is there a way to know if the  
> result was inconclusive?)

In this thread: 
http://groups.google.com/group/sage-devel/browse_thread/thread/bcdc671d2791056e/e086a9d59ff4b9ba
it seems that the consensus was to throw an error here; but nobody
ever implemented it (or even opened a trac ticket, as far as I know).

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: Symbolic GCD

2008-05-29 Thread Carl Witty

On May 29, 5:11 am, Gaëtan Bisson <[EMAIL PROTECTED]> wrote:
> Carl Witty wrote :
>
>
>
> > > For instance:
> > >   R. = NumberField(x^2-3,'g')[]
> > >   S. = R.fraction_field()[]
> > >   xgcd(y^2, a*y+b)
>
> > > returns the error: (more below)
> > >   : unsupported operand type(s) for %: 
> > > 'sage.rings.number_field.number_field_element_quadratic.NumberFieldElement_quadratic'
> > >  and 
> > > 'sage.rings.number_field.number_field_element_quadratic.NumberFieldElement_quadratic'
>
> > This should work, but doesn't due to a bug (well, perhaps you could
> > call it a missing feature instead).  I've posted a patch here,
> >http://trac.sagemath.org/sage_trac/ticket/3327so this will work in
> > some future version of Sage (likely the next version, assuming that
> > somebody positively reviews my patch).
>
> Thank you so much. The patch is indeed working fine.
>
> I still have issues when involving a tower of number fields, though.
> That is, the following code:
>
>   R. = NumberField(x^2-3,'g').extension(x^2-7,'h')[]
>   h = R.base_ring().gen()    
>   S. = R.fraction_field()[]
>   xgcd(y^2, a*h*y+b)
>
> raises the error:
>   NameError: name 'h' is not defined
>
> Note, however, that when the first line is replaced by:
>   R. = NumberField(x^2-3,'h')[]
> computations run flawlessly and SAGE outputs the result:
>   (b^2/(3*a^2), 1, ((-1)/(h*a))*y + b/(3*a^2))
>
> Do I have to define 'h' in a more "robust" way to avoid that
> or is this unrelated to the way it's defined?

This is not yet implemented.

Sage keeps its fraction field elements in reduced form, by performing
GCDs between the numerator and denominator.  Sage uses Singular to
find the GCD of multivariate polynomials, but Singular does not
support towers of number fields.  The above traceback shows Sage
trying, and failing, to use Singular with towers of number fields.

I've opened a couple of bug reports for this example,
http://trac.sagemath.org/sage_trac/ticket/3329 and
http://trac.sagemath.org/sage_trac/ticket/3330; the first just says
there should be a better error message, and the second requests an
actual implementation.

Until somebody fixes the code (maybe you want to work on it
yourself?), probably the best solution is to convert your tower of
number fields into a single absolute number field and do the
computation with this single field.  You can do this with
the .absolute_field() method, and convert back and forth using the
isomorphisms from the .structure() method on the absolute field.

sage: K = NumberField(x^2-3,'g').extension(x^2-7,'h')
sage: Kabs = K.absolute_field('j'); Kabs
Number Field in j with defining polynomial x^4 - 20*x^2 + 16
sage: Kabs.structure()

(Isomorphism from Number Field in j with defining polynomial x^4 -
20*x^2 + 16 to Number Field in h with defining polynomial x^2 - 7 over
its base field,
 Isomorphism from Number Field in h with defining polynomial x^2 - 7
over its base field to Number Field in j with defining polynomial x^4
- 20*x^2 + 16)

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: Symbolic GCD

2008-05-28 Thread Carl Witty

On May 26, 3:04 am, Gaëtan Bisson <[EMAIL PROTECTED]> wrote:
> Carl Witty wrote:
> > You need to explicitly use the field of fractions of R:
>
> > sage: R. = QQ[]
> > sage: S. = R.fraction_field()[]
> > sage: xgcd(x^2, a*x+b)
> > (b^2/a^2, 1, ((-1)/a)*x + b/a^2)
>
> Thanks. Is it possible to do the same computation over a number field
> (instead of QQ)?
>
> For instance:
>   R. = NumberField(x^2-3,'g')[]
>   S. = R.fraction_field()[]
>   xgcd(y^2, a*y+b)
>
> returns the error: (more below)
>   : unsupported operand type(s) for %: 
> 'sage.rings.number_field.number_field_element_quadratic.NumberFieldElement_quadratic'
>  and 
> 'sage.rings.number_field.number_field_element_quadratic.NumberFieldElement_quadratic'

This should work, but doesn't due to a bug (well, perhaps you could
call it a missing feature instead).  I've posted a patch here,
http://trac.sagemath.org/sage_trac/ticket/3327 so this will work in
some future version of Sage (likely the next version, assuming that
somebody positively reviews my patch).

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: python (?) help: equivalent of lisp's "let"

2008-05-28 Thread Carl Witty

On May 28, 11:48 am, John H Palmieri <[EMAIL PROTECTED]> wrote:
> I currently have a function, set_output_format, so users can do this:
>
> sage: set_output_format('old')
> 'old'
> sage: x = (blah); x
> (x printed in 'old' format)
>
> I would like to be able to do this:
>
> sage: x.format('new')
> (x printed in 'new' format)
> sage: x   # output_format should still be set to 'old'
> (x printed in 'old' format)
>
> Anyway, I've almost solved my problem (using a try...finally...
> block).  Now my question is this: is there an existing sage command
> which does this:
>
> if in notebook mode and typeset box is on:
>    view(x)
> else:
>    print(x)
>
> Then I can do:
>
> try:
>     old = set_output_format()   # with no arguments, set_output_format
> returns the current format
>     set_output_format(new)
>     fancy_print_command(x)    # which behaves as I described above
> finally:
>     set_output_format(old)

You should look at the Python "with" statement (http://docs.python.org/
ref/with.html; see also http://docs.python.org/ref/context-managers.html).
You could implement a function "output_format" so that:

  with output_format(new):
  fancy_print_command(x)

is the equivalent of your try-finally block above.

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: Symbolic GCD

2008-05-23 Thread Carl Witty

On May 23, 3:21 am, Gaëtan Bisson <[EMAIL PROTECTED]> wrote:
> Dear SAGE community,
>
> I would like to do some symbolic computation using SAGE, namely, to
> compute the extended GCD of two polynomials, one of them having symbolic
> coefficients.
>
> Here is a short example:
>   sage: R.=PolynomialRing(RationalField(),2);
>   sage: S.=PolynomialRing(R);
>   sage: xgcd(x^2,a+x*b)
>
> As an answer, I would expect:
>   (b^2/a^2, 1, -x/a+b/a^2)

You need to explicitly use the field of fractions of R:

sage: R. = QQ[]
sage: S. = R.fraction_field()[]
sage: xgcd(x^2, a*x+b)
(b^2/a^2, 1, ((-1)/a)*x + b/a^2)

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: take Sage formulas into MSWord

2008-05-22 Thread Carl Witty

On May 22, 6:23 am, roleic <[EMAIL PROTECTED]> wrote:
> Mike,
> what data format is used when sage exchanges symbolic math with math
> packages like maxima, maple, mathematica? Maybe there is a converter
> for one of these formats.
> Roland

In each case, we use the native format of that package (the format you
use to type formulas at the command line in that package).  That is,
we have converters from Sage->Maxima, Maxima->Sage, Sage->Maple, etc.
(These converters are only partially complete; some Sage expressions
will not successfully translate into expressions in the other
packages, and some expressions in the other packages will not
successfully translate back into Sage.)

These conversions are available as foo._XXX_init(), for the
appropriate "XXX"; for instance:

sage: sin(x^2)._mathematica_init_()
'Sin[(x) ^ (2)]'

The LaTeX conversion is implemented in a very similar way, with the
_latex_ method:

sage: sin(x^2)._latex_()
'\\sin \\left( {x}^{2}  \\right)'

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: Problem in Programming Guide Cython example

2008-05-19 Thread Carl Witty

On May 19, 12:03 pm, mabshoff <[EMAIL PROTECTED]
dortmund.de> wrote:
> Hehe, it is good to share the blame. I meant had I know that this
> issue causes this much trouble I would have attempted to do 3.0.2
> quicker instead of the two week cycle. Is there any way to test Cython
> introspection automatically via the standard doctests, so that we
> could catch such an issue via the normal doctesting? It would also be
> interesting to see if once we have the XMLRPC stuff in place [I think
> we do already] to run some tests via the commandline by "injecting"
> content into some worksheet so that we do more automated testing.

It's also possible to doctest the Sage command line (to some extent)
using sage/interfaces/sage0.py.  In sage/misc/randstate.pyx, search
for "subsage" to see an example of this technique.

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: matrix over the booleans

2008-05-14 Thread Carl Witty

On May 14, 7:17 am, "William Stein" <[EMAIL PROTECTED]> wrote:
> So 1+1 = 1 and 1*1 = 1 and 1*0 = 0 and 1+0 = 1 and 0+0=0?
> That's *not* a ring, so you shouldn't make matrices over it in
> Sage, since in Sage all matrices are over rings.

Once #2519 (lattices in the poset sense) is merged, I was going to
suggest modifying Sage matrices to support lattices as well as rings.
(The booleans are a lattice).  This might end up being totally new
code, since most current Sage matrix operations are meaningless on
matrices over lattices; but matrix addition and multiplication are
well-defined.

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: Simple continued fractions in Pari

2008-05-05 Thread Carl Witty

On May 1, 3:15 am, bill purvis <[EMAIL PROTECTED]> wrote:
> On Thursday 01 May 2008, Dan Drake wrote:
>
> > On Wed, 30 Apr 2008 at 09:10AM -0700, bill.p wrote:
> > > > My present thought is that I'd need a list of integers plus another
> > > > integer - the integer could either be the number of non-recurring
> > > > terms, or it could be the number of recurring terms. Given the way
> > > > that Python handles negative indices I guess the second option could
> > > > amount to the same thing by making it negative. Again, feedback
> > > > welcomed.
>
> > > > Bill
>
> > > Hmmm, I'll take that as 'No Interest' then
>
> > I haven't been following this carefully, but I'd like to see a format
> > for quadratic irrationals that is along the same lines as Mathematica:
>
> >   ContinuedFraction[Sqrt[15]]
>
> > yields
>
> >   {3, {1, 6}}.
>
> > The first entry is the integer part, and after that, we'd have a tuple
> > or list that gives you the periodic stuff. Rational numbers would be
> > just a list of integers:
>
> >  {3, 7, 15, 1, 292, 1, 1, 1, 2, 1}
>
> > It would also be nice if you could do symbolic expressions as entries in
> > the list.
>
> > Dan
>
> Thanks for the suggestion. That means I can handle the existing stuff as
> a special case (no sublists).
>
> I've not been able to afford a copy of Mathmatica (impoverished, retired,
> software engineer) so I was unaware
> of what it provided.
>
> If anyone can supply more info on what Mathmatica can do in this area
> it would be appreciated

The Mathematica documentation is available online; for example, the
documentation for ContinuedFraction is at
http://reference.wolfram.com/mathematica/ref/ContinuedFraction.html

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: Posets or others

2008-04-17 Thread Carl Witty

On Apr 17, 6:03 am, kcrisman <[EMAIL PROTECTED]> wrote:
> However, what I really want is to be able to do this dynamically and
> to have the output be an "ordered set".  Maybe an example would be
> that I might want to list different orders of operations, so that
> object A="exponentiation>multiplication>addition" would be my normal
> list, but then I could have another ordering be the (wrong but
> potentially fun) B="addition>multiplication>exponentiation", and that
> if I wanted to then put in subtraction in B, I could infix it to be
> B="addition>multiplication=subtraction>exponentiation" for a LOT of
> fun.
>
> I was thinking now that maybe just a list (which has an implicit
> ordering and lots of functions on it) would work, but I don't know
> that it would allow "=" between elements very easily.

For tiny sets, you could use graphs.  For your final example, start
with a graph with edges "addition->multiplication", "multiplication-
>subtraction", "subtraction->multiplication", and "subtraction-
>exponentiation".  Then compute the transitive closure of the graph.
To test whether A>B, A=B, AB and B->A in the graph.

Unfortunately the current implementation of transitive closure looks
pretty slow, so this will currently only work for tiny sets.

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: pylab inside notebook

2008-04-12 Thread Carl Witty

On Apr 8, 4:34 am, "Fabio Tonti" <[EMAIL PROTECTED]> wrote:
> sage: from pylab import *
> sage: imshow([[(0,0,0)]])
> sage: savefig('foo.png')
> Traceback (most recent call last):
> ...
> NameError: global name 'npy' is not defined
>
> I would just like to make an image from a 2-dimensional Array (of
> rgb-values)!

This is a bug in our current version of matplotlib; it is being
tracked here: http://trac.sagemath.org/sage_trac/ticket/2900

For now, it looks like you may be able to work around the problem by
using RGBA 4-tuples instead of RGB 3-tuples; that is, add an extra ",
255" on the end of each pixel.

You also need to be sure to use Python ints instead of Sage integers.
So with the commands:
sage: imshow([[(0r,0r,0r,255r)]])
sage: savefig('foo.png')
I at least don't get any more exceptions, and I do get a saved image.
However, I don't see a black pixel in the saved image, so it may not
actually be working.

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: Trying to create a vector of rounded floats

2008-04-11 Thread Carl Witty

On Apr 11, 7:40 pm, Jason Grout <[EMAIL PROTECTED]> wrote:
> Is making an _integer_ method in the RDF class the right method to write?

Yes, that will work.

> Also, round(RR(3.0)) returns an Integer...should RDF behave the same
> way? (currently round(RDF(3.0)) returns an RDF).

We recently changed round, floor, ceiling, and trunc on RR to return
integers; yes, I think the corresponding RDF methods should change as
well.

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: Resultants of real polynomials

2008-03-27 Thread Carl Witty

On Mar 23, 2:15 pm, shreevatsa <[EMAIL PROTECTED]> wrote:
> Hello,
>
> If I try to compute the resultant of two polynomials in RR['x','y'],
> it fails with a NotImplemented error. Like:
>
> R. = RR[]
> p = x + y
> q = x*y
> p.resultant(q)
>
> It works when I use QQ[] instead. I don't know how resultants are
> computed (it seems to be done by libsingular), but if is done using a
> determinant, say, then shouldn't it work for real polynomials too? Is
> this perchance just an error translating Sage's real polynomials to
> Singular's terms?

This issue is now being tracked at 
http://trac.sagemath.org/sage_trac/ticket/2693

As a workaround, you can instead do:

R. = RR[]
p = x + y
q = x*y
p.polynomial(x).resultant(q.polynomial(x))

where p.polynomial(x) gives a univariate polynomial in x over the ring
RR['y'].  Sage's univariate resultant implementation is more generic
than the multivariate implementation, and handles this case.

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: polynomial object and symoblic computations

2008-03-25 Thread Carl Witty

On Mar 25, 2:18 am, continuum121 <[EMAIL PROTECTED]> wrote:
> Hi!
>
> I have a problem. Here is its formulation. I work in some polynomial
> ring - lets say
> R,(x,y) = PolynomialRing(QQ, 2, 'xy', order='lex').objgens()
> and consider ideal in R
> I = ideal(x+y^3-2,y+x^3-2)
> then I calculate grobner basis for ideal I
> B = I.groebner_basis(); B
> B[0] is univariate polynomial. Here the real problem begins. I would
> like to get real roots of polynomial B[0]. I can do B[0].factor() but
> it gives only part of information us factorization is over Q[x,y].
> More intuitive way for me is to treat it symbolicly. I want to write
> solve(B[0] == 0, x) but it doesn't work us function solve() needs
> symbolic object and gets boolean expression.
>
> The question is: how to find real roots for polynomial object either
> symbolicly (more desired) or numericly?

Root-finding is implemented for univariate polynomials.  Here is one
way to get your polynomial in a univariate ring:

sage: U = QQ['y']
sage: U(B[0])
y^9 - 6*y^6 + 12*y^3 - y - 6

You can then use the .roots() method to find the roots.  In
particular, .roots(ring=AA) will find all the real roots exactly.  (It
finds them numerically first, but maintains enough information to
recover the exact root later.)

sage: rts = U(B[0]).roots(ring=AA); rts
[([0.99988 .. 1.0003], 1)]

We see that this polynomial has one real root (of multiplicity one).
Given this approximation, it seems very likely that the root is
actually equal to 1; we can prove this by testing:

sage: rt = rts[0][0]; rt == 1
True

If you want the entire real variety of a zero-dimensional ideal, you
can just compute it directly:

sage: I.variety(ring=AA)
[{x: [1. .. 1.], y:
[1. .. 1.]}]

(This functionality is new in Sage 2.10.3.)

All of these techniques work great for fairly small examples, but get
very very slow for larger examples.  If you're actually interested in
larger examples, you may be better off with Marshall Hampton's
suggestion of phcpack.

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-2.10.4 on opensuse 10.3

2008-03-24 Thread Carl Witty

On Mar 24, 5:38 am, Florin <[EMAIL PROTECTED]> wrote:
> 3. "make html" and "make pdf" fail because [EMAIL PROTECTED] cannot be 
> handled.

You just need to delete devel/doc-main/ref/ref.aux and .../ref.toc and
try again.  (These cache files should not be distributed at all; and
they seem not to be present in my copy of 2.11.alpha0.)

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: Bug converting real numbers to integers?

2008-03-07 Thread Carl Witty

On Mar 7, 12:42 am, Nikos Apostolakis <[EMAIL PROTECTED]> wrote:
> Carl Witty <[EMAIL PROTECTED]> writes:
> > Didier mentioned floor(); if you actually want to round, instead of
> > taking the floor, then this works (even though it's a little verbose):
> > sage: ZZ((num*100).round())
>
> I thought that `floor' is what I was looking for: I want to get the
> integer that appears in screen as output to the command
>
> sage: RealField(12).random_element(1,9.99)*100
>
> as an element of ZZ.  However this doesn't seem to work in all
> cases!  For example:
>
> ,
> | sage: foo = RealField(16).random_element(20,99.99)*100
> | sage: foo
> | 2036.
> | sage: floor(foo)
> | 2035
> | sage: foo.round()
> | 2036.
> `

You can see the exact true value of a floating-point number with
foo.exact_rational().

For printing, the code determines a number of digits which is
(deliberately) slightly too low to represent floating-point numbers of
that precision; then it rounds to the nearest printable value.  For
example,  1.0/49*49 prints as 1.00, even though the
floating-point number you get is actually
9007199254740991/9007199254740992 or
0.99988897769753748434595763683319091796875 .

You can see the number printed with enough digits to distinguish
adjacent floating-point numbers like this:
sage: (1.0/49*49).str(truncate=False)
'0.99989'

floor gives the greatest integer which is <= the given floating-point
number:
sage: floor(1.0/49*49)
0
round gives the integer which is closest to the given floating-point
number:
sage: round(1.0/49*49)
1.00
except that it gives that integer in the form of a floating-point
number.  (IMHO, this is a bug, which I've reported here:
http://trac.sagemath.org/sage_trac/ticket/2421)

This rounding-off when printing floating-point numbers was supposed to
reduce confusion for people who don't care about floating-point
numbers, and who would be surprised (and would complain) if 1.0/49*49
did not print as 1.0.  Unfortunately, as in your case, this comes at
the cost of increasing confusion for people who do care about floating-
point numbers; I don't know how to decide if the tradeoff is worth it.

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: Bug converting real numbers to integers?

2008-03-06 Thread Carl Witty

On Mar 6, 2:48 pm, Nikos Apostolakis <[EMAIL PROTECTED]> wrote:
> > I can confirm this. I think numbers are rounded up when they are
> > printed, which leads to confusion:
> > {{{
> > sage: num = RealField(12).random_element(1,9.99)*100
> > sage: num
> >  406.
> > }}}
>
> > But num is actually ~405.725! :
> > {{{
> > sage: num -406
> >  -0.375
>
> > }}}
>
> > And so ZZ(num) will fail, as it should, since num ~ 405.725.
>
> Hm, I see! This behavior is very confusing. Wouldn't you say it *is*
> a bug?

I'm not sure which part you're talking about: are you complaining that
this particular number prints as an integer even though it isn't
exactly, or that coercion to ZZ fails?

For the former, I disclaim responsibility. :)  The decision to round-
off floating-point numbers was made before I started working on Sage;
I don't really care one way or the other.

For the latter: I think that coercion to ZZ should fail.  Regardless
of how the number prints, it really is not an integer.

> Anyway to get what I expected to get I can do something like
>
> sage: Integer(sage_eval(str(num))*100)
> 318
>
> but it seems like an ugly hack.  Is there another way?

Didier mentioned floor(); if you actually want to round, instead of
taking the floor, then this works (even though it's a little verbose):
sage: ZZ((num*100).round())

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: clearing the denominator of a rational polynomial

2008-03-06 Thread Carl Witty

On Mar 6, 11:20 am, David <[EMAIL PROTECTED]> wrote:
> I am trying to use the reduce() command on a rational pollynomial.  I
> first clear the denominator by multiplying by the denominator but when
> I use reduce() I get an error.  When I print out the polynomial it is
> no longer rational but SAGE doesn't like it.  I would appriciate any
> advice.  Below is an example script with ouput.  Thank you.

The resulting polynomial does not print as rational, but Sage still
considers it to be a rational polynomial with denominator 1.  (You can
see this by printing parent(Z).)

The general principle for this sort of situation in Sage is that you
should be able to get the polynomial you want by treating your ring as
a function and calling your rational polynomial; that is, I would
expect R1(Z) to give you your polynomial.  Unfortunately, it doesn't;
I've reported this as a bug here: http://sagetrac.org/sage_trac/ticket/2411

Instead, there's a somewhat ugly workaround you can use: R1(str(Z))
converts your polynomial to a string, then parses it again, giving you
a polynomial in the correct ring.  And R1(str(Z)).reduce(I2) returns
0.

> Untitled
> system:sage
>
> {{{id=0|
> R1 = PolynomialRing(RationalField(),9,
> ["x0","x1","x2","y0","y1","y2","a0","a1","a2"], "lex")
> x0,x1,x2,y0,y1,y2,a0,a1,a2=R1.gens()
> X=[
> x0*y0 - x2*y1 + x1*y2,
> a2*y0 + a1*y1 - a0*y2,
> a1*x0 - a0*x1 - a2*x2
> ]
> I=R1.ideal(X)
> I2 = I.groebner_basis()
> print X[2].reduce(I2)
> Y=X[2]/a1
> Z=a1*Y
> print Z
> print Z.reduce(I2)
> ///
>
> 0
>
> -x1*a0 + x0*a1 - x2*a2
>
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/home/notebook/sage_notebook/worksheets/admin/61/code/3.py",
> line 17, in 
> exec compile(ur'print Z.reduce(I2)' + '\n', '', 'single')
>   File "/usr/local/sage/data/extcode/sage/", line 1, in 
>
> TypeError: reduce() takes exactly 1 argument (2 given)
>
> }}}
>
> {{{id=1|
>
> }}}

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: Reserved words

2008-03-06 Thread Carl Witty

On Mar 6, 3:46 pm, David Harvey <[EMAIL PROTECTED]> wrote:
> I think the real problem here is that Sage by default has so many
> identifiers in the global namespace. I don't really like having so
> many names there. I think it was a deliberate design decision in
> python to keep the global namespace really clean, and I quite like
> it. Sage unfortunately (in my opinion) doesn't do that.

You could try "sage -min" ("do not populate global namespace").

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: Reserved words

2008-03-06 Thread Carl Witty

On Mar 6, 12:53 pm, Jason Grout <[EMAIL PROTECTED]> wrote:
> As another option, though, how about
> having the S or Sage namespace include all of the global namespace (at
> least the default global namespace), so that S.pi (or Sage.pi) would
> always refer to the sage system pi (as opposed to having to find that pi
> is sage.functions.constants.pi).

William mentions that sage.all is this default global namespace; if
you want a shorter name, you can do:

sage: import sage.all as S
sage: S.pi
pi

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: Animation speed question

2008-03-02 Thread Carl Witty

On Mar 1, 1:09 pm, "dean moore" <[EMAIL PROTECTED]> wrote:
> When I wrote the code living at  I
> was inspired by the
> wikipedia image (made via MuPAD) on the page at 
> 
> (permalink 
> ).

It looks like both images animate at about 10 frames per second in my
Firefox; your image has 240 frames, and the Wikipedia image has 66, so
the Wikipedia animation completes in about 1/4 the time.

I don't know why setting "delay=1" doesn't seem to be honored.  I
tried "delay=100" and that worked.  (I'm guessing it's a deliberate
design decision in Firefox, to prevent people from making fast,
flickery animated GIFs; but it also might be a bug in Sage, or a bug
in ImageMagick or Firefox.)

But anyway, the solution is to use fewer frames.

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: Animation speed question

2008-03-01 Thread Carl Witty

On Mar 1, 5:46 pm, "dean moore" <[EMAIL PROTECTED]> wrote:
> > ... *delay=20, delay=n* info ...
>
> Thanks.  I have a parameter called *delayBetweenImages*, set to 0,
> and tried manually setting delay = 0.  Same thing -- a slowish image.
> Tried *delayBetweenImages *= 5, *delayBetweenImages *= 20 -- same thing.
> Image slow, slower than the wikipedia image.  The MuPAD package seems
> written at least partly in C/C++ & maybe faster than SAGE, at least largely
> written in Python.  But how can that affect the speed of the final image?

The speed of MuPAD vs. Sage won't affect the animation speed of the
image.

I think we need to see the actual code you're using before we can help
further.

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: Peculiar Arithmetic Results

2008-02-24 Thread Carl Witty

On Feb 24, 11:17 am, Carl Witty <[EMAIL PROTECTED]> wrote:
> Thanks for reporting this!  This is a bug when transferring floating-
> point values from Sage to interpreters such as gp and octave.  We are
> now tracking this bug here:http://trac.sagemath.org/sage_trac/ticket/2294;
> I expect to have a fix shortly.

A proposed fix is now posted at http://trac.sagemath.org/sage_trac/ticket/2294
.

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: Peculiar Arithmetic Results

2008-02-24 Thread Carl Witty

On Feb 24, 10:56 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> Support team:
>
> Here is a puzzle (to me if not to you).
>
> In sage 2.10.2 (although the problem occurs in earlier versions)
> on a CoreDuo MacIntosh running under MacOS X.5.2 we have:
>
> a = gp.sin(1)
> octave.eval('format long g')
> b = octave.sin(1)
> c = math.sin(1)
> eps = 1. - (4./3.-1.)*3.
> d = a*eps
> a
> 0.8414709848078965066525023216
> b
> 0.841470984807897
> c
> 0.8414709848078965
> (a-b)/d
> -2.640423314436302686
> (a-c)/d
> -553.9021661362176753
> (b-c)/d
> -553.7921192926074518167939202
>
> Notice that a, b, c all seem to agree to about 16 digits, but when
> the 'native' sage value is mixed with the gp and octave values a
> horrendously large error occurs.

Thanks for reporting this!  This is a bug when transferring floating-
point values from Sage to interpreters such as gp and octave.  We are
now tracking this bug here: http://trac.sagemath.org/sage_trac/ticket/2294;
I expect to have a fix shortly.

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: Typo in Sage Reference Manual

2008-02-16 Thread Carl Witty

On Feb 12, 2:16 am, bill purvis <[EMAIL PROTECTED]> wrote:
> Just spotted what I think is a typo in the Reference manual:
> module-sage.plot.plot.html
> Scroll down about two screen-fulls and I find the line:
>
> We combine together different graphics objects using ``62#6 '':
>
> What's that bit in quotes? I'd assume it should be ``+''?
> Just did a check on the HTML source and it's on line 196.
> (This the online html from www.sagemath.org)

Thanks for reporting this problem; it is now being tracked at
http://trac.sagemath.org/sage_trac/ticket/2178, and will probably be
fixed in the next version of Sage.

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: Another possible bug in parametric_plot/show

2008-02-16 Thread Carl Witty

On Feb 16, 6:59 am, "bill.p" <[EMAIL PROTECTED]> wrote:
> def f(x):
>   y = 1729 - x^3
>   return sgn(y) * abs(y)^(1/3)
...
> f = parametric_plot((x,line((12,1),(9,10),x)),8,18)

You are defining f twice, first as a function then as a graphics
object.  You need to pick a different name for one or the other.

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: Odd behaviour of parametric_plot

2008-02-16 Thread Carl Witty

On Feb 12, 2:07 am, bill purvis <[EMAIL PROTECTED]> wrote:
> I wanted to make a plot of x^3+y^3=1729 (the well-known taxicab problem).
> I'm sure there are better ways of acieving this but I opted for a naive
> approach:
>
> {{{
> def sng(x):
>   if x < 0:
> return -1
>   return 1
>
> def f(x):
>   y3 = 1729 - x^3
>   return sgn(y3) * abs(y3)^(1/3)
>
> }}}
>
> {{{
> c = parametric_plot((x,f(x)),-15,15)
> c.show()
>
> }}}
>
> (I want to add other things to the plot).
> However, when I run this in the notebook, the plot has a cusp at x=12+
> and behaves as if the sgn(x) has been taken as +1. I tried evaluating
> f(x) at 12 and 13 and the result changes sign as I'd expect.

The problem is here:
sage: sgn(1729-x^3)
1
sage: 1729-x^3 < 0
1729 - x^3 < 0
sage: bool(1729-x^3 < 0)
False

You're applying the Python function f to the symbolic variable x,
which calls sgn(1729-x^3).  Then sgn(x) checks whether 1729-x^3<0,
which is taken to mean "Can you prove that 1729-x^3 is always less
than 0"?  Since the answer is no, sgn() returns 1.

The fix is easy: instead of passing the symbolic expression f(x) to
parametric_plot, pass the function f.
c = parametric_plot((x,f),-15,15)
Or even easier, there's no reason for this to be a parametric plot:
c = plot(f,-15,15)

As to whether there's a bug here... I don't know how to decide if any
of the above should count as a bug.  (I use the symbolic part of Sage
very seldom.)  If there is a bug, it may be difficult to fix.  The
thing I can see to do would be to make bool(x<0) signal an error,
instead of just returning False; but I don't know how much that would
break.

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: Another possible bug in parametric_plot/show

2008-02-16 Thread Carl Witty

On Feb 12, 3:47 am, "bill.p" <[EMAIL PROTECTED]> wrote:
> The Notebook is getting rather long now, so I've saved it to a file:
>
>  http://www.billp.org/Fermat-1729.sws

When I try to download this, I get "ERROR 404: Not Found".

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: Bug in function save...

2008-02-04 Thread Carl Witty

On Feb 4, 7:18 am, Georg <[EMAIL PROTECTED]> wrote:
> Hi,
> start sage-2.10.1 in a directory which contains a subdirectory 'foo':
>
> sage: a = srange(3)
> sage: save(a, 'foo/foo')
> sage: b = load('foo/foo')
> sage: b
> [0, 1, 2]
> sage: save(a, './foo/foo')
> ---
> Traceback (most recent call
> last)
>
> /home/georg/ in ()
>
> /home/georg/sage_object.pyx in sage.structure.sage_object.save()
>
> : 'list' object has no attribute
> 'save'
> sage: save(5, './foo/foo')
> sage: b = load('foo/foo')
> sage: b
> 5
>
> Looks like a bug..., or?
> Georg

Yes, this is a bug; thanks for reporting it.  I've posted a patch at
http://sagetrac.org/sage_trac/ticket/2046, which will probably be in
Sage 2.10.2.

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: Putting parentheses around -1.

2008-01-24 Thread Carl Witty

On Jan 23, 11:41 pm, Paul Zimmermann <[EMAIL PROTECTED]> wrote:
> Thus you have constructed a nice expression for 1:
>
> sage: sol[2].subs(a=1).right()
> (2/(3*sqrt(3)) + 10/27)^(1/3) - 2/(9*(2/(3*sqrt(3)) + 10/27)^(1/3)) + 1/3
>
> Quiz: how to simplify that expression to 1 within SAGE? I've tried simplify,
> and radical_simplify, but neither succeeds...

The Sage rings AA and QQbar can decide equalities between radical
expressions (over the reals and complex numbers respectively):

sage: a = AA((2/(3*sqrt(3)) + 10/27)^(1/3) - 2/(9*(2/(3*sqrt(3)) +
10/27)^(1/3)) + 1/3)
sage: a
[0.99988 .. 1.0003]
sage: a == 1
True

By the way, when I implemented AA/QQbar, I decided on the following
behavior for exponentiation:

sage: AA(-1)^(1/3)
-1
sage: QQbar(-1)^(1/3)
[0.49994 .. 0.50012] + [0.86602540378443859 ..
0.86602540378443871]*I

So when taking roots, for AA we prefer real roots if they exist, but
for QQbar we take the principal root.

Carl Witty

--~--~-~--~~~---~--~~
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: int / Integer question

2008-01-22 Thread Carl Witty

On Jan 22, 1:31 am, Paul Zimmermann <[EMAIL PROTECTED]> wrote:
> I also "enjoyed" several times converting from 'int' to 'Integer' and back.
> For beginners, this is a real difficulty, and in my opinion range? or xrange?
> should give a big warning that the "list of integers" output contains Python
> integers, which cannot be mixed with SAGE integers 'Integer'.
>
> It would also be nice to have a pointer from range? to srange (which does
> mention the difference between SAGE integers and Python int's).
>
> Finally, is there a valid reason why we have both 'int' and 'Integer'?
> (The 'int' type does not seem to have any size limitation.)

The 'int' (and its bignum counterpart, 'long') are native Python
types.  As far as I know, we don't modify Python at all; removing
'int' would be major surgery, and we're not going to do it.

'Integer' is a Sage type.  This means it has lots of useful
mathematical convenience methods (like .is_square()), it participates
in the coercion model, etc.  Also, 'Integer' is implemented with GMP,
and 'long' is not, so 'Integer' is much faster for large numbers.

range() and xrange() are Python builtins, so they return Python values
('int' or 'long'), and have documentation that doesn't mention any
other types.  srange() was written for Sage.

The final state of affairs, where we have multiple integral types that
show up in different contexts, is certainly annoying; but I don't see
how to avoid it while basing Sage on an unmodified Python; and we get
so much benefit from that decision that I wouldn't want to change it.

Some particular annoyances may be fixable.  For instance, you can just
do:

sage: range=srange

to overwrite Python's built-in range with Sage's for the current
command-line session.  I suppose we could do that globally on Sage
startup; but 1) this might break other Python code that expects to use
the original range(); and 2) I'm not sure we want to go down the path
of modifying Python's behavior, other than the preparser.

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: associativity of addition on ell. curves

2008-01-14 Thread Carl Witty

On Jan 11, 3:09 pm, Paul Zimmermann <[EMAIL PROTECTED]> wrote:
> I was able to do the job with SAGE, but I have to confess it was not as easy
> as in Maple (however I am still more fluent in Maple):
>
> --
> | SAGE Version 2.9.3, Release Date: 2008-01-05   |
> | Type notebook() for the GUI, and license() for information.|
> --
> sage: var('x1,y1,x2,y2,x3,y3,a,b')
> sage: eq1 = y1^2 -(x1^3+a*x1+b)
> sage: eq2 = y2^2 -(x2^3+a*x2+b)
> sage: eq3 = y3^2 -(x3^3+a*x3+b)
> sage: lambda12 = (y1 - y2)/(x1 - x2)
> sage: x4   = (lambda12*lambda12 - x1 - x2)
> sage: nu12 = (y1 - lambda12*x1)
> sage: y4   = (-lambda12*x4 - nu12)
> sage: lambda23 = ((y2 - y3)/(x2 - x3))
> sage: x5   = (lambda23*lambda23 - x2 - x3)
> sage: nu23 = (y2 - lambda23*x2)
> sage: y5   = (-lambda23*x5 - nu23)
> sage: s1 =(x1 - x5)*(x1 - x5)*((y3 - y4)*(y3-y4) - (x3+x4)*(x3-x4)*(x3-x4))
> sage: s2 =(x3 - x4)*(x3 - x4)*((y1 - y5)*(y1-y5) - (x1+x5)*(x1-x5)*(x1-x5))
> sage: n12 = numerator(factor(s1-s2))
> sage: R = singular.ring(0, '(a,b,x1,x2,x3,y1,y2,y3)')
> sage: I = singular.ideal([repr(eq1), repr(eq2), repr(eq3)])
> sage: I2 = I.groebner()
> sage: singular.reduce(repr(n12), I2)
>
> 0

Here is a more idiomatic way to do this computation in Sage.  We work
in the fraction field of a multivariate polynomial ring; this means
that our polynomial arithmetic is handled by libSingular instead of by
maxima, and that we can get the numerator directly with "numerator",
since fraction field elements are always normalized.  Also, we use
Sage's wrapper of ideals and Groebner bases (which I believe is
implemented with libSingular), rather than calling Singular.
(Avoiding the call to "factor(s1-s2)" means that this version is much
faster.)

sage: R. = QQ[]
sage: eq1 = y1^2 -(x1^3+a*x1+b)
sage: eq2 = y2^2 -(x2^3+a*x2+b)
sage: eq3 = y3^2 -(x3^3+a*x3+b)
sage: lambda12 = (y1 - y2)/(x1 - x2)
sage: x4   = (lambda12*lambda12 - x1 - x2)
sage: nu12 = (y1 - lambda12*x1)
sage: y4   = (-lambda12*x4 - nu12)
sage: lambda23 = ((y2 - y3)/(x2 - x3))
sage: x5   = (lambda23*lambda23 - x2 - x3)
sage: nu23 = (y2 - lambda23*x2)
sage: y5   = (-lambda23*x5 - nu23)
sage: s1 =(x1 - x5)*(x1 - x5)*((y3 - y4)*(y3-y4) - (x3+x4)*(x3-x4)*(x3-
x4))
sage: s2 =(x3 - x4)*(x3 - x4)*((y1 - y5)*(y1-y5) - (x1+x5)*(x1-x5)*(x1-
x5))
sage: n12 = numerator(s1-s2)
sage: I = ideal([eq1,eq2,eq3])
sage: I.reduce(n12)
0

> Paul Zimmermann

Carl Witty

--~--~-~--~~~---~--~~
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://sage.math.washington.edu/sage/ and http://sage.scipy.org/sage/
-~--~~~~--~~--~--~---



[sage-support] Re: OLPC and sage

2007-12-20 Thread Carl Witty

On Dec 19, 4:45 pm, "David Joyner" <[EMAIL PROTECTED]> wrote:
> Hi:
> I just got a OLPC laptop and of course tried to connect to sagemath.
> I connected to the wifi using the neighborhood screen then
> opened the browser. It opens to google, so I typed sage and it was
> the number 2 choice. I tried to connect to the online server on sagemath.org
> but the laptop apparently could not achieve a secure connection.

I'm guessing you ran into http://dev.laptop.org/ticket/542, where the
XO browser cannot connect to secure sites with self-signed
certificates.

> I wonder if a SAGE binary can be run from an SD card?

I'm sure it can.  It might be tricky to get a Sage binary that runs on
the XO, though; I'm guessing it would need to be compiled on a machine
without SSE (or at least without SSE2).  (Either that, or we would
need to fix all the Sage components that currently do CPU probing to
allow compiling for a specific x86 variant instead.)

Carl Witty

--~--~-~--~~~---~--~~
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://sage.math.washington.edu/sage/ and http://sage.scipy.org/sage/
-~--~~~~--~~--~--~---



[sage-support] Re: Strangeness with axes in matplotlib

2007-12-19 Thread Carl Witty

On Dec 18, 3:59 pm, wdbragg <[EMAIL PROTECTED]> wrote:
> I am seeing some strange things with the labelling of axes in
> matplotlib.
...
> First problem, the y-axis labelling is different.  On the matplotlib
> page, the largest y-axis value labeled is 140.
> In sage, it is 1.4 x1e+2.

This is a known bug in Sage (http://sagetrac.org/sage_trac/ticket/
924).  Hopefully somebody will fix it soon.  (I'll try to fix it in
early January if nobody beats me to it.)

Carl Witty

--~--~-~--~~~---~--~~
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://sage.math.washington.edu/sage/ and http://sage.scipy.org/sage/
-~--~~~~--~~--~--~---



[sage-support] Re: side effect problem of numpy.dot with Integer and QQ arrays.

2007-10-30 Thread Carl Witty

On Oct 29, 12:05 am, Manny <[EMAIL PROTECTED]> wrote:
> In sage, the arguments of numpy.dot can be changed when they
> shouldn't. The following illustrates the problem:
>
> import numpy as npy
> # With sage.rings.integer.Integer:
> x = npy.array([1])
> print x
>   # [1]
> npy.dot(x, npy.array([0]))
> print x
>   # [0]
>
> # This also happens with QQ arrays, but not
> # with any of the finite fields I tried.
> y = MatrixSpace(QQ,2).identity_matrix().numpy()
> print y # [[1 0] [0 1]]
> npy.dot(y, npy.array(VectorSpace(QQ,2).basis()[0]))
> print y # [[1 0] [0 0]]
>
> I am using SAGE version 2.8.7.
>
> Explanations and workarounds are appreciated.

Thank you for reporting this problem!  I've opened a ticket here:
http://sagetrac.org/sage_trac/ticket/1038

Here's the (slightly technical) explanation.  Recently, Robert
Bradshaw added a significant optimization to arithmetic in Sage.  The
optimization is that if you're about to compute a*b, and you know that
the old value of a will no longer be used after this multiplication,
you can reuse the old storage to hold the result of the
multiplication.  This significantly cuts down on the number of memory
allocations and deallocations to perform basic arithmetic.  However,
for this to be safe, we need added restrictions on Python's C API,
above and beyond what Python normally requires.  All of the core Sage
code does follow these restrictions (because it's all generated using
Cython, and Robert added a command-line argument to Cython to generate
compliant code).  However, numpy's C code, unsurprisingly, does not.

The simplest workaround is not to try to store Sage values in numpy
arrays.  Is there a reason you can't use Sage matrices?  If there is
some matrix functionality that numpy has and Sage doesn't, maybe we
could add it to Sage.

At this point, I can only think of two other workarounds; both are
fairly ugly.  The simplest, very ugly and fairly inefficient
workaround is to replace:
x = npy.dot(a, b)
with:
copies = copy(a), copy(b)
x = npy.dot(a, b)

The extra references to the values of a and b held by "copies" should
keep the optimization from triggering.

The other workaround is to remove the optimization from Sage.  Find
the file sage/structure/element.pyx, and search for blocks of code
that look like this:

if  (left).ob_refcnt < inplace_threshold:
return _iadd_c(left,
right)
else:
return _add_c(left,
right)

Remove (or comment out) the first three lines of each block.  There
are eight such blocks, and you can find them by searching for
"inplace_threshold".

Then run "sage -b".  This will recompile that file.

Carl Witty


--~--~-~--~~~---~--~~
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://sage.math.washington.edu/sage/ and http://sage.scipy.org/sage/
-~--~~~~--~~--~--~---