# Path: arybo/lib/mba_if.py
# class MBA(MBAImpl):
#     ''' Represents an MBA (Mixed Boolean Arithmetic) space of a fixed number of bits. '''
#     def var(self, name):
#         ''' Get an n-bit named symbolic variable
# 
#         Returns:
#             An :class:`MBAVariable` object representing a symbolic variable
# 
#         Example:
#             >>> mba.var('x')
#             Vec([
#             x0,
#             x1,
#             x2,
#             x3
#             ])
#         '''
# 
#         ret = self.from_vec(self.var_symbols(name)) 
#         ret.name = name
#         return ret
# 
#     def from_vec(self, v):
#         ''' Get an :class:`MBAVariable` object with the vector's values.
# 
#         Args:
#             v: a pytanque vector holding boolean expressions
# 
#         Returns:
#             An :class:`MBAVariable` object with the vector's values
#         '''
#         return MBAVariable.from_vec(self, v)
# 
#     def evaluate(self, E, values):
#         if isinstance(E, MBAVariable):
#             E = E.vec
#         return super(MBA, self).evaluate(E, values)
# 
#     def permut2expr(self, P):
#         ''' Convert a substitution table into an arybo application
# 
#         Args:
#             P: list of integers. The list must not contain more than 2**nbits elements.
# 
#         Returns:
#             A tuple containing an :class:`MBAVariable` object with the result
#             and the symbolic input variable used in this object. A typical use
#             case is to feed these into vectorial_decomp.
# 
#         Example:
#             >>> mba = MBA(4)
#             >>> P = [i^7 for i in range(16)]
#             >>> E,X = mba.permut2expr(P)
#             >>> E.vectorial_decomp([X])
#             App NL = Vec([
#             0,
#             0,
#             0,
#             0
#             ])
#             AffApp matrix = Mat([
#             [1, 0, 0, 0]
#             [0, 1, 0, 0]
#             [0, 0, 1, 0]
#             [0, 0, 0, 1]
#             ])
#             AffApp cst = Vec([
#             1,
#             1,
#             1,
#             0
#             ])
#         '''
#         if len(P) > (1<<self.nbits):
#             raise ValueError("P must not contain more than %d elements" % (1<<self.nbits))
#         X = self.var('X')
#         ret = super(MBA, self).permut2expr(P, X.vec)
#         return self.from_vec(ret), X
# 
#     def symbpermut2expr(self, P):
#         X = self.var('X')
#         ret = super(MBA, self).symbpermut2expr(P, X.vec)
#         return self.from_vec(ret), X
# 
#     def from_cst(self, C):
#         return self.from_vec(self.get_vector_from_cst(C))
# 
#     def from_bytes(self, s):
#         if not isinstance(s, bytes):
#             raise ValueError("s must be an instance of bytes!")
#         # TODO: fix this...
#         if self.nbits % 8 != 0:
#             raise ValueError("self.nbits must be a multiple of 8")
#         nbytes = self.nbits//8
#         if len(s) > nbytes:
#             s = s[:nbytes]
#         elif len(s) < nbytes:
#             s = s + 'b\x00'*(nbytes-len(s))
#         return self.from_vec(super(MBA, self).from_bytes(s))
# 
# Path: arybo/lib/bool_solver.py
# def boolean_expr_solve(e, X, v=1):
#     if e.is_add():
#         monomes = e.args()
#     elif e.is_sym():
#         monomes = (e,)
#     else:
#         raise ValueError("e should be normalized!")
# 
#     len_monomes = len(monomes)
#     if len_monomes == 0:
#         return []
#     last = monomes[len_monomes-1]
#     if last.is_imm() and last.imm_value() == True:
#         v = int(not v)
#         len_monomes -= 1
# 
#     if v not in (0,1):
#         raise ValueError("v should be equal to 0 or 1!")
# 
#     ret = []
#     all_monomes = set(range(len_monomes))
#     def solve(ones):
#         BSS = BooleanSystemSolver()
#         for m in ones:
#             BSS.equalsOne(monomes[m])
#         for m in all_monomes.difference(ones):
#             BSS.equalsZero(monomes[m])
#         ret.extend(BSS.solve(X))
# 
#     # If v equals to 1, we want an odd number of ones.
#     # On the contrary, we need an even number of ones (zero included).
#     for nones in range(v, len_monomes+1, 2):
#         for c in itertools.combinations(range(len_monomes), nones):
#             solve(c)
#     return ret


from arybo.lib import MBA, boolean_expr_solve
mba = MBA(64)
x = mba.var('x')
def f(X):

# Path: arybo/lib/mba_if.py
# class MBA(MBAImpl):
#     ''' Represents an MBA (Mixed Boolean Arithmetic) space of a fixed number of bits. '''
#     def var(self, name):
#         ''' Get an n-bit named symbolic variable
# 
#         Returns:
#             An :class:`MBAVariable` object representing a symbolic variable
# 
#         Example:
#             >>> mba.var('x')
#             Vec([
#             x0,
#             x1,
#             x2,
#             x3
#             ])
#         '''
# 
#         ret = self.from_vec(self.var_symbols(name)) 
#         ret.name = name
#         return ret
# 
#     def from_vec(self, v):
#         ''' Get an :class:`MBAVariable` object with the vector's values.
# 
#         Args:
#             v: a pytanque vector holding boolean expressions
# 
#         Returns:
#             An :class:`MBAVariable` object with the vector's values
#         '''
#         return MBAVariable.from_vec(self, v)
# 
#     def evaluate(self, E, values):
#         if isinstance(E, MBAVariable):
#             E = E.vec
#         return super(MBA, self).evaluate(E, values)
# 
#     def permut2expr(self, P):
#         ''' Convert a substitution table into an arybo application
# 
#         Args:
#             P: list of integers. The list must not contain more than 2**nbits elements.
# 
#         Returns:
#             A tuple containing an :class:`MBAVariable` object with the result
#             and the symbolic input variable used in this object. A typical use
#             case is to feed these into vectorial_decomp.
# 
#         Example:
#             >>> mba = MBA(4)
#             >>> P = [i^7 for i in range(16)]
#             >>> E,X = mba.permut2expr(P)
#             >>> E.vectorial_decomp([X])
#             App NL = Vec([
#             0,
#             0,
#             0,
#             0
#             ])
#             AffApp matrix = Mat([
#             [1, 0, 0, 0]
#             [0, 1, 0, 0]
#             [0, 0, 1, 0]
#             [0, 0, 0, 1]
#             ])
#             AffApp cst = Vec([
#             1,
#             1,
#             1,
#             0
#             ])
#         '''
#         if len(P) > (1<<self.nbits):
#             raise ValueError("P must not contain more than %d elements" % (1<<self.nbits))
#         X = self.var('X')
#         ret = super(MBA, self).permut2expr(P, X.vec)
#         return self.from_vec(ret), X
# 
#     def symbpermut2expr(self, P):
#         X = self.var('X')
#         ret = super(MBA, self).symbpermut2expr(P, X.vec)
#         return self.from_vec(ret), X
# 
#     def from_cst(self, C):
#         return self.from_vec(self.get_vector_from_cst(C))
# 
#     def from_bytes(self, s):
#         if not isinstance(s, bytes):
#             raise ValueError("s must be an instance of bytes!")
#         # TODO: fix this...
#         if self.nbits % 8 != 0:
#             raise ValueError("self.nbits must be a multiple of 8")
#         nbytes = self.nbits//8
#         if len(s) > nbytes:
#             s = s[:nbytes]
#         elif len(s) < nbytes:
#             s = s + 'b\x00'*(nbytes-len(s))
#         return self.from_vec(super(MBA, self).from_bytes(s))
# 
# Path: arybo/lib/bool_solver.py
# def boolean_expr_solve(e, X, v=1):
#     if e.is_add():
#         monomes = e.args()
#     elif e.is_sym():
#         monomes = (e,)
#     else:
#         raise ValueError("e should be normalized!")
# 
#     len_monomes = len(monomes)
#     if len_monomes == 0:
#         return []
#     last = monomes[len_monomes-1]
#     if last.is_imm() and last.imm_value() == True:
#         v = int(not v)
#         len_monomes -= 1
# 
#     if v not in (0,1):
#         raise ValueError("v should be equal to 0 or 1!")
# 
#     ret = []
#     all_monomes = set(range(len_monomes))
#     def solve(ones):
#         BSS = BooleanSystemSolver()
#         for m in ones:
#             BSS.equalsOne(monomes[m])
#         for m in all_monomes.difference(ones):
#             BSS.equalsZero(monomes[m])
#         ret.extend(BSS.solve(X))
# 
#     # If v equals to 1, we want an odd number of ones.
#     # On the contrary, we need an even number of ones (zero included).
#     for nones in range(v, len_monomes+1, 2):
#         for c in itertools.combinations(range(len_monomes), nones):
#             solve(c)
#     return ret


# Path: examples/dirac.py
from arybo.lib import MBA, boolean_expr_solve

mba = MBA(64)
x = mba.var('x')
def f(X):

  T = ((X+1)&(~X))