2019年11月23日土曜日

学習環境

代数への出発 (新装版 数学入門シリーズ) (松坂 和夫(著)、岩波書店)の第2章(整式の計算)、4(整式の除法)の問17の解答を求めてみる。



    1. 2x2+7x-42x-1=2x-1x+42x-1=x+4

    2. x3-38x-12x+6=x+6x2-6x-2x+6=x2-6x-2

    3. a4+a2+1a2-a+1=a2-a+1a2+a+1a2-a+1=a2+a+1

    4. 6y4+3y3+2y2-2y-42y2+y+2=2y2+y+23y2-22y2+y+2=3y2-2

コード

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

print('17.')

x = symbols('x')


class MyTest(TestCase):

    def test(self):
        spam = [(2 * x ** 2 + 7 * x - 4, 2 * x - 1),
                (x ** 3 - 38 * x - 12, x + 6),
                (x ** 4 + x ** 2 + 1, x ** 2 - x + 1),
                (6 * x ** 4 + 3 * x ** 3 + 2 * x ** 2 - 2 * x - 4, 2 * x ** 2 + x + 2)]
        egg = [x + 4,
               x ** 2 - 6 * x - 2,
               x ** 2 + x + 1,
               3 * x ** 2 - 2]
        for (num, den), t in zip(spam, egg):
            self.assertEqual((num / den).simplify(), t)


if __name__ == '__main__':
    main()

入出力結果(Zsh、cmd.exe(コマンドプロンプト)、Terminal、Jupyter(IPython))

% ./sample17.py -v
17.
test (__main__.MyTest) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.322s

OK
%

0 コメント:

コメントを投稿