2020年5月22日金曜日

学習環境

代数への出発 (新装版 数学入門シリーズ) (松坂 和夫(著)、岩波書店)の第6章(1次方程式、2次方程式)、1(集合とその表し方)、問1の解答を求めてみる。



    1. x 2 = - 1 x = ± i x | x 2 + 1 = 0 = - i , i

    2. y | 2 y = 3 = ϕ

    3. z | z 2 - 2 = 0 = ϕ

    4. z | z > 0 z 2 - 2 = 0 = 2

コード

#!/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()

入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))

% ./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
%

0 コメント:

コメントを投稿