Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion patches for the calculus code

MIME-Version: 1.0
Received: by 10.150.57.17 with SMTP id f17mr1819yba.14.1225707819387; Mon, 03 
	Nov 2008 02:23:39 -0800 (PST)
Date: Mon, 3 Nov 2008 02:23:39 -0800 (PST)
In-Reply-To: <b23250da-d33e-41f5-a6ea-8e5fea4feb26@d36g2000prf.googlegroups.com>
X-IP: 129.27.150.27
References: <d99e7418-4bd9-4ebf-a4c5-9f3f3fe6d330@b31g2000prf.googlegroups.com> 
	<85e81ba30811021138m1114cbadk57b80367a2459ac5@mail.gmail.com> 
	<b23250da-d33e-41f5-a6ea-8e5fea4feb26@d36g2000prf.googlegroups.com>
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.16) 
	Gecko/20080702 Firefox/2.0.0.16,gzip(gfe),gzip(gfe)
Message-ID: <e4a644e3-73d6-413a-821f-63ae3e427cac@q26g2000prq.googlegroups.com>
Subject: Re: patches for the calculus code
From: Wilfried_Huss <h...@finanz.math.tugraz.at>
To: sage-devel <sage-devel@googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit



On 2 Nov., 20:46, mabshoff <mabsh...@googlemail.com> wrote:
> On Nov 2, 11:38 am, "William Stein" <wst...@gmail.com> wrote:
>
> > On Sun, Nov 2, 2008 at 3:10 AM, Wilfried_Huss
>
> Hi,
>
>
>
> > <h...@finanz.math.tugraz.at> wrote:
>
> > > Hi,
>
> > > I have written some code for the Maxima interface.
> > > You can find the patches at:
> > >  http://www.math.tugraz.at/~huss/sage
>
> > > calculus1.patch implements the conversion from Maxima
> > > matrices to Sage matrices.
>
> This should come in handy, but starting with 3.2 we will finally have
> pynac available for some of the basic symbolic manipulation tasks. It
> is far from bullet proof, but it is a start, so the days of Maxima as
> the default implementation of the low level symbolic stuff is coming
> finally to an end :)

Yes, but as far as I understand Maxima will still be used for the high
level
symbolic stuff for the foreseeable future. So I think it makes sense
to have
the conversions between Sage and Maxima as complete as possible.

> > > calculus2.patch adds symbolic gamma and factorial functions.
> > > (The factorial is named fact() so it doesn't clash with the
> > > factorial in sage.rings.arith)
>
> Provided the factorial bit does not interfere with the current non-
> symbolic code this could be useful.
>
> > > Finally calculus3.patch renames the symbolic factorial to factorial(),
> > > and changes all imports of sage.rings.arith.factorial to
> > > sage.calculus.calculus.factorial. I had to keep a renamed version
> > > of the factorial function in sage.rings.arith to avoid circular
> > > imports at startup.
>
> I don't like this patch at all since it forces us to use a Maxima
> function even for integers which ought to be the most common use of
> factorial.

But it doesn't use Maxima for non-symbolic input.

Just as before factorial(x) just tries to call

x.factorial()

only if this raises an exception the symbolic version is
constructed.

sage: def f(n):
sage:   s = 0
sage:   for i in xrange(n):
sage:      s += factorial(2^i)
sage:   return s.ndigits()

sage: time f(22)
 12346641
CPU time: 10.89 s,  Wall time: 10.94 s

This is the same with or without the patch.

> When the point counting code was using Maxima to compute
> ceil, floor and sqrt the code as a whole was slower by a factor of
> three which illustrates nicely why we don't want to use Maxima unless
> there is a good reason to do so. Especially considering that using
> mpfr's functions was abotu a million times faster since there is no
> pexpect overhead. I could see using that code in case the argument is
> non-integer, but not using the highly optimized gmp implementation for
> something that is many orders of magnitude slower is just not what we
> want to do.
>
> Cheers,
>
> Michael
>
> > > The patches are against 3.2-alpha1, after applying all 3 patches
> > > all tests passed.
>
> > > Here is a sample session with the new functionality:
>
> > > sage: var('x,y')
> > > sage: v = maxima('v: vandermonde_matrix([x, y, 1/2])')
> > > sage: v
> > > matrix([1,x,x^2],[1,y,y^2],[1,1/2,1/4])
> > > sage: type(v)
> > > <class 'sage.interfaces.maxima.MaximaElement'>
> > > sage: v.sage()
>
> > > [  1   x x^2]
> > > [  1   y y^2]
> > > [  1 1/2 1/4]
> > > sage: mlist = maxima('[v, sin(x), 1, v.v]').sage()
> > > sage: mlist
>
> > > [[  1   x x^2]
> > > [  1   y y^2]
> > > [  1 1/2 1/4],
> > >    sin(x),
> > >    1,
> > >    [       x^2 + x + 1    x*y + x^2/2 + x    x*y^2 + 5*x^2/4]
> > > [       y^2 + y + 1        3*y^2/2 + x  y^3 + y^2/4 + x^2]
> > > [               7/4      y/2 + x + 1/8 y^2/2 + x^2 + 1/16]]
> > > sage: [parent(i) for i in mlist]
>
> > > [Full MatrixSpace of 3 by 3 dense matrices over Symbolic Ring,
> > >    Symbolic Ring,
> > >    Symbolic Ring,
> > >    Full MatrixSpace of 3 by 3 dense matrices over Symbolic Ring]
>
> > > sage: gamma(x/2)(x=5)
> > > 3*sqrt(pi)/4
>
> > > sage: f = factorial(x + factorial(y))
> > > sage: maxima(f).sage()
> > > factorial(factorial(y) + x)
>
> > > sage: f(y=x)(x=3)
> > > 362880
>
> > > I hope it is useful.
>
> > > Greetings,
> > > Wilfried Huss
>
> > Thanks!  Could you write to Michael Abshoff (<mabsh...@googlemail.com>) and ask
> > for a trac account, then open three trac tickets, one
> > for each of the above? Thanks again!
>
> > William

Greetings,