Re: Ask Mathematica to sub for a long expression

• To: mathgroup at smc.vnet.net
• Subject: [mg71878] Re: Ask Mathematica to sub for a long expression
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Sat, 2 Dec 2006 05:10:44 -0500 (EST)
• Organization: The Open University, Milton Keynes, UK
• References: <ekp4o4\$2fq\$1@smc.vnet.net>

```aaronfude at gmail.com wrote:
> Hi,
>
> Is it possible to ask Mathematica to replace a long expression, such as
> Sqrt[a^2+b^2-2*a*b*Cos[theta]] with "c", whenever it encounters that
> long expression?
>
> Thanks!
>
> Aaron Fude
>

Use transformation rules [1]. For example,

f = 3*Sqrt[a^2 + b^2 - 2*a*b*Cos[\[Theta]]];
f /. Sqrt[a^2 + b^2 - 2*a*b*Cos[\[Theta]]] -> c

--> 3*c

f = 3*Sqrt[a^2 + b^2 - 2*a*b*Cos[\[Theta]]] + 1/Sqrt[a^2 + b^2 -
2*a*b*Cos[\[Theta]]];
Together[f /. a^2 + b^2 - 2*a*b*Cos[\[Theta]] -> c]

--> (1 + 3*c)/Sqrt[c]

Regards,
Jean-Marc

1. _The Mathematica Book_, /Section 2.5: Transformation Rules and
Definitions/, http://documents.wolfram.com/mathematica/book/section-2.5

```

• Prev by Date: Re: SubValues
• Next by Date: When I Get[] a package - how can I tell where the error message came from?
• Previous by thread: Re: Ask Mathematica to sub for a long expression
• Next by thread: Re: Ask Mathematica to sub for a long expression