## 2019年12月24日火曜日

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

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

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

3. 2通りの方法で。

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

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

5. $\begin{array}{l}{\left(2a+3b\right)}^{3}-{\left(2a-3b\right)}^{3}\\ =\left(\left(2a+3b\right)-\left(2a-3b\right)\right)\left({\left(2a+3b\right)}^{2}+\left(2a+3b\right)\left(2a-3b\right)+{\left(2a-3b\right)}^{2}\right)\\ =6b\left(4{a}^{2}+6ab+9{b}^{2}+4{a}^{2}-9{b}^{2}+4{a}^{2}-6ab+9{b}^{2}\right)\\ =6b\left(12{a}^{2}+9{b}^{2}\right)\\ =18b\left(4{a}^{2}+3{b}^{2}\right)\end{array}$

コード

#!/usr/bin/env python3
from unittest import TestCase, main
import math
from sympy import symbols, sqrt, solveset, S

print('5.')

class MyTest(TestCase):
def test1(self):
x, a, b = symbols('x, a, b')
spam = [27 * x ** 3 - 1,
x ** 3 + 125,
a ** 6 - b ** 6,
x ** 3 / 8 + 3 * x ** 2 / 4 + 3 * x / 2 + 1,
(2 * a + 3 * b) ** 3 - (2 * a - 3 * b) ** 3]
egg = [(3 * x - 1) * (9 * x ** 2 + 3 * x + 1),
(x + 5) * (x ** 2 - 5 * x + 25),
(a + b) * (a - b) * (a ** 2 + a * b +
b ** 2) * (a ** 2 - a * b + b ** 2),
(x + 2) ** 3 / 8,
18 * b * (4 * a ** 2 + 3 * b ** 2)]
for s, t in zip(spam, egg):
self.assertEqual(s.expand(), t.expand())
self.assertEqual(s.factor(), t)

if __name__ == '__main__':
main()


% ./sample5.py -v
5.
test1 (__main__.MyTest) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.093s

OK
%