## 2020年5月22日金曜日

### 数学 - Python - 代数学 - 1次関数、2次関数 - 集合とその表し方 - 要素(元)、空集合、平方、整数、有理数、実数、無理数、複素数

1. $\begin{array}{l}{x}^{2}=-1\\ x=±i\\ \left\{x\in \text{ℂ}|{x}^{2}+1=0\right\}=\left\{-i,i\right\}\end{array}$

2. $\left\{y\in \text{ℤ}|2y=3\right\}=\varphi$

3. $\left\{z\in \text{ℚ}|{z}^{2}-2=0\right\}=\varphi$

4. $\left\{z\in \text{ℝ}|z>0\wedge {z}^{2}-2=0\right\}=\left\{\sqrt{2}\right\}$

コード

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

print('1.')

class TestEmptySet(TestCase):
def test_imginary(self):
x = symbols('x', imag=True)
self.assertEqual(set(solve(x ** 2 + 1)),
{-I, I})

def test_integer(self):
y = symbols('y', integer=True)
self.assertEqual(solve(2 * y - 3),
[])

def test_rational(self):
z = symbols('z', rational=True)
self.assertEqual(solve(z ** 2 - 2),
[])

def test_positive_real(self):
z = symbols('z', real=True, positive=True)
self.assertEqual(solve(z ** 2 - 2),
[sqrt(2)])

if __name__ == "__main__":
main()


% ./sample1.py -v
1.
test_imginary (__main__.TestEmptySet) ... ok
test_integer (__main__.TestEmptySet) ... ok
test_positive_real (__main__.TestEmptySet) ... ok
test_rational (__main__.TestEmptySet) ... ok

----------------------------------------------------------------------
Ran 4 tests in 0.308s

OK
%