## 2019年12月21日土曜日

### 数学 - Python - 代数学 - 因数分解と分数式 - 因数分解 - 展開の逆、公式

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

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

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

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

5. $\begin{array}{l}36{x}^{3}+4{x}^{2}y+\frac{1}{9}x{y}^{2}\\ =x\left(36{x}^{2}+4xy+\frac{1}{9}{y}^{2}\right)\\ =x{\left(6x+\frac{1}{3}y\right)}^{2}\\ =\frac{1}{9}x{\left(18x+y\right)}^{2}\end{array}$

6. $\begin{array}{l}25{a}^{2}{b}^{2}-9{c}^{2}{d}^{2}\\ =\left(5ab-3cd\right)\left(5ab+3cd\right)\end{array}$

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

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

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

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

11. $\begin{array}{l}16{x}^{2}-8xy+{y}^{2}-9{z}^{2}\\ ={\left(4x-y\right)}^{2}-9{z}^{2}\\ =\left(4x-y-3z\right)\left(4x-y+3z\right)\end{array}$

12. $\begin{array}{l}4{a}^{2}{b}^{2}-{\left({a}^{2}+{b}^{2}-{c}^{2}\right)}^{2}\\ =\left(2ab-\left({a}^{2}+{b}^{2}-{c}^{2}\right)\right)\left(2ab+\left({a}^{2}+{b}^{2}-{c}^{2}\right)\right)\\ =-\left({\left(a-b\right)}^{2}-{c}^{2}\right)\left({\left(a+b\right)}^{2}-{c}^{2}\right)\\ =-\left(a-b+c\right)\left(a-b-c\right)\left(a+b+c\right)\left(a+b-c\right)\end{array}$

コード

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

print('2.')

class MyTest(TestCase):
def test(self):
x, y, z, a, b, c, d = symbols('x, y, z, a, b, c, d')
spam = [25 * x ** 2 - 20 * x + 4,
x ** 2 / 4 - x * y / 5 + y ** 2 / 25,
4 * a ** 2 + 12 * a + 9,
(x + y) ** 2 / 4 - a * (x + y) + a ** 2,
36 * x ** 3 + 4 * x ** 2 * y + x * y ** 2 / 9,
25 * a ** 2 * b ** 2 - 9 * c ** 2 * d ** 2,
(a - 2 * b) ** 2 - (3 * a + 4 * b) ** 2,
x ** 2 * y ** 2 - x ** 2 - y ** 2 + 1,
a ** 4 - b ** 4,
a ** 5 - a,
16 * x ** 2 - 8 * x * y + y ** 2 - 9 * z ** 2,
4 * a ** 2 * b ** 2 - (a ** 2 + b ** 2 - c ** 2) ** 2]
egg = [(5 * x - 2) ** 2,
(x / 2 - y / 5) ** 2,
(2 * a + 3) ** 2,
(x + y - 2 * a) ** 2 / 4,
x * (18 * x + y) ** 2 / 9,
(5 * a * b - 3 * c * d) * (5 * a * b + 3 * c * d),
-4 * (2 * a + b) * (a + 3 * b),
(x - 1) * (x + 1) * (y - 1) * (y + 1),
(a ** 2 + b ** 2) * (a + b) * (a - b),
(a ** 2 + 1) * a * (a + 1) * (a - 1),
(4 * x - y - 3 * z) * (4 * x - y + 3 * z),
-(a - b + c) * (a - b - c) * (a + b + c) * (a + b - c)]

for s, t in zip(spam, egg):
self.assertEqual(s.expand(), t.expand())

if __name__ == '__main__':
main()


% ./sample2.py -v
2.
test (__main__.MyTest) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.124s

OK
%