将公式转换为cnf python - python

我想将公式转换为CNF。有图书馆可以这样做吗?这是我的代码。我创建了许多函数来将任何(a或b)转换为CNF格式。

但是,如果有很多命题,那将很难(a> b)&(c&d)或不是(f)。

operator="&|>=~"

def isOperand(c):
    return c >= 'a' and c <= 'z'

operators ="&|>=~"
def isOperator(c): #it cheak if the the given c is on the operators
 return c in operators
def dblimplique(a):
    if(a=='a = b' ):
       a='(a > b) & (b > a)'
    return a
def limplique(a):
    if(a=='a > b' ):
       a='~a | b'
    return a
def nonAouB(a):
    if(a=='~(a | b)' ):
       a='~a & ~b'
    return a
def nonAetB(a):
    if (a == '~(a & b)'):
        a = '~a | ~b'
    return a
def doublenon(a):
    if (a == '~~a'):
        a = 'a'
    return a
def doublenon(a):
    if (a == '~~a'):
        a = 'a'
    return a
def AetBouc(a):
    if (a == 'a & (b | c)'):
        a = '(a & b) | (a & c)'
    return a


def AouBetc(a):
    if (a == 'a | (b & c)'):
        a = '(a | b) & (a | c)'
    return a


def FNC():
    input_string = input("Entrer votre formule:")
    if(input_string == 'a = b'):
           return dblimplique(input_string)

    elif(input_string=='a > b'):
            return limplique(input_string)

    elif(input_string=='~(a | b)'):
            return  nonAouB(input_string)

    elif(input_string == '~(a & b)'):
            return nonAetB(input_string)

    elif(input_string =='~~a'):
            return  doublenon(input_string)
    elif(input_string =='a & (b | c)'):
        return AetBouc(input_string)
    elif(input_string=='a | (b & c)'):
        return AouBetc(input_string)
    elif(input_string=='a | b' or 'a | b | c' or 'a | b | c | d' or 'a | b | c | d'):
        return input_string
    else:
      for i in input_string:
          if(i == 'a > b' or 'c > d' or 'e > f'):
              return limplique(i)


print(FNC())

参考方案

使用此模块pip install sympy

from sympy.logic.boolalg import to_cnf
from sympy.abc import A, B, D
to_cnf(~(A | B) | D)

这是一个很好的库:https://docs.sympy.org/latest/modules/logic.html

这是两个代码:
https://github.com/ldkrsi/cnf_py

https://github.com/omkarkarande/CNF-Converter

在返回'Response'(Python)中传递多个参数 - python

我在Angular工作,正在使用Http请求和响应。是否可以在“响应”中发送多个参数。角度文件:this.http.get("api/agent/applicationaware").subscribe((data:any)... python文件:def get(request): ... return Response(seriali…

Python exchangelib在子文件夹中读取邮件 - python

我想从Outlook邮箱的子文件夹中读取邮件。Inbox ├──myfolder 我可以使用account.inbox.all()阅读收件箱,但我想阅读myfolder中的邮件我尝试了此页面folder部分中的内容,但无法正确完成https://pypi.python.org/pypi/exchangelib/ 参考方案 您需要首先掌握Folder的myfo…

R'relaimpo'软件包的Python端口 - python

我需要计算Lindeman-Merenda-Gold(LMG)分数,以进行回归分析。我发现R语言的relaimpo包下有该文件。不幸的是,我对R没有任何经验。我检查了互联网,但找不到。这个程序包有python端口吗?如果不存在,是否可以通过python使用该包? python参考方案 最近,我遇到了pingouin库。

Python ThreadPoolExecutor抑制异常 - python

from concurrent.futures import ThreadPoolExecutor, wait, ALL_COMPLETED def div_zero(x): print('In div_zero') return x / 0 with ThreadPoolExecutor(max_workers=4) as execut…

如何用'-'解析字符串到节点js本地脚本? - python

我正在使用本地节点js脚本来处理字符串。我陷入了将'-'字符串解析为本地节点js脚本的问题。render.js:#! /usr/bin/env -S node -r esm let argv = require('yargs') .usage('$0 [string]') .argv; console.log(argv…