From: blamm64 on
Given the expression:

eff = (L*(-L*mu+dm*Pi*Cos[b]))/(dm*Pi*(dm*Pi*mu+L*Cos[b]))

After this I enter

eff /. {dm*Pi -> L/Tan[a]}

and get a result that does not, for a reason I cannot fathom and
believe to be a bug, replace one instance of dm*Pi. The result of the
evaluation yields

L*(-L*mu+L*Cos[b]*Cot[a])/(dm*Pi*(L*Cos[b]+L*mu*Cot[a]))

Precisely the same result occurs with eff //.{dm*Pi->L/Tan[a]}

Why is the one remaining dm*Pi not replaced with L/Tan[a]?

In fact, when define manually define eff1 as

eff1 = (L*(-L*mu + L*Cos[b]*Cot[b]))/(dm*Pi*(L*Cos[b]+L*mu*Cot[a]))

which is as you can see the result of the first ReplaceAll execution,
and then enter

eff1 /. {dm*Pi->L/Tan[a]}

Mathematica returns eff1 unaltered!

Now, I say this is a bug, so of course I'm probably missing something
and it isn't a bug. I have to jump through syntactic hoops to get the
'right' answer:

FullSimplify[eff /.{dm*Pi->L/Tan[a]}]/.{dm*Pi->L/Tan[a]}//FullSimplify

and FullSimplify[eff /. {dm*Pi->L/Tan[a]} does no good either.

It is not at all obvious to me what I might be missing with such an
apparently simple replacement.

By the way, how do you guys copy input or output from Mathematica
notebook into this usergroup window? I had to do all this by hand,
copy it from here into a notebook, and execute the notebook cells just
to make sure I was getting it correct. I ran across this originally
when I was constructing a simple notebook for doing some Acme power
screw calculations.

-Brian Lamm
(Windows XP x64 Version 2003 SP2, Mathematica 7.0.1)

From: Mark Adler on
On 2010-08-02 04:04:36 -0700, blamm64 said:
> eff = (L*(-L*mu+dm*Pi*Cos[b]))/(dm*Pi*(dm*Pi*mu+L*Cos[b]))
> eff /. {dm*Pi -> L/Tan[a]}
> L*(-L*mu+L*Cos[b]*Cot[a])/(dm*Pi*(L*Cos[b]+L*mu*Cot[a]))

I find that FullForm usually illuminates what's going on. In this case
that particular dm*Pi doesn't show up as Times[dm,Pi,...], but rather
this:

Times[Power[dm, -1], L, Power[Pi, -1], ...]

That is why the rule is not finding Times[dm, Pi, ...].

Mark

From: Eric Loots on
Hi,

I'm new to this group, but I'll have a go at this.

The rule dm*Pi -> L/Tan[a] must look for matches of the pattern. I
guess that the pattern just doesn't match in all cases. When you look
at the output after entering the first line of input, you see that one
of the dm * Pi terms is rearranged.

A simple solution to your problem is to apply another for of the rule:

dm -> L / Pi / Tan[a]

Adding Simplify on top of that:

(L*(-L*mu + dm*Pi*Cos[b]))/(dm*Pi*(dm*Pi*mu + L*Cos[b])) /. dm -> L /
=CF=80/Tan[a] // Simplify

gives:

(Cos[b] - mu Tan[a])/(Cos[b] + mu Cot[a])

With respect to copy/paste from a Notebook to the group, I'm using
regular mail to post this reply, and an ordinary copy/past just works.

Regards -- Eric

On 02 Aug 2010, at 13:04, blamm64 wrote:

> Given the expression:
>
> eff == (L*(-L*mu+dm*Pi*Cos[b]))/(dm*Pi*(dm*Pi*mu+L*Cos[b]))
>
> After this I enter
>
> eff /. {dm*Pi -> L/Tan[a]}
>
> and get a result that does not, for a reason I cannot fathom and
> believe to be a bug, replace one instance of dm*Pi. The result of the
> evaluation yields
>
> L*(-L*mu+L*Cos[b]*Cot[a])/(dm*Pi*(L*Cos[b]+L*mu*Cot[a]))
>
> Precisely the same result occurs with eff //.{dm*Pi->L/Tan[a]}
>
> Why is the one remaining dm*Pi not replaced with L/Tan[a]?
>
> In fact, when define manually define eff1 as
>
> eff1 == (L*(-L*mu + L*Cos[b]*Cot[b]))/(dm*Pi*(L*Cos[b]+L*mu*Cot[a]))
>
> which is as you can see the result of the first ReplaceAll execution,
> and then enter
>
> eff1 /. {dm*Pi->L/Tan[a]}
>
> Mathematica returns eff1 unaltered!
>
> Now, I say this is a bug, so of course I'm probably missing something
> and it isn't a bug. I have to jump through syntactic hoops to get the
> 'right' answer:
>
> FullSimplify[eff /.{dm*Pi->L/Tan[a]}]/.{dm*Pi->L/Tan[a]}//FullSimplify
>
> and FullSimplify[eff /. {dm*Pi->L/Tan[a]} does no good either.
>
> It is not at all obvious to me what I might be missing with such an
> apparently simple replacement.
>
> By the way, how do you guys copy input or output from Mathematica
> notebook into this usergroup window? I had to do all this by hand,
> copy it from here into a notebook, and execute the notebook cells just
> to make sure I was getting it correct. I ran across this originally
> when I was constructing a simple notebook for doing some Acme power
> screw calculations.
>
> -Brian Lamm
> (Windows XP x64 Version 2003 SP2, Mathematica 7.0.1)
>


From: Leonid Shifrin on
Hi Brian,

FullForm will reveal that some auto-evaluations are happening after you
enter
your eff, during Mathematica's evaluation process. As a result, one of the
products
dm*Pi gets rewritten into a different form
(Times[Power[dm,-1],L,Power[Pi,-1],...)
and does not match your pattern any more:

In[13]:=
FullForm[eff]
Out[13]//FullForm=
Times[Power[dm,-1],L,Power[Pi,-1],Power[Plus[Times[dm,mu,Pi],Times[L,Cos[b]]],-1],Plus[Times[-1,L,mu],Times[dm,Pi,Cos[b]]]]

The simplest way to get what you want that I can think of is something like
the following:

In[26]:=
Unevaluated[(L*(-L*mu + dm*Pi*Cos[b]))/(dm*
Pi*(dm*Pi*mu + L*Cos[b]))] //. {dm*Pi ->
L/Tan[a]} // FullSimplify

Out[26]= (Cos[b] - mu Tan[a])/(Cos[b] + mu Cot[a])

By using Unevaluated I postpone evaluation until your rules have been
applied,
and then the auto-evaluation does not happen. Alternatively, you may want
to
construct a more complicated pattern, but that seems considerably harder to
get right.

If you still want to keep your expression in a variable, I suggest to use
the
following trick:

Clear[eff];
eff := (L*(-L*mu + dm*Pi*Cos[b]))/(dm*Pi*(dm*Pi*mu + L*Cos[b]));

Here, delayed assignment is used. Then:

In[32]:= FullSimplify(a)ReleaseHold
[Hold[eff]/.OwnValues[eff]//.{dm*Pi->L/Tan[a]}]

Out[32]= (Cos[b]-mu Tan[a])/(Cos[b]+mu Cot[a])

This trick can generalize to more complex expressions involving any number
of
variables like <eff>, like this for example:

In[42]:= Clear[f];
f[x_]:=x^2-2x+1

In[41]:= FullSimplify(a)ReleaseHold
[Hold[f[eff]]/.DownValues[f]/.OwnValues[eff]//.{dm*Pi->L/Tan[a]}]
Out[41]= (mu^2 Sec[a]^2)/(mu Cos[a]+Cos[b] Sin[a])^2

Basically, these are the first steps for creating a custom evaluator, which
does not
evaluate expressions all the way, but only uses those rules you want. It
kind of interpolates
between purely local rule application and the full global Mathematica
evaluation, and adds
the convenience of globally defined variables and functions to the level of
control you have
with local rule application. I find this quite useful at times.

Hope this helps.

Regards,
Leonid


On Mon, Aug 2, 2010 at 3:04 PM, blamm64 <blamm64(a)charter.net> wrote:

> Given the expression:
>
> eff = (L*(-L*mu+dm*Pi*Cos[b]))/(dm*Pi*(dm*Pi*mu+L*Cos[b]))
>
> After this I enter
>
> eff /. {dm*Pi -> L/Tan[a]}
>
> and get a result that does not, for a reason I cannot fathom and
> believe to be a bug, replace one instance of dm*Pi. The result of the
> evaluation yields
>
> L*(-L*mu+L*Cos[b]*Cot[a])/(dm*Pi*(L*Cos[b]+L*mu*Cot[a]))
>
> Precisely the same result occurs with eff //.{dm*Pi->L/Tan[a]}
>
> Why is the one remaining dm*Pi not replaced with L/Tan[a]?
>
> In fact, when define manually define eff1 as
>
> eff1 = (L*(-L*mu + L*Cos[b]*Cot[b]))/(dm*Pi*(L*Cos[b]+L*mu*Cot[a]))
>
> which is as you can see the result of the first ReplaceAll execution,
> and then enter
>
> eff1 /. {dm*Pi->L/Tan[a]}
>
> Mathematica returns eff1 unaltered!
>
> Now, I say this is a bug, so of course I'm probably missing something
> and it isn't a bug. I have to jump through syntactic hoops to get the
> 'right' answer:
>
> FullSimplify[eff /.{dm*Pi->L/Tan[a]}]/.{dm*Pi->L/Tan[a]}//FullSimplify
>
> and FullSimplify[eff /. {dm*Pi->L/Tan[a]} does no good either.
>
> It is not at all obvious to me what I might be missing with such an
> apparently simple replacement.
>
> By the way, how do you guys copy input or output from Mathematica
> notebook into this usergroup window? I had to do all this by hand,
> copy it from here into a notebook, and execute the notebook cells just
> to make sure I was getting it correct. I ran across this originally
> when I was constructing a simple notebook for doing some Acme power
> screw calculations.
>
> -Brian Lamm
> (Windows XP x64 Version 2003 SP2, Mathematica 7.0.1)
>
>

From: Bob Hanlon on

eff = (L*(-L*mu + dm*Pi*Cos[b]))/(dm*Pi*(dm*Pi*mu + L*Cos[b]));

The replacement rule operates on the FullForm:

eff // FullForm

Times[Power[dm,-1],L,Power[Pi,-1],Power[Plus[Times[dm,mu,Pi],Times[L,Cos[b]]],-1],Plus[Times[-1,L,mu],Times[dm,Pi,Cos[b]]]]

Keep the LHS of a rule as simple as possible

eff /. {dm -> L/(Tan[a] Pi)}

(Tan[a]*(L*Cot[a]*Cos[b] - L*mu))/
(L*mu*Cot[a] + L*Cos[b])

Before copy and paste convert expressions to InputForm.


Bob Hanlon

---- blamm64 <blamm64(a)charter.net> wrote:

=============
Given the expression:

eff = (L*(-L*mu+dm*Pi*Cos[b]))/(dm*Pi*(dm*Pi*mu+L*Cos[b]))

After this I enter

eff /. {dm*Pi -> L/Tan[a]}

and get a result that does not, for a reason I cannot fathom and
believe to be a bug, replace one instance of dm*Pi. The result of the
evaluation yields

L*(-L*mu+L*Cos[b]*Cot[a])/(dm*Pi*(L*Cos[b]+L*mu*Cot[a]))

Precisely the same result occurs with eff //.{dm*Pi->L/Tan[a]}

Why is the one remaining dm*Pi not replaced with L/Tan[a]?

In fact, when define manually define eff1 as

eff1 = (L*(-L*mu + L*Cos[b]*Cot[b]))/(dm*Pi*(L*Cos[b]+L*mu*Cot[a]))

which is as you can see the result of the first ReplaceAll execution,
and then enter

eff1 /. {dm*Pi->L/Tan[a]}

Mathematica returns eff1 unaltered!

Now, I say this is a bug, so of course I'm probably missing something
and it isn't a bug. I have to jump through syntactic hoops to get the
'right' answer:

FullSimplify[eff /.{dm*Pi->L/Tan[a]}]/.{dm*Pi->L/Tan[a]}//FullSimplify

and FullSimplify[eff /. {dm*Pi->L/Tan[a]} does no good either.

It is not at all obvious to me what I might be missing with such an
apparently simple replacement.

By the way, how do you guys copy input or output from Mathematica
notebook into this usergroup window? I had to do all this by hand,
copy it from here into a notebook, and execute the notebook cells just
to make sure I was getting it correct. I ran across this originally
when I was constructing a simple notebook for doing some Acme power
screw calculations.

-Brian Lamm
(Windows XP x64 Version 2003 SP2, Mathematica 7.0.1)