[GiNaC-list] Substitution troubles

Alexei Sheplyakov varg at metalica.kh.ua
Wed Feb 25 08:37:52 CET 2009


Hi,

On Tue, Feb 24, 2009 at 08:50:46AM -0500, Jeremy Jay wrote:

> Hmm I guess it makes sense in that regard, but it is certainly
> non-intuitive.

In every CAS I know of substitution (and pattern matching) operates on
the internal representation of expressions, not on their mathematical
meaning. For example, in M.........a (version 5.1):

In[1]:= x^4 + 1/(16*y^4);
In[2]:= InputForm[% /. a_^2 :> a]
Out[3]//InputForm= 
x^4 + 1/(16*y^4) 

In[4]:= InputForm[x^4 + 1/(16*y^4) /. 1 -> q]
Out[5]//InputForm= 
x^4 + 1/(16*y^4)

Not quite intuitive, is it?

> Printing the poly shows exactly what I want to replace
> and not the interal representation.

cout << tree << poly << endl;

prints the internal representation.

> Might I suggest someone update the
> tutorial with a statement like "Numeric literals are strongly
> discouraged in the left side of a substitution, and will not produce the
> desired effect."

That's kind of vague, because it's not quite clear what `desired effect'
exactly is.

Best regards,
	Alexei

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: Digital signature
URL: <http://www.cebix.net/pipermail/ginac-list/attachments/20090225/1a7034a0/attachment.sig>


More information about the GiNaC-list mailing list