## 2020年3月20日金曜日

### 数学 - Python - 代数学 - 1次方程式, 2次方程式 - 解と係数の関係、判別式、式の変形

1. 2次方程式の解と係数の関係により、

$\begin{array}{l}\alpha +\beta =-\frac{b}{a}\\ \alpha \beta =\frac{c}{a}\\ b=-a\left(\alpha +\beta \right)\\ c=a\alpha \beta \end{array}$

よって判別式は、

$\begin{array}{l}D\\ ={b}^{2}-4ac\\ ={a}^{2}{\left(\alpha +\beta \right)}^{2}-4{a}^{2}\alpha \beta \\ ={a}^{2}\left({\left(\alpha +\beta \right)}^{2}-4\alpha \beta \right)\\ ={a}^{2}\left({\alpha }^{2}-2\alpha \beta +{\beta }^{2}\right)\\ ={a}^{2}{\left(\alpha -\beta \right)}^{2}\end{array}$

（証明終）

1. $\begin{array}{l}\alpha +\beta =-\frac{b}{a}\\ \alpha \beta =\frac{c}{a}\\ \left(2\alpha +\beta \right)\left(\alpha +2\beta \right)\\ =2{\alpha }^{2}+5\alpha \beta +2{\beta }^{2}\\ =2{\left(\alpha +\beta \right)}^{2}+\alpha \beta \\ =\frac{2{b}^{2}}{{a}^{2}}+\frac{c}{a}\end{array}$

2. $\begin{array}{l}{\alpha }^{3}+{\beta }^{3}\\ =\left(\alpha +\beta \right)\left({\alpha }^{2}-\alpha \beta +{\beta }^{2}\right)\\ =\left(\alpha +\beta \right)\left({\left(\alpha +\beta \right)}^{2}-3\alpha \beta \right)\\ =-\frac{b}{a}\left(\frac{{b}^{2}}{{a}^{2}}-\frac{3c}{a}\right)\end{array}$

3. $\begin{array}{l}\frac{1}{{\alpha }^{2}}+\frac{1}{{\beta }^{2}}\\ =\frac{{\alpha }^{2}+{\beta }^{2}}{{\alpha }^{2}{\beta }^{2}}\\ =\frac{{\left(\alpha +\beta \right)}^{2}-2\alpha \beta }{{\left(\alpha \beta \right)}^{2}}\\ =\frac{\frac{{b}^{2}}{{a}^{2}}-\frac{2c}{a}}{\frac{{c}^{2}}{{a}^{2}}}\\ =\frac{{b}^{2}-2ac}{{c}^{2}}\end{array}$

4. $\begin{array}{l}{\alpha }^{4}+{\beta }^{4}\\ ={\left({\alpha }^{2}+{\beta }^{2}\right)}^{2}-2{\left(\alpha \beta \right)}^{2}\\ =\left({\left(\alpha +\beta \right)}^{2}-2\alpha \beta \right)-2{\left(\alpha \beta \right)}^{2}\\ ={\left(\frac{{b}^{2}}{{a}^{2}}-\frac{2c}{a}\right)}^{2}-\frac{2{c}^{2}}{{a}^{2}}\end{array}$

コード

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

print('14.')

def discriminant(a, b, c):
return b ** 2 - 4 * a * c

x = symbols('x')
a, b, c = symbols('a:c')
eq = a * x ** 2 + b * x + c
alpha, beta = solve(eq, x)
d = discriminant(a, b, c)

class MyTestCase(TestCase):
def test14(self):
self.assertEqual(
d.simplify(), (a ** 2 * (alpha - beta) ** 2).simplify())

def test15_1(self):
self.assertEqual(((2 * alpha + beta) * (alpha + 2 * beta)).simplify(),
(2 * b ** 2 / a ** 2 + c / a).simplify())

def test15_2(self):
self.assertEqual((alpha ** 3 + beta ** 3).simplify(),
(-b / a * (b ** 2 / a ** 2 - 3 * c / a)).simplify())

def test15_3(self):
self.assertEqual((1 / alpha ** 2 + 1 / beta ** 2).simplify(),
((b ** 2 - 2 * a * c) / c ** 2).simplify())

def test15_4(self):
self.assertEqual((alpha ** 4 + beta ** 4).expand(),
((b ** 2 / a ** 2 - 2 * c / a) ** 2 - 2 * c ** 2 / a ** 2).expand())

if __name__ == "__main__":
main()


% ./sample14.py -v
14.
test14 (__main__.MyTestCase) ... ok
test15_1 (__main__.MyTestCase) ... ok
test15_2 (__main__.MyTestCase) ... ok
test15_3 (__main__.MyTestCase) ... ok
test15_4 (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 5 tests in 0.368s

OK
%