On Feb 10, 1:39 am, Stan Schymanski <[email protected]> wrote: > Dear all, > > I suppose that the below is not possible yet, so I am forwarding this > to sage-devel. I think it would be great if one was able to access > parts of an expression in a nested way, e.g. > > expr1 = (a*x^3 + b*x)/(1 - Sqrt((1 - x)/(x - c))) + c/x > > expr1[0] > (a*x^3 + b*x)/(1 - Sqrt((1 - x)/(x - c))) > > expr1[1] > c/x > > expr1[0][0] > (a*x^3 + b*x)
I'm not sure you want to reserve indexing notation for that purpose, since it can have legitimate mathematical roles inside the expression already: If you are doing vector calculus then v[1] might make perfect sense. By extension, if you want the second coordinate of a vector sum v+w, then one would write (v+w)[1]. With the proposed extension this would be "w" instead, which would probably surprise the user. You can access expressions in a nested way already, but you have to accept a bit more pythonic notation: expr.operands()[0] expr.operands()[1] expr.operands()[0].operands()[1] It might make sense to introduce a shorthand expr.operand(0) expr.operand(1) expr.operand(0).operand(1) or, if one finds it's a frequent usage pattern, abbreviate the last to expr.operand([0,1]) maple has such a routine, called "op". beware that any code that makes assumptions about what it finds several levels deep in an expression is going to be very fragile. -- To post to this group, send an email to [email protected] To unsubscribe from this group, send an email to [email protected] For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org
