示例#1
0
def _projective_general_unitary_order(n, field):
    q = field.order
    return (Integer({field.char: field.pow * (n * (n - 1) // 2)}) *
            prod((Integer(q ** i - 1) *
                  Integer(q ** i + 1) for i in range(1, n // 2 + 1))) *
            prod((Integer(q ** (2 * i + 1) + 1)) for i in range(1,
                (n + 1) // 2)))
示例#2
0
def _get_factorized(base, pow):
    x = _integers.get((base, pow), None)
    if x is None:
        x = Integer(base ** pow - 1)
        x.factorize()
        _integers[(base, pow)] = x
    return x
示例#3
0
def _get_factorized(base, pow):
    x = _integers.get((base, pow), None)
    if x is None:
        x = Integer(base**pow - 1)
        x.factorize()
        _integers[(base, pow)] = x
    return x
示例#4
0
 def order(n, field):
     q = field.order
     n //= 2
     o = (Integer({field.char: field.pow * n * (n - 1)}) *
          Integer(q**n - e) * prod((Integer(q**i - 1) * Integer(q**i + 1)
                                    for i in xrange(1, n))))
     if field.char != 2:
         o.div_by_prime(2)
     return o
示例#5
0
def _min_power(p, n, primes):
    """Minimal power t such that \pi(p(p^t-1)(p^2t-1)...(p^nt-1)) contains given set
    of primes.
    """
    t = 0
    primes = set(primes)
    primes.remove(p)
    while primes:
        t += 1
        x = Integer()
        for i in range(1, n + 1):
            x *= _get_factorized(p, t * i)
            # x = prod(Integer(p ** (t * i) - 1) for i in range(1, n + 1))
        x.factorize()
        primes -= set(x.factors)
    return t
示例#6
0
def _min_power(p, n, primes):
    """Minimal power t such that \pi(p(p^t-1)(p^2t-1)...(p^nt-1)) contains given set
    of primes.
    """
    t = 0
    primes = set(primes)
    primes.remove(p)
    while primes:
        t += 1
        x = Integer()
        for i in range(1, n + 1):
            x *= _get_factorized(p, t * i)
            #x = prod(Integer(p ** (t * i) - 1) for i in range(1, n + 1))
        x.factorize()
        primes -= set(x.factors)
    return t
示例#7
0
 def __init__(self, group):
     Graph.__init__(self)
     apex = group.apex()
     for elem in apex:
         factors = Integer(elem).factorize().keys()
         self.add_vertices(factors)
         self.add_edges(itertools.combinations(factors, 2))
示例#8
0
 def __init__(self, group):
     Graph.__init__(self)
     apex = group.apex()
     for elem in apex:
         self._add_element(elem)
     for i, vertex in enumerate(self._vertices):
         instance = MultiModeStringFormatter.mixin_to(Integer(vertex))
         instance.str_mode = 'verbose'
         self._vertices[i] = instance
示例#9
0
 def __init__(self,
              quotient=1,
              q=0,
              partition=None,
              signs=None,
              verbose=True):
     """Creates element = quotient * [q ^ n_1 + e_1, ...] for n_i in
     'partition', e_i in 'signs'
     """
     if partition is None:
         partition = []
     if signs is None:
         signs = []
     self._quotient = Integer(quotient)
     self._q = q
     self._partition = partition
     self._signs = signs
     super(SpectraElement, self).__init__(self)
示例#10
0
    def __init__(self, parent, integer=Integer(), **kw):
        Frame.__init__(self, parent, **kw)

        self._integer_view = IntegerView(self, integer)
        self._integer_view.pack(expand=True, fill='x', side='left')

        self._button = CheckBox(self,
                                indicatoron=0,
                                text="F",
                                command=self._set_factorization)
        self._button.pack(side='left')
示例#11
0
 def __init__(self, quotient=1, q=0, partition=None, signs=None, verbose=True):
     """Creates element = quotient * [q ^ n_1 + e_1, ...] for n_i in
     'partition', e_i in 'signs'
     """
     if partition is None:
         partition = []
     if signs is None:
         signs = []
     self._quotient = Integer(quotient)
     self._q = q
     self._partition = partition
     self._signs = signs
     super(SpectraElement, self).__init__(self)
示例#12
0
def _projective_special_unitary_order(n, field):
    q = field.order
    return (Integer({field.char: field.pow * (n * (n - 1) / 2)}) * prod(
        (Integer(q**i - 1) * Integer(q**i + 1)
         for i in xrange(2, n // 2 + 1))) * prod(
             (Integer(q**(2 * i + 1) + 1))
             for i in xrange(1, (n + 1) // 2)) * Integer(q - 1) * Integer(
                 (q + 1) // gcd(n, q + 1)))
示例#13
0
 def order(n, field):
     q = field.order
     n //= 2
     part = prod(
         (Integer(q**k - 1) * Integer(q**k + 1) for k in xrange(1, n)))
     if not e:
         return (part * Integer({field.char: field.pow * n * n}) *
                 Integer(q**n - 1) * Integer(q**n + 1))
     if field.char == 2:
         part *= 2
     return (part * Integer({field.char: field.pow * n * (n - 1)}) *
             Integer(q**n - e))
示例#14
0
    def __init__(self, parent, integer=Integer(), **kw):
        #kw['state'] = 'disabled'
        kw.setdefault('anchor', 'nw')
        kw.setdefault('relief', 'sunken')

        kw.setdefault('width', 10)
        kw.setdefault('justify', 'left')
        self._var = StringVar()
        Label.__init__(self, parent, textvariable=self._var, **kw)
        self._factorization_enabled = False
        self.integer = integer
        self.bind("<Configure>", self._update_width)

        self._init_menu()
示例#15
0
class SpectraElement(long):
    """Special long extension for spectra elements. It contains information on
    how it was calculated. If 'verbose' is False, creates long, without any
    additional info
    """

    def __new__(cls, quotient=1, q=0, partition=None, signs=None, verbose=True):
        if partition is None:
            partition = []
        if signs is None:
            signs = []
        class_ = SpectraElement if verbose else long
        return long.__new__(
            class_, quotient * reduce(numeric.lcm, (q ** ni + ei for (ni, ei) in zip(partition, signs)), 1)
        )

    def __init__(self, quotient=1, q=0, partition=None, signs=None, verbose=True):
        """Creates element = quotient * [q ^ n_1 + e_1, ...] for n_i in
        'partition', e_i in 'signs'
        """
        if partition is None:
            partition = []
        if signs is None:
            signs = []
        self._quotient = Integer(quotient)
        self._q = q
        self._partition = partition
        self._signs = signs
        super(SpectraElement, self).__init__(self)

    @property
    def quotient(self):
        return self._quotient

    @property
    def partition(self):
        return self._partition

    @property
    def signs(self):
        return self._signs

    def str_verbose(self):
        quotient = self._quotient.str_factorized() if (self._quotient != 1) else ""
        sign = lambda e: "+" if e > 0 else "-"
        power = lambda k: "^" + str(k) if k > 1 else ""
        element = lambda ni, ei: "{}{} {} 1".format(self._q, power(ni), sign(ei))
        elements = ", ".join(element(ni, ei) for (ni, ei) in sorted(zip(self._partition, self._signs)))
        if len(self._partition) == 1:
            brackets = "({})" if self._quotient != 1 else "{}"
        else:
            brackets = "[{}]"
        lcm_str = brackets.format(elements) if elements else ""
        return " * ".join(filter(bool, (quotient, lcm_str)))

    def str_latex(self):
        quotient = self._quotient.str_factorized() if (self._quotient != 1) else ""
        sign = lambda e: "+" if e > 0 else "-"

        def power(k):
            if k == 1:
                return ""
            template = "^{}" if k < 10 else "^{{{}}}"
            return template.format(k)

        element = lambda ni, ei: "{}{} {} 1".format(self._q, power(ni), sign(ei))
        elements = ", ".join(element(ni, ei) for (ni, ei) in sorted(zip(self._partition, self._signs), reverse=True))
        if len(self._partition) == 1:
            brackets = "({})" if self._quotient != 1 else "{}"
        else:
            brackets = "[{}]"
        lcm_str = brackets.format(elements) if elements else ""
        return " ".join(filter(bool, (quotient, lcm_str)))

    def lcm(self, other):
        """Returns lcm of this and other. 'q' must be the same. Quotients are
        multiplied.
        """
        elem = long.__new__(SpectraElement, numeric.lcm(self, other))
        quotient = self._quotient * other._quotient
        elem.__init__(
            quotient=quotient,
            q=self._q,
            partition=list(self._partition) + list(other._partition),
            signs=list(self._signs) + list(other._signs),
        )
        return elem

    def __mul__(self, other):
        """Multiplies quotient by integer
        """
        elem = long.__new__(SpectraElement, long(self) * other)
        elem.__init__(quotient=self._quotient * other, q=self._q, partition=self._partition, signs=self._signs)
        return elem

    def __rmul__(self, other):
        return self * other
示例#16
0
 def order(self):
     if self._order is None:
         func = orders.classical_orders.get(self._name,
                                            lambda *arg: Integer())
         self._order = func(self._dim, self._field)
     return self._order
示例#17
0
 def order(self):
     if self._order is None:
         func = orders.exceptional_orders.get(self._name,
                                              lambda *arg: Integer())
         self._order = func(self._field)
     return self._order
示例#18
0
       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

"""
from spectrum.calculations.numeric import Integer, gcd, prod

__author__ = 'Daniel Lytkin'

sporadic_orders = {
    "M11": (Integer((2, 4), (3, 2), 5, 11)),
    "M12": (Integer((2, 6), (3, 3), 5, 11)),
    "M22": (Integer((2, 7), (3, 2), 5, 7, 11)),
    "M23": (Integer((2, 7), (3, 2), 5, 7, 11, 23)),
    "M24": (Integer((2, 10), (3, 3), 5, 7, 11, 23)),
    "J1": (Integer((2, 3), 3, 5, 7, 11, 19)),
    "J2": (Integer((2, 7), (3, 3), (5, 2), 7)),
    "J3": (Integer((2, 7), (3, 5), 5, 17, 19)),
    "J4": (Integer((2, 21), (3, 3), 5, 7, (11, 3), 23, 29, 31, 37, 43)),
    "Co1": (Integer((2, 21), (3, 9), (5, 4), (7, 2), 11, 13, 23)),
    "Co2": (Integer((2, 18), (3, 6), (5, 3), 7, 11, 23)),
    "Co3": (Integer((2, 10), (3, 7), (5, 3), 7, 11, 23)),
    "Fi22": (Integer((2, 17), (3, 9), (5, 2), 7, 11, 13)),
    "Fi23": (Integer((2, 18), (3, 13), (5, 2), 7, 11, 13, 17, 23)),
    "Fi24'": (Integer((2, 21), (3, 16), (5, 2), (7, 3), 11, 13, 17, 23, 29)),
    "HS": (Integer((2, 9), (3, 2), (5, 3), 7, 11)),
示例#19
0
def _e6_order(field):
    q = field.order
    return (_order_product(field, 36, [6, 4, 3, 3, 2, 1, 1], [9, 5, 3, 3, 1]) *
            Integer((q - 1) // gcd(3, q - 1)))
示例#20
0
 def order(self):
     if self._order is None:
         # n!/2
         self._order = numeric.prod(range(3, self._degree + 1))
     return Integer(self._order)
示例#21
0
def _projective_special_linear_order(n, field):
    q = field.order
    return (Integer({field.char: field.pow * (n * (n - 1) / 2)}) * prod(
        (Integer(q**i - 1)
         for i in xrange(3, n + 1))) * Integer(q + 1) * Integer(
             (q - 1) // gcd(n, q - 1)))
示例#22
0
 def transform_number(number):
     if type(number) in (SpectraElement, Integer):
         return StringViewFormatter(number)
     return StringViewFormatter(Integer(number))
示例#23
0
def _2g2_order(field):
    q = field.order
    return Integer({3: field.pow * 3}) * (q**3 + 1) * (q - 1)
示例#24
0
def _2b2_order(field):
    q = field.order
    return Integer({2: field.pow * 2}) * (q**2 + 1) * (q - 1)
示例#25
0
def _2e6_order(field):
    q = field.order
    return (_order_product(field, 36, [9, 6, 5, 4, 3, 3, 2, 1], [3, 3, 1, 1]) *
            Integer((q + 1) // gcd(3, q + 1)))
示例#26
0
def _e7_order(field):
    q = field.order
    return (_order_product(field, 63, [9, 7, 6, 5, 4, 3, 3, 2, 1, 1],
                           [9, 7, 5, 3, 3, 1]) * Integer(
                               (q - 1) // gcd(2, q - 1)))
示例#27
0
class SpectraElement(long):
    """Special long extension for spectra elements. It contains information on
    how it was calculated. If 'verbose' is False, creates long, without any
    additional info
    """
    def __new__(cls,
                quotient=1,
                q=0,
                partition=None,
                signs=None,
                verbose=True):
        if partition is None:
            partition = []
        if signs is None:
            signs = []
        class_ = SpectraElement if verbose else long
        return long.__new__(
            class_,
            quotient * reduce(numeric.lcm,
                              (q**ni + ei
                               for (ni, ei) in zip(partition, signs)), 1))

    def __init__(self,
                 quotient=1,
                 q=0,
                 partition=None,
                 signs=None,
                 verbose=True):
        """Creates element = quotient * [q ^ n_1 + e_1, ...] for n_i in
        'partition', e_i in 'signs'
        """
        if partition is None:
            partition = []
        if signs is None:
            signs = []
        self._quotient = Integer(quotient)
        self._q = q
        self._partition = partition
        self._signs = signs
        super(SpectraElement, self).__init__(self)

    @property
    def quotient(self):
        return self._quotient

    @property
    def partition(self):
        return self._partition

    def str_verbose(self):
        quotient = self._quotient.str_factorized() if (
            self._quotient != 1) else ""
        sign = lambda e: "+" if e > 0 else "-"
        power = lambda k: "^" + str(k) if k > 1 else ""
        element = lambda ni, ei: "{}{} {} 1".format(self._q, power(ni), sign(ei
                                                                             ))
        elements = ", ".join(
            element(ni, ei)
            for (ni, ei) in sorted(zip(self._partition, self._signs)))
        if len(self._partition) == 1:
            brackets = "({})" if self._quotient != 1 else "{}"
        else:
            brackets = "[{}]"
        lcm_str = brackets.format(elements) if elements else ""
        return " * ".join(filter(bool, (quotient, lcm_str)))

    def str_latex(self):
        quotient = self._quotient.str_factorized() if (
            self._quotient != 1) else ""
        sign = lambda e: "+" if e > 0 else "-"

        def power(k):
            if k == 1:
                return ""
            template = "^{}" if k < 10 else "^{{{}}}"
            return template.format(k)

        element = lambda ni, ei: "{}{} {} 1".format(self._q, power(ni), sign(ei
                                                                             ))
        elements = ", ".join(
            element(ni, ei) for (
                ni,
                ei) in sorted(zip(self._partition, self._signs), reverse=True))
        if len(self._partition) == 1:
            brackets = "({})" if self._quotient != 1 else "{}"
        else:
            brackets = "[{}]"
        lcm_str = brackets.format(elements) if elements else ""
        return " ".join(filter(bool, (quotient, lcm_str)))

    def lcm(self, other):
        """Returns lcm of this and other. 'q' must be the same. Quotients are
        multiplied.
        """
        elem = long.__new__(SpectraElement, numeric.lcm(self, other))
        quotient = self._quotient * other._quotient
        elem.__init__(quotient=quotient,
                      q=self._q,
                      partition=list(self._partition) + list(other._partition),
                      signs=list(self._signs) + list(other._signs))
        return elem

    def __mul__(self, other):
        """Multiplies quotient by integer
        """
        elem = long.__new__(SpectraElement, long(self) * other)
        elem.__init__(quotient=self._quotient * other,
                      q=self._q,
                      partition=self._partition,
                      signs=self._signs)
        return elem

    def __rmul__(self, other):
        return self * other
示例#28
0
def _projective_general_linear_order(n, field):
    q = field.order
    return (Integer({field.char: field.pow * (n * (n - 1) / 2)}) * prod(
        (Integer(q**i - 1) for i in xrange(2, n + 1))))
示例#29
0
 def transform_number(number):
     if type(number) not in (SpectraElement, Integer):
         number = Integer(number)
     return MultiModeStringFormatter.mixin_to(number)
示例#30
0
 def __init__(self, spectrum):
     Graph.__init__(self)
     for elem in spectrum:
         factors = Integer(elem).factorize().keys()
         self.add_vertices(factors)
         self.add_edges(itertools.combinations(factors, 2))
示例#31
0
def _symplectic_order(n, field):
    n //= 2
    q = field.order
    return (Integer({field.char: field.pow * n * n}) * prod(
        (Integer(q**i - 1) * Integer(q**i + 1) for i in xrange(1, n + 1))))
示例#32
0
def _order_product(field, pow, pluses, minuses):
    q = field.order
    return (Integer({field.char: field.pow * pow}) * prod(
        (Integer(q**i + 1) for i in pluses)) * prod(
            (Integer(q**i - 1) for i in minuses)))