Skip to content
Advertisement

Python – dictionary with propositions (replace string values)

I have some dictionary e.g. of form:

JavaScript

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)?

Advertisement

Answer

I found some solution by my own using some prolog:

Prolog-file (called “logic.pl“) has to contain the following code:

JavaScript

Now we can define some function:

JavaScript

With that background its possible to normalize the dictionary very easy:

JavaScript

Output:

JavaScript

Only problem, for some reason I cant use ¬ instead of ~ with pyswip library (Version: 0.2.11), cause with ¬ I get the curios error:

JavaScript

whereby ¬ has unicode U+00AC ..

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement