-
Notifications
You must be signed in to change notification settings - Fork 59
/
filter.coffee
71 lines (60 loc) · 999 Bytes
/
filter.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
###
Remove terms that involve a given symbol or expression. For example...
filter(x^2 + x + 1, x) => 1
filter(x^2 + x + 1, x^2) => x + 1
###
Eval_filter = ->
p1 = cdr(p1)
push(car(p1))
Eval()
p1 = cdr(p1)
while (iscons(p1))
push(car(p1))
Eval()
filter()
p1 = cdr(p1)
###
For example...
push(F)
push(X)
filter()
F = pop()
###
filter = ->
save()
p2 = pop()
p1 = pop()
filter_main()
restore()
filter_main = ->
if (car(p1) == symbol(ADD))
filter_sum()
else if (istensor(p1))
filter_tensor()
else if (Find(p1, p2))
push_integer(0)
else
push(p1)
filter_sum = ->
push_integer(0)
p1 = cdr(p1)
while (iscons(p1))
push(car(p1))
push(p2)
filter()
add()
p1 = cdr(p1)
filter_tensor = ->
i = 0
n = 0
n = p1.tensor.nelem
p3 = alloc_tensor(n)
p3.tensor.ndim = p1.tensor.ndim
for i in [0...p1.tensor.ndim]
p3.tensor.dim[i] = p1.tensor.dim[i]
for i in [0...n]
push(p1.tensor.elem[i])
push(p2)
filter()
p3.tensor.elem[i] = pop()
push(p3)