转换为CNF转换为、CNF

2023-09-11 07:07:23 作者:跑调情歌

这是一个任务。我不得不将设置的语句CNF和实施。我知道我需要转换输入preFIX符号就先缀,然后重复应用德摩根定律。但是,我不知道如何将其转换为中间符号后继续执行。

This is for an assignment. I have to convert the set of statements to CNF and implement them. I know that I need to convert the input in prefix notation it to infix first and then repeatedly apply De Morgans's Laws. However, I don't know how to proceed with the implementation after converting it to infix notation.

我必须把它转换为中缀,或是否有更好的方法来做到这一点? 我一直在阅读了从Python中的这里 。我编码在Java中,我想我自己做不使用任何外部库。在实现算法任何指针?我是不是在正确的方向将其转换为中缀? Do I have to convert it to infix or is there a better process to do this? I have been reading up on BDDs from the implementation in Python here. I'm coding in Java and I'd like to do it by myself without using any external libraries. Any pointers on the implementation algorithm? Am I going in the right direction converting it to infix?

谢谢!

推荐答案

无需将其转换为中缀 - 你想要得到的字符串的领域尽快,例如:

There is no need to convert this to infix - you want to get out of the domain of strings as quickly as possible, for example

public abstract class Expression
public abstract class BinaryExpression extends Expression {
    private Expression expr1;
    private Expression expr2;
    public Expression getExpr1() { return expr1; }
    public void setExpr1(Expression expr) { expr1 = expr; }
}
public abstract class UnaryExpression extends Expression
public class Or extends BinaryExpression
public class Not extends UnaryExpression

等。解析输入到防爆pressions 您可能会发现它很有用的递归下降解析器,虽然这肯定是不解析您输入的唯一途径。一旦你有你的输入转换为一个象征性的防爆pression 格式,它应该是更容易被接受布尔法律将其转换为CNF。

and so on. To parse the input into Expressions you may find it useful to use a Recursive Descent Parser, although this is certainly not the only way to parse your input. Once you have your input converted to a symbolic Expression format it should be much easier to apply the boolean laws to convert it to CNF.