def SUB_ZZ_Z(list1, list2):
    # Семёнов Михаил
    # Вычитание целых чисел
    if POZ_Z_D(list1) == '+' and POZ_Z_D(list2) == '-':
        return f1.ADD_NN_N(list1, ABS_Z_N(list2))
    elif POZ_Z_D(list1) == '-' and POZ_Z_D(list2) != '-':
        if POZ_Z_D(list2) == '+':
            return ['-'] + f1.ADD_NN_N(ABS_Z_N(list1), ABS_Z_N(list2))
        else:
            return list1

    elif f1.COM_NN_D(ABS_Z_N(list1), ABS_Z_N(list2)) == 2:
        if list2 != 0:
            return f1.SUB_NN_N(ABS_Z_N(list1), ABS_Z_N(list2))
        else:
            return list1
    elif POZ_Z_D(list1) == 0:
        if POZ_Z_D(list2) == '-':
            return list2[1:]
        elif list2 == [0]:
            return list2
        else:
            return ['-'] + list2

    else:
        if POZ_Z_D(list1) == '+':
            return ['-'] + f1.SUB_NN_N(ABS_Z_N(list2), ABS_Z_N(list1))
        else:
            return f1.SUB_NN_N(ABS_Z_N(list2), ABS_Z_N(list1))
def DER_P_P(coefficient, power):
    # Производная многочлена
    # Аносов Павел
    for i in range(len(power)):
        coefficient[i] = rat.MUL_QQ_Q(coefficient[i], rat.TRANS_Z_Q(
            power[i]))  # Коэффициенты домножаем на степени
        power[i] = nat.SUB_NN_N(power[i], [1])  # Степени уменьшаем на единицу
    return coefficient, power
Пример #3
0
def ADD_ZZ_Z(list1, list2):
    # Дашкин Дамир
    # Сложение целых чисел
    if POZ_Z_D(list1) == '+' and POZ_Z_D(list2) == '+':
        return nat.ADD_NN_N(list1, list2)
    elif POZ_Z_D(list1) == '-' and POZ_Z_D(list2) == '-':
        return ['-'] + nat.ADD_NN_N(ABS_Z_N(list1), ABS_Z_N(list2))
    elif nat.COM_NN_D(ABS_Z_N(list1), ABS_Z_N(list2)) == 2:
        if POZ_Z_D(list1) == '-':
            return ['-'] + nat.SUB_NN_N(ABS_Z_N(list1), ABS_Z_N(list2))
        else:
            return nat.SUB_NN_N(ABS_Z_N(list1), ABS_Z_N(list2))
    elif nat.COM_NN_D(ABS_Z_N(list1), ABS_Z_N(list2)) == 1:
        if POZ_Z_D(list2) == '-':
            return ['-'] + nat.SUB_NN_N(ABS_Z_N(list2), ABS_Z_N(list1))
        else:
            return nat.SUB_NN_N(ABS_Z_N(list2), ABS_Z_N(list1))
    elif nat.COM_NN_D(ABS_Z_N(list1), ABS_Z_N(list2)) == 0:
        return [0]
Пример #4
0
 def on_btn_n_subn_released(self):
     try:
         n1 = self.get_n_n(1)
         n2 = self.get_n_n(2)
         result = natural.SUB_NN_N(n1, n2)
         self.add_history_record('%d - %d = %d' % (
             common.N_to_num(n1),
             common.N_to_num(n2),
             common.N_to_num(result),
             ))
     except Exception as e:
         self.on_exception(e)
def ADD_ZZ_Z(b1, n1, list1, b2, n2, list2):
    #Дашкин Дамир
    #Сложение целых чисел
    str1 = ""
    str2 = ""
    for i in range(len(list1)):
        str1 = str1 + str(list1[i])
    for j in range(len(list2)):
        str2 = str2 + str(list2[j])
    if b1 == 1:
        str1 = "-" + str1
    num1 = int(str1)
    if b2 == 1:
        str2 = "-" + str2
    num2 = int(str2)
    if f1.POZ_Z_D(num1) == 2 and f1.POZ_Z_D(num2) == 2:
        res = f1.ADD_NN_N(num1, num2)
    if f1.POZ_Z_D(num1) == 1 and f1.POZ_Z_D(num2) == 1:
        mod1 = f1.ABS_Z_N(num1)
        mod2 = f1.ABS_Z_N(num2)
        res = f1.ADD_NN_N(mod1, mod2)
        res = f1.MUL_ZM_Z(res)
    else:
        mod1 = f1.ABS_Z_N(num1)
        mod2 = f1.ABS_Z_N(num2)
        if f1.COM_NN_D(mod1, mod2) == 2:
            if f1.POZ_Z_D(num1) == 1:
                res = f1.SUB_NN_N(mod1, mod2)
                res = f1.MUL_ZM_Z(res)
            else:
                res = f1.SUB_NN_N(mod1, mod2)
        if f1.COM_NN_D(mod1, mod2) == 1:
            if f1.POZ_Z_D(num2) == 1:
                res = f1.SUB_NN_N(mod2, mod1)
                res = MUL_ZM_Z(res)
            else:
                res = f1.SUB_NN_N(mod2, mod1)
        else:
            res = 0
    return res
Пример #6
0
def open_window_nat_sub():
    layout = [
        [sg.Text('Enter two naturals')],
        [sg.Input(key='dig1')],
        [sg.Button('-', key='start')],
        [sg.Input(key='dig2')],
        [sg.Text(size=(400, 10), key='out')]
    ]
    window = sg.Window('The subtraction of natural numbers', layout, size=(460, 260), resizable=True)
    while True:
        event, values = window.read()
        if event == "start":
            window['out'].update(nat.SUB_NN_N(values['dig1'], values['dig2']))
        if event == sg.WINDOW_CLOSED:
            break
def DIV_PP_P(coefficient1, power1, coefficient2, power2):
    # Деление многочленов
    # Аносов Павел
    new_power = []
    new_coefficient = []
    try:
        while integer.SUB_ZZ_Z(power1[0], power2[0]) != ['-', 1] and power1:
            new_power.append(nat.SUB_NN_N(power1[0], power2[0]))
            new_coefficient.append(
                rat.DIV_QQ_Q(coefficient1[0], coefficient2[0]))
            coef, pow = MUL_PP_P(coefficient2, power2, [new_coefficient[-1]],
                                 [new_power[-1]])
            coefficient1, power1 = SUB_PP_P(coefficient1, power1, coef, pow)

            del coefficient1[0]
            del power1[0]
    except:
        pass
    return new_coefficient, new_power
Пример #8
0
 def test_shift(self):
     number1 = [3, [0, 0, 1]]
     number2 = [1, [3]]
     expect = [2, [7, 9]]
     result = natural.SUB_NN_N(number1, number2)
     self.assertEqual(result, expect)
Пример #9
0
 def test_equal(self):
     number = [3, [6, 7, 4]]
     expect = [1, [0]]
     result = natural.SUB_NN_N(number, number)
     self.assertEqual(result, expect)
Пример #10
0
 def test_normal(self):
     number1 = [3, [6, 7, 4]]
     number2 = [3, [2, 3, 1]]
     expect = [3, [4, 4, 3]]
     result = natural.SUB_NN_N(number1, number2)
     self.assertEqual(result, expect)
Пример #11
0
 def test_zero(self):
     number = [3, [2, 6, 4]]
     zero = [1, [0]]
     expect = number
     result = natural.SUB_NN_N(number, zero)
     self.assertEqual(result, expect)
Пример #12
0
 def test_zeros(self):
     number = [1, [0]]
     expect = number
     result = natural.SUB_NN_N(number, number)
     self.assertEqual(result, expect)