2019年12月21日土曜日

学習環境

代数への出発 (新装版 数学入門シリーズ) (松坂 和夫(著)、岩波書店)の第3章(因数分解と分数式)、1(因数分解)の問2の解答を求めてみる。



    1. 25 x 2 - 20 x + 4 = 5 x - 2 2

    2. 1 4 x 2 - 1 5 x y + 1 25 y = 1 2 x - 1 5 y 2

    3. 4 a 2 + 12 a + 9 = 2 a + 3 2

    4. 1 4 x + y 2 - a x + y + a 2 = 1 2 x + y - a 2 = 1 2 x + 1 2 y - a 2 = 1 4 x + y - 2 a 2

    5. 36 x 3 + 4 x 2 y + 1 9 x y 2 = x ( 36 x 2 + 4 x y + 1 9 y 2 ) = x 6 x + 1 3 y 2 = 1 9 x 18 x + y 2

    6. 25 a 2 b 2 - 9 c 2 d 2 = 5 a b - 3 c d 5 a b + 3 c d

    7. a - 2 b 2 - 3 a + 4 b 2 = a - 2 b + 3 a + 4 b a - 2 b - 3 a - 4 b = 4 a + 2 b - 2 a - 6 b = - 4 2 a + b a + 3 b

    8. x 2 y 2 - x 2 - y 2 + 1 = y 2 - 1 x 2 - y 2 - 1 = 1 2 - 1 x 2 - 1 = x - 1 x + 1 y - 1 y + 1

    9. a 4 - b 4 = a 2 + b 2 a 2 - b 2 = a 2 + b 2 a + b a - b

    10. a 5 - a = a a 4 - 1 = a a 2 + 1 a 2 - 1 = a 2 + 1 a a + 1 a - 1

    11. 16 x 2 - 8 x y + y 2 - 9 z 2 = 4 x - y 2 - 9 z 2 = 4 x - y - 3 z 4 x - y + 3 z

    12. 4 a 2 b 2 - a 2 + b 2 - c 2 2 = 2 a b - a 2 + b 2 - c 2 2 a b + a 2 + b 2 - c 2 = - a - b 2 - c 2 a + b 2 - c 2 = - a - b + c a - b - c a + b + c a + b - c

コード

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

print('2.')


class MyTest(TestCase):
    def test(self):
        x, y, z, a, b, c, d = symbols('x, y, z, a, b, c, d')
        spam = [25 * x ** 2 - 20 * x + 4,
                x ** 2 / 4 - x * y / 5 + y ** 2 / 25,
                4 * a ** 2 + 12 * a + 9,
                (x + y) ** 2 / 4 - a * (x + y) + a ** 2,
                36 * x ** 3 + 4 * x ** 2 * y + x * y ** 2 / 9,
                25 * a ** 2 * b ** 2 - 9 * c ** 2 * d ** 2,
                (a - 2 * b) ** 2 - (3 * a + 4 * b) ** 2,
                x ** 2 * y ** 2 - x ** 2 - y ** 2 + 1,
                a ** 4 - b ** 4,
                a ** 5 - a,
                16 * x ** 2 - 8 * x * y + y ** 2 - 9 * z ** 2,
                4 * a ** 2 * b ** 2 - (a ** 2 + b ** 2 - c ** 2) ** 2]
        egg = [(5 * x - 2) ** 2,
               (x / 2 - y / 5) ** 2,
               (2 * a + 3) ** 2,
               (x + y - 2 * a) ** 2 / 4,
               x * (18 * x + y) ** 2 / 9,
               (5 * a * b - 3 * c * d) * (5 * a * b + 3 * c * d),
               -4 * (2 * a + b) * (a + 3 * b),
               (x - 1) * (x + 1) * (y - 1) * (y + 1),
               (a ** 2 + b ** 2) * (a + b) * (a - b),
               (a ** 2 + 1) * a * (a + 1) * (a - 1),
               (4 * x - y - 3 * z) * (4 * x - y + 3 * z),
               -(a - b + c) * (a - b - c) * (a + b + c) * (a + b - c)]

        for s, t in zip(spam, egg):
            self.assertEqual(s.expand(), t.expand())


if __name__ == '__main__':
    main()

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

% ./sample2.py -v
2.
test (__main__.MyTest) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.124s

OK
%

0 コメント:

コメントを投稿