## 2019年8月27日火曜日

### 数学 - Python - 急速・緩慢に変化する関係 - 指数関数・対数関数 - 指数の拡張 - 指数の拡張(1) - 変形、有理数の指数

1. $\sqrt{a}$

2. $\sqrt[3]{{a}^{4}}$

3. $\begin{array}{l}1.75\\ =\frac{175}{100}\\ =\frac{7}{4}\\ {a}^{\frac{3}{4}}=\sqrt[4]{{a}^{3}}\end{array}$

4. $\sqrt[4]{{a}^{-5}}$

コード

Python 3

#!/usr/bin/env python3
from sympy import pprint, symbols, sqrt, root, Rational, simplify
from unittest import TestCase, main
import random

print('6.')

class MyTestCase(TestCase):
def setUp(self):
pass

def tearDown(self):
pass

def test_symbol(self):
a = symbols('a')
spam = [Rational(1, 2), Rational(4, 3), 1.75, -Rational(5, 4)]
egg = [(2, 1), (3, 4), (4, 7), (4, -5)]
for s, (t, u) in zip(spam, egg):
self.assertEqual(simplify((a ** s)), simplify(root(a ** u, t)))

def test_int(self):
spam = [Rational(1, 2), Rational(4, 3), 1.75, -Rational(5, 4)]
egg = [(2, 1), (3, 4), (4, 7), (4, -5)]
for _ in range(10):
a = random.randrange(1, 101)
for s, (t, u) in zip(spam, egg):
self.assertEqual(float((a ** s)), float(root(a ** u, t)))

def test_int_almost(self):
spam = [Rational(1, 2), Rational(4, 3), 1.75, -Rational(5, 4)]
egg = [(2, 1), (3, 4), (4, 7), (4, -5)]
for _ in range(10):
a = random.randrange(1, 101)
for s, (t, u) in zip(spam, egg):
self.assertAlmostEqual(float((a ** s)), float(root(a ** u, t)))

if __name__ == '__main__':
main()


C:\Users\...>py sample6.py
6.
test_int (__main__.MyTestCase) ... FAIL
test_int_almost (__main__.MyTestCase) ... ok
test_symbol (__main__.MyTestCase) ... FAIL

======================================================================
FAIL: test_int (__main__.MyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "./sample6.py", line 29, in test_int
self.assertEqual(float((a ** s)), float(root(a ** u, t)))
AssertionError: 0.012180114016663296 != 0.012180114016663295

======================================================================
FAIL: test_symbol (__main__.MyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "./sample6.py", line 21, in test_symbol
self.assertEqual(simplify((a ** s)), simplify(root(a ** u, t)))
AssertionError: a**(4/3) != (a**4)**(1/3)

----------------------------------------------------------------------
Ran 3 tests in 0.251s

FAILED (failures=2)

C:\Users\...>