## 2019年11月25日月曜日

### 数学 - Python - 代数学 - 整式の計算 - 整式の除法 - 商と余り(剰余)、次数

1. $\begin{array}{l}{x}^{3}-{x}^{2}+x-1\\ =\left(x+2\right)\left({x}^{2}-3x+7\right)-15\end{array}$

よって商、 余り （剰余）はそれぞれ

${x}^{2}-3x+7,-15$

2. $A=\left(x-3\right)\left(2{x}^{3}-3{x}^{2}+x-4\right)-7$

3. $A=\left(2{x}^{2}+2x-3\right)\left(x-\frac{5}{2}\right)+\left(7x-\frac{7}{2}\right)$

4. $A=\left({y}^{2}-y-2\right)\left({y}^{2}-y+1\right)+\left(-2y+10\right)$

5. $A=\left({x}^{2}+4x-6\right)\left({x}^{3}-2{x}^{2}+3x-1\right)$

コード

#!/usr/bin/env python3
from sympy import symbols, Rational
from unittest import TestCase, main

print('19.')

x = symbols('x')

class MyTest(TestCase):

def test(self):
x = symbols('x')
a = [(0, 0, 1, -1, 1, -1),
(0, 2, -9, 10, -7, 5),
(0, 0,  2, -3, -1, 4),
(0, 1, -2, 0, -1, 8),
(1, 2, -11, 23, -22, 6)]
b = [(0, 1, 2),
(0, 1, -3),
(2, 2, -3),
(1, -1, -2),
(1, 4, -6)]
q = [(0, 1, -3, 7),
(2, -3, 1, -4),
(0, 0, 1, -Rational(5, 2)),
(0, 1, -1, 1),
(1, -2, 3, -1)]
r = [(0, -15),
(0, -7),
(7, -Rational(7, 2)),
(-2, 10),
(0, 0, 0, 0)]
for a0, b0, q0, r0 in zip(a, b, q, r):
a1 = sum([c * x ** (5 - i) for i, c in enumerate(a0)])
b1 = sum([c * x ** (2 - i) for i, c in enumerate(b0)])
q1 = sum([c * x ** (3 - i) for i, c in enumerate(q0)])
r1 = sum([c * x ** (1 - i) for i, c in enumerate(r0)])
self.assertEqual(a1, (b1 * q1 + r1).expand())

if __name__ == '__main__':
main()


% ./sample19.py -v
19.
test (__main__.MyTest) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.027s

OK
%