/usr/lib/python2.7/dist-packages/brial/intpolys.py is in python-brial 1.2.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87  | if __name__ == '__main__':
    from sys import path as search_path
    from os import path as file_path
    search_path.append(file_path.join(file_path.dirname(__file__), '..'))
from .PyPolyBoRi import Monomial, Polynomial, BooleSet, BooleConstant
from .PyPolyBoRi import Variable as VariableType
class IntegerPolynomial(object):
    """Polynomial with positive integer coefficients"""
    def __init__(self, boolean_polys):
        super(IntegerPolynomial, self).__init__()
        if not isinstance(boolean_polys, dict):
            boolean_polys = dict([(0, Polynomial(boolean_polys))])
        self.boolean_polys = boolean_polys
    def __coerce__(self, other):
        #TODO handle long
        if isinstance(other, int) and other >= 0:
            i = 0
            res = []
            while 2 ** i <= other:
                and_ = 2 ** i & other
                if and_:
                    res.append(i)
            return (self, IntegerPolynomial(dict([(i, BooleConstant(1)) for i
                in res])))
        if not isinstance(other, IntegerPolynomial):
            other = Polynomial(other)
        return (self, IntegerPolynomial(dict([(0, other)])))
    def __add__(self, other):
        """
        >>> from brial import *
        >>> r= declare_ring([Block("x",1000)], globals()) # doctest: +ELLIPSIS
        >>> p=IntegerPolynomial(x(1))
        >>> p
        {0: x(1)}
        >>> p=p+p;p
        {1: x(1)}
        >>> p=p+x(2); p
        {0: x(2), 1: x(1)}
        >>> p+p
        {1: x(2), 2: x(1)}
        """
        if not isinstance(other, IntegerPolynomial):
            (self, other) = coerce(self, other)
            return self + other
        assert isinstance(other, IntegerPolynomial)
        def add_simple_poly(p, i):
            p = Polynomial(p)
            if p.is_zero():
                return
            res_p = Polynomial(res.get(i, Polynomial(0, p.ring())))
            res[i] = res_p + p
            if res[i].is_zero():
                del res[i]
            inter = BooleSet(res_p).intersect(BooleSet(p))
            add_simple_poly(inter, i + 1)
            return
        res = dict(self.boolean_polys.items())
        for (k, p) in other.boolean_polys.items():
            add_simple_poly(p=p, i=k)
        return IntegerPolynomial(res)
    def __unicode__(self):
        return unicode(self.boolean_polys)
    def __str__(self):
        return str(self.boolean_polys)
    def __repr__(self):
        try:
            return unicode(self)
        except NameError:
            return str(self)
def _test():
    import doctest
    doctest.testmod()
if __name__ == "__main__":
    _test()
 |