24 from __future__
import print_function
27 VERSION =
'combinator --- 2010 April 12'
29 import collections, sys, types
40 """Fonction pour la dynamique du combinateur atomique B : Bxyz... --> x(yz)...
41 Pour s = [x_1, x_2, x_3, x_4, ..., x_k]
42 si len(s) => 3 et ((nb == None) ou (nb > 0))
43 alors renvoie (Combinator(x_1, x_3, Combinator(x_2, x_3), x_4, ... , x_k)
45 sinon renvoie (Combinator(a, x_1, x_2, x_3, x_4, ..., x_k),
47 (Seul a est évalué, une seule fois, et pas les x_i)
50 s: Iterable de Combinator
53 Result: (Combinator, naturel)
56 assert isinstance(a, Atom), (type(a), a)
57 assert isinstance(s, collections.Iterable), (type(s), s)
60 assert isinstance(x, Combinator), (type(x), x, s)
66 1)
if (len(s) >= 3)
and ((nb ==
None)
or (nb > 0))
73 """Fonction pour la dynamique du combinateur atomique C : Cxyz... --> xzy...
74 Pour s = [x_1, x_2, x_3, x_4, ..., x_k]
75 si len(s) => 3 et ((nb == None) ou (nb > 0))
76 alors renvoie (Combinator(x_1, x_3, Combinator(x_2, x_3), x_4, ... , x_k)
78 sinon renvoie (Combinator(a, x_1, x_2, x_3, x_4, ..., x_k),
80 (Seul a est évalué, une seule fois, et pas les x_i)
83 s: Iterable de Combinator
86 Result: (Combinator, naturel)
89 assert isinstance(a, Atom), (type(a), a)
90 assert isinstance(s, collections.Iterable), (type(s), s)
93 assert isinstance(x, Combinator), (type(x), x, s)
97 1)
if (len(s) >= 3)
and ((nb ==
None)
or (nb > 0))
104 """Fonction pour une "dynamique constante" : a... --> a...
105 Pour s = [x_1, x_2, x_3, x_4, ..., x_k]
106 renvoie (Combinator(a, x_1, x_2, x_3, x_4, ..., x_k),
108 (Seul a est évalué, une seule fois, et pas les x_i)
111 s: Iterable de Combinator
114 Result: (Combinator, naturel)
117 assert isinstance(a, Atom), (type(a), a)
118 assert isinstance(s, collections.Iterable), (type(s), s)
121 assert isinstance(x, Combinator), (type(x), x, s)
130 """Fonction pour la dynamique du combinateur atomique I : Ix... --> x...
131 Pour s = [x_1, x_2, x_3, x_4, ..., x_k]
132 si len(s) => 1 et ((nb == None) ou (nb > 0))
133 alors renvoie (Combinator(x_1, x_2, x_3, x_4, ..., x_k),
135 sinon renvoie (Combinator(a, x_1, x_2, x_3, x_4, ... ,x_k),
137 (Seul a est évalué, une seule fois, et pas les x_i)
140 s: Iterable de Combinator
143 Result: (Combinator, naturel)
146 assert isinstance(a, Atom), (type(a), a)
150 assert isinstance(x, Combinator), (type(x), x, s)
151 assert isinstance(s, collections.Iterable), (type(s), s)
154 1)
if (len(s) >= 1)
and ((nb ==
None)
or (nb > 0))
161 """Fonction pour la dynamique du combinateur atomique K : Kxy... --> x...
162 Pour s = [x_1, x_2, x_3, x_4, ..., x_k]
163 si len(s) => 2 et ((nb == None) ou (nb > 0))
164 alors renvoie (Combinator(x_1, x_3, x_4, ..., x_k),
166 sinon renvoie (Combinator(a, x_1, x_2, x_3, x_4, ... ,x_k),
168 (Seul a est évalué, une seule fois, et pas les x_i)
171 s: Iterable de Combinator
174 Result: (Combinator, naturel)
177 assert isinstance(a, Atom), (type(a), a)
181 assert isinstance(x, Combinator), (type(x), x, s)
182 assert isinstance(s, collections.Iterable), (type(s), s)
185 1)
if (len(s) >= 2)
and ((nb ==
None)
or (nb > 0))
192 """Fonction pour la dynamique du combinateur atomique S : Sxyz... --> xz(yz)...
193 Pour s = [x_1, x_2, x_3, x_4, ..., x_k]
194 si len(s) => 3 et ((nb == None) ou (nb > 0))
195 alors renvoie (Combinator(x_1, x_3, Combinator(x_2, x_3), x_4, ... , x_k)
197 sinon renvoie (Combinator(a, x_1, x_2, x_3, x_4, ..., x_k),
199 (Seul a est évalué, une seule fois, et pas les x_i)
202 s: Iterable de Combinator
205 Result: (Combinator, naturel)
208 assert isinstance(a, Atom), (type(a), a)
209 assert isinstance(s, collections.Iterable), (type(s), s)
212 assert isinstance(x, Combinator), (type(x), x, s)
219 1)
if (len(s) >= 3)
and ((nb ==
None)
or (nb > 0))
226 """Fonction pour la dynamique du combinateur atomique W : Wxy... --> xyy...
227 Pour s = [x_1, x_2, x_3, x_4, ..., x_k]
228 si len(s) => 2 et ((nb == None) ou (nb > 0))
229 alors renvoie (Combinator(x_1, x_2, x_2, x_3, x_4, ..., x_k),
231 sinon renvoie (Combinator(a, x_1, x_2, x_3, x_4, ... ,x_k),
233 (Seul a est évalué, une seule fois, et pas les x_i)
236 s: Iterable de Combinator
239 Result: (Combinator, naturel)
242 assert isinstance(a, Atom), (type(a), a)
246 assert isinstance(x, Combinator), (type(x), x, s)
247 assert isinstance(s, collections.Iterable), (type(s), s)
249 return ((
Combinator(s[0], s[1], s[1], *s[2:]),
250 1)
if (len(s) >= 2)
and ((nb ==
None)
or (nb > 0))
257 """Fonction pour le remplacement de la "méta-variable" x
258 Pour s = [x_1, x_2, x_3, x_4, ..., x_k]
259 si var_x != None et ((nb == None) ou (nb > 0))
260 alors renvoie (Combinator(var_x, x_1, x_2, x_3, x_4, ..., x_k),
262 sinon renvoie (Combinator(a, x_1, x_2, x_3, x_4, ... ,x_k),
264 (Seul a est évalué, une seule fois, et pas les x_i)
267 s: Iterable de Combinator
270 Result: (Combinator, naturel)
273 assert isinstance(a, Atom), (type(a), a)
274 assert isinstance(s, collections.Iterable), (type(s), s)
277 assert isinstance(x, Combinator), (type(x), x, s)
281 1)
if (var_x !=
None)
and ((nb ==
None)
or (nb > 0))
288 """Fonction pour le remplacement de la "méta-variable" y
289 Pour s = [x_1, x_2, x_3, x_4, ..., x_k]
290 si var_y != None et ((nb == None) ou (nb > 0))
291 alors renvoie (Combinator(var_y, x_1, x_2, x_3, x_4, ..., x_k),
293 sinon renvoie (Combinator(a, x_1, x_2, x_3, x_4, ... ,x_k),
295 (Seul a est évalué, une seule fois, et pas les x_i)
298 s: Iterable de Combinator
301 Result: (Combinator, naturel)
304 assert isinstance(a, Atom), (type(a), a)
305 assert isinstance(s, collections.Iterable), (type(s), s)
308 assert isinstance(x, Combinator), (type(x), x, s)
312 1)
if (var_y !=
None)
and ((nb ==
None)
or (nb > 0))
319 """Fonction pour le remplacement de la "méta-variable" z
320 Pour s = [x_1, x_2, x_3, x_4, ..., x_k]
321 si var_z != None et ((nb == None) ou (nb > 0))
322 alors renvoie (Combinator(var_z, x_1, x_2, x_3, x_4, ..., x_k),
324 sinon renvoie (Combinator(a, x_1, x_2, x_3, x_4, ... ,x_k),
326 (Seul a est évalué, une seule fois, et pas les x_i)
329 s: Iterable de Combinator
332 Result: (Combinator, naturel)
335 assert isinstance(a, Atom), (type(a), a)
336 assert isinstance(s, collections.Iterable), (type(s), s)
339 assert isinstance(x, Combinator), (type(x), x, s)
343 1)
if (var_z !=
None)
and ((nb ==
None)
or (nb > 0))
353 class Atom(collections.Hashable, collections.Callable):
354 """"Atome" pour les combinateurs"""
358 """Initialise l'atome
360 Pre: s: string non vide composée de caractères alphanumériques ou '_',
361 f: fonction : (Atom, Combinator, None ou naturel a) -> (Combinator, naturel b)
362 tel a == None ou a >= b
365 assert isinstance(s, str), (type(s), s)
369 assert c.isalnum()
or (c ==
'_'), (c, s)
370 assert isinstance(f, types.FunctionType), type(f)
382 """Renvoie (l'évaluation du combinateur atomique suivi des combinateurs de args,
383 nombre d'étapes effectuées)
384 En fait renvoie self.f()(self, args, nb) répétée jusqu'à épuisé nb
385 Si nb == None alors évalue tant que le combinateur atomique du début réagit
386 (! certains combinateurs peuvent ne jamais s'arrêter)
387 sinon évalue au plus nb étapes
389 Pre: args: Iterable de Combinator
390 keywords: nb=None ou naturel
392 Result: (Combinator, naturel)
395 assert isinstance(args, collections.Iterable), (type(args), args)
398 assert isinstance(x, Combinator), (type(x), x, args)
399 assert len(keywords) <= 1, (len(keywords), keywords)
400 assert (len(keywords) == 0)
or (
'nb' in keywords), keywords
402 nb = (keywords[
'nb']
if 'nb' in keywords
407 x, nb_eval = self.
f()(self, args, nb)
411 assert nb >= nb_eval, (nb, nb_eval)
415 while (nb ==
None)
or (nb > 0):
416 x, nb_tmp = x[0].
f()(x[0], x[1:], nb=nb)
421 assert nb >= nb_tmp, (nb, nb_tmp)
431 <0 si la représentation (string) de self < la représentation (string) de other,
432 0 si la représentation (string) de self == la représentation (string) de other,
433 >0 si la représentation (string) de self > la représentation (string) de other
437 Exception: TypeError si other n'est pas un Atom
440 if not isinstance(other, Atom):
443 return (cmp(self.
_s, other._s)
if sys.version_info[0] < 3
444 else (self.
_s > other._s) - (self.
_s < other._s))
449 """Renvoie True si other est un Atom qui a même représentation (string) que self,
451 (Ne se préoccupe pas des fonctions associées aux dynamiques des atomes)
456 return isinstance(other, Atom)
and (self.
_s == other._s)
461 """Renvoie True si la représentation (string) de self >= la représentation (string) de other
466 Exception: TypeError si other n'est pas un Atom
469 if not isinstance(other, Atom):
472 return self.
_s >= other._s
477 """Renvoie True si la représentation (string) de self > la représentation (string) de other
482 Exception: TypeError si other n'est pas un Atom
485 if not isinstance(other, Atom):
488 return self.
_s > other._s
493 """Renvoie le hashcode de self
503 """Renvoie True si la représentation (string) de self <= la représentation (string) de other
508 Exception: TypeError si other n'est pas un Atom
511 if not isinstance(other, Atom):
514 return self.
_s <= other._s
519 """Renvoie True si la représentation (string) de self < la représentation (string) de other
524 Exception: TypeError si other n'est pas un Atom
527 if not isinstance(other, Atom):
530 return self.
_s < other._s
535 """Renvoie True si other n'est pas un Atom
536 ou n'a pas la même représentation (string) que self,
538 (Ne se préoccupe pas des fonctions associées aux dynamiques des atomes)
543 return not isinstance(other, Atom)
or (self.
_s != other._s)
548 """Renvoie l'atome sous forme de string "Atom('...')"
550 Result: string "Atom('...')"
553 return ''.join((
"Atom('", self.
_s,
"')"))
558 """Renvoie l'atome sous forme de string
568 """Renvoie la fonction correspondant à la dynamique de l'atome
570 Result: fonction : (Atom, Combinator, None ou naturel) -> (Combinator, naturel)
578 """Renvoie le nombre d'argument nécessaires pour déclencher l'atome
579 Si max==None alors essaie avec de plus en plus d'arguments,
580 sans s'arrêter jusqu'à ce que l'atome déclenche
581 (ou sans jamais s'arrêter si l'atome ne déclenche jamais)
582 Si max est un naturel alors essaie avec au plus max arguments.
583 Si l'atome n'a pas déclenché alors renvoie None
585 Pre: max: None ou naturel
587 Result: naturel ou None
594 while (max ==
None)
or (max >= nb):
595 if self(*l, nb=1)[1] > 0:
597 l.append(_COMB_CONST)
605 class Combinator(collections.Sequence, collections.Hashable, collections.Callable):
607 (Sequence non vide dont le premier élément est un Atom et les suivants des Combinator)"""
611 """Initialise le Combinator
613 Pre: seq: Sequence non vide de Combinator, Atom,
614 bool, naturel (selon le système spécifié par natural_sys)
615 ou string représentant un combinateur
617 Exception: TypeError si l contient des string incorrectes
620 assert isinstance(seq, collections.Sequence), (type(seq), seq)
625 if not (isinstance(x, Combinator)
or isinstance(x, Atom)):
626 if isinstance(x, bool):
630 x = Combinator.n_to(x)
631 elif isinstance(x, str):
632 x = Combinator.str_to(x)
636 assert isinstance(x, Combinator)
or isinstance(x, Atom), (type(x), x, seq)
638 if isinstance(x, Combinator)
and x.atomic_is():
640 l = ([x]
if isinstance(x, Atom)
645 if isinstance(x, bool):
648 elif isinstance(x, str):
649 x = Combinator.str_to(x)
653 assert isinstance(x, Combinator)
or isinstance(x, Atom), (type(x), x, seq)
663 """self & other (combinateur booléen et)
664 En fait renvoie Combinator(Band, self, other)
666 Pre: other: Combinator ou bool
670 Exception: TypeError si other n'est pas un Combinator ou un bool
673 if not (isinstance(other, Combinator)
or isinstance(other, bool)):
681 """Renvoie (le combinateur évalué,
682 le nombre d'étapes réalisées)
683 Si nb == None alors tente d'évaluer jusqu'au bout
684 (! certains combinateurs peuvent ne jamais s'arrêter)
685 sinon évalue au plus nb étapes
687 Pre: nb: None ou naturel
689 Result: (Combinator, naturel)
694 x, nb_eval = self[0](*self[1:], nb=nb)
696 assert nb >= nb_eval, (nb, nb_eval)
705 for i
in range(1, len(x)):
706 assert isinstance(x[i], Combinator), (type(x[i]), x[i])
708 t, nb_tmp = x[i](nb=nb)
712 assert nb >= nb_tmp, (nb, nb_tmp)
717 return ((
Combinator(*(tuple(l) + x[i:])), nb_eval)
if len(x) > i
724 """Renvoie <0 si self < other
727 Si len(self) < len(other) alors renvoie <0
728 Si len(self) > len(other) alors renvoie >0
729 Si len(self) == len(other) alors c'est les premiers éléments différents qui déterminent
733 Exception: TypeError si other n'est pas un Combinator
736 if not isinstance(other, Combinator):
739 i = cmp(len(self), len(other))
741 else cmp(self.
_seq, other._seq))
746 """Renvoie True si le combinateur self contient le combinateur atomique item,
751 Exception: TypeError si item n'est pas un Atom ou un Combinator
754 if not (isinstance(item, Atom)
or isinstance(item, Combinator)):
756 if isinstance(item, Combinator)
and (
not item.atomic_is()):
757 return NotImplemented
759 if isinstance(item, Combinator):
773 """Renvoie True si other est un Combinator égal à self,
775 (Ne se préoccupe pas de l'éventuelle équivalence (théorique) entre les combinateurs)
780 return (isinstance(other, Combinator)
781 and (self.
atomic_is() == other.atomic_is())
782 and (self[0] == other[0])
784 or (self[1:] == other[1:])))
792 return self._seq.__getitem__(key)
797 """Renvoie le hashcode de self
802 return hash(self.
_seq)
807 """Nombre naturel correspondant à self
808 (Selon le système spécifié par natural_sys : BARENDREGT ou CHURCH)
810 Pre: self: Combinator correspondant à un nombre naturel dans le système spécifié
815 assert (natural_sys == BARENDREGT)
or (natural_sys == CHURCH), natural_sys
817 if natural_sys == BARENDREGT:
828 assert len(self) >= len(x), (len(self), len(x), self, x)
835 """Renvoie la longueur du combinateur
840 return len(self.
_seq)
845 """Renvoie True si other n'est pas un Combinator
846 ou n'est pas la même Combinator que self,
848 (Ne se préoccupe pas de l'éventuelle équivalence (théorique) entre les combinateurs)
850 return not self.
__eq__(other)
855 """Renvoie True si self == K,
857 (Ne se préoccupe pas de l'éventuelle équivalence (théorique) entre les combinateurs)
867 """self | other (combinateur booléen ou inclusif)
868 En fait renvoie Combinator(Bor, self, other)
870 Pre: other: Combinator ou bool
874 Exception: TypeError si other n'est pas un Combinator ou un bool
877 if not (isinstance(other, Combinator)
or isinstance(other, bool)):
885 """Renvoie le combinateur sous forme de string "Combinator('...')"
887 Result: string "Combinator('...')"
890 return ''.join((
"Combinator('", str(self),
"')"))
894 def __str__(self, allparent=False, left='(
', right=')
', space=' '):
895 """Renvoie le combinateur sous forme de string.
896 Si allparent alors avec toutes les parenthèses,
897 sinon évite les parenthèses superflues.
898 left représente la parenthèse gauche et right la droite.
899 Les "morceaux" du combinateur sont séparés par space
901 Pre: allparent: valeur booléenne
909 assert isinstance(left, str), (type(left), left)
910 assert isinstance(right, str), (type(right), right)
911 assert isinstance(space, str), (type(space), space)
912 assert isinstance(self[0], Atom)
917 l = [left*(len(self) - 1) + str(self[0])
if allparent
920 assert isinstance(x, Combinator)
922 s = x.__str__(allparent=allparent, left=left, right=right, space=space)
923 if (
not allparent)
and (
not x.atomic_is()):
925 if allparent
or (
not x.atomic_is()):
933 """self ^ other (combinateur booléen ou exclusif)
934 En fait renvoie Combinator(Bxor, self, other)
936 Pre: other: Combinator ou bool
940 Exception: TypeError si other n'est pas un Combinator ou un bool
943 if not (isinstance(other, Combinator)
or isinstance(other, bool)):
946 return NotImplemented
951 """Renvoie True si le combinateur est atomique,
957 assert isinstance(self[0], Atom), (type(self[0]), self[0])
959 return len(self) == 1
964 """Non self (combinateur négation booléenne)
965 En fait renvoie Combinator(Bnot, self)
975 """Renvoie le combinateur dans lequel chaque Atom atom est remplacé par new
978 new: Combinator ou Atom
983 assert isinstance(atom, Atom), type(atom)
984 assert isinstance(new, Combinator)
or isinstance(new, Atom), type(new)
986 l = [new
if self[0] == atom
989 l.append(x.change_atom(atom, new))
995 """Renvoie la profondeur du combinateur
996 == (profondeur de l'arbre binaire correspondant) - 1.
997 depth(combinateur atomique) == 0
998 depth(combinateur (a b)) == max(depth(a), depth(b)) + 1
1005 n = max(n, x.depth()) + 1
1013 """ Renvoie le combinateur correspondant au nombre naturel n
1014 (Selon le système spécifié par natural_sys : BARENDREGT ou CHURCH)
1021 assert (natural_sys == BARENDREGT)
or (natural_sys == CHURCH), natural_sys
1024 return (Combinator.n_to_Barendregt(n)
if natural_sys == BARENDREGT
1025 else Combinator.n_to_Church(n))
1031 """Renvoie le combinateur correspondant au nombre naturel n de Barendregt
1049 """Renvoie le combinateur correspondant au nombre naturel n de Church
1066 """Renvoie le nombre de combinateurs atomiques composant le combinateur (sa taille)
1067 == nombre de feuilles de l'arbre binaire correspondant.
1068 nb_atom(combinateur atomique) == 1
1069 nb_atom(combinateur (a b)) == nb_atom(a) + nb_atom(b)
1082 """Renvoie True si le combinateur est stable (il ne déclenche plus),
1088 return self(nb=1)[1] == 0
1094 """Renvoie le combinateur représenté par le string s
1095 (Si s n'est pas une réprésentation correcte alors renvoie None)
1096 Un string correcte est un string non vide
1097 comprenant des string appartenant à str_combs et des '(' et ')',
1102 Result: Combinator ou None
1105 assert isinstance(s, str), (type(s), s)
1114 if (s[i] ==
' ')
or (s[i] ==
'('):
1116 if s[k:i]
in str_combs:
1117 x = str_combs[s[k:i]]
1138 comb = Combinator.str_to(s[i + 1:k])
1143 elif (s[i] !=
'_')
and (
not s[i].isalnum()):
1148 if s[k:]
in str_combs:
1149 x = str_combs[s[k:]]
1201 assert isinstance(K, Combinator)
1202 assert len(K) == 1, (len(K), K)
1203 assert K.atomic_is()
1204 assert isinstance(K[0], Atom)
1209 assert isinstance(S, Combinator)
1210 assert len(S) == 1, (len(S), S)
1211 assert S.atomic_is()
1212 assert isinstance(S[0], Atom)
1220 assert isinstance(KK, Combinator)
1221 assert len(KK) == 2, (len(KK), KK)
1222 assert not KK.atomic_is()
1223 assert isinstance(KK[0], Atom)
1224 assert isinstance(KK[1], Combinator)
1229 assert isinstance(KS, Combinator)
1230 assert len(KS) == 2, (len(KS), KS)
1231 assert not KS.atomic_is()
1232 assert isinstance(KS[0], Atom)
1233 assert isinstance(KS[1], Combinator)
1424 natural_sys = CHURCH
1428 str_combs = {
'K' : K,
1449 if __name__ ==
'__main__':
1451 """Test du module"""
1457 if not 'profile' in dir():
1465 debug.test_begin(VERSION, __debug__)
1467 BASICS = (K, S, KK, KS, SS, SK)
1468 STDS = (B, C, I, iota, KI, L, M, O, R, T, U, V, W, Y)
1469 BOOLS = (Bnot, Bnot_my, Band, Bor, Bimp, Bnotrec)
1470 NATURALS_FCT = (NBzero_is, NBsucc, NBprev, NBadd)
1471 NATURALS_FCT_CHURCH = (NCsucc, NCadd)
1473 STABLES = BASICS + STDS + BOOLS + (NCsucc, )
1474 UNSTABLES = (Omega, ) + NATURALS_FCT + (NCadd, )
1476 ALLS = STABLES + UNSTABLES
1479 ALLS_VARS = ALLS + VARS
1483 print(
'func_B()...', end=
''); sys.stdout.flush()
1514 for i
in range(3, len(ALLS_VARS)):
1515 assert func_B(Atom_K, ALLS_VARS[:i], 0) == (
Combinator(Atom_K, *ALLS_VARS[:i]), 0)
1519 *ALLS_VARS[3:i]), 1)
1523 *ALLS_VARS[3:i]), 1)
1527 *ALLS_VARS[3:i]), 1)
1529 assert func_B(Atom_S, ALLS_VARS[:i], 0) == (
Combinator(Atom_S, *ALLS_VARS[:i]), 0)
1533 *ALLS_VARS[3:i]), 1)
1537 *ALLS_VARS[3:i]), 1)
1541 *ALLS_VARS[3:i]), 1)
1542 print(
'ok'); sys.stdout.flush()
1545 print(
'func_C()...', end=
''); sys.stdout.flush()
1576 for i
in range(3, len(ALLS_VARS)):
1577 assert func_C(Atom_K, ALLS_VARS[:i], 0) == (
Combinator(Atom_K, *ALLS_VARS[:i]), 0)
1581 *ALLS_VARS[3:i]), 1)
1585 *ALLS_VARS[3:i]), 1)
1589 *ALLS_VARS[3:i]), 1)
1591 assert func_C(Atom_S, ALLS_VARS[:i], 0) == (
Combinator(Atom_S, *ALLS_VARS[:i]), 0)
1595 *ALLS_VARS[3:i]), 1)
1599 *ALLS_VARS[3:i]), 1)
1603 *ALLS_VARS[3:i]), 1)
1604 print(
'ok'); sys.stdout.flush()
1607 print(
'func_const()...', end=
''); sys.stdout.flush()
1608 for i
in range(len(ALLS_VARS)):
1612 assert func_const(Atom_K, ALLS_VARS[:i],
None) \
1618 assert func_const(Atom_S, ALLS_VARS[:i],
None) \
1620 print(
'ok'); sys.stdout.flush()
1623 print(
'func_I()...', end=
''); sys.stdout.flush()
1635 assert func_I(Atom_K, (Vx, ), 1) == (Vx, 1)
1636 assert func_I(Atom_K, (Vx, ), 2) == (Vx, 1)
1637 assert func_I(Atom_K, (Vx, ),
None) == (Vx, 1)
1640 assert func_I(Atom_S, (Vx, ), 1) == (Vx, 1)
1641 assert func_I(Atom_S, (Vx, ), 2) == (Vx, 1)
1642 assert func_I(Atom_S, (Vx, ),
None) == (Vx, 1)
1644 for i
in range(1, len(ALLS_VARS)):
1645 assert func_I(Atom_K, ALLS_VARS[:i], 0) == (
Combinator(Atom_K, *ALLS_VARS[:i]), 0)
1648 assert func_I(Atom_K, ALLS_VARS[:i],
None) == (
Combinator(*ALLS_VARS[:i]), 1)
1650 assert func_I(Atom_S, ALLS_VARS[:i], 0) == (
Combinator(Atom_S, *ALLS_VARS[:i]), 0)
1653 assert func_I(Atom_S, ALLS_VARS[:i],
None) == (
Combinator(*ALLS_VARS[:i]), 1)
1654 print(
'ok'); sys.stdout.flush()
1657 print(
'func_K()...', end=
''); sys.stdout.flush()
1678 for i
in range(2, len(ALLS_VARS)):
1679 assert func_K(Atom_K, ALLS_VARS[:i], 0) == (
Combinator(Atom_K, *ALLS_VARS[:i]), 0)
1680 assert func_K(Atom_K, ALLS_VARS[:i], 1) \
1681 == (
Combinator(ALLS_VARS[0], *ALLS_VARS[2:i]), 1)
1682 assert func_K(Atom_K, ALLS_VARS[:i], 2) \
1683 == (
Combinator(ALLS_VARS[0], *ALLS_VARS[2:i]), 1)
1684 assert func_K(Atom_K, ALLS_VARS[:i],
None) \
1685 == (
Combinator(ALLS_VARS[0], *ALLS_VARS[2:i]), 1)
1687 assert func_K(Atom_S, ALLS_VARS[:i], 0) == (
Combinator(Atom_S, *ALLS_VARS[:i]), 0)
1688 assert func_K(Atom_S, ALLS_VARS[:i], 1) \
1689 == (
Combinator(ALLS_VARS[0], *ALLS_VARS[2:i]), 1)
1690 assert func_K(Atom_S, ALLS_VARS[:i], 2) \
1691 == (
Combinator(ALLS_VARS[0], *ALLS_VARS[2:i]), 1)
1692 assert func_K(Atom_S, ALLS_VARS[:i],
None) \
1693 == (
Combinator(ALLS_VARS[0], *ALLS_VARS[2:i]), 1)
1694 print(
'ok'); sys.stdout.flush()
1697 print(
'func_S()...', end=
''); sys.stdout.flush()
1728 for i
in range(3, len(ALLS_VARS)):
1729 assert func_S(Atom_K, ALLS_VARS[:i], 0) == (
Combinator(Atom_K, *ALLS_VARS[:i]), 0)
1734 *ALLS_VARS[3:i]), 1)
1739 *ALLS_VARS[3:i]), 1)
1744 *ALLS_VARS[3:i]), 1)
1746 assert func_S(Atom_S, ALLS_VARS[:i], 0) == (
Combinator(Atom_S, *ALLS_VARS[:i]), 0)
1751 *ALLS_VARS[3:i]), 1)
1756 *ALLS_VARS[3:i]), 1)
1761 *ALLS_VARS[3:i]), 1)
1762 print(
'ok'); sys.stdout.flush()
1765 print(
'func_W()...', end=
''); sys.stdout.flush()
1786 for i
in range(2, len(ALLS_VARS)):
1787 assert func_W(Atom_K, ALLS_VARS[:i], 0) == (
Combinator(Atom_K, *ALLS_VARS[:i]), 0)
1788 assert func_W(Atom_K, ALLS_VARS[:i], 1) \
1789 == (
Combinator(ALLS_VARS[0], ALLS_VARS[1], ALLS_VARS[1], *ALLS_VARS[2:i]), 1)
1790 assert func_W(Atom_K, ALLS_VARS[:i], 2) \
1791 == (
Combinator(ALLS_VARS[0], ALLS_VARS[1], ALLS_VARS[1], *ALLS_VARS[2:i]), 1)
1792 assert func_W(Atom_K, ALLS_VARS[:i],
None) \
1793 == (
Combinator(ALLS_VARS[0], ALLS_VARS[1], ALLS_VARS[1], *ALLS_VARS[2:i]), 1)
1795 assert func_W(Atom_S, ALLS_VARS[:i], 0) == (
Combinator(Atom_S, *ALLS_VARS[:i]), 0)
1796 assert func_W(Atom_S, ALLS_VARS[:i], 1) \
1797 == (
Combinator(ALLS_VARS[0], ALLS_VARS[1], ALLS_VARS[1], *ALLS_VARS[2:i]), 1)
1798 assert func_W(Atom_S, ALLS_VARS[:i], 2) \
1799 == (
Combinator(ALLS_VARS[0], ALLS_VARS[1], ALLS_VARS[1], *ALLS_VARS[2:i]), 1)
1800 assert func_W(Atom_S, ALLS_VARS[:i],
None) \
1801 == (
Combinator(ALLS_VARS[0], ALLS_VARS[1], ALLS_VARS[1], *ALLS_VARS[2:i]), 1)
1802 print(
'ok'); sys.stdout.flush()
1805 print(
'func_x()...', end=
''); sys.stdout.flush()
1806 print(
'???', end=
'')
1807 print(
'ok'); sys.stdout.flush()
1810 print(
'func_y()...', end=
''); sys.stdout.flush()
1811 print(
'???', end=
'')
1812 print(
'ok'); sys.stdout.flush()
1815 print(
'func_z()...', end=
''); sys.stdout.flush()
1816 print(
'???', end=
'')
1817 print(
'ok'); sys.stdout.flush()
1823 print(
"Atom_K: '{0}'".format(Atom_K)); sys.stdout.flush()
1824 print(
"Atom_S: '{0}'".format(Atom_S)); sys.stdout.flush()
1825 print(
"Atom_Vx: '{0}'".format(Atom_Vx)); sys.stdout.flush()
1826 print(
"Atom_Vy: '{0}'".format(Atom_Vy)); sys.stdout.flush()
1827 print(
"Atom_Vz: '{0}'".format(Atom_Vz)); sys.stdout.flush()
1831 print(
'Atom()...', end=
''); sys.stdout.flush()
1832 assert Atom_K._f == func_K, Atom_K._f
1833 assert Atom_K._s ==
'K', Atom_K._s
1835 assert Atom_S._f == func_S, Atom_S._f
1836 assert Atom_S._s ==
'S', Atom_S._s
1838 assert Atom(
'xyz_ABC')._f == func_const,
Atom(
'xyz_ABC')._f
1839 assert Atom(
'xyz_ABC')._s ==
'xyz_ABC',
Atom(
'xyz_ABC')._s
1841 assert Atom(
'xyz_ABC', func_K)._f == func_K,
Atom(
'xyz_ABC', func_K)._f
1842 assert Atom(
'xyz_ABC', func_K)._s ==
'xyz_ABC',
Atom(
'xyz_ABC', func_K)._s
1843 print(
'ok'); sys.stdout.flush()
1846 print(
'Atom.__call__()...', end=
''); sys.stdout.flush()
1851 assert Atom_K(Vx, Vy, Vz, nb=0) == (
Combinator(K, Vx, Vy, Vz), 0),
Atom_K(Vx, Vy, Vz, nb=0)
1865 Vx), 1),
Atom_S(Vx, Vy, Vz, Vx)
1866 assert Atom_S(Vx, Vy, Vz, Vx, nb=0) == (
Combinator(S, Vx, Vy, Vz, Vx), 0), \
1867 Atom_S(Vx, Vy, Vz, Vx, nb=0)
1878 for x
in STDS[:-1
if debug.assertspeed > debug.ASSERT_NORMAL
else 7]:
1880 (x,
Atom(
'_const')(x))
1888 for y
in STDS[:-1
if debug.assertspeed > debug.ASSERT_NORMAL
else 7]:
1890 (x,
Atom(
'_const')(x, y))
1893 assert Atom_K(x, y, nb=
None) == (x, 1), (x, y,
Atom_K(x, y, nb=
None))
1898 for z
in STDS[:-1
if debug.assertspeed > debug.ASSERT_NORMAL
else 5]:
1900 (x, y, z,
Atom_K(x, y, z, nb=0))
1902 (x, y, z,
Atom_K(x, y, z, nb=1))
1907 (x, y, z,
Atom_S(x, y, z, nb=0))
1909 (x, y, z,
Atom_S(x, y, z, nb=1))
1911 (x, y, z,
Atom_S(x, y, z, nb=2))
1913 assert Atom_S(x, y, z, Vx, nb=1) \
1915 (x, y, z,
Atom_S(x, y, z, Vx, nb=1))
1924 if debug.assertspeed <= debug.ASSERT_NORMAL:
1925 print(debug.assertspeed_str(), end=
'')
1926 print(
'ok'); sys.stdout.flush()
1929 print(
'Atom.__cmp__()...', end=
''); sys.stdout.flush()
1930 if sys.version_info[0] >= 3:
1937 assert mycmp(Atom_K, Atom_K) == 0, mycmp(Atom_K, Atom_K)
1938 assert mycmp(Atom_S, Atom_S) == 0, mycmp(Atom_S, Atom_S)
1939 assert mycmp(Atom_K, Atom_S) < 0, mycmp(Atom_K, Atom_S)
1940 assert mycmp(Atom_S, Atom_K) > 0, mycmp(Atom_S, Atom_K)
1942 assert mycmp(Atom_K,
Atom(
'K')) == 0, mycmp(Atom_K,
Atom(
'K'))
1943 assert mycmp(Atom_K,
Atom(
'K', func_S)) == 0, mycmp(Atom_K,
Atom(
'K', func_S))
1945 assert mycmp(Atom_S,
Atom(
'K')) > 0, mycmp(Atom_S,
Atom(
'K'))
1946 assert mycmp(Atom_S,
Atom(
'K', func_S)) > 0, mycmp(Atom_S,
Atom(
'K', func_S))
1948 assert mycmp(Atom_S,
Atom(
'S')) == 0, mycmp(Atom_S,
Atom(
'S'))
1949 assert mycmp(Atom_S,
Atom(
'S', func_K)) == 0, mycmp(Atom_S,
Atom(
'S', func_K))
1951 assert mycmp(Atom_K,
Atom(
'S')) < 0, mycmp(Atom_K,
Atom(
'S'))
1952 assert mycmp(Atom_K,
Atom(
'S', func_K)) < 0, mycmp(Atom_K,
Atom(
'S', func_K))
1954 assert mycmp(Atom_K,
Atom(
'k')) < 0, mycmp(Atom_K,
Atom(
'k'))
1955 assert mycmp(Atom_K,
Atom(
'K_')) < 0, mycmp(Atom_K,
Atom(
'K_'))
1956 print(
'ok'); sys.stdout.flush()
1959 print(
'Atom.__eq__()...', end=
''); sys.stdout.flush()
1960 assert Atom_K == Atom_K, Atom_K
1961 assert Atom_S == Atom_S, Atom_S
1962 assert not(Atom_K == Atom_S), (Atom_K, Atom_S)
1963 assert not(Atom_S == Atom_K), (Atom_S, Atom_K)
1964 assert not(Atom_K ==
'K')
1965 assert not(Atom_S ==
'S')
1967 assert Atom_K ==
Atom(
'K'), (Atom_K,
Atom(
'K'))
1968 assert Atom_K ==
Atom(
'K', func_S), (Atom_K,
Atom(
'K', func_S))
1970 assert Atom_S ==
Atom(
'S'), (Atom_K,
Atom(
'S'))
1971 assert Atom_S ==
Atom(
'S', func_K), (Atom_S,
Atom(
'S', func_K))
1973 assert not(Atom_K ==
Atom(
'k')), (Atom_K,
Atom(
'k'))
1974 assert not(Atom_K ==
Atom(
'K_')), (Atom_K,
Atom(
'K_'))
1975 print(
'ok'); sys.stdout.flush()
1978 print(
'Atom.__ge__()...', end=
''); sys.stdout.flush()
1979 assert Atom_K >= Atom_K, Atom_K
1980 assert Atom_S >= Atom_S, Atom_S
1981 assert not(Atom_K >= Atom_S), (Atom_K, Atom_S)
1982 assert Atom_S >= Atom_K, (Atom_S, Atom_K)
1984 assert Atom_K >=
Atom(
'K'), (Atom_K,
Atom(
'K'))
1985 assert Atom_K >=
Atom(
'K', func_S), (Atom_K,
Atom(
'K', func_S))
1987 assert Atom_S >=
Atom(
'K'), (Atom_S,
Atom(
'K'))
1988 assert Atom_S >=
Atom(
'K', func_S), (Atom_S,
Atom(
'K', func_S))
1990 assert Atom_S >=
Atom(
'S'), (Atom_S,
Atom(
'S'))
1991 assert Atom_S >=
Atom(
'S', func_K), (Atom_S,
Atom(
'S', func_K))
1993 assert not(Atom_K >=
Atom(
'S')), (Atom_K,
Atom(
'S'))
1994 assert not(Atom_K >=
Atom(
'S', func_K)), (Atom_K,
Atom(
'S', func_K))
1996 assert not(Atom_K >=
Atom(
'k')), (Atom_K,
Atom(
'k'))
1997 assert not(Atom_K >=
Atom(
'K_')), (Atom_K,
Atom(
'K_'))
1998 print(
'ok'); sys.stdout.flush()
2001 print(
'Atom.__gt__()...', end=
''); sys.stdout.flush()
2002 assert not(Atom_K > Atom_K), Atom_K
2003 assert not(Atom_S > Atom_S), Atom_S
2004 assert not(Atom_K > Atom_S), (Atom_K, Atom_S)
2005 assert Atom_S > Atom_K, (Atom_S, Atom_K)
2007 assert not(Atom_K >
Atom(
'K')), (Atom_K,
Atom(
'K'))
2008 assert not(Atom_K >
Atom(
'K', func_S)), (Atom_K,
Atom(
'K', func_S))
2010 assert Atom_S >
Atom(
'K'), (Atom_S,
Atom(
'K'))
2011 assert Atom_S >
Atom(
'K', func_S), (Atom_S,
Atom(
'K', func_S))
2013 assert not(Atom_S >
Atom(
'S')), (Atom_S,
Atom(
'S'))
2014 assert not(Atom_S >
Atom(
'S', func_K)), (Atom_S,
Atom(
'S', func_K))
2016 assert not(Atom_K >
Atom(
'S')), (Atom_K,
Atom(
'S'))
2017 assert not(Atom_K >
Atom(
'S', func_K)), (Atom_K,
Atom(
'S', func_K))
2019 assert not(Atom_K >
Atom(
'k')), (Atom_K,
Atom(
'k'))
2020 assert not(Atom_K >
Atom(
'K_')), (Atom_K,
Atom(
'K_'))
2021 print(
'ok'); sys.stdout.flush()
2024 print(
'Atom.__hash__()...', end=
''); sys.stdout.flush()
2025 assert hash(Atom_K) == hash(Atom_K)
2026 assert hash(Atom_S) == hash(Atom_S)
2027 assert hash(Atom_K) != hash(Atom_S)
2028 assert hash(Atom_S) != hash(Atom_K)
2030 assert hash(Atom_K) == hash(
Atom(
'K'))
2031 assert hash(Atom_K) == hash(
Atom(
'K', func_S))
2033 assert hash(Atom_S) == hash(
Atom(
'S'))
2034 assert hash(Atom_S) == hash(
Atom(
'S', func_K))
2035 assert hash(Atom_S) != hash(
Atom(
'K'))
2037 assert hash(Atom_S) != hash(
Atom(
's'))
2038 assert hash(Atom_S) != hash(
Atom(
'S_'))
2040 for x
in (Atom_K, Atom_S, Atom_Vx, Atom_Vy, Atom_Vz):
2041 for y
in (Atom_K, Atom_S, Atom_Vx, Atom_Vy, Atom_Vz):
2043 assert hash(x) == hash(y), (hash(x), hash(y), x, y)
2045 assert hash(x) != hash(y), (hash(x), hash(y), x, y)
2046 print(
'ok'); sys.stdout.flush()
2049 print(
'Atom.__le__()...', end=
''); sys.stdout.flush()
2050 assert Atom_K <= Atom_K, Atom_K
2051 assert Atom_S <= Atom_S, Atom_S
2052 assert Atom_K <= Atom_S, (Atom_K, Atom_S)
2053 assert not(Atom_S <= Atom_K), (Atom_S, Atom_K)
2055 assert Atom_K <=
Atom(
'K'), (Atom_K,
Atom(
'K'))
2056 assert Atom_K <=
Atom(
'K', func_S), (Atom_K,
Atom(
'K', func_S))
2058 assert not(Atom_S <=
Atom(
'K')), (Atom_S,
Atom(
'K'))
2059 assert not(Atom_S <=
Atom(
'K', func_S)), (Atom_S,
Atom(
'K', func_S))
2061 assert Atom_S <=
Atom(
'S'), (Atom_S,
Atom(
'S'))
2062 assert Atom_S <=
Atom(
'S', func_K), (Atom_S,
Atom(
'S', func_K))
2064 assert Atom_K <=
Atom(
'S'), (Atom_K,
Atom(
'S'))
2065 assert Atom_K <=
Atom(
'S', func_K), (Atom_K,
Atom(
'S', func_K))
2067 assert Atom_K <=
Atom(
'k'), (Atom_K,
Atom(
'k'))
2068 assert Atom_K <=
Atom(
'K_'), (Atom_K,
Atom(
'K_'))
2069 print(
'ok'); sys.stdout.flush()
2072 print(
'Atom.__lt__()...', end=
''); sys.stdout.flush()
2073 assert not(Atom_K < Atom_K), Atom_K
2074 assert not(Atom_S < Atom_S), Atom_S
2075 assert Atom_K < Atom_S, (Atom_K, Atom_S)
2076 assert not(Atom_S < Atom_K), (Atom_S, Atom_K)
2078 assert not(Atom_K <
Atom(
'K')), (Atom_K,
Atom(
'K'))
2079 assert not(Atom_K <
Atom(
'K', func_S)), (Atom_K,
Atom(
'K', func_S))
2081 assert not(Atom_S <
Atom(
'K')), (Atom_S,
Atom(
'K'))
2082 assert not(Atom_S <
Atom(
'K', func_S)), (Atom_S,
Atom(
'K', func_S))
2084 assert not(Atom_S <
Atom(
'S')), (Atom_S,
Atom(
'S'))
2085 assert not(Atom_S <
Atom(
'S', func_K)), (Atom_S,
Atom(
'S', func_K))
2087 assert Atom_K <
Atom(
'S'), (Atom_K,
Atom(
'S'))
2088 assert Atom_K <
Atom(
'S', func_K), (Atom_K,
Atom(
'S', func_K))
2090 assert Atom_K <
Atom(
'k'), (Atom_K,
Atom(
'k'))
2091 assert Atom_K <
Atom(
'K_'), (Atom_K,
Atom(
'K_'))
2092 print(
'ok'); sys.stdout.flush()
2095 print(
'Atom.__ne__()...', end=
''); sys.stdout.flush()
2096 assert not(Atom_K != Atom_K), Atom_K
2097 assert not(Atom_S != Atom_S), Atom_S
2098 assert Atom_K != Atom_S, (Atom_K, Atom_S)
2099 assert Atom_S != Atom_K, (Atom_S, Atom_K)
2100 assert Atom_K !=
'K'
2101 assert Atom_S !=
'S'
2103 assert not(Atom_K !=
Atom(
'K')), (Atom_K,
Atom(
'K'))
2104 assert not(Atom_K !=
Atom(
'K', func_S)), (Atom_K,
Atom(
'K', func_S))
2106 assert not(Atom_S !=
Atom(
'S')), (Atom_K,
Atom(
'S'))
2107 assert not(Atom_S !=
Atom(
'S', func_K)), (Atom_S,
Atom(
'S', func_K))
2109 assert Atom_K !=
Atom(
'k'), (Atom_K,
Atom(
'k'))
2110 assert Atom_K !=
Atom(
'K_'), (Atom_K,
Atom(
'K_'))
2111 print(
'ok'); sys.stdout.flush()
2114 print(
'Atom.__repr__()...', end=
''); sys.stdout.flush()
2115 assert repr(Atom_K) ==
"Atom('K')", repr(Atom_K)
2116 assert repr(Atom_S) ==
"Atom('S')", repr(Atom_S)
2118 assert repr(
Atom(
'K')) ==
"Atom('K')", repr(
Atom(
'K'))
2119 assert repr(
Atom(
'K', func_S)) ==
"Atom('K')", repr(
Atom(
'K', func_S))
2121 assert repr(
Atom(
'S')) ==
"Atom('S')", repr(
Atom(
'S'))
2122 assert repr(
Atom(
'S', func_K)) ==
"Atom('S')", repr(
Atom(
'S', func_K))
2124 assert repr(
Atom(
'xyz_ABC')) ==
"Atom('xyz_ABC')", repr(
Atom(
'xyz_ABC'))
2125 print(
'ok'); sys.stdout.flush()
2128 print(
'Atom.__str__()...', end=
''); sys.stdout.flush()
2129 assert str(Atom_K) ==
'K', str(Atom_K)
2130 assert str(Atom_S) ==
'S', str(Atom_S)
2132 assert str(
Atom(
'K')) ==
'K', str(
Atom(
'K'))
2133 assert str(
Atom(
'K', func_S)) ==
'K', str(
Atom(
'K', func_S))
2135 assert str(
Atom(
'S')) ==
'S', str(
Atom(
'S'))
2136 assert str(
Atom(
'S', func_K)) ==
'S', str(
Atom(
'S', func_K))
2138 assert str(
Atom(
'xyz_ABC')) ==
'xyz_ABC', str(
Atom(
'xyz_ABC'))
2139 print(
'ok'); sys.stdout.flush()
2142 print(
'Atom.f()...', end=
''); sys.stdout.flush()
2143 assert Atom_K.f() == func_K, (Atom_K.f(), func_K)
2144 assert Atom_S.f() == func_S, (Atom_S.f(), func_S)
2146 assert Atom(
'K').f() == func_const, (
Atom(
'K').f(), func_const)
2147 assert Atom(
'xyz_ABC').f() == func_const, (
Atom(
'xyz_ABC').f(), func_const)
2149 assert Atom(
'xyz_ABC', func_S).f() == func_S, (
Atom(
'xyz_ABC', func_S).f(), func_S)
2150 print(
'ok'); sys.stdout.flush()
2153 print(
'Atom.nb_args()...', end=
''); sys.stdout.flush()
2154 assert Atom_K.nb_args() == 2, Atom_K.nb_args()
2155 assert Atom_S.nb_args() == 3, Atom_S.nb_args()
2157 assert Atom(
'z', func_const).nb_args() ==
None,
Atom(
'z', func_const).nb_args()
2159 assert Atom(
'z', func_B).nb_args() == 3,
Atom(
'z', func_B).nb_args()
2160 assert Atom(
'z', func_B).nb_args(max=2) ==
None,
Atom(
'z', func_B).nb_args(max=2)
2162 assert Atom(
'z', func_C).nb_args() == 3,
Atom(
'z', func_C).nb_args()
2163 assert Atom(
'z', func_C).nb_args(max=2) ==
None,
Atom(
'z', func_C).nb_args(max=2)
2165 assert Atom(
'z', func_I).nb_args() == 1,
Atom(
'z', func_I).nb_args()
2166 assert Atom(
'z', func_I).nb_args(max=0) ==
None,
Atom(
'z', func_I).nb_args(max=2)
2168 assert Atom(
'z', func_K).nb_args() == 2,
Atom(
'z', func_K).nb_args()
2169 assert Atom(
'z', func_K).nb_args(max=1) ==
None,
Atom(
'z', func_K).nb_args(max=2)
2171 assert Atom(
'z', func_S).nb_args() == 3,
Atom(
'z', func_S).nb_args()
2172 assert Atom(
'z', func_S).nb_args(max=2) ==
None,
Atom(
'z', func_S).nb_args(max=2)
2174 assert Atom(
'z', func_W).nb_args() == 2,
Atom(
'z', func_W).nb_args()
2175 assert Atom(
'z', func_W).nb_args(max=1) ==
None,
Atom(
'z', func_W).nb_args(max=2)
2176 print(
'ok'); sys.stdout.flush()
2182 print(
"BARENDREGT: '{0}'".format(BARENDREGT)); sys.stdout.flush()
2183 print(
"CHURCH: '{0}'".format(CHURCH)); sys.stdout.flush()
2186 print(
"K: '{0}'".format(K)); sys.stdout.flush()
2187 print(
"S: '{0}'".format(S)); sys.stdout.flush()
2188 print(
"KK: '{0}'".format(KK)); sys.stdout.flush()
2189 print(
"KS: '{0}'".format(KS)); sys.stdout.flush()
2190 print(
"SS: '{0}'".format(SS)); sys.stdout.flush()
2191 print(
"SK: '{0}'".format(SK)); sys.stdout.flush()
2193 print(
"B: '{0}'".format(B)); sys.stdout.flush()
2194 print(
"C: '{0}'".format(C)); sys.stdout.flush()
2195 print(
"I: '{0}'".format(I)); sys.stdout.flush()
2196 print(
"iota: '{0}'".format(iota)); sys.stdout.flush()
2197 print(
"KI: '{0}'".format(KI)); sys.stdout.flush()
2198 print(
"L: '{0}'".format(L)); sys.stdout.flush()
2199 print(
"M: '{0}'".format(M)); sys.stdout.flush()
2200 print(
"O: '{0}'".format(O)); sys.stdout.flush()
2201 print(
"Omega: '{0}'".format(Omega)); sys.stdout.flush()
2202 print(
"R: '{0}'".format(R)); sys.stdout.flush()
2203 print(
"T: '{0}'".format(T)); sys.stdout.flush()
2204 print(
"U: '{0}'".format(U)); sys.stdout.flush()
2205 print(
"V: '{0}'".format(V)); sys.stdout.flush()
2206 print(
"W: '{0}'".format(W)); sys.stdout.flush()
2207 print(
"Y: '{0}'".format(Y)); sys.stdout.flush()
2209 print(
"Bnot: '{0}'".format(Bnot)); sys.stdout.flush()
2210 print(
"Bnot_my: '{0}'".format(Bnot_my)); sys.stdout.flush()
2211 print(
"Band: '{0}'".format(Band)); sys.stdout.flush()
2212 print(
"Bor: '{0}'".format(Bor)); sys.stdout.flush()
2213 print(
"Bimp: '{0}'".format(Bimp)); sys.stdout.flush()
2214 print(
"Bnotrec: '{0}'".format(Bnotrec)); sys.stdout.flush()
2216 print(
"NBzero_is: '{0}'".format(NBzero_is)); sys.stdout.flush()
2217 print(
"NBsucc: '{0}'".format(NBsucc)); sys.stdout.flush()
2218 print(
"NBprev: '{0}'".format(NBprev)); sys.stdout.flush()
2219 print(
"NBadd: '{0}'".format(NBadd)); sys.stdout.flush()
2221 print(
"NCsucc: '{0}'".format(NCsucc)); sys.stdout.flush()
2222 print(
"NCadd: '{0}'".format(NCadd)); sys.stdout.flush()
2224 print(
"Vx: '{0}'".format(Vx)); sys.stdout.flush()
2225 print(
"Vy: '{0}'".format(Vy)); sys.stdout.flush()
2226 print(
"Vz: '{0}'".format(Vz)); sys.stdout.flush()
2229 assert str(K) ==
'K', str(K)
2230 assert str(S) ==
'S', str(S)
2231 assert str(KK) ==
'K K', str(KK)
2232 assert str(KS) ==
'K S', str(KS)
2233 assert str(SS) ==
'S S', str(SS)
2234 assert str(SK) ==
'S K', str(SK)
2236 assert str(B) ==
'S (K S) K', str(B)
2237 assert str(C) ==
'S (S (K (S (K S) K)) S) (K K)', str(C)
2238 assert str(I) ==
'S K K', str(I)
2239 assert str(iota) ==
'S (S (S K K) (K S)) (K K)', str(iota)
2240 assert str(KI) ==
'K (S K K)', str(KI)
2241 assert str(L) ==
'S (S (K S) K) (K (S (S K K) (S K K)))', str(L)
2242 assert str(M) ==
'S (S K K) (S K K)', str(M)
2243 assert str(O) ==
'S (S K K)', str(O)
2244 assert str(Omega) ==
'S (S K K) (S K K) (S (S K K) (S K K))', str(Omega)
2245 assert str(R) ==
'S (K (S (K S) K)) (S (K (S (S K K))) K)', str(R)
2246 assert str(T) ==
'S (K (S (S K K))) K', str(T)
2247 assert str(U) ==
'S (K (S (S K K))) (S (S K K) (S K K))', str(U)
2248 assert str(V) ==
'S (K (S (S (K (S (K S) K)) S) (K K))) (S (K (S (S K K))) K)', str(V)
2249 assert str(W) ==
'S S (K (S K K))', str(W)
2250 assert str(Y) ==
'S (K (S (S K K) (S K K))) (S (S (K S) K) (K (S (S K K) (S K K))))', str(Y)
2252 assert str(Bnot) ==
'S (S (S K K) (K (K (S K K)))) (K K)', str(Bnot)
2253 assert str(Bnot_my) ==
'S (S (S K K) (S (S K K) (K (S K K)))) (K K)', str(Bnot_my)
2254 assert str(Band) ==
'S (K (S (S K K) (K (K (S K K)))))', str(Band)
2255 assert str(Bor) ==
'S (S K K) (K K)', str(Bor)
2256 assert str(Bimp) ==
'S (K (S (S K K) (K K)))', str(Bimp)
2257 assert str(Bnotrec) ==
'S (S K K) (K (K (S K K)))', str(Bnotrec)
2259 assert str(NBzero_is) ==
'S (K (S (S K K))) K K', str(NBzero_is)
2260 assert str(NBsucc) == \
2261 'S (K (S (S (K (S (K S) K)) S) (K K))) (S (K (S (S K K))) K) (K (S K K))', \
2263 assert str(NBprev) ==
'S (K (S (S K K))) K (K (S K K))', str(NBprev)
2266 assert str(NCsucc) ==
'S (S (K S) K)', str(NCsucc)
2267 assert str(NCadd) ==
'S (K S) K S (S (K S) K (S (K S) K))', str(NCadd)
2269 assert str(Vx) ==
'x', str(Vx)
2270 assert str(Vy) ==
'y', str(Vy)
2271 assert str(Vz) ==
'z', str(Vz)
2274 print(
'natural_sys: {0}'.format(natural_sys))
2275 assert (natural_sys == BARENDREGT)
or (natural_sys == CHURCH), \
2278 x = sorted(str_combs.keys())
2279 print(
'str_combs.keys(): {0}'.format(x))
2281 assert x == str(str_combs[x]), (x, str(str_combs[x]))
2285 print(
'Combinator()...', end=
''); sys.stdout.flush()
2301 natural_sys = BARENDREGT
2311 natural_sys = CHURCH
2328 assert Combinator(
'S (S (K (S (K S) K)) S) (K K)') == C, \
2329 (
Combinator(
'S (S (K (S (K S) K)) S) (K K)'), C)
2331 assert Combinator(
' S (K (S(S K K)(S K K))) (S (S(K S) K)(K (S (S K K)(S K K)) )) ') == Y, \
2332 (
Combinator(
' S (K (S(S K K)(S K K))) (S (S(K S) K)(K (S (S K K)(S K K)) )) '), Y)
2334 for x
in (ALLS
if debug.assertspeed >= debug.ASSERT_NORMAL
else BASICS):
2336 assert Combinator(
'({0})'.format(x)) == x, (x,
'({0})'.format(x))
2337 for y
in (ALLS
if debug.assertspeed > debug.ASSERT_NORMAL
else BASICS):
2341 assert Combinator(
'( (({0}) ) ({1}))'.format(x, y)) \
2343 (x, y,
Combinator(
'( (({0}) ) ({1}))'.format(x, y)))
2347 for n
in range(1, len(ALLS)):
2350 for i
in range(1, n):
2353 if debug.assertspeed <= debug.ASSERT_NORMAL:
2354 print(debug.assertspeed_str(), end=
'')
2355 print(
'ok'); sys.stdout.flush()
2358 print(
'Combinator.__and__()...', end=
''); sys.stdout.flush()
2359 assert (K & K)()[0] == K, (K & K, (K & K)())
2360 assert (K & KI)()[0] == KI, (K & KI, (K & KI)())
2361 assert (KI & K)()[0] == KI, (KI & K, (KI & K)())
2362 assert (KI & KI)()[0] == KI, (KI & KI, (KI & KI)())
2364 assert (K &
True)()[0] == K, (K &
True, (K &
True)())
2365 assert (K &
False)()[0] == KI, (K &
False, (K &
False)())
2366 assert (KI &
True)()[0] == KI, (KI &
True, (KI &
True)())
2367 assert (KI &
False)()[0] == KI, (KI &
False, (KI &
False)())
2370 for y
in ALLS_VARS + (
True,
False):
2372 print(
'ok'); sys.stdout.flush()
2375 print(
'Combinator.__call__()...', end=
''); sys.stdout.flush()
2376 assert K() == (K, 0),
K()
2377 assert S() == (S, 0),
S()
2378 assert KK() == (KK, 0),
KK()
2379 assert KS() == (KS, 0),
KS()
2380 assert SS() == (SS, 0),
SS()
2381 assert SK() == (SK, 0),
SK()
2383 assert x(nb=0) == (x, 0), (x, x(nb=0))
2384 assert x() == (x, 0), (x, x())
2386 assert x(nb=0) == (x, 0), (x, x(nb=0))
2387 assert x(nb=1)[0] != x, (x, x(nb=1)[0])
2388 assert x(nb=1)[1] == 1, (x, x(nb=1)[1])
2404 assert x() == (x, 0), (x, x())
2409 if (x != M)
and (x != U)
and (x != Y):
2413 if (x != U)
and (x != Y):
2418 assert x(nb=1)[0] != x, (x, x(nb=1))
2419 assert x(nb=1)[1] == 1, (x, x(nb=1))
2421 if debug.assertspeed >= debug.ASSERT_NORMAL:
2427 assert Combinator(T, K, I, x, y)()[0] == x, (x, y,
Combinator(T, K, I, x, y)())
2428 assert Combinator(T, K, S, x, y)()[0] == y, (x, y,
Combinator(T, K, S, x, y)())
2429 if (x
in (M, U, Y))
or (y
in (M, U, Y)):
2440 if debug.assertspeed > debug.ASSERT_NORMAL:
2441 for x
in (K, S, KK, KS, SS, SK, B, C, I, KI, O, T, Bnot_my):
2442 for y
in (K, S, KK, KS, SK, B, C, KI, Bnot_my):
2444 if (z == U)
or (z == Y):
2459 if debug.assertspeed <= debug.ASSERT_NORMAL:
2460 print(debug.assertspeed_str(), end=
'')
2461 print(
'???', end=
'')
2462 print(
'ok'); sys.stdout.flush()
2465 print(
'Combinator.__cmp__()...', end=
''); sys.stdout.flush()
2466 print(
'???', end=
'')
2467 print(
'ok'); sys.stdout.flush()
2470 print(
'Combinator.__contains__()...', end=
''); sys.stdout.flush()
2471 print(
'???', end=
'')
2472 print(
'ok'); sys.stdout.flush()
2475 print(
'Combinator.__eq__()...', end=
''); sys.stdout.flush()
2476 for i
in range(len(ALLS)):
2478 assert x == x, (i, x)
2479 for j
in range(len(ALLS)):
2482 assert y == x, (i, j, x, y)
2484 assert not(y == x), (i, j, x, y)
2485 print(
'???', end=
'')
2486 print(
'ok'); sys.stdout.flush()
2489 print(
'Combinator.__getitem__()...', end=
''); sys.stdout.flush()
2490 print(
'???', end=
'')
2491 print(
'ok'); sys.stdout.flush()
2494 print(
'Combinator.__hash__()...', end=
''); sys.stdout.flush()
2495 assert hash(K) == hash(K)
2496 assert hash(S) == hash(S)
2497 assert hash(K) != hash(S)
2498 assert hash(S) != hash(K)
2508 assert hash(x) == hash(y), (hash(x), hash(y), x, y)
2510 assert hash(x) != hash(y), (hash(x), hash(y), x, y)
2511 print(
'ok'); sys.stdout.flush()
2514 print(
'Combinator.__int__()...', end=
''); sys.stdout.flush()
2515 natural_sys = BARENDREGT
2516 assert int(I) == 0, int(I)
2519 natural_sys = CHURCH
2520 assert int(KI) == 0, int(KI)
2524 natural_sys = BARENDREGT
2526 assert n == int(x), (n, int(x), x)
2528 natural_sys = CHURCH
2530 assert n == int(x), (n, int(x), x)
2531 print(
'ok'); sys.stdout.flush()
2534 print(
'Combinator.__len__()...', end=
''); sys.stdout.flush()
2535 print(
'???', end=
'')
2536 print(
'ok'); sys.stdout.flush()
2539 print(
'Combinator.__ne__()...', end=
''); sys.stdout.flush()
2540 for i
in range(len(ALLS)):
2542 assert not(x != x), (i, x)
2543 for j
in range(len(ALLS)):
2546 assert y != x, (i, j, x, y)
2548 assert not(y != x), (i, j, x, y)
2549 print(
'???', end=
'')
2550 print(
'ok'); sys.stdout.flush()
2553 print(
'Combinator.__nonzero__()...', end=
''); sys.stdout.flush()
2554 assert K.__nonzero__()
2555 assert not KI.__nonzero__()
2558 assert isinstance(x.__nonzero__(), bool), (type(x.__nonzero__()), x.__nonzero__())
2560 assert x.__nonzero__()
2562 assert not x.__nonzero__()
2563 print(
'ok'); sys.stdout.flush()
2566 print(
'Combinator.__or__()...', end=
''); sys.stdout.flush()
2567 assert (K | K)()[0] == K, (K | K, (K | K)())
2568 assert (K | KI)()[0] == K, (K | KI, (K | KI)())
2569 assert (KI | K)()[0] == K, (KI | K, (KI | K)())
2570 assert (KI | KI)()[0] == KI, (KI | KI, (KI | KI)())
2572 assert (K |
True)()[0] == K, (K |
True, (K |
True)())
2573 assert (K |
False)()[0] == K, (K |
False, (K |
False)())
2574 assert (KI |
True)()[0] == K, (KI |
True, (KI |
True)())
2575 assert (KI |
False)()[0] == KI, (KI |
False, (KI |
False)())
2578 for y
in ALLS_VARS + (
True,
False):
2580 print(
'ok'); sys.stdout.flush()
2583 print(
'Combinator.__repr__()...', end=
''); sys.stdout.flush()
2584 assert repr(K) ==
"Combinator('K')", repr(K)
2585 assert repr(S) ==
"Combinator('S')", repr(S)
2586 print(
'???', end=
'')
2587 print(
'ok'); sys.stdout.flush()
2590 print(
'Combinator.__str__()...', end=
''); sys.stdout.flush()
2591 assert str(K) ==
'K', str(K)
2592 assert str(S) ==
'S', str(S)
2593 assert str(KK) ==
'K K', str(KK)
2594 assert str(KS) ==
'K S', str(KS)
2595 assert str(I) ==
'S K K', str(I)
2596 assert str(B) ==
'S (K S) K', str(B)
2597 assert str(M) ==
'S (S K K) (S K K)', str(M)
2598 assert str(Y) ==
'S (K (S (S K K) (S K K))) (S (S (K S) K) (K (S (S K K) (S K K))))', str(Y)
2599 assert K.__str__(allparent=
True) ==
'K', K.__str__(allparent=
True)
2600 assert S.__str__(allparent=
True) ==
'S', S.__str__(allparent=
True)
2601 assert KK.__str__(allparent=
True) ==
'(K K)', KK.__str__(allparent=
True)
2602 assert KS.__str__(allparent=
True) ==
'(K S)', KS.__str__(allparent=
True)
2603 assert I.__str__(allparent=
True) ==
'((S K) K)', I.__str__(allparent=
True)
2604 assert B.__str__(allparent=
True) ==
'((S (K S)) K)', B.__str__(allparent=
True)
2605 assert M.__str__(allparent=
True) ==
'((S ((S K) K)) ((S K) K))', M.__str__(allparent=
True)
2606 assert Y.__str__(allparent=
True) ==
'((S (K ((S ((S K) K)) ((S K) K))))' \
2607 +
' ((S ((S (K S)) K)) (K ((S ((S K) K)) ((S K) K)))))', \
2608 Y.__str__(allparent=
True)
2609 print(
'???', end=
'')
2610 print(
'ok'); sys.stdout.flush()
2613 print(
'Combinator.__xor__()...', end=
''); sys.stdout.flush()
2614 print(
'???', end=
'')
2615 print(
'ok'); sys.stdout.flush()
2618 print(
'Combinator.atomic_is()...', end=
''); sys.stdout.flush()
2619 print(
'???', end=
'')
2620 print(
'ok'); sys.stdout.flush()
2623 print(
'Combinator.bnot()...', end=
''); sys.stdout.flush()
2624 assert K.bnot()()[0] == KI, (K.bnot(), KI.bnot()())
2625 assert KI.bnot()()[0] == K, (KI.bnot(), K.bnot()())
2629 print(
'ok'); sys.stdout.flush()
2632 print(
'Combinator.change_atom()...', end=
''); sys.stdout.flush()
2633 assert K.change_atom(Atom_K, Atom_S) == S, K.change_atome(Atom_K, Atom_S)
2634 assert K.change_atom(Atom_K, S) == S, K.change_atome(Atom_K, S)
2635 assert K.change_atom(
Atom(
'K'), S) == S, K.change_atome(
Atom(
'K'), S)
2636 assert K.change_atom(Atom_K,
Atom(
'S')) == S, K.change_atome(Atom_K,
Atom(
'S'))
2637 assert K.change_atom(K[0], S) == S, K.change_atome(K[0], S)
2639 assert K.change_atom(Atom_K, Atom_K) == K, K.change_atome(Atom_K, Atom_K)
2640 assert K.change_atom(Atom_K, K) == K, K.change_atome(Atom_K, K)
2642 assert S.change_atom(Atom_S, Atom_K) == K, S.change_atome(Atom_S, Atom_K)
2643 assert S.change_atom(Atom_S, K) == K, S.change_atome(Atom_S, K)
2644 assert S.change_atom(
Atom(
'S'), K) == K, S.change_atome(
Atom(
'S'), K)
2645 assert S.change_atom(Atom_S,
Atom(
'K')) == K, S.change_atome(Atom_S,
Atom(
'K'))
2646 assert S.change_atom(S[0],
Atom(
'K')) == K, S.change_atome(S[0],
Atom(
'K'))
2648 assert S.change_atom(Atom_S, Atom_S) == S, S.change_atome(Atom_S, Atom_S)
2649 assert S.change_atom(Atom_S, S) == S, S.change_atome(Atom_S, S)
2651 assert str(M.change_atom(Atom_K, S)) ==
'S (S S S) (S S S)', str(M.change_atom(Atom_K, S))
2652 x = M.change_atom(Atom_K, Vx)
2653 assert str(x) ==
'S (S x x) (S x x)', str(x)
2654 assert str(x.change_atom(Atom_Vx, K)) ==
'S (S K K) (S K K)', str(x.change_atom(Atom_Vx, K))
2656 if x
not in (S, SS):
2657 y = x.change_atom(Atom_K, Vx)
2658 assert x != y, (x, y)
2659 y = y.change_atom(Vx[0], Vz)
2660 assert x != y, (x, y)
2661 y = y.change_atom(Vz[0], K)
2662 assert x == y, (x, y)
2664 if x
not in (K, KK):
2665 y = x.change_atom(Atom_S, Vz)
2666 assert x != y, (x, y)
2667 y = y.change_atom(Vz[0], Vy)
2668 assert x != y, (x, y)
2669 y = y.change_atom(Vy[0], S)
2670 assert x == y, (x, y)
2671 print(
'ok'); sys.stdout.flush()
2674 print(
'Combinator.depth()...', end=
''); sys.stdout.flush()
2675 assert K.depth() == 0, K.depth()
2676 assert S.depth() == 0, S.depth()
2677 assert KK.depth() == 1, KK.depth()
2678 assert KS.depth() == 1, KS.depth()
2679 assert SS.depth() == 1, SS.depth()
2680 assert SK.depth() == 1, SK.depth()
2682 assert B.depth() == 3, B.depth()
2683 assert C.depth() == 8, C.depth()
2684 assert I.depth() == 2, I.depth()
2685 assert iota.depth() == 6, iota.depth()
2686 assert KI.depth() == 3, KI.depth()
2687 assert L.depth() == 6, L.depth()
2688 assert M.depth() == 4, M.depth()
2689 assert O.depth() == 3, O.depth()
2690 assert Omega.depth() == 5, Omega.depth()
2691 assert R.depth() == 7, R.depth()
2692 assert T.depth() == 6, T.depth()
2693 assert V.depth() == 11, V.depth()
2694 assert W.depth() == 4, W.depth()
2695 assert Y.depth() == 7, Y.depth()
2697 assert Bnot.depth() == 7, Bnot.depth()
2698 assert Band.depth() == 7, Band.depth()
2699 assert Bor.depth() == 4, Bor.depth()
2700 assert Bimp.depth() == 6, Bimp.depth()
2701 assert Bnotrec.depth() == 5, Bnotrec.depth()
2702 print(
'???', end=
'')
2703 print(
'ok'); sys.stdout.flush()
2706 print(
'Combinator.n_to()...', end=
''); sys.stdout.flush()
2708 natural_sys = BARENDREGT
2709 assert Combinator.n_to(n) == Combinator.n_to_Barendregt(n), \
2710 (Combinator.n_to(n), Combinator.n_to_Barendregt(n))
2712 x = Combinator.n_to(n)
2714 assert n == int(x), (n, int(x), x)
2716 natural_sys = CHURCH
2717 assert Combinator.n_to(n) == Combinator.n_to_Church(n), \
2718 (Combinator.n_to(n), Combinator.n_to_Church(n))
2720 x = Combinator.n_to(n)
2722 assert n == int(x), (n, int(x), x)
2723 print(
'ok'); sys.stdout.flush()
2726 print(
'Combinator.n_to_Barendregt()...', end=
''); sys.stdout.flush()
2727 assert Combinator.n_to_Barendregt(0) == I, (Combinator.n_to_Barendregt(0), I)
2728 assert Combinator.n_to_Barendregt(1) ==
Combinator(V, KI, I), \
2729 (Combinator.n_to_Barendregt(1),
Combinator(V, KI, I))
2734 natural_sys = BARENDREGT
2735 assert Combinator.n_to_Barendregt(n) == c, (n, Combinator.n_to_Barendregt(n), c)
2737 assert Combinator(NBzero_is, c)()[0] == K, (n, Combinator.n_to_Barendregt(n), c)
2739 assert Combinator(NBzero_is, c)()[0] == KI, (n, Combinator.n_to_Barendregt(n), c)
2741 natural_sys = CHURCH
2742 assert Combinator.n_to_Barendregt(n) == c, (n, Combinator.n_to_Barendregt(n), c)
2745 print(
'ok'); sys.stdout.flush()
2748 print(
'Combinator.n_to_Church()...', end=
''); sys.stdout.flush()
2749 assert Combinator.n_to_Church(0) == KI, (Combinator.n_to_Church(0), KI)
2750 assert Combinator.n_to_Church(1) ==
Combinator(S, B, KI), \
2751 (Combinator.n_to_Church(1),
Combinator(S, B, KI))
2756 natural_sys = BARENDREGT
2757 assert Combinator.n_to_Church(n) == c, (n, Combinator.n_to_Church(n), c)
2759 natural_sys = CHURCH
2760 assert Combinator.n_to_Church(n) == c, (n, Combinator.n_to_Church(n), c)
2763 print(
'ok'); sys.stdout.flush()
2766 print(
'Combinator.nb_atom()...', end=
''); sys.stdout.flush()
2767 assert K.nb_atom() == 1, K.nb_atom()
2768 assert S.nb_atom() == 1, S.nb_atom()
2769 assert KK.nb_atom() == 2, KK.nb_atom()
2770 assert KS.nb_atom() == 2, KS.nb_atom()
2771 assert SS.nb_atom() == 2, SS.nb_atom()
2772 assert SK.nb_atom() == 2, SK.nb_atom()
2774 assert B.nb_atom() == 4, B.nb_atom()
2775 assert C.nb_atom() == 10, C.nb_atom()
2776 assert I.nb_atom() == 3, I.nb_atom()
2777 assert KI.nb_atom() == 4, KI.nb_atom()
2778 assert M.nb_atom() == 7, M.nb_atom()
2779 assert O.nb_atom() == 4, O.nb_atom()
2780 assert Omega.nb_atom() == 14, Omega.nb_atom()
2781 assert T.nb_atom() == 7, T.nb_atom()
2782 assert W.nb_atom() == 6, W.nb_atom()
2784 assert Bnot.nb_atom() == 12, Bnot.nb_atom()
2785 assert Band.nb_atom() == 11, Band.nb_atom()
2786 assert Bor.nb_atom() == 6, Bor.nb_atom()
2787 assert Bimp.nb_atom() == 8, Bimp.nb_atom()
2788 assert Bnotrec.nb_atom() == 9, Bnotrec.nb_atom()
2792 assert x.nb_atom() == 1, (x.nb_atom(), x)
2794 assert x.nb_atom() > 1, (x.nb_atom(), x)
2795 print(
'???', end=
'')
2796 print(
'ok'); sys.stdout.flush()
2799 print(
'Combinator.stable_is()...', end=
''); sys.stdout.flush()
2800 for x
in STABLES + VARS:
2801 assert x.stable_is()
2803 assert not x.stable_is()
2804 print(
'???', end=
'')
2805 print(
'ok'); sys.stdout.flush()
2808 print(
'Combinator.str_to()...', end=
''); sys.stdout.flush()
2809 assert Combinator.str_to(
'K') == K, Combinator.str_to(
'K')
2810 assert Combinator.str_to(
'S') == S, Combinator.str_to(
'S')
2812 assert Combinator.str_to(
'K K') == KK, Combinator.str_to(
'K K')
2813 assert Combinator.str_to(
'K S') == KS, Combinator.str_to(
'K S')
2814 assert Combinator.str_to(
'S K') == SK, Combinator.str_to(
'S K')
2815 assert Combinator.str_to(
'S S') == SS, Combinator.str_to(
'S S')
2817 assert Combinator.str_to(
'S K K') == I, Combinator.str_to(
'S K K')
2819 assert Combinator.str_to(
'S (S (K (S (K S) K)) S) (K K)') == C, \
2820 (Combinator.str_to(
'S (S (K (S (K S) K)) S) (K K)'), C)
2822 assert Combinator.str_to(
' S (K (S(S K K)(S K K))) '
2823 +
'(S (S(K S) K)(K (S (S K K)(S K K)) )) ') == Y, \
2824 (Combinator.str_to(
' S (K (S(S K K)(S K K))) '
2825 +
'(S (S(K S) K)(K (S (S K K)(S K K)) )) '), Y)
2827 for x
in (ALLS
if debug.assertspeed >= debug.ASSERT_NORMAL
else BASICS):
2828 assert Combinator.str_to(str(x)) == x, (x, Combinator.str_to(str(x)))
2829 assert Combinator.str_to(
'({0})'.format(x)) == x, (x,
'({0})'.format(x))
2830 for y
in (ALLS
if debug.assertspeed > debug.ASSERT_NORMAL
else BASICS):
2831 assert Combinator.str_to(
'{0}({1})'.format(x, y)) \
2832 ==
Combinator(Combinator.str_to(str(x)), Combinator.str_to(str(y))), \
2833 (x, y, Combinator.str_to(
'{0}({1})'.format(x, y)))
2834 assert Combinator.str_to(
'( (({0}) ) ({1}))'.format(x, y)) \
2835 ==
Combinator(Combinator.str_to(str(x)), Combinator.str_to(str(y))), \
2836 (x, y, Combinator.str_to(
'( (({0}) ) ({1}))'.format(x, y)))
2837 if debug.assertspeed <= debug.ASSERT_NORMAL:
2838 print(debug.assertspeed_str(), end=
'')
2839 print(
'???', end=
'')
2840 print(
'ok'); sys.stdout.flush()
2845 print(
'Kxy -> x ...', end=
''); sys.stdout.flush()
2848 assert func_K(
Atom(
'z'), (Vx, Vy),
None) == (Vx, 1), \
2853 print(
'ok'); sys.stdout.flush()
2856 print(
'Sxyz -> xz(yz) ...', end=
''); sys.stdout.flush()
2861 assert func_S(
Atom(
'z'), (Vx, Vy, Vz),
None) \
2869 print(
'ok'); sys.stdout.flush()
2872 print(
'Bxyz -> x(yz) ...', end=
''); sys.stdout.flush()
2882 print(
'ok'); sys.stdout.flush()
2885 print(
'Cxyz -> xzy ...', end=
''); sys.stdout.flush()
2894 print(
'ok'); sys.stdout.flush()
2897 print(
'Ix -> x ...', end=
''); sys.stdout.flush()
2898 assert func_I(
Atom(
'z'), (Vx, ),
None) == (Vx, 1), \
2902 print(
'ok'); sys.stdout.flush()
2905 print(
'iota x -> xSK ...', end=
''); sys.stdout.flush()
2907 print(
'ok'); sys.stdout.flush()
2910 print(
'Lxy -> x(yy) ...', end=
''); sys.stdout.flush()
2913 print(
'ok'); sys.stdout.flush()
2916 print(
'Mx -> xx ...', end=
''); sys.stdout.flush()
2919 print(
'ok'); sys.stdout.flush()
2922 print(
'Oxy -> y(xy) ...', end=
''); sys.stdout.flush()
2925 print(
'ok'); sys.stdout.flush()
2928 print(
'Omega x -> Omega x ...', end=
''); sys.stdout.flush()
2931 print(
'???', end=
'')
2932 print(
'ok'); sys.stdout.flush()
2935 print(
'Rxyz -> yzx ...', end=
''); sys.stdout.flush()
2937 print(
'ok'); sys.stdout.flush()
2940 print(
'Txy -> yx ...', end=
''); sys.stdout.flush()
2942 print(
'ok'); sys.stdout.flush()
2945 print(
'Uxy -> y(xxy) ...', end=
''); sys.stdout.flush()
2948 print(
'ok'); sys.stdout.flush()
2951 print(
'Vxyz -> zxy ...', end=
''); sys.stdout.flush()
2953 print(
'ok'); sys.stdout.flush()
2956 print(
'Wxy -> xyy ...', end=
''); sys.stdout.flush()
2963 print(
'ok'); sys.stdout.flush()
2966 print(
'Yx -> x(Yx) ...', end=
''); sys.stdout.flush()
2969 print(
'???', end=
'')
2970 print(
'ok'); sys.stdout.flush()
2976 print(
'Evaluation of some combinators...', end=
'')
2999 print(
'ok'); sys.stdout.flush()
3003 print(
'Evaluation by step...', end=
'')
3005 if x
in (Y, ) + VARS:
3009 assert n > 0, (nb, x, x_finish)
3010 assert x != x_finish, (nb, x, x_finish)
3014 x_step, nb_step = x_step(nb=1)
3015 assert nb_step == 1, (x, i, x_step, nb_step, nb, x_finish)
3017 assert x_step == x_finish, (x, x_step, nb, x_finish)
3018 assert x_step(nb=1) == (x_finish, 0), (x, x_step(nb=1), nb, x_finish)
3019 assert x_step() == (x_finish, 0), (x, x_step(), nb, x_finish)
3021 for k
in range(1, nb * 2):
3024 for i
in range((nb + k - 1)//k):
3025 x_step, nb_step = x_step(nb=k)
3026 assert 0 < nb_step <= k, (x, i, x_step, nb_step, nb, x_finish)
3029 assert nb_total == nb, (x, x_step, nb_total, nb, x_finish)
3030 assert x_step == x_finish, (x, x_step, nb, x_finish)
3031 assert x_step(nb=1) == (x_finish, 0), (x, x_step(nb=1), nb, x_finish)
3032 assert x_step() == (x_finish, 0), (x, x_step(), nb, x_finish)
3033 print(
'ok'); sys.stdout.flush()
3037 assert str(K) ==
'K', str(K)
3038 assert str(S) ==
'S', str(S)
3039 assert str(KK) ==
'K K', str(KK)
3040 assert str(KS) ==
'K S', str(KS)
3041 assert str(SS) ==
'S S', str(SS)
3042 assert str(SK) ==
'S K', str(SK)
3044 assert str(B) ==
'S (K S) K', str(B)
3045 assert str(C) ==
'S (S (K (S (K S) K)) S) (K K)', str(C)
3046 assert str(I) ==
'S K K', str(I)
3047 assert str(iota) ==
'S (S (S K K) (K S)) (K K)', str(iota)
3048 assert str(KI) ==
'K (S K K)', str(KI)
3049 assert str(L) ==
'S (S (K S) K) (K (S (S K K) (S K K)))', str(L)
3050 assert str(M) ==
'S (S K K) (S K K)', str(M)
3051 assert str(O) ==
'S (S K K)', str(O)
3052 assert str(Omega) ==
'S (S K K) (S K K) (S (S K K) (S K K))', str(Omega)
3053 assert str(R) ==
'S (K (S (K S) K)) (S (K (S (S K K))) K)', str(R)
3054 assert str(T) ==
'S (K (S (S K K))) K', str(T)
3055 assert str(U) ==
'S (K (S (S K K))) (S (S K K) (S K K))', str(U)
3056 assert str(V) ==
'S (K (S (S (K (S (K S) K)) S) (K K))) (S (K (S (S K K))) K)', str(V)
3057 assert str(W) ==
'S S (K (S K K))', str(W)
3058 assert str(Y) ==
'S (K (S (S K K) (S K K))) (S (S (K S) K) (K (S (S K K) (S K K))))', str(Y)
3060 assert str(Bnot) ==
'S (S (S K K) (K (K (S K K)))) (K K)', str(Bnot)
3061 assert str(Bnot_my) ==
'S (S (S K K) (S (S K K) (K (S K K)))) (K K)', str(Bnot_my)
3062 assert str(Band) ==
'S (K (S (S K K) (K (K (S K K)))))', str(Band)
3063 assert str(Bor) ==
'S (S K K) (K K)', str(Bor)
3064 assert str(Bimp) ==
'S (K (S (S K K) (K K)))', str(Bimp)
3065 assert str(Bnotrec) ==
'S (S K K) (K (K (S K K)))', str(Bnotrec)
3067 assert str(NBzero_is) ==
'S (K (S (S K K))) K K', str(NBzero_is)
3068 assert str(NBsucc) ==
'S (K (S (S (K (S (K S) K)) S) (K K))) (S (K (S (S K K))) K) ' \
3069 +
'(K (S K K))', str(NBsucc)
3070 assert str(NBprev) ==
'S (K (S (S K K))) K (K (S K K))', str(NBprev)
3072 assert str(NCsucc) ==
'S (S (K S) K)', str(NCsucc)
3073 assert str(NCadd) ==
'S (K S) K S (S (K S) K (S (K S) K))', str(NCadd)
3076 assert str(Vx) ==
'x', str(Vx)
3077 assert str(Vy) ==
'y', str(Vy)
3078 assert str(Vz) ==
'z', str(Vz)