# What is the difference in pattern matching

Here is some pattern code:

parse2[a_ < b_ < c_] := (Print["Matched!"];)
iterAnd[x_ && y_] := y;

Print["Good example"]
ccr = a < b < c
parse2[ccr]

ccr2 = iterAnd[BooleanConvert[Reduce[a < b < c, {b}, Reals]]]
parse2[ccr2]


And here is the result:

Good example
a < b < c
Matched!

a < b < c
parse2[a < b < c]


The source expressions look similar, but pattern match results vary. What is the reason?

• I find your question hard to follow. Can you create a simple but complete example that shows the problem? Show the input, actual output and expected output. Your example is neither simple nor complete at the moment. – Szabolcs Aug 18 '16 at 9:33
• closely related: Converting inequalities to intervals – Kuba Aug 18 '16 at 11:47

This is confusing indeed. Let me repeat what you are showing here:

In[25]:= ccr2
Out[25]= a < b < c

In[26]:= parse2[ccr2]
Out[26]= parse2[a < b < c]

In[27]:= parse2[a < b < c]

During evaluation of In[27]:= Matched!


Out[26] and In[27] looks exactly the same, yet one evaluates the other doesn't. Are they really the same? The first thing to check in such cases is their FullForm.

In[30]:= FullForm[ccr2]
Out[30]//FullForm= Inequality[a,Less,b,Less,c]

In[31]:= FullForm[a<b<c]
Out[31]//FullForm= Less[a,b,c]


As you can see, they are not the same, even though they are formatted in the same way in StandardForm. This explains why there is a match in one case but there isn't a match in another.

I'll update the post if I can come up with a workaround that seems better than the obvious (i.e. manual transformation of Inequality expressions).

Possible workarounds:

The undocumented function ReduceInequalityExpand seems to convert inequalities such as a < b < c to the form a < b && b < c. This may be useful for your purposes.

The documented function LogicalExpand also carries out this transformation. But it also does other things which may or may not be desirable depending on your specific problem.

• Thank you for this function, let it be the weapon of a last chance. :) For my purpose it would be better not to expand this. The final goal is to extract integration limits from the system of inequalities. So I take a big expression, reduce it to an disjunctive form, which carries this way all limits cyphered in inequalities. So I want just to parse this result. – Игорь Моисеев Aug 18 '16 at 11:53
• @ИгорьМоисеев You could also try matching both on Less[a_, b_, c_] and Inequality[a_, Less, b_, Less, c_]`. But then we'd have to think very carefully if there are any other possible forms that represent the same thing ... – Szabolcs Aug 18 '16 at 11:57
• Thank you very much, thought about this too. :) – Игорь Моисеев Aug 18 '16 at 11:59