-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathcircexp.coffee
140 lines (118 loc) · 1.87 KB
/
circexp.coffee
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
### circexp =====================================================================
Tags
----
scripting, JS, internal, treenode, general concept
Parameters
----------
x
General description
-------------------
Returns expression x with circular and hyperbolic functions converted to exponential forms. Sometimes this will simplify an expression.
###
Eval_circexp = ->
push(cadr(p1))
Eval()
circexp()
# normalize
Eval()
circexp = ->
i = 0
h = 0
save()
p1 = pop()
if (car(p1) == symbol(COS))
push(cadr(p1))
expcos()
restore()
return
if (car(p1) == symbol(SIN))
push(cadr(p1))
expsin()
restore()
return
if (car(p1) == symbol(TAN))
p1 = cadr(p1)
push(imaginaryunit)
push(p1)
multiply()
exponential()
p2 = pop()
push(imaginaryunit)
push(p1)
multiply()
negate()
exponential()
p3 = pop()
push(p3)
push(p2)
subtract()
push(imaginaryunit)
multiply()
push(p2)
push(p3)
add()
divide()
restore()
return
if (car(p1) == symbol(COSH))
p1 = cadr(p1)
push(p1)
exponential()
push(p1)
negate()
exponential()
add()
push_rational(1, 2)
multiply()
restore()
return
if (car(p1) == symbol(SINH))
p1 = cadr(p1)
push(p1)
exponential()
push(p1)
negate()
exponential()
subtract()
push_rational(1, 2)
multiply()
restore()
return
if (car(p1) == symbol(TANH))
p1 = cadr(p1)
push(p1)
push_integer(2)
multiply()
exponential()
p1 = pop()
push(p1)
push_integer(1)
subtract()
push(p1)
push_integer(1)
add()
divide()
restore()
return
if (iscons(p1))
h = tos
while (iscons(p1))
push(car(p1))
circexp()
p1 = cdr(p1)
list(tos - h)
restore()
return
if (p1.k == TENSOR)
push(p1)
copy_tensor()
p1 = pop()
for i in [0...p1.tensor.nelem]
push(p1.tensor.elem[i])
circexp()
p1.tensor.elem[i] = pop()
push(p1)
restore()
return
push(p1)
restore()