Forms in the denominator of the replacement rule

Mathematica 7.0 does not seem to like having spaces in the denominator. Can someone explain why this is?

Input:

ClearAll["Global`*"];
(*Without blanks:*)
a^2 / b^2 /. a^2 / b^2 -> d
(*with:*)
a^2 / b^2 /. a^c_ / b^c_ -> d
(*Without blanks:*)
a^2 / b^2 /. (a / b)^2 -> d
(*With:*)
a^2 / b^2 /. (a / b)^c_ -> d
(*Without blanks:*)    
a^2 / b^2 /. a^2 * b^(-2) -> d
(*With:*)
a^2 / b^2 /. a^c_ * b^(-c_) -> d

Conclusion:

d
a^2/b^2
d
a^2/b^2
d
a^2/b^2

I am trying to do this for a more complex problem. The substitution I want to do is in the form expression:

(a ^ c_. * Coefficient1_. / b ^ c_. / Coefficient2_.)  +  (a ^ d_. * Coefficient3_. / b ^ d_. / Coefficient4_.)

If the coefficients may include the amounts, products and coefficients of the variables, which may or may not include aand b.

Perhaps relevant:

FullForm shows that the power in the denominator is stored as the product of -1 and c:

Input:

FullForm[a^2/b^2]
FullForm[a^c_/b^c_]
FullForm[ (a / b)^2 ]
FullForm[(a / b)^c_ ]
FullForm[a^2 * b^(-2) ]
FullForm[a^c_ * b^(-c_)]

Conclusion:

Times[Power[a,2],Power[b,-2]]
Times[Power[a,Pattern[c,Blank[]]],Power[b,Times[-1,Pattern[c,Blank[]]]]]
Times[Power[a,2],Power[b,-2]]
Power[Times[a,Power[b,-1]],Pattern[c,Blank[]]]
Times[Power[a,2],Power[b,-2]]
Times[Power[a,Pattern[c,Blank[]]],Power[b,Times[-1,Pattern[c,Blank[]]]]]

Edit: bold bias in my real case.

+3
source share
3 answers

, Mr.Wizard. , , , :

a^2/b^2 /. (Times[Power[a,c_],Power[b,e_]]/; e == -c )-> d

a^2/b^2 /.  (a^c_ b^e_/; e == -c )-> d

, /; e == -c, -c_, Times[-1,c_]

+6

, , ReplaceAll, .

FullForm, TreeForm :

a^2/b^2   // TreeForm
a^c_/b^c_ // TreeForm

enter image description hereenter image description here

, , . , ( ), Mathematica.

, , .


, Mathematica "" , , . , .

+11

a^2 / b^2 /. a^c_ / b^c_ -> d , Rule (->) RuleDelayed (:>). , FullForm, , a/b Times[a, Power[b,-1]], . ,

a^2 / b^2 /. a^n_ b^m_ :> {n,m}

{2, -2}. ,

a / b^2 /. a^n_. b^m_. :> {n,m}

{1,-2}.

: , , Condition (/;)

a^2 / b^2 /. a^n_. b^m_. /; n == m :> n

: _. a/b.

+4

All Articles