Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pattern matching Inequality

I'd like to extract arguments from instances of Inequality. Following doesn't work, any idea why and how to fix it?

Inequality[1, Less, x, Less, 2] /. Inequality[a_, _, c_, _, e_] -> {a, c, e}
like image 269
Yaroslav Bulatov Avatar asked Oct 03 '10 20:10

Yaroslav Bulatov


2 Answers

Inequality[1,Less,x,Less,2] /. HoldPattern[Inequality[a_,_,b_,_,c_]] -> {a, b, c}


Out: {1, x, 2}
like image 62
Dr. belisarius Avatar answered Sep 28 '22 05:09

Dr. belisarius


Also, you can do this:

Inequality[1, Less, x, Less, 2] /. Literal @ Inequality[ a_ , _ , c_ , _ , e_ ] -> {a, c, e}

ADL

like image 38
user465365 Avatar answered Sep 28 '22 05:09

user465365