ldkrsi / cnf_java

Conversion into CNF step by step

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Conversion into CNF

Use java and regular expression

What is CNF(Conjunctive Normal Form)?

Conjunctive normal form - Wikipedia

Conversion step

  1. Add brackets to match order of precedence
  2. Convert "if only if" into "implies"
  3. Replace "implies" by "and", "or", "not"
  4. Doing de morgan
  5. Doing distributive

Input format

Operator

  • neg .... "Negation"
  • and
  • or
  • imp ..... "implies"
  • iff ..... "if only if"
  • ()

Symbol

Any word character but non-digit.
ex.
A and AA ....... ok
A1 and B ....... not ok

Usage

javac mainclass.java
java mainclass input.txt output.txt

Sample

After ....

java mainclass sample_input.txt output.txt

output.txt is

((A imp C) and (C imp A)) or B
((neg A or C) and (neg C or A)) or B
((neg A or C) and (neg C or A)) or B
(A or B or neg C) and (B or C or neg A)

Issue

when input is

(A and neg A) or B

the output was

(A or B) and (neg A or B)

but it should be

B

About

Conversion into CNF step by step

License:MIT License


Languages

Language:Java 100.0%