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 derivative 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 Washington
http://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