Search code examples
boolean-expressiondigital

Can a contradiction Boolean expression with variables 𝑎 and 𝑏 be represented in NAND form?


I have f(a,b) = 0 and want to represent it in NAND form (only using NAND gates) in terms of a and b, but I don't think is possible.


Solution

  • def NAND(a, b):
        return (a & b) ^ 1
    
    def f(a, b):
        return NAND(
            NAND(a, NAND(a, a)),
            NAND(b, NAND(b, b)),
        )
    
    for a in 0, 1:
        for b in 0, 1:
            print(f(a, b))
    

    Output (Attempt This Online!):

    0
    0
    0
    0