I would really like to not have to annoy you with this stuff, but I
really think I'm missing something important (and useful!!)

The first thing I have to say is: how do I check which is the type of
the coefficients (whether they are rationals or something else)? Even
when I do multivariate polynomials, I am comfortable with using
symbolic variables (probably I should switch, but I still have to
learn how to threat polynomials in SAGE).

One thing that really surprises me is: how comes in this simple
following example, expand() is so much slower than factor()? I often
do factor(expand(argument)) to be sure that factor is effective, and I
was supposing that expand() should have been so straightforward to not
require any particular computational effort! But look at this:

var('x1 x2')
var('u')
var('s')
var('a1 b1 c1 d1')
var('a2 b2 c2 d2')
var('e1 f1')
var('e2 f2')

A1 = matrix([[a1,b1],[c1,d1]])
A2 = matrix([[a2,b2],[c2,d2]])
B1 = matrix([[e1],[f1]])
B2 = matrix([[e2],[f2]])

var('D')
Am = D*A1 + (1-D)*A2
Bm = D*B1 + (1-D)*B2
Id=identity_matrix(parent(s),Am.nrows());
solm = (Am-Id*s)\(-Bm*u); solm

[u*(-e1*D - e2*(1 - D))/(a1*D + a2*(1 - D) - s) - (b1*D + b2*(1 -
D))*(u*(-f1*D - f2*(1 - D)) + u*(-c1*D - c2*(1 - D))*(-e1*D - e2*(1 -
D))/(a1*D + a2*(1 - D) - s))/((a1*D + a2*(1 - D) - s)*((b1*D + b2*(1 -
D))*(-c1*D - c2*(1 - D))/(a1*D + a2*(1 - D) - s) + d1*D + d2*(1 - D) -
s))]
[
(u*(-f1*D - f2*(1 - D)) + u*(-c1*D - c2*(1 - D))*(-e1*D - e2*(1 -
D))/(a1*D + a2*(1 - D) - s))/((b1*D + b2*(1 - D))*(-c1*D - c2*(1 -
D))/(a1*D + a2*(1 - D) - s) + d1*D + d2*(1 - D) - s)]

sol1 = solm[0];
time a = SR(repr(sol1)).factor()

Time: CPU 0.04 s, Wall: 0.17 s

time a = SR(repr(sol1)).expand()

Time: CPU 69.00 s, Wall: 116.28 s


Do you consider this acceptable? I think there is some issue here!
Please, notice that this is SAGE 3.3... Is this a good reason to
upgrade? This is a multiuser environment, so it is slower to upgrade
than my laptop.

Another question: is possible that whenever I got Wall time much
higher than CPU time in factor, this should be recognized as a symptom
of having factor done via maxima? E.g.:

time igrFac = SR(repr(igrSol)).factor()
Time: CPU 0.51 s, Wall: 2.07 s

This is a completely different example. Also in this case, the expand
took forever to accomplish...

> Here's an example where the factorization could be done quickly via
> Singular, but isn't because we haven't bothered:
>
> sage: g = SR(f).subs(x=pi)          # replace x by the transcendental pi
> sage: time g.factor()
> CPU times: user 0.02 s, sys: 0.01 s, total: 0.03 s
> Wall time: 1.55 s

About this point, does substitution by 0 matter as well to make
Singular unusable? This would be really bad, because I usually do
something like this:

simpleDict = {"rQ":0, "rCb":0, "rCf":0,"rLf":0}
[soluz[0][vCb].subs(simpleDict)

to simplify my expressions.

Last but not least. Do you think is this a reasonable way to work with
the solution of a linear system, represented by matrices? The matrices
are Aave, Bave, Cave, Dave (canonical dynamic system representation)

inVec = matrix([[gr],[ib]]); inVec
xVec = matrix([[vCb],[vCf],[iLf]]); xVec
sys = (Aave - I*w*Id)*xVec + Bave*inVec
xSys = [vCb,vCf,iLf]
soluz = solve(sys,xSys, solution_dict = True)
xSol = matrix([[soluz[0][vCb].subs(simpleDict)],[soluz[0][vCf].subs
(simpleDict)],[soluz[0][iLf].subs(simpleDict)]])
outVec = Cave*xSol + Dave*inVec
igrSol = SR(repr(outVec[0])).subs(simpleDict)
vbSol = SR(repr(outVec[1])).subs(simpleDict)

I fear that I'm confusing SAGE by going back and forth with different
packages, so this is taking me hours to do simple operations (am I
wrong) like expand(), factor(), collect() and others (especially
expand, as you could see!)

Many, many thanks

Maurizio

On Mar 30, 4:44 pm, William Stein <wst...@gmail.com> wrote:
> On Mon, Mar 30, 2009 at 7:29 AM, Maurizio <maurizio.gran...@gmail.com> wrote:
>
> > I'm sorry... I wanted to say: is there any plan to make factor()
> > working with new symbolic as well? I could see one minute ago that
> > expand is already there (although I'm not aware whether is this
> > performed through maxima or not, but I don't think so, since it is a
> > built-in method for a pynac object).
>
> Yes, factor will work.  I think it will work in cases involving only
> rational numbers, roots, and transcendentals by converting the
> expression to a multivariate polynomial and using sage's multivariate
> polynomial factorization (i.e., Singular).
>
> > Yes, the problem is that I found them quite slow, even though this
> > could arise from complex expressions. Unfortunately, I have not any
> > commercial software to compare with. Should I compare it with
> > evaluation time from working directly within maxima?
>
> For factoring over the rationals say, try comparing to the following:
>
> sage: R.<x,y,z> = QQ[]
> sage: f = prod([R.random_element(degree=15) for _ in range(3)])
> sage: f
> -1/20*x^14*y^20*z^8 + 1/2*x^18*y^20*z^3 - 1/20*x^9*y^25*z^7 +
> 1/2*x^13*y^25*z^2 - 6/5*x^19*y^8*z^13 + 12*x^23*y^8*z^8 -
> 6/5*x^14*y^13*z^12 + 12*x^18*y^13*z^7 + 5/6*x^15*y^20*z^2 +
> 5/6*x^10*y^25*z - 2*x^10*y^21*z^4 + 20*x^20*y^8*z^7 - 2*x^5*y^26*z^3 +
> 20*x^15*y^13*z^6 + 4/5*x^17*y^10*z^7 + 1/4*x^6*y^16*z^12 -
> 8*x^21*y^10*z^2 + 4/5*x^12*y^15*z^6 - 5/2*x^10*y^16*z^7 -
> 48*x^15*y^9*z^9 - 8*x^16*y^15*z - 48*x^10*y^14*z^8 + 6*x^11*y^4*z^17 -
> 60*x^15*y^4*z^12 - 40/3*x^18*y^10*z - 25/6*x^7*y^16*z^6 -
> 40/3*x^13*y^15 + 32*x^13*y^11*z^3 + 10*x^2*y^17*z^8 -
> 100*x^12*y^4*z^11 + 32*x^8*y^16*z^2 - 4*x^9*y^6*z^11 + 40*x^13*y^6*z^6
> + 240*x^7*y^5*z^13 + 200/3*x^10*y^6*z^5 - 160*x^5*y^7*z^7
> sage: time f.factor()
> CPU times: user 0.05 s, sys: 0.00 s, total: 0.05 s
> Wall time: 0.05 s
> sage: time maxima(f).factor()
> CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
> Wall time: 1.46 s
> x^2*y^4*(5*z^5-x^8*y^4*z-x^3*y^9)*(3*x^4*z^6+120*y*z^2-30*x^8*z-50*x^5)*(24*x^5*z^6+y^12*z-16*x^3*y^2)/60
>
> Note that if you do SR(f).factor(), it is just as fast:
>
> sage: time SR(f).factor()
> CPU times: user 0.06 s, sys: 0.00 s, total: 0.06 s
> Wall time: 0.06 s
> x^2*y^4*(-5*z^5 + x^8*y^4*z + x^3*y^9)*(-3*x^4*z^6 - 120*y*z^2 +
> 30*x^8*z + 50*x^5)*(24*x^5*z^6 + y^12*z - 16*x^3*y^2)/60
>
> This is because (from SR's factor docstring): "If you are factoring a
> polynomial with rational coefficients (and dontfactor is empty) the
> factorization is done using Singular
>             instead of Maxima, so the following is very fast instead of
>             dreadfully slow"
>
> Here's an example where the factorization could be done quickly via
> Singular, but isn't because we haven't bothered:
>
> sage: g = SR(f).subs(x=pi)          # replace x by the transcendental pi
> sage: time g.factor()
> CPU times: user 0.02 s, sys: 0.01 s, total: 0.03 s
> Wall time: 1.55 s
> pi^2*y^4*(5*z^5 - pi^8*y^4*z - pi^3*y^9)*(3*pi^4*z^6 + 120*y*z^2 -
> 30*pi^8*z - 50*pi^5)*(24*pi^5*z^6 + y^12*z - 16*pi^3*y^2)/60
>
> I think the Pynac symbolics will make the pi --> var switch
> automatically in all cases.
>
> Note that Ginac itself (the project pynac is based on = forked)
> doesn't even have a factor function:
>
> ----
> wst...@sage:~$ ginsh
> ginsh - GiNaC Interactive Shell (ginac V1.4.1)
>   __,  _______  Copyright (C) 1999-2007 Johannes Gutenberg University Mainz,
>  (__) *       | Germany.  This is free software with ABSOLUTELY NO WARRANTY.
>   ._) i N a C | You are welcome to redistribute it under certain conditions.
> <-------------' For details type `warranty;'.
>
> Type ?? for a list of help topics.> factor(x^2 - y^2);
>
> unknown function 'factor'
> ----
>
> This should tell you something about the sophistication of Ginac as a
> computer algebra system -- it's really just for fast symbolic
> manipulation, and for that it is very very good indeed.     Ginac does
> have a GCD implementation, but I don't think we'll use it, since
> Singular already has one that is probably comparable or better.
>
>  -- William
>
>
>
>
>
> > Maurizio
>
> > On Mar 30, 4:24 pm, William Stein <wst...@gmail.com> wrote:
> >> On Mon, Mar 30, 2009 at 7:19 AM, Maurizio <maurizio.gran...@gmail.com> 
> >> wrote:
>
> >> > One question: is there any plan to replace expand(), factor() and
> >> > other functions like these?
>
> >> Replace them with what? Do you mean, implement them?
>
> >> >I don't see them mentioned in the todo,
> >> > and I always find their usage so much time consuming...
>
> >> Do you mean that they are too slow in the current symbolics?
>
> >> > Thanks
>
> >> > Maurizio
>
> >> > On Mar 29, 1:47 pm, Burcin Erocal <bur...@erocal.org> wrote:
> >> >> Hi,
>
> >> >> I put up a preliminary todo list for the switch to pynac here:
>
> >> >>http://wiki.sagemath.org/symbolics/switch_todo
>
> >> >> I made the list by changing the default of the "var" command to create
> >> >> pynac variables, and running the doctests. Looking at the results I
> >> >> realised that I should have made other changes, such as export the new
> >> >> symbolic ring (NSR) to the command line as SR. These are listed in the
> >> >> first section of that page.
>
> >> >> Next section gives a list of methods which the pynac symbolic
> >> >> expressions (sage.symbolic.expression.Expression) need to implement.
> >> >> The last section is miscellaneous stuff I didn't want to classify
> >> >> further.
>
> >> >> Some time next week, I will put a clean version of the switchover
> >> >> patch, along with a new pynac package and some fixes to the sage
> >> >> library so others can reproduce the results above.
>
> >> >> After looking through the errors caused by the switch, I have a few
> >> >> questions:
>
> >> >> - Syntax for d

erivative and integrate functions:
>
> >> >> Current symbolics allows this:
>
> >> >> sage: (x^2).integrate()
> >> >> x^3/3
>
> >> >> I propose to make the integration variable explicit, by deprecating
> >> >> this use, and encouraging the use of this:
>
> >> >> sage: (x^2).integrate(x)
> >> >> x^3/3
>
> >> >> Note that the MMA syntax for Integrate also asks for the variable
> >> >> explicitly.
>
> >> >> Same goes for .derivative(), current symbolics works without specifying
> >> >> a variable. While this usage might be ok in a univariate polynomial
> >> >> ring, where the variable is known already, I think it's better to ask
> >> >> the user to explicitly state the variable.
>
> >> >> - What do we do with the old tests?
>
> >> >> In the sage/calculus/ directory there are files which contain only
> >> >> tests. What shall I do with these? Copy them to sage/symbolics/test,
> >> >> change the old ones to use old symbolics variables to test the old
> >> >> code, and make the new copies test the new code?
>
> >> >> Or, what do you think should happen to the old code? How long are we
> >> >> going to keep it around?
>
> >> >> Comments?
>
> >> >> Cheers,
> >> >> Burcin
>
> >> --
> >> William Stein
> >> Associate Professor of Mathematics
> >> University of Washingtonhttp://wstein.org
>
> --
> William Stein
> Associate Professor of Mathematics
> University of Washingtonhttp://wstein.org
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to