## 2019年11月23日土曜日

### 数学 - Python - 代数学 - 整式の計算 - 整式の除法 - 割り切れる場合、約数、因数、倍数

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

2. $\begin{array}{l}\frac{{x}^{3}-38x-12}{x+6}\\ =\frac{\left(x+6\right)\left({x}^{2}-6x-2\right)}{x+6}\\ ={x}^{2}-6x-2\end{array}$

3. $\begin{array}{l}\frac{{a}^{4}+{a}^{2}+1}{{a}^{2}-a+1}\\ =\frac{\left({a}^{2}-a+1\right)\left({a}^{2}+a+1\right)}{{a}^{2}-a+1}\\ ={a}^{2}+a+1\end{array}$

4. $\begin{array}{l}\frac{6{y}^{4}+3{y}^{3}+2{y}^{2}-2y-4}{2{y}^{2}+y+2}\\ =\frac{\left(2{y}^{2}+y+2\right)\left(3{y}^{2}-2\right)}{2{y}^{2}+y+2}\\ =3{y}^{2}-2\end{array}$

コード

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

print('17.')

x = symbols('x')

class MyTest(TestCase):

def test(self):
spam = [(2 * x ** 2 + 7 * x - 4, 2 * x - 1),
(x ** 3 - 38 * x - 12, x + 6),
(x ** 4 + x ** 2 + 1, x ** 2 - x + 1),
(6 * x ** 4 + 3 * x ** 3 + 2 * x ** 2 - 2 * x - 4, 2 * x ** 2 + x + 2)]
egg = [x + 4,
x ** 2 - 6 * x - 2,
x ** 2 + x + 1,
3 * x ** 2 - 2]
for (num, den), t in zip(spam, egg):
self.assertEqual((num / den).simplify(), t)

if __name__ == '__main__':
main()


% ./sample17.py -v
17.
test (__main__.MyTest) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.322s

OK
%