## 2019年10月23日水曜日

### 数学 - Python - 代数学 - 実数 - 平方根の和の逆数、差の逆数、和と積

1. $\begin{array}{l}\frac{1}{\sqrt{5}-\sqrt{3}}+\frac{1}{\sqrt{5}+\sqrt{3}}\\ =\frac{2\sqrt{5}}{5-3}\\ =\sqrt{5}\end{array}$

2. $\begin{array}{l}\frac{1}{\sqrt{5}-\sqrt{3}}·\frac{1}{\sqrt{5}-\sqrt{3}}\\ =\frac{1}{2}\end{array}$

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

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

コード

Python 3

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

print('7.')

x = 1 / (sqrt(5) - sqrt(3))
y = 1 / (sqrt(5) + sqrt(3))

class MyTest(TestCase):
def setUp(self):
pass

def tearDown(self):
pass

def test(self):
spam = [x + y, x * y, x ** 2 + x * y + y ** 2, y / x + x / y]
egg = [sqrt(5), Rational(1, 2), Rational(9, 2), 8]
for s, t in zip(spam, egg):
self.assertEqual(s.simplify(), t)

if __name__ == '__main__':
main()


% ./sample7.py -v
7.
test (__main__.MyTest) ... ok

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

OK
%