## 2019年12月22日日曜日

### 数学 - Python - 代数学 - 因数分解と分数式 - 因数分解 - 係数、積に分解、たすき掛けの図式

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

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

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

4. $\begin{array}{l}10{x}^{2}+19x+6\\ =\left(2x+3\right)\left(5x+2\right)\end{array}$

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

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

7. $\begin{array}{l}3{a}^{2}-7ab-10{b}^{2}\\ =\left(a+b\right)\left(3a-10b\right)\end{array}$

8. $\begin{array}{l}16{x}^{2}+22xy-45{y}^{2}\\ =\left(2x+5y\right)\left(8x-9y\right)\end{array}$

コード

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

print('3.')

class MyTest(TestCase):
def test(self):
x = symbols('x')
spam = [x ** 2 + 9 * x + 14,
x ** 2 + 3 * x - 28,
x ** 2 - 7 * x - 144,
10 * x ** 2 + 19 * x + 6,
6 * x ** 2 - 13 * x + 6,
7 * x ** 2 + 39 * x - 18,
3 * x ** 2 - 7 * x - 10,
16 * x ** 2 + 22 * x - 45]
egg = [(x + 2) * (x + 7),
(x + 7) * (x - 4),
(x - 16) * (x + 9),
(2 * x + 3) * (5 * x + 2),
(2 * x - 3) * (3 * x - 2),
(7 * x - 3) * (x + 6),
(x + 1) * (3 * x - 10),
(2 * x + 5) * (8 * x - 9)]
for s, t in zip(spam, egg):
self.assertEqual(s.expand(), t.expand())

if __name__ == '__main__':
main()


% ./sample3.py -v
3.
test (__main__.MyTest) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.066s

OK
%