示例#1
0
 def on_btn_z_mulm_released(self):
     try:
         z1 = self.get_z_z(1)
         result = integer.MUL_ZM_Z(z1)
         self.add_history_record('%d * (-1) = %d' % (
             common.Z_to_num(z1),
             common.Z_to_num(result),
             ))
     except Exception as e:
         self.on_exception(e)
示例#2
0
 def on_btn_z_mod_released(self):
     try:
         z1 = self.get_z_z(1)
         z2 = self.get_z_z(2)
         result = integer.MOD_ZZ_Z(z1, z2)
         self.add_history_record('%d %% %d = %d' % (
             common.Z_to_num(z1),
             common.Z_to_num(z2),
             common.Z_to_num(result),
             ))
     except Exception as e:
         self.on_exception(e)
示例#3
0
def polynom(P):
    result = ''

    for rank in range(P[0] + 1):
        coef = P[1][rank]
        # Если коэффициент не ноль
        if coef[0][1] != 1 or coef[0][2][0] != 0:
            sign = '+'
            elem = ''
            # Если коеффициент - целое
            if INT_Q_B(coef):
                num = common.Z_to_num(TRANS_Q_Z(RED_Q_Q(coef)))
                sign = '+' if num > 0 else '-'
                num = abs(num)
                if num != 1 or rank == 0:
                    elem = '%d' % num
            else:
                if coef[0][0] == 1:
                    sign = '-'
                elem = '%s' % rational([[0, coef[0][1], coef[0][2]], coef[1]])

            if rank:
                elem += 'x'
                if rank > 1:
                    elem += '^%d' % rank

            result = '%s %s %s' % (sign, elem, result)

    result = result.strip()
    if result.startswith('+'):
        result = result[1:]
        result = result.strip()
    return result if result else '0'
示例#4
0
def rational(Q):
    #   if Q[1][0] == 1 and Q[1][1][0] == 1:
    #       return str(common.Z_to_num(Q[0]))

    return '%d/%d' % (
        common.Z_to_num(Q[0]),
        common.N_to_num(Q[1]),
    )
示例#5
0
 def on_btn_q_transqz_released(self):
     try:
         q1 = self.get_q_q(1)
         result = rational.TRANS_Q_Z(q1)
         self.add_history_record('%s = %d' % (
             pretty.rational(q1),
             common.Z_to_num(result),
             ))
     except Exception as e:
         self.on_exception(e)
示例#6
0
 def on_btn_q_transzq_released(self):
     try:
         z = self.get_q_z()
         result = rational.TRANS_Z_Q(z)
         self.add_history_record('%d = %s' % (
             common.Z_to_num(z),
             pretty.rational(result),
             ))
     except Exception as e:
         self.on_exception(e)
示例#7
0
 def on_btn_z_abs_released(self):
     try:
         z1 = self.get_z_z(1)
         result = integer.ABS_Z_N(z1)
         self.add_history_record('|%d| = %d' % (
             common.Z_to_num(z1),
             common.N_to_num(result),
             ))
     except Exception as e:
         self.on_exception(e)
示例#8
0
    def on_btn_z_poz_released(self):
        try:
            z1 = self.get_z_z(1)
            result = integer.POZ_Z_D(z1)
            if result == 2:
                sign = '>'
            elif result == 0:
                sign = '='
            else:
                sign = '<'

            self.add_history_record('%d %s 0' % (
                common.Z_to_num(z1),
                sign,
                ))
        except Exception as e:
            self.on_exception(e)