def move_not_inwards(s):
    """Rewrite sentence s by moving negation sign inward.
    >>> move_not_inwards(~(A | B))
    (~A & ~B)
    >>> move_not_inwards(~(A & B))
    (~A | ~B)
    >>> move_not_inwards(~(~(A | ~B) | ~~C))
    ((A | ~B) & ~C)
    """
    if s.op == '~':
        NOT = lambda b: move_not_inwards(~b)
        a = s.args[0]
        if a.op == '~': return move_not_inwards(a.args[0]) # ~~A ==> A
        if a.op =='&': return associate('|', map(NOT, a.args))
        if a.op =='|': return associate('&', map(NOT, a.args))
        return s
    elif is_symbol(s.op) or not s.args:
        return s
    else:
        return Expr(s.op, *map(move_not_inwards, s.args))
def move_not_inwards(s):
    """Rewrite sentence s by moving negation sign inward.
    >>> move_not_inwards(~(A | B))
    (~A & ~B)
    >>> move_not_inwards(~(A & B))
    (~A | ~B)
    >>> move_not_inwards(~(~(A | ~B) | ~~C))
    ((A | ~B) & ~C)
    """
    if s.op == '~':
        NOT = lambda b: move_not_inwards(~b)
        a = s.args[0]
        if a.op == '~': return move_not_inwards(a.args[0]) # ~~A ==> A
        if a.op =='&': return associate('|', map(NOT, a.args))
        if a.op =='|': return associate('&', map(NOT, a.args))
        return s
    elif is_symbol(s.op) or not s.args:
        return s
    else:
        return Expr(s.op, *map(move_not_inwards, s.args))
def move_not_inwards ( s ) : if s . op == '~' : NOT = lambda b : move_not_inwards ( ~ b ) a = s . args [ 0 ] if a . op == '~' : return move_not_inwards ( a . args [ 0 ] ) # ~~A ==> A if a . op == '&' : return associate ( '|' , map ( NOT , a . args ) ) if a . op == '|' : return associate ( '&' , map ( NOT , a . args ) ) return s elif is_symbol ( s . op ) or not s . args : return s else : return Expr ( s . op , * map ( move_not_inwards , s . args ) )
Rewrite sentence s by moving negation sign inward.
    >>> move_not_inwards(~(A | B))
    (~A & ~B)
    >>> move_not_inwards(~(A & B))
    (~A | ~B)
    >>> move_not_inwards(~(~(A | ~B) | ~~C))
    ((A | ~B) & ~C)
Rewrite sentence s by moving negation sign inward . >>> move_not_inwards ( ~ ( A | B )) ( ~A & ~B ) >>> move_not_inwards ( ~ ( A & B )) ( ~A | ~B ) >>> move_not_inwards ( ~ ( ~ ( A | ~B ) | ~~C )) (( A | ~B ) & ~C )