2020年1月5日日曜日

数学 - Python - 代数学 - 因数分解と分数式 - 分数式とその計算 - 分数式の演算、乗法と除法

1. $\begin{array}{l}\frac{36x{y}^{3}}{5{a}^{2}}·\frac{25{a}^{2}x}{12{y}^{3}}\\ =15{x}^{2}\end{array}$

2. $\frac{2}{3abcd}$

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

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

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

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

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

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

9. $\begin{array}{l}\frac{\left(1+a\right)\left(1-a\right)\left(1+b\right)\left(1-b\right)}{\left(1+b\right)a\left(1+a\right)\left(1-a\right)}\\ =\frac{1-b}{a}\end{array}$

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

コード

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

print('14.')

class MyTest(TestCase):
def test(self):
x, y, a, b, c, d = symbols('x, y, a, b, c, d')
spam = [36 * x * y ** 3 * 25 * a ** 2 * x / (5 * a ** 2) / (12 * y ** 3),
8 * c ** 2 * d ** 2 / (9 * a ** 2 * b ** 2) *
3 * a * b / (4 * c ** 3 * d ** 3),
(x * y ** 4 - x ** 3 * y ** 2) * 6 * x ** 2 /
(3 * x ** 3 * y + 9 * x ** 2 * y ** 2) / (5 * y ** 2),
(x ** 2 - 49) * (x + 2) / (x ** 2 + 2 * x) / (x - 7),
(x ** 2 - y ** 2) * (x - y) /
(x ** 2 - 2 * x * y + y ** 2) / (x ** 2 + x * y),
(x ** 2 + 3 * x + 2) * (x ** 2 + x - 12) /
(x ** 2 - 5 * x + 6) / (x ** 2 + 4 * x + 3),
(5 * x - 5) * (x ** 3 + 8) /
(x ** 2 - 4 * x - 12) / (4 * x ** 2 - 4),
(x ** 2 - 5 * x + 6) * (6 * x ** 2 + 10 * x + 4) /
(3 * x ** 2 - x - 2) / (x ** 2 - x - 6),
(1 - a ** 2) * (1 - b ** 2) * 1 /
(1 + b) / (a + a ** 2) / (1 - a),
(6 * x ** 2 - 7 * x - 20) * (x ** 2 - x - 2) * (x ** 2 + 2 * x) / (x ** 2 - 4) / (6 * x ** 2 - 15 * x) / (3 * x ** 2 + 7 * x + 4)]
egg = [15 * x ** 2,
2 / (3 * a * b * c * d),
2 * x * (y ** 2 - x ** 2) / (5 * y * (x + 3 * y)),
(x + 7) / x,
1 / x,
(x + 2) * (x + 4) / (x - 2) / (x + 3),
5 * (x ** 2 - 2 * x + 4) / 4 / (x - 6) / (x + 1),
2 * (x - 2) * (x + 1) / (x - 1) / (x + 2),
(1 - b) / a,
Rational(1, 3)]
for s, t in zip(spam, egg):
self.assertEqual(s.factor(), t.factor())

if __name__ == '__main__':
main()


% ./sample14.py -v
14.
test (__main__.MyTest) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.270s

OK
%