2
$\begingroup$

The following returns False:

MatchQ[(-1 + (1 + E^-x)^0.1 )/(1 + E^-x)^0.2, ((1 + Exp[-x_])^v_. - 1)/(1 + Exp[-x_])^u_.]

False

And the following returns True:

    MatchQ[(-1 + (1 + E^-x)^0.1 )/(1 + E^-x)^h, ((1 + Exp[-x_])^v_. - 1)/(1 + Exp[-x_])^u_.]

True

It is strange because it looks pretty similar but Mathematica says that the pattern does not match.

$\endgroup$
1
  • 2
    $\begingroup$ Mathematica matches exact "structures" and sometimes the displayed expression is in a different form from the internal structure. Try FullForm[(-1+(1+E^-x)^0.1)/(1+E^-x)^0.2] and FullForm[((1+Exp[-x_])^v_.- 1)/(1+Exp[-x_])^u_.] Then repeat this with your second pair of expressions and see if this exposes why Mathematica thinks they are different in one case and the same in the other. Many years ago someone wrote an article showing how he had implemented "mathematical" matching instead of MMA's "structure" matching, but that never seemed to catch on and that code likely wouldn't work today $\endgroup$
    – Bill
    Commented Nov 16, 2021 at 22:13

1 Answer 1

3
$\begingroup$

The expression 1/(E^B)^C Has full form

Power[Power[E,B],Times[-1,C]]

But 1/(E^B)^0.2 has full form

Power[Power[E,B],-0.2`]

Notice the difference. Since you have literal -0.2 and not a symbol, Mathematica changed it from Times[-1,C] to -0.2 instead of Times[-1,0.2] so same pattern will not work on both. To match both of the above you need pattern which will capture both cases. Literal numbers and symbols. For this small example, this will do (need to use Alternatives)

pat   =  Power[Power[E,any1_],Alternatives[Times[-1,any2_],any3_]];
expr  =  1/(E^B)^C;
MatchQ[expr,pat]
 (* True *)
expr  = 1/(E^B)^0.2;
MatchQ[expr,pat]
 (* True *)

This explains why in your case (1 + E^-x)^0.2 and (1 + E^-x)^h did not give same result using the same pattern.

I have to run now. But will try later on to adjust your pattern to handle both case as in the small example I showed earlier.

Always use FullForm to find the actual pattern for expression.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.