1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Eval_decomp = ->
|
18 | save()
|
19 | console.log "Eval_decomp is being called!!!!!!!!!!!!!!!!!!!!"
|
20 | h = tos
|
21 | push(symbol(NIL))
|
22 | push(cadr(p1))
|
23 | Eval()
|
24 | push(caddr(p1))
|
25 | Eval()
|
26 | p1 = pop()
|
27 | if (p1 == symbol(NIL))
|
28 | guess()
|
29 | else
|
30 | push(p1)
|
31 | decomp(false)
|
32 | list(tos - h)
|
33 | restore()
|
34 |
|
35 |
|
36 | pushTryNotToDuplicate = (toBePushed) ->
|
37 | if tos > 0
|
38 | if DEBUG then console.log "comparing " + toBePushed + " to: " + stack[tos-1]
|
39 | if equal(toBePushed, stack[tos-1])
|
40 | if DEBUG then console.log "skipping " + toBePushed + " because it's already on stack "
|
41 | return
|
42 | push(toBePushed)
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | decomp = (generalTransform) ->
|
48 | save()
|
49 |
|
50 | p2 = pop()
|
51 | p1 = pop()
|
52 |
|
53 | if DEBUG then console.log "DECOMPOSING " + p1
|
54 |
|
55 |
|
56 |
|
57 | if generalTransform
|
58 | if !iscons(p1)
|
59 | if DEBUG then console.log " ground thing: " + p1
|
60 | pushTryNotToDuplicate p1
|
61 | restore()
|
62 | return
|
63 | else
|
64 | if (Find(p1, p2) == 0)
|
65 | if DEBUG then console.log " entire expression is constant"
|
66 | pushTryNotToDuplicate(p1)
|
67 |
|
68 |
|
69 | restore()
|
70 | return
|
71 |
|
72 |
|
73 |
|
74 | if (isadd(p1))
|
75 | decomp_sum(generalTransform)
|
76 | restore()
|
77 | return
|
78 |
|
79 |
|
80 |
|
81 | if (ismultiply(p1))
|
82 | decomp_product(generalTransform)
|
83 | restore()
|
84 | return
|
85 |
|
86 |
|
87 |
|
88 | if DEBUG then console.log " naive decomp"
|
89 | p3 = cdr(p1)
|
90 | if DEBUG then console.log "startig p3: " + p3
|
91 | while (iscons(p3))
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 | if generalTransform
|
98 | push(car(p3))
|
99 |
|
100 | if DEBUG then console.log "recursive decomposition"
|
101 | push(car(p3))
|
102 |
|
103 | if DEBUG then console.log "car(p3): " + car(p3)
|
104 | push(p2)
|
105 | if DEBUG then console.log "p2: " + p2
|
106 | decomp(generalTransform)
|
107 | p3 = cdr(p3)
|
108 |
|
109 | restore()
|
110 |
|
111 | decomp_sum = (generalTransform) ->
|
112 | if DEBUG then console.log " decomposing the sum "
|
113 | h = 0
|
114 |
|
115 |
|
116 |
|
117 |
|
118 | p3 = cdr(p1)
|
119 |
|
120 | while (iscons(p3))
|
121 | if (Find(car(p3), p2) or generalTransform)
|
122 | push(car(p3))
|
123 | push(p2)
|
124 | decomp(generalTransform)
|
125 | p3 = cdr(p3)
|
126 |
|
127 |
|
128 |
|
129 | h = tos
|
130 |
|
131 | p3 = cdr(p1)
|
132 |
|
133 | while (iscons(p3))
|
134 | if (Find(car(p3), p2) == 0)
|
135 | pushTryNotToDuplicate(car(p3))
|
136 | p3 = cdr(p3)
|
137 |
|
138 | if (tos - h)
|
139 | add_all(tos - h)
|
140 | p3 = pop()
|
141 | pushTryNotToDuplicate(p3)
|
142 | push(p3)
|
143 | negate();
|
144 |
|
145 | decomp_product = (generalTransform) ->
|
146 | if DEBUG then console.log " decomposing the product "
|
147 | h = 0
|
148 |
|
149 |
|
150 |
|
151 | p3 = cdr(p1)
|
152 |
|
153 | while (iscons(p3))
|
154 | if (Find(car(p3), p2) or generalTransform)
|
155 | push(car(p3))
|
156 | push(p2)
|
157 | decomp(generalTransform)
|
158 | p3 = cdr(p3)
|
159 |
|
160 |
|
161 |
|
162 | h = tos
|
163 |
|
164 | p3 = cdr(p1)
|
165 |
|
166 | while (iscons(p3))
|
167 | if (Find(car(p3), p2) == 0)
|
168 | pushTryNotToDuplicate(car(p3))
|
169 | p3 = cdr(p3)
|
170 |
|
171 | if (tos - h)
|
172 | multiply_all(tos - h)
|
173 |
|
174 |
|
175 |
|
176 |
|