2020年1月5日日曜日

学習環境

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



    1. 36xy35a2·25a2x12y3=15x2

    2. 23abcd

    3. xy2y2-x23x2yx+3y·6x25y2=25·xy·y2-x2x+3y=2xy2-x25yx+3y

    4. x+7x-7x+2xx+2x-7=x+7x

    5. x+yx-y2x-y2xx+y=1x

    6. x+1x+2x+4x-3x-2x-3x+1x+3=x+2x+4x-2x+3

    7. 5x-1x+2x2-2x+4x-6x+24x+1x-1=5x2-2x+44x-6x+1

    8. x-3x-223x2+5x+23x-2x+1x-3x+2=2x-3x-23x+2x+13x-2x-3x+1x+2=2x-23x+23x-2x+2

    9. 1+a1-a1+b1-b1+ba1+a1-a=1-ba

    10. 2x-53x+4x-12xx+2x+2x-23x2x-5x+13x+4=x-123x-2x+1

コード

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

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

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

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

OK
%

0 コメント:

コメントを投稿