I have some dictionary e.g. of form: Is their a simple way to replace all strings appearing in the dictionary values of form →(q, ∧(¬(p), ∨(y, z))) or →(p, q) by (q→(¬(p)∧(y∨z))) or (p→q)? Answer I found some solution by my own using some prolog: Prolog-file (called “logic.pl”) has to contain the following code: Now we can define some function: