2020年1月4日土曜日

学習環境

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



    1. a-bc+ab-c+bc-aabc=0

    2. 1-x+2x1-x2=1+x1-x2=11-x

    3. x-4-x+3x2-16=-7x2-16

    4. x+12-x2+32x2-1=x2+2x+1-x2-32x2-1=2x-12x2-1=1x+1

    5. x+8x-1x+2-x+4x+1x+2=x+1x+8-x-1x+4x-1x+1x+2=x2+9x+8-x2-3x+4x-1x+1x+2=6x+2x-1x+1x+2=6x2-1

    6. x+12-x-2x+2+x2-4x+2x+1=x2+2x+1-x2+4+x2-4x+1x+2=x2+2x+1x+1x+2=x+1x+2

    7. x+2x+1-2xx+1-3x2+4xx+1=x2+x+2x+1-3x2+4xx+1=x3-2x2+2x-4xx+1

    8. x2-x-2-x2+x-1x3+1+x2+x+3x3+1=x2+xx3+1

    9. 2aa2-1+2aa2+1+4a3a4+1=4a3a4-1+4a3a4+1=8a7a8-1

    10. x3+x+xx2+12+1xx2+12=x4+2x2+1xx2+12=x2+12xx2+12=1x

    11. x-22x-3x-1+3x-12x-3x+2+2x2-5x+2x-1=x2-4+3x2-4x+12x-3x-1x+2+2x2-5x+2x-1=4x2-4x-32x-3x-1x+2+4x3-6x2-10x+152x-3x-1x+2=4x3-2x2-14x+122x-3x-1x+2

コード

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

print('13.')


class MyTest(TestCase):
    def test(self):
        x, a, b, c = symbols('x, a, b, c')
        spam = [(a - b) / (a * b) + (b - c) / (b * c) + (c - a) / (c * a),
                1 / (1 + x) + 2 * x / (1 - x ** 2),
                1 / (x + 4) - (x + 3) / (x ** 2 - 16),
                (x + 1) / (2 * x - 2) - (x ** 2 + 3) / (2 * x ** 2 - 2),
                (x + 8) / (x ** 2 + x - 2) - (x + 4) / (x ** 2 + 3 * x + 2),
                (x + 1) / (x + 2) - (x - 2) / (x + 1) +
                (x ** 2 - 4) / (x ** 2 + 3 * x + 2),
                x + 2 - 2 * x / (x + 1) - (3 * x ** 2 + 4) / x / (x + 1),
                (x - 2) / (x ** 2 - x + 1) - 1 /
                (x + 1) + (x ** 2 + x + 3) / (x ** 3 + 1),
                1 / (a - 1) + 1 / (a + 1) + 2 * a /
                (a ** 2 + 1) + 4 * a ** 3 / (a ** 4 + 1),
                x / (x ** 2 + 1) + x / (x ** 2 + 1) ** 2 +
                1 / (x * (x ** 2 + 1) ** 2),
                (x - 2) / (2 * x ** 2 - 5 * x + 3) + (3 * x - 1) /
                (2 * x ** 2 + x - 6) + (2 *
                                        x ** 2 - 5) / (x ** 2 + x - 2),
                a / ((a - b) * (a - c)) + b / (b - c) / (b - a) + c / (c - a) / (c - b)]
        egg = [0,
               1 / (1 - x),
               -7 / (x ** 2 - 16),
               1 / (x + 1),
               6 / (x ** 2 - 1),
               (x + 1) / (x + 2),
               (x ** 3 - 2 * x ** 2 + 2 * x - 4) / x / (x + 1),
               (x ** 2 + x) / (x ** 3 + 1),
               8 * a ** 7 / (a ** 8 - 1),
               1 / x,
               (4 * x ** 3 - 2 * x ** 2 - 14 * x + 12) / (2 * x - 3) / (x - 1) / (x + 2)]
        for s, t in zip(spam, egg):
            self.assertEqual((s - t).simplify(), 0)


if __name__ == '__main__':
    main()

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

% ./sample13.py -v
13.
test (__main__.MyTest) ... ok

----------------------------------------------------------------------
Ran 1 test in 1.029s

OK
%

0 コメント:

コメントを投稿