## 2019年8月26日月曜日

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

1. ${a}^{\frac{3}{2}}$

2. ${a}^{\frac{2}{3}}$

3. ${a}^{\frac{5}{3}}$

4. ${a}^{-\frac{2}{5}}$

コード

Python 3

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

print('5.')

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

def tearDown(self):
pass

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

def test_int(self):
a = 2
spam = [sqrt(a ** 3, 2), root(a ** 2, 3),
root(a ** 5, 3), root(1 / a ** 2, 5)]
egg = [a ** Rational(3, 2), a ** Rational(2, 3), a **
Rational(5, 3), a ** -Rational(2, 5)]
for t, s in zip(spam, egg):
self.assertEqual(float(t), float(s))

if __name__ == '__main__':
main()


C:\Users\...>py sample5.py
5.
.F
======================================================================
FAIL: test_symbol (__main__.MyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "./sample5.py", line 22, in test_symbol
self.assertEqual(t, s)
AssertionError: sqrt(a**3) != a**(3/2)

----------------------------------------------------------------------
Ran 2 tests in 0.017s

FAILED (failures=1)

C:\Users\...>py sample5.py
5.
test_int (__main__.MyTestCase) ... ok
test_symbol (__main__.MyTestCase) ... FAIL

======================================================================
FAIL: test_symbol (__main__.MyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "./sample5.py", line 22, in test_symbol
self.assertEqual(t, s)
AssertionError: sqrt(a**3) != a**(3/2)

----------------------------------------------------------------------
Ran 2 tests in 0.016s

FAILED (failures=1)

C:\Users\...>


Symbolでは上手くいかないみたい。