-
Notifications
You must be signed in to change notification settings - Fork 167
/
Copy pathsymbolics_06.py
58 lines (51 loc) · 1.38 KB
/
symbolics_06.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from sympy import Symbol, sin, cos, exp, log, Abs, pi, diff, sign
from lpython import S
def test_elementary_functions():
# test sin, cos
x: S = Symbol('x')
assert(sin(pi) == S(0))
assert(sin(pi/S(2)) == S(1))
assert(sin(S(2)*pi) == S(0))
assert(cos(pi) == S(-1))
assert(cos(pi/S(2)) == S(0))
assert(cos(S(2)*pi) == S(1))
assert(diff(sin(x), x) == cos(x))
assert(diff(cos(x), x) == S(-1)*sin(x))
# test exp, log
assert(exp(S(0)) == S(1))
assert(log(S(1)) == S(0))
assert(diff(exp(x), x) == exp(x))
assert(diff(log(x), x) == S(1)/x)
# test Abs
assert(Abs(S(-10)) == S(10))
assert(Abs(S(10)) == S(10))
assert(Abs(S(-1)*x) == Abs(x))
# test sign
assert(sign(S(-10)) == S(-1))
assert(sign(S(0)) == S(0))
assert(sign(S(10)) == S(1))
assert(sign(S(2)* x) == sign(x))
assert(sign(S(-1)* x) == S(-1) * sign(x))
# test composite functions
a: S = exp(x)
b: S = sin(a)
b1: bool = b.func == sin
c: S = cos(b)
d: S = log(c)
d1: bool = d.func == log
e: S = Abs(d)
print(e)
assert(b1 == True)
if b.func == sin:
assert True
else:
assert False
assert(b.func == sin)
assert(d1 == True)
if d.func == log:
assert True
else:
assert False
assert(d.func == log)
assert(e == Abs(log(cos(sin(exp(x))))))
test_elementary_functions()