MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Using the same symbol for different quantities

  • To: mathgroup at smc.vnet.net
  • Subject: [mg52425] Re: Using the same symbol for different quantities
  • From: David Bailey <dave at Remove_Thisdbailey.co.uk>
  • Date: Fri, 26 Nov 2004 06:20:32 -0500 (EST)
  • References: <co4e29$l9c$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Geronimo wrote:
> Hi Group
> 
> I would like to define, e.g.,
> 
>         y = f[x]
> `       z = g[y]
> 
> in such a way that when I type y I get f[x] and when I type z I get g[y], 
> and not g[f[x]]. For example from
> 
>         Cos[y] + Exp[z]
> 
> I would like to obtain
> 
>         Cos[f[x]] + Exp[g[y]]
> 
> In other words, I would like to use the same symbol (y) for two different 
> objects depending on whether y is in the lhs or rhs of the affectation. I 
> really need affectations rather than rules for y and z.
> 
> I could define different contexts for y. Is there a lighter solution ?
> 
> Many thanks
> 
> Geronimo

Hi,

It might be a good idea to share more of your project with this group so 
that people can suggest alternative formulations of your problem. 
However, you will gain much flexibility by not defining things with '=', 
but using transformation rules. For example, this gives you what you want:

z /. {y -> f[x], z -> g[y]}

If you used //. you would get exhaustive evaluation and end up with 
g[f[x]] - which is what you don't want.

I hope this helps,

David Bailey


  • Prev by Date: Re: Boolean Type
  • Next by Date: Re: Speeding UP Indexing and Joining of Different Size Rectangular Matrixes
  • Previous by thread: Using the same symbol for different quantities
  • Next by thread: Re: Using the same symbol for different quantities