-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPW-E6.py
119 lines (56 loc) · 1.25 KB
/
PW-E6.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
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
def succ(Z):
return Z+1
def pred(Z):
if Z>=1:
return Z-1
else:
return 0
"""Esta es la macro de la resta acotada
Si X < Y, X-Y retorna 0
En otro caso X-Y"""
def resta(X,Y):
Z=0
while Z!=Y:
X=pred(X)
Z=succ(Z)
return X
""" PW-E6: Construir un PW sin macro-tes equivalente a este
begin
Z=succ(X)
while (X!=Y) or (Z<T) do
begin
Y:=succ(Y);
Z:=pred(Z);
end
end
"""
"""
T =(X!=Y) or (Z<T)
ET = ET1+ET2
T1 =(X!=Y)= (X<Y) or (Y<X) ET1 =ET11+ET12
T11 =(X<Y) ET11 =(Y-X)
T12 =(Y<X) ET12 =(X-Y)
T2 = (Z<T) ET2 = (T-Z)
"""
def main(X,Y,Z,T):
Z=succ(X)
print X,Y,Z,T
# Quitamos el macro test
U=resta(Y,X) # ET11
V=resta(X,Y) # ET12
U=U+V # ET1
V=resta(T,Z) # ET2
U=U+V #ET= ET1+ET2
V=0
while U!=V:
print "Dentro Bucle"
Y=succ(Y)
Z=pred(Z)
# Actualizamos condicion del bucle
U=resta(Y,X) # ET11
V=resta(X,Y) # ET12
U=U+V # ET1
V=resta(T,Z) # ET2
U=U+V #ET= ET1+ET2
V=0
main(2,1,1,2) # Entro al bucle