[sage-support] Re: polynomial division by increasing powers
Hi Johannes! On 16 Nov., 23:48, Johannes Huisman wrote: > Does sage have a command for polynomial division by increasing powers? I > could not find such a command. Of course, one may use power series > division in order to compute the quotient, but it would be neat if one > could avoid all that. What exactly do you expect? For example: sage: P. = QQ[] sage: p = P.random_element() sage: q = P.random_element() sage: p 4/3*x^2 - x + 7 sage: q 2/7*x^2 - x 1. Apparently you do not want that the quotient of p and q lives in the fraction field, as it is currently the case: sage: p/q (4/3*x^2 - x + 7)/(2/7*x^2 - x) 2. Do you need the "quotient with remainder"? Then you could do sage: p.quo_rem(q) (14/3, 11/3*x + 7) 3. Or do you want that the quotient of p and q actually is a power series? So, like this: sage: p/q # not implemented -7*x^-1 - 1 - 34/21*x - 68/147*x^2 - 136/1029*x^3 - 272/7203*x^4 - 544/50421*x^5 - 1088/352947*x^6 - 2176/2470629*x^7 - 4352/17294403*x^8 - 8704/121060821*x^9 - 17408/847425747*x^10 - 34816/5931980229*x^11 - 69632/41523861603*x^12 - 139264/290667031221*x^13 - 278528/2034669218547*x^14 - 557056/14242684529829*x^15 - 1114112/99698791708803*x^16 - 2228224/697891541961621*x^17 - 4456448/4885240793731347*x^18 + O(x^19) Possibility 3. requires that Frac(P) does not return a formal fraction field (which is currently the case) but a power series ring. I am sure that it would require much persuasion and a poll on sage-devel if one wants such change. Also note that the term order in P and Q differs (with the additional complication that Q(p) does not have an attribute leading_coefficient, but p does). sage: p 4/3*x^2 - x + 7 sage: Q(p) 7 - x + 4/3*x^2 So, if what you want is 3., then currently you have to use the power series ring manually, such as: sage: Q = PowerSeriesRing(QQ,'x') sage: Q(p)/q # q is automatically coerced into Q -7*x^-1 - 1 - 34/21*x - 68/147*x^2 - 136/1029*x^3 - 272/7203*x^4 - 544/50421*x^5 - 1088/352947*x^6 - 2176/2470629*x^7 - 4352/17294403*x^8 - 8704/121060821*x^9 - 17408/847425747*x^10 - 34816/5931980229*x^11 - 69632/41523861603*x^12 - 139264/290667031221*x^13 - 278528/2034669218547*x^14 - 557056/14242684529829*x^15 - 1114112/99698791708803*x^16 - 2228224/697891541961621*x^17 - 4456448/4885240793731347*x^18 + O(x^19) Cheers, Simon -- 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
Re: [sage-support] writing docs with sage
On Tue, 16 Nov 2010 at 10:37AM -0800, craigp wrote: > I'm thinking of using sage to write various kinds of technical docs > (math in particular, naturally). I've just started to learn Latex, but > I find some of aspects of that limiting (macros in particular). "Limiting" is an amusing choice of words, since TeX's macros constitute a Turing-complete programming language. > 1) I'd like to use rst (restructured text) for other docs, eg: a trac > wiki. Ideally, I'd like to embed sage into wiki pages (perhaps with an > option to save-as latex, pdf, etc). I noticed trac is an optional part > of the sage distribution, but it isn't clear whether this supports > embedding rst/sage (exactly as sage's manuals are written). Is this > supported, and if not, is anyone working in this direction, or would > there be interest if I wrote a trac plugin to accomplish this? I'm not sure precisely what you mean here, but AFAIK the optional Trac package doesn't do anything special with embedding Sage into ReST. Do you want to embed Sage into ReST in the same way that SageTeX embeds Sage into LaTeX, or that Sweave embeds R into LaTeX? That is, you have special bits in the text that are somehow processed and replaced by the results of the corresponding Sage computations. There is nothing like that for ReST that I know of, but I'd love to hear about it. > 2) Is there support for introspection in sage? For example, could I > query a notebook/worksheet/session to find all definitions and > references to vector defined functions, or functions starting with a > certain name, or 4*4 complex-valued matrices, etc? Yes. If you have a function, add a question mark and evaluate the cell. Try sin? or search_def? If you add two question marks, you get the corresponding source code. Above you say that you want to query a "notebook/worksheet/session" about these things; I don't know any way to limit something like search_def to the current session, although there is extensive tab completion available. Dan -- --- Dan Drake - http://mathsci.kaist.ac.kr/~drake --- signature.asc Description: Digital signature
[sage-support] Re: bool(arcsin(x) == 2*arctan(x/(1+sqrt(1-x^2)))) returns false !!!
On Nov 16, 8:28 pm, Derrick wrote: > ok, I got your point. Now, a different issue with "bool" > > bool( sin(2*x) == 2*sin(x)*cos(x) ) returns True > while > bool( sin(x) == 2*sin(x/2)*cos(x/2) ) returns False > > Similarly, > bool( tan(x) == sin(2*x)/(1+cos(2*x)) ) returns True > while > bool( tan(x/2) == sin(x)/(1+cos(x)) ) returns False > > Do you have any idea why sage "bool" fails for trig functions with > fractional angles? > Can you suggest any work around? > This is a little tricky, because Sage uses certain simplifications of Maxima, but not *every* conceivable one available, for checking this. If you read the documentation for the following command, you'll see various options that look promising, but none of them do what you want - if Maxima has a command that would simplify this instead of using half-angle formulas, we haven't wrapped it. sage: b = 2*sin(1/2*x)*cos(1/2*x) sage: b.expand_trig() 2*sin(1/2*x)*cos(1/2*x) sage: b.expand_trig?? - kcrisman does what you want -- 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: bool(arcsin(x) == 2*arctan(x/(1+sqrt(1-x^2)))) returns false !!!
ok, I got your point. Now, a different issue with "bool" bool( sin(2*x) == 2*sin(x)*cos(x) ) returns True while bool( sin(x) == 2*sin(x/2)*cos(x/2) ) returns False Similarly, bool( tan(x) == sin(2*x)/(1+cos(2*x)) ) returns True while bool( tan(x/2) == sin(x)/(1+cos(x)) ) returns False Do you have any idea why sage "bool" fails for trig functions with fractional angles? Can you suggest any work around? On Nov 12, 9:36 pm, Robert Bradshaw wrote: > On Fri, Nov 12, 2010 at 3:44 PM, Derrick wrote: > > Any clue why bool(arcsin(x) == 2*arctan(x/(1+sqrt(1-x^2 returns > > false where the expressions are mathematically equivalent. > > Because an expression being equal to zero is, in general, and > undecideable question. If it can't tell, it'd rather error on the side > of caution (not being equal) than claim they're equal. > > > I found that arcsin(x) - 2*arctan(x/(1+sqrt(1-x^2))) is not exactly 0 > > for all x in [-1,1]. > > True. You can't even represent arcsin(x) exactly as a floating point > number for most values of x. There's rounding error and all when you > combine operations as well. > > > In sage, is there any way to compare expressions > > with some numerical precision? > > sage: expr.subs(x=1/3).n() > 0.000 > sage: expr.subs(x=1/3).n(100) > 3.9443045261050590270586428264e-31 > sage: expr.subs(x=1/3).n(1000) > 0. > > - Robert -- 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] polynomial division by increasing powers
Hello, Does sage have a command for polynomial division by increasing powers? I could not find such a command. Of course, one may use power series division in order to compute the quotient, but it would be neat if one could avoid all that. Thanks in advance, Johannes -- http://pageperso.univ-brest.fr/~huisman -- 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] writing docs with sage
Hi - I'm thinking of using sage to write various kinds of technical docs (math in particular, naturally). I've just started to learn Latex, but I find some of aspects of that limiting (macros in particular). I think my options come down to sagetex or rst + sphinx + sage. I'm more interested in the latter at the moment. So, here are my questions: 1) I'd like to use rst (restructured text) for other docs, eg: a trac wiki. Ideally, I'd like to embed sage into wiki pages (perhaps with an option to save-as latex, pdf, etc). I noticed trac is an optional part of the sage distribution, but it isn't clear whether this supports embedding rst/sage (exactly as sage's manuals are written). Is this supported, and if not, is anyone working in this direction, or would there be interest if I wrote a trac plugin to accomplish this? Perhaps the online sage notebook already does this (I'm a bit confused on exactly what this does), but ideally, it would be (somehow) be integrated with trac. 2) Is there support for introspection in sage? For example, could I query a notebook/worksheet/session to find all definitions and references to vector defined functions, or functions starting with a certain name, or 4*4 complex-valued matrices, etc? thanks! --craig -- 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: long input in sage notebook
Many thanks Robert On 15 lis, 13:25, Jason Grout wrote: > Try: > > sage: x=RealNumber('0.13546543513\ > 35216544435213132\ > 354351321321321') > sage: x > 0.135465435133521654443521313235435132132132 -- 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
Re: [sage-support] Heavy memory usage in a basic example: what happens? How to manage it?
Hello, On Tue, Nov 16, 2010 at 12:03 AM, Rolandb wrote: > 3) I could not find a Sage standard function to deliver this output. > There are so many functions around... > Is there such a function? An iterator is even better. N.B.: The above > example "splits" can easily transformed to an iterator, but that is > not the issue. SetPartitions is what you want. sage: S = SetPartitions(range(4),2); S Set partitions of [0, 1, 2, 3] with 2 parts sage: S.list() [{{1, 2, 3}, {0}}, {{0, 2, 3}, {1}}, {{2}, {0, 1, 3}}, {{0, 1, 2}, {3}}, {{2, 3}, {0, 1}}, {{1, 3}, {0, 2}}, {{1, 2}, {0, 3}}] sage: it = iter(S) sage: it.next() {{1, 2, 3}, {0}} sage: S.cardinality() 7 --Mike -- 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] Heavy memory usage in a basic example: what happens? How to manage it?
Hi, I assumed that pure python would not consume (too much) memory. But consider the following simple pure python example: sage: def splits(lijst,n): ... ... """ ... Divides a list in all combinations of n smaller partitions ... example: ... splits(range(5),2)= [[[0], [1, 2, 3]], [[0, 1], [2, 3]], [[1], [0, 2, 3]], [[0, 2], [1, 3]], ... [[2], [0, 1, 3]], [[0, 3], [1, 2]], [[3], [0, 1, 2]]] ... """ ... lengte=len(lijst) ... if lengtehttp://groups.google.com/group/sage-support URL: http://www.sagemath.org