Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Putting things inside HoldPattern

I'm generating a list of replacement rules like this

ops = {LessEqual, GreaterEqual};
ineqRules = Table[HoldPattern[Inequality[a_, op1, c_, _, e_]] -> a == c, {op1, ops}]

Above doesn't work because "op1" is hidden from Table by HoldPattern, how do I fix it?

This is a follow-up to previous question

like image 206
Yaroslav Bulatov Avatar asked Mar 02 '26 16:03

Yaroslav Bulatov


1 Answers

How about

ops = {LessEqual, GreaterEqual};    
ineqRules = (HoldPattern[Inequality[a_, #, c_, _, e_]] :> a == c) & /@ ops

Edit: To fix the problem noted in belisarius's answer, try:

ineqRules=Flatten[{HoldPattern[Inequality[a_,#,c_,___]]:>a==c,HoldPattern[#[a_,c_]&&___]:>a==c}&/@ops]

This obviously depends on you having a simple structure to begin with, i.e. no other &&'s.

like image 113
Simon Avatar answered Mar 05 '26 11:03

Simon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!