I'm trying to re-write / translate logic statements written arithmetically, into strings of min/max functions, some of them fairly complicated. Preferably using things like sed, awk, perl, python, etc. I'm working with a program in which, for my purposes, AND=MIN and OR=MAX. I'm able to convert/rewrite XOR, IMPL, etc. so that it understands accordingly without issue - what I'm struggling with (and looking to automate) is the rearranging of the syntax.
A complex example (partially based on a constructive dilemma):
((p implies q) and (r implies s)) and (p or r)
Would be:
min(min(max(~p,q),max(~r,s)),max(p,r))
I just need to convert from the first format to the second (doesn't need to work in reverse). I can convert individual elements (like a single "(p or r)" to "max(p,r)", in isolation) but once it comes time to re-arrange and nest them relative to eachother I'm pretty lost.
("and", ("and", ("implies", p, q), ("implies", r, s)), ("or", p, r)). Then you recursively "evaluate" the tree using simple rules likeeval x = x,eval ("and", p, q) = ("max", eval(p), eval(q)),eval ("implies", p, q) = eval ("or", eval(("not", p)), eval("q")), etc.bashfor this; it simply does not have the data-structure support needed to write this kind of code easily.