An example to demostrate functionality of ExpressionConvert.pyΒΆ

from __future__ import print_function
from BinPy.algorithms.ExpressionConvert import *
# Given Expression:
expr = '~(((A^B)|(~a^b^C))) ~^ c'
# Obtained Expression
converted = convertExpression(expr)

print(converted)
OR(XNOR(A, B), XNOR(a, b, C, c))
# Given Expression:
expr = '((A AND B)xor(NOT(B) and C) xor(C and NOT(D)))or   E or NOT(F)'
# Obtained Expression
converted = convertExpression(expr)

print(converted)
OR(XOR(AND(A, B), AND(NOT(B), C), AND(C, NOT(D))), E, NOT(F))
# Obtained Expression with two input gate contraint
converted2 = convertExpression(expr, two_input = 1)

print(converted2)
OR(XOR(XOR(AND(A, B), AND(NOT(B), C)), AND(C, NOT(D))), OR(E, NOT(F)))
# Given Expression:
expr = '(A XOR B XOR C)'
# Obtained Expression
converted = convertExpression(expr)

print(converted)
XOR(A, B, C)
# Obtained Expression with two input gate contraint
converted2 = convertExpression(expr, two_input = 1)

print(converted2)
XOR(A, XOR(B, C))
# Equivalent Expression with only AND, OR & NOT gates
converted3 = convertExpression(expr, only_and_or_not=1)

print(converted3)
OR(AND(A, NOR(AND(B, NOT(C)), AND(NOT(B), C))), AND(NOT(A), OR(AND(B, NOT(C)), AND(NOT(B), C))))
# Given Expression
expr = 'A XOR B'
# Equivalent Expression with only NAND gates
converted = convertExpression(expr, only_nand=1)

print(converted)
NAND(NAND(A, NAND(A, B)), NAND(B, NAND(A, B)))
# Equivalent Expression with only NOR gates
converted2 = convertExpression(expr, only_nor=1)

print(converted2)
NOR(NOR(NOR(A, NOR(A, B)), NOR(B, NOR(A, B))), NOR(NOR(A, NOR(A, B)), NOR(B, NOR(A, B))))