## 2019年12月2日月曜日

### 数学 - Python - 代数学 - 整式の計算 - 2変数、式の整理

1. $\begin{array}{l}A-B-C\\ =5{x}^{2}-6xy+2{y}^{2}\end{array}$

2. $\begin{array}{l}4A-3B+2C\\ =\left(4-9-14\right){x}^{2}+\left(-4-15\right)xy+\left(8+12+8\right){y}^{2}\\ =-19{x}^{2}-19xy+28{y}^{2}\end{array}$

3. $\begin{array}{l}2A-3\left(C-B\right)\\ =2A+3B-3C\\ =\left(2+9+21\right){x}^{2}+\left(-2+15\right)xy+\left(4-12-12\right){y}^{2}\\ =32{x}^{2}+13xy-20{y}^{2}\end{array}$

コード

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

print('1.')

x, y = symbols('x, y')
A = x ** 2 - x * y + 2 * y ** 2
B = 3 * x ** 2 + 5 * x * y - 4 * y ** 2
C = -7 * x ** 2 + 4 * y ** 2

class MyTest(TestCase):
def test(self):
spam = [A - B - C,
4 * A - 3 * B + 2 * C,
2 * A - 3 * (C - B)]
egg = [(5, -6, 2),
(-19, -19, 28),
(32, 13, -20)]
for s, (a, b, c) in zip(spam, egg):
self.assertEqual(s, a * x ** 2 + b * x * y + c * y ** 2)

if __name__ == '__main__':
main()


% ./sample1.py -v
1.
test (__main__.MyTest) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.005s

OK
%