# 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))


from arybo.lib import MBA
import unittest

class TestMBA(unittest.TestCase):
    def setUp(self):
        mba6 = MBA(6)
        mba6.use_esf = False

# 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: tests/arybo/examples.py
from arybo.lib import MBA
import unittest


class TestMBA(unittest.TestCase):
    def setUp(self):
        mba6 = MBA(6)
        mba6.use_esf = False

        mba8 = MBA(8)