Mercurial > hg > Applications > Tokio
comparison Examples/etc/mac @ 0:cfb7c6b24319
Initial revision
author | kono |
---|---|
date | Thu, 30 Aug 2007 14:57:44 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:cfb7c6b24319 |
---|---|
1 | |
2 /* Three diferent descriptions of | |
3 calcurate maginitude of vector */ | |
4 | |
5 /* data flow calcuration */ | |
6 | |
7 magasync_dataflow(A,B,Res):- | |
8 Aab = 0, Bab = 0, G = 0, Res = 0, | |
9 L = 0, Sqs = 0, G1 = 0, % initialize | |
10 #abs_unit(A,Aab), | |
11 #abs_unit(B,Bab), | |
12 #maxmin(Aab,Bab,G,L), | |
13 #calc(G,L,Sqs), | |
14 #delay(G,G1), | |
15 #result(G1,Sqs,Res). | |
16 | |
17 delay(G,G1):- | |
18 @G1 = G. | |
19 | |
20 abs_unit(I,O):- | |
21 if I < 0 then @O = -I else @O = I . | |
22 | |
23 maxmin(I1,I2,O1,O2):- | |
24 if I1 > I2 then (@O1 = I1, @O2 = I2) | |
25 else (@O1 = I2, @O2 = I1) . | |
26 | |
27 calc(I1,I2,O):- | |
28 @O = I1 * 7 / 8 + I2 / 2 . | |
29 | |
30 result(I1,I2,O):- | |
31 if I1 > I2 then @O = I1 else @O = I2 . | |
32 | |
33 /* algorithmic description */ | |
34 | |
35 magasync(A,B,Res):- | |
36 (if A < 0 | |
37 then Aab <- - A | |
38 else Aab <- A ), | |
39 (if B < 0 | |
40 then Bab <- - B | |
41 else Bab <- B ) | |
42 && | |
43 (if Aab > Bab | |
44 then G <- Aab, L <- Bab | |
45 else G <- Bab, L <- Aab) | |
46 && | |
47 Sqs <- G * 7 / 8 + L / 2 , G <- G | |
48 && | |
49 (if G > Sqs | |
50 then Res <- G | |
51 else Res <- Sqs). | |
52 | |
53 /* head is interval name */ | |
54 | |
55 mag_name(A,B,Res) :- int1(A,B,Res). | |
56 | |
57 int1(A,B,Res) :- | |
58 skip, | |
59 (if A < 0 then Aab <- - A | |
60 else Aab <- A ), | |
61 (if B < 0 then Bab <- - B | |
62 else Bab <- B ) | |
63 && int2(Aab,Bab,Res). | |
64 | |
65 int2(Aab,Bab,Res) :- | |
66 skip, | |
67 (if Aab > Bab | |
68 then (G <- Aab, L <- Bab) | |
69 else (G <- Bab, L <- Aab)) | |
70 && int3(G,L,Res). | |
71 | |
72 int3(G,L,Res) :- | |
73 skip, | |
74 Sqs <- G * 7 / 8 + L / 2 , G <- G | |
75 && int4(Sqs,G,Res). | |
76 | |
77 int4(Sqs,G,Res) :- | |
78 skip, | |
79 (if G > Sqs | |
80 then Res <- G | |
81 else Res <- Sqs) | |
82 && true. | |
83 | |
84 /* data generator */ | |
85 | |
86 input_data(0,[]) :- !,empty. | |
87 input_data(V,[H|T]):- | |
88 V = H, | |
89 @T = T, | |
90 @input_data(V,T). | |
91 | |
92 write_fk(A) :- fin(write(A)),keep(write(A)). | |
93 | |
94 test1:- A=5,B=6, | |
95 magasync(A,B,Res), write_fk([A,B,Res]). | |
96 | |
97 test2:- Va = [1,2,3,4,5,6,7], Vb = [1,2,3,4,5,6,7], | |
98 input_data(A,Va),input_data(B,Vb), | |
99 magasync_dataflow(A,B,Res), write_fk([A,B,Res]). | |
100 | |
101 test3:- A=5,B=6, | |
102 mag_name(A,B,Res), write_fk([A,B,Res]). |