It occurred to me that maybe I should supply a more non-trivial
example of rules/patterns/subs in mathematica. Here is just one: we
replace exponents of polynomials with the famous 3x+1 sequence
(Collatz, whatever) until they stabilize:
In: {x^2, x^3 + x^200, x^4 + z^909} //. {y_^n_ /; Mod[n, 2] == 1 ->
y^(3 n + 1), y_^n_ /; Mod[n, 2] == 0 -> y^(n/2)}
Out: {x, 2 x, x + z}
-MH
On May 9, 12:25 pm, Marshall Hampton <[EMAIL PROTECTED]> wrote:
> Well, the design is somewhat different to start with: in Sage, you
> have to declare variables explicitly (i.e. with var('x,y') or
> whatever), but then symbolic variables can automatically act like
> functions (as in the usage/bug above). In mathematica, anything
> undefined is _assumed_ to be a new symbolic object.
>
> Strings behave in a funny way in mathematica. They are usually
> evaluated to symbolic expressions. Here is a (hopefully) relevant
> example, setting the value of something to a string and then using it
> in a function:
>
> In: a = "test"
> Out: test
>
> In: f[x_] := x^2
> In: f[a]
> Out: test^2
>
> The output is misleading since the returned object is really
> Power["test",2] but that is displayed the same way that the symbolic
> expression Power[test,2] is.
>
> Somewhat relevant to this are the (IMHO) very nice substitutions,
> rules, and patterns in mathematica (although the syntax is pretty
> odd). As a very simple example, the command:
>
> In: {x, x*y} /. {{x -> 1, y -> 2}, {x -> 2, y -> 3}}
>
> returns
>
> Out: {{1,2},{2,6}}
>
> The Sage subs command is quite weak compared to such substitutions in
> mathematica. One can do very complicated condition substitutions,
> regular-expression like matching, etc.
>
> Cheers,
> Marshall
>
> On May 9, 11:54 am, "William Stein" <[EMAIL PROTECTED]> wrote:
>
> > On Fri, May 9, 2008 at 10:03 AM, Marshall Hampton <[EMAIL PROTECTED]> wrote:
>
> > > Ah, ok. I am probably not the right person to weigh in on what
> > > symbolics should do. I'll be happy if I can do most of what I could
> > > do in mathematica - since I used it for 16 years, it defines what I
> > > expect, but of course it won't always be the right design to follow
> > > for Sage.
>
> > > -M. Hampton
>
> > Wait -- please *do* weigh in, and do explain what Mathematica would
> > do in analogous situations. I do care to hear.
>
> > William
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---