+
    ‹°³jZL  ã                   óÈ   € R t ^ RIHt ^ RIHt ^RIHtHtHtH	t	 R t
R tR tR tR tR	 t ! R
 R]4      t ! R R4      t ! R R4      t ! R R]4      t ! R R]4      tR# )a>  This is rule-based deduction system for SymPy

The whole thing is split into two parts

 - rules compilation and preparation of tables
 - runtime inference

For rule-based inference engines, the classical work is RETE algorithm [1],
[2] Although we are not implementing it in full (or even significantly)
it's still worth a read to understand the underlying ideas.

In short, every rule in a system of rules is one of two forms:

 - atom                     -> ...      (alpha rule)
 - And(atom1, atom2, ...)   -> ...      (beta rule)


The major complexity is in efficient beta-rules processing and usually for an
expert system a lot of effort goes into code that operates on beta-rules.


Here we take minimalistic approach to get something usable first.

 - (preparation)    of alpha- and beta- networks, everything except
 - (runtime)        FactRules.deduce_all_facts

             _____________________________________
            ( Kirr: I've never thought that doing )
            ( logic stuff is that difficult...    )
             -------------------------------------
                    o   ^__^
                     o  (oo)\_______
                        (__)\       )\/\
                            ||----w |
                            ||     ||


Some references on the topic
----------------------------

[1] https://en.wikipedia.org/wiki/Rete_algorithm
[2] http://reports-archive.adm.cs.cmu.edu/anon/1995/CMU-CS-95-113.pdf

https://en.wikipedia.org/wiki/Propositional_formula
https://en.wikipedia.org/wiki/Inference_rule
https://en.wikipedia.org/wiki/List_of_rules_of_inference
)Údefaultdict)ÚIterator)ÚLogicÚAndÚOrÚNotc                óJ   € \        V \        4      '       d   V P                  # V # )z\Return the literal fact of an atom.

Effectively, this merely strips the Not around a fact.
©Ú
isinstancer   Úarg©Úatoms   &ÚQ/home/luca/screen-checking/.venv/lib/python3.14/site-packages/sympy/core/facts.pyÚ
_base_factr   7   s   € ô
 �$œ×ÒØ�x‰xˆàˆó    c                 óR   € \        V \        4      '       d   V P                  R 3# V R3# )FTr	   r   s   &r   Ú_as_pairr   B   s(   € Ü�$œ×ÒØ—‘˜%Ð Ð à�dˆ|Ðr   c                óê   € \        V 4      p\        4       P                  ! \        \         V4      !  pV F;  pV F2  pWC3V9   g   K  V F  pW53V9   g   K  VP                  WE34       K!  	  K4  	  K=  	  V# )z­
Computes the transitive closure of a list of implications

Uses Warshall's algorithm, as described at
http://www.cs.hope.edu/~cusack/Notes/Notes/DiscreteMath/Warshall.pdf.
)ÚsetÚunionÚmapÚadd)ÚimplicationsÚfull_implicationsÚliteralsÚkÚiÚjs   &     r   Útransitive_closurer   K   ss   € ô ˜LÓ)ÐÜ‹u�{Š{œC¤Ð%6Ó7Ñ8€HãˆÛˆAØˆvÐ*Ö*Û!�AØ�vÐ!2Ö2Ø)×-Ñ-¨q¨fÖ5ó "ó ñ ð Ðr   c           	     óž  € Y  UUu. uF  w  r\        V4      \        V4      3NK  	  upp,           p \        \        4      p\        V 4      pV F$  w  rVWV8X  d   K  W5,          P	                  V4       K&  	  VP                  4        F>  w  rWVP                  V4       \        V4      pW‡9   g   K)  \        RV: RV: RV: 24      h	  V# u uppi )zðdeduce all implications

Description by example
----------------------

given set of logic rules:

  a -> b
  b -> c

we deduce all possible rules:

  a -> b, c
  b -> c


implications: [] of (a,b)
return:       {} of a -> set([b, c, ...])
zimplications are inconsistent: z -> Ú )r   r   r   r   r   ÚitemsÚdiscardÚ
ValueError)	r   r   r   Úresr   ÚaÚbÚimplÚnas	   &        r   Údeduce_alpha_implicationsr)   _   sµ   € ð(  À,Ô"OÁ,¹¸¤C¨£F¬C°«FÓ#3Á,Ò"OÕO€LÜ
”cÓ
€CÜ*¨<Ó8ÐÛ!‰ˆØŒ6Ùà��
‰
�1Žñ	 "ð —9‘9–;‰ˆØ�‰�QŒÜ�‹VˆØŽ:ÝÛ@AÃ2ÂtÐLóNð Nñ	 ð €Jùó# #Ps   †!C	c                óî  aa€ / pV P                  4        F  p\        W,          4      . 3W#&   K  	  V F/  w  poVP                   F  pWR9   d   K  \        4       . 3W%&   K  	  K1  	  RpV'       dÅ   RpV Fº  w  po\        V\        4      '       g   \        R4      h\        VP                  4      oVP                  4        Fj  w  pw  rxWs0,          p	SV	9  g   K  SP                  V	4      '       g   K3  VP                  S4       VP                  S4      p
V
e   Wz^ ,          ,          pRpKl  	  K¼  	  KÌ  \        V4       F²  w  pw  po\        VP                  4      oVP                  4        F€  w  pw  rxWs0,          p	SV	9   d   K  \        ;QJ d     VV3R lV	 4       F  '       g   K   RM	  RM! VV3R lV	 4       4      '       d   K^  SV	,          '       g   Ko  VP                  V4       K‚  	  K´  	  V# )a~  apply additional beta-rules (And conditions) to already-built
alpha implication tables

   TODO: write about

   - static extension of alpha-chains
   - attaching refs to beta-nodes to alpha chains


   e.g.

   alpha_implications:

   a  ->  [b, !c, d]
   b  ->  [d]
   ...


   beta_rules:

   &(b,d) -> e


   then we'll extend a's rule to the following

   a  ->  [b, !c, d, e]
TFzCond is not Andc              3   ól   <"  € T F)  p\        V4      S9   ;'       g    \        V4      S8H  x € K+  	  R # 5i©N)r   )Ú.0ÚxiÚbargsÚbimpls   & €€r   Ú	<genexpr>Ú,apply_beta_to_alpha_route.<locals>.<genexpr>Í   s.   øé € ÐHÁ%¸B”3�r“7˜eÑ#×7Ð7¤s¨2£w°%Ñ'7Ô7Ã%ùs   ƒ4�4)Úkeysr   Úargsr
   r   Ú	TypeErrorr!   Úissubsetr   ÚgetÚ	enumerateÚanyÚappend)Úalpha_implicationsÚ
beta_rulesÚx_implÚxÚbcondÚbkÚseen_static_extensionÚximplsÚbbÚx_allÚ
bimpl_implÚbidxr/   r0   s   &&          @@r   Úapply_beta_to_alpha_routerG   ‡   s¢  ù€ ð8 €FØ×$Ñ$Ö&ˆÜÐ+Õ.Ó/°Ð4ˆ‹	ñ 'ã"‰ˆˆuØ—*”*ˆBØŒ|ÙÜ›% ˜ˆF‹Jó ñ #ð !Ðß
Ø %Ðã&‰LˆE�5Ü˜e¤S×)Ò)ÜÐ 1Ó2Ð2Ü˜Ÿ
™
“OˆEØ#)§<¡<¦>‘�‘<�FØ ��à Ö%¨%¯.©.¸×*?Ô*?Ø—J‘J˜uÔ%ð "(§¡¨EÓ!2�JØ!Ò-Ø¨Q¥-Õ/˜Ø,0Ò)ó $2ó	 'ô$ !*¨*Ö 5Ñˆ‰nˆu�eÜ�E—J‘J“ˆØ%Ÿ|™|ž~‰OˆA‰|�Ø˜S•LˆEà˜Œ~Ù÷ ‹sÕHÁ%ÓH�s�sŠsÕHÁ%ÓH×HÒHÙà�u�}Ž}Ø—	‘	˜$–ó  .ñ !6ð €Mr   c                óD  € \        \        4      pV P                  4        F|  w  w  r#p\        V\        4      '       d   VP
                  ^ ,          pV FE  w  rS\        V\        4      '       d   VP
                  ^ ,          pW,          P                  V4       KG  	  K~  	  V# )aî  build prerequisites table from rules

Description by example
----------------------

given set of logic rules:

  a -> b, c
  b -> c

we build prerequisites (from what points something can be deduced):

  b <- a
  c <- a, b

rules:   {} of a -> [b, c, ...]
return:  {} of c <- [a, b, ...]

Note however, that this prerequisites may be *not* enough to prove a
fact. An example is 'a -> b' rule, where prereq(a) is b, and prereq(b)
is a. That's because a=T -> b=T, and b=F -> a=F, but a=F -> b=?
)r   r   r!   r
   r   r4   r   )ÚrulesÚprereqr%   Ú_r'   r   s   &     r   Úrules_2prereqrL   Ö   sy   € ô. œÓ€FØŸ™ž‰‰ˆ�Ü�aœ×ÒØ—‘�q•	ˆAÛ‰FˆQÜ˜!œS×!Ò!Ø—F‘F˜1•I�Ø�I�M‰M˜!Öó ñ &ð €Mr   c                   ó   € ] tR t^ütRtRtR# )ÚTautologyDetectedz:(internal) Prover uses it for reporting detected tautology© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__static_attributes__rO   r   r   rN   rN   ü   s   † ÙDÛr   rN   c                   ó\   a € ] tR tRt o RtR tR t]R 4       t]R 4       t	R t
R tR	tV tR
# )ÚProveri  aí  ai - prover of logic rules

given a set of initial rules, Prover tries to prove all possible rules
which follow from given premises.

As a result proved_rules are always either in one of two forms: alpha or
beta:

Alpha rules
-----------

This are rules of the form::

  a -> b & c & d & ...


Beta rules
----------

This are rules of the form::

  &(a,b,...) -> c & d & ...


i.e. beta rules are join conditions that say that something follows when
*several* facts are true at the same time.
c                ó2   € . V n         \        4       V n        R # r,   )Úproved_rulesr   Ú_rules_seen©Úselfs   &r   Ú__init__ÚProver.__init__  s   € ØˆÔÜ›5ˆÖr   c                ó²   € . p. pV P                    FA  w  r4\        V\        4      '       d   VP                  W434       K/  VP                  W434       KC  	  W3# )z-split proved rules into alpha and beta chains)rY   r
   r   r:   )r\   Úrules_alphaÚ
rules_betar%   r&   s   &    r   Úsplit_alpha_betaÚProver.split_alpha_beta"  sV   € àˆØˆ
Ø×%Ô%‰DˆAÜ˜!œS×!Ò!Ø×!Ñ! 1 &Ö)à×"Ñ" A 6Ö*ñ	 &ð
 Ð&Ð&r   c                ó0   € V P                  4       ^ ,          # )é    ©rb   r[   s   &r   r`   ÚProver.rules_alpha-  ó   € à×$Ñ$Ó& qÕ)Ð)r   c                ó0   € V P                  4       ^,          # )é   rf   r[   s   &r   ra   ÚProver.rules_beta1  rh   r   c                ó  € V'       d   \        V\        4      '       d   R# \        V\        4      '       d   R# W3V P                  9   d   R# V P                  P                  W34        V P	                  W4       R#   \
         d     R# i ; i)zprocess a -> b ruleN)r
   ÚboolrZ   r   Ú_process_rulerN   )r\   r%   r&   s   &&&r   Úprocess_ruleÚProver.process_rule5  sr   € ç”j ¤D×)Ò)ÙÜ�aœ×ÒÙØˆ6�T×%Ñ%Ô%Ùà×Ñ× Ñ  ! Ô(ð	Ø×Ñ˜qÖ$øÜ ô 	Úð	ús   Á*A= Á=BÂBc           
     óÈ  € \        V\        4      '       d8   \        VP                  \        R 7      pV F  pV P                  W4       K  	  R# \        V\        4      '       dï   \        VP                  \        R 7      p\        V\        4      '       g   W9   d   \        WR4      hT P                  \        VP                   Uu. uF  p\        V4      NK  	  up!  \        V4      4       \        \        V4      4       FL  pW5,          pVRV W5^,           R ,           pV P                  \        V\        V4      4      \        V!  4       KN  	  R# \        V\        4      '       dL   \        VP                  \        R 7      pW'9   d   \        WR4      hV P                  P                  W34       R# \        V\        4      '       dJ   \        VP                  \        R 7      pW'9   d   \        WR4      hV F  pV P                  W‚4       K  	  R# V P                  P                  W34       V P                  P                  \        V4      \        V4      34       R# u upi ))Úkeyza -> a|c|...Nz
a & b -> az
a | b -> a)r
   r   Úsortedr4   Ústrro   r   r   rN   r   ÚrangeÚlenrY   r:   )	r\   r%   r&   Úsorted_bargsÚbargrF   ÚbrestÚsorted_aargsÚaargs	   &&&      r   rn   ÚProver._process_ruleF  sÎ  € ô �aœ×ÒÜ! !§&¡&¬cÔ2ˆLÛ$�Ø×!Ñ! !Ö*ó %ô ˜œ2×ÒÜ! !§&¡&¬cÔ2ˆLä˜a¤×'Ò'àÔ$Ü+¨A°.ÓAÐAØ×Ñœc¸!¿&º&Ó#A¹&°$¤C¨¦I¹&Ñ#AÑBÄCÈÃFÔKäœc ,Ó/Ö0�Ø#Õ)�Ø$ U dÐ+¨lÀ!½8¸9Ð.EÕE�Ø×!Ñ!¤# a¬¨T«Ó"3´R¸±ZÖ@ó 1ô ˜œ3×ÒÜ! !§&¡&¬cÔ2ˆLØÔ Ü'¨¨lÓ;Ð;Ø×Ñ×$Ñ$ a VÖ,ô ˜œ2×ÒÜ! !§&¡&¬cÔ2ˆLØÔ Ü'¨¨lÓ;Ð;Û$�Ø×!Ñ! $Ö*ó %ð
 ×Ñ×$Ñ$ a VÔ,Ø×Ñ×$Ñ$¤c¨!£f¬c°!«fÐ%5Ö6ùò9 $Bs   ÃI)rZ   rY   N)rP   rQ   rR   rS   rT   r]   rb   Úpropertyr`   ra   ro   rn   rU   Ú__classdictcell__©Ú__classdict__s   @r   rW   rW     sK   ø‡ € ñò8!ò	'ð ñ*ó ð*ð ñ*ó ð*ò÷"17ð 17r   rW   c                   ó‚   a € ] tR tRt o RtR tV 3R lR lt]V 3R lR l4       tR t	R	 t
R
 tR tV 3R lR ltRtV tR# )Ú	FactRulesi|  a  Rules that describe how to deduce facts in logic space

When defined, these rules allow implications to quickly be determined
for a set of facts. For this precomputed deduction tables are used.
see `deduce_all_facts`   (forward-chaining)

Also it is possible to gather prerequisites for a fact, which is tried
to be proven.    (backward-chaining)


Definition Syntax
-----------------

a -> b       -- a=T -> b=T  (and automatically b=F -> a=F)
a -> !b      -- a=T -> b=F
a == b       -- a -> b & b -> a
a -> b & c   -- a=T -> b=T & c=T
# TODO b | c


Internals
---------

.full_implications[k, v]: all the implications of fact k=v
.beta_triggers[k, v]: beta rules that might be triggered when k=v
.prereq  -- {} k <- [] of k's prerequisites

.defined_facts -- set of defined fact names
c           	     óÐ  € \        V\        4      '       d   VP                  4       p\        4       pV F™  pVP	                  R^4      w  rEp\
        P                  ! V4      p\
        P                  ! V4      pVR8X  d   VP                  WF4       K^  VR8X  d%   VP                  WF4       VP                  Wd4       K‰  \        RV,          4      h	  . V n	        VP                   FN  w  rxV P                  P                  VP                   Uu0 uF  p\        V4      kK  	  up\        V4      34       KP  	  \        VP                  4      p	\!        W’P                  4      p
V
P#                  4        Uu0 uF  p\%        V4      kK  	  upV n        \)        \*        4      p\)        \*        4      pV
P-                  4        F<  w  pw  rïV Uu0 uF  p\        V4      kK  	  upV\        V4      &   Wý\        V4      &   K>  	  WÀn        WÐn        \)        \*        4      p\3        V4      pVP-                  4        F  w  ppVV;;,          V,          uu&   K  	  VV n        R# u upi u upi u upi )z)Compile rules into internal lookup tablesNz->z==zunknown op %r)r
   rt   Ú
splitlinesrW   Úsplitr   Ú
fromstringro   r#   r<   ra   r:   r4   r   r)   r`   rG   r3   r   Údefined_factsr   r   r!   r   Úbeta_triggersrL   rJ   )r\   rI   ÚPÚruler%   Úopr&   r?   r0   Úimpl_aÚimpl_abr   r   rˆ   r'   Úbetaidxsr   rJ   Ú
rel_prereqÚpitemss   &&                  r   r]   ÚFactRules.__init__›  sù  € ô �eœS×!Ò!Ø×$Ñ$Ó&ˆEô ‹HˆãˆDà—z‘z $¨Ó*‰HˆA�1ä× Ò  Ó#ˆAÜ× Ò  Ó#ˆAà�TŒzØ—‘˜qÖ$Ø�t”Ø—‘˜qÔ$Ø—‘˜qÖ$ä  °2Õ!5Ó6Ð6ñ ð  ˆŒØŸLœL‰LˆEØ�O‰O×"Ñ"Ø',§z¢zÓ2¡z !”(˜1–+¡zÑ2´H¸U³OÐDöFñ )ô
 +¨1¯=©=Ó9ˆô ,¨F·L±LÓAˆð 6=·\±\´^ÓD±^°œj¨žm±^ÑDˆÔô (¬Ó,ÐÜ#¤CÓ(ˆØ#*§=¡=¦?ÑˆAÑ�ÙCGÓ-HÁ4¸a¬h°q®kÁ4Ñ-HÐœh q›kÑ*Ø)1œ( 1›+Ó&ñ $3ð "3ÔØ*Ôô œSÓ!ˆÜ"Ð#4Ó5ˆ
Ø#×)Ñ)Ö+‰IˆAˆvØ�1�I˜Õ�Iñ ,àˆŽùò; 3ùò Eùò .Is   ÄI
Å1IÇI#c                ó    <€ V ^8„  d   QhRS[ /# ©é   Úreturn)rt   )Úformatr€   s   "€r   Ú__annotate__ÚFactRules.__annotate__Ö  s   ø€ ÷ -ñ -™Cñ -r   c                ó@   € RP                  V P                  4       4      # )zCGenerate a string with plain python representation of the instance Ú
)ÚjoinÚprint_rulesr[   s   &r   Ú
_to_pythonÚFactRules._to_pythonÖ  s   € à�y‰y˜×)Ñ)Ó+Ó,Ð,r   c                ó    <€ V ^8„  d   QhRS[ /# )r”   Údata)Údict)r–   r€   s   "€r   r—   r˜   Û  s   ø€ ÷ 
ñ 
¡ñ 
r   c                óÖ   € V ! R4      pR F5  p\        \        4      pVP                  W,          4       \        W#V4       K7  	  VR,          Vn        \        VR,          4      Vn        V# )z:Generate an instance from the plain python representation Ú r<   r‡   )r   rˆ   rJ   )r   r   ÚupdateÚsetattrr<   r‡   )Úclsr    r\   rr   Úds   &&   r   Ú_from_pythonÚFactRules._from_pythonÚ  s_   € ñ �2‹wˆÛCˆCÜœ#ÓˆAØ�H‰H�T•YÔÜ�D˜qÖ!ñ Dð ˜|Õ,ˆŒÜ   oÕ!6Ó7ˆÔàˆr   c              #  óh   "  € R x € \        V P                  4       F  pRV: R2x € K  	  Rx € R# 5i)zdefined_facts = [ú    Ú,z] # defined_factsN)rs   r‡   )r\   Úfacts   & r   Ú_defined_facts_linesÚFactRules._defined_facts_linesç  s5   é € Ø!Ò!Ü˜4×-Ñ-Ö.ˆDØ˜™ Ð"Ô"ñ /à!Ô!ùs   ‚02c              #  ó  "  € R x € \        V P                  4       F[  pR FR  pRV RV R2x € RV: RV: R2x € V P                  W3,          p\        V4       F  pRV: R2x € K  	  R	x € R
x € KT  	  K]  	  Rx € R# 5i)zfull_implications = dict( [z    # Implications of ú = Ú:z    ((ú, z	), set( (ú        r¬   z       ) ),z     ),z ] ) # full_implicationsN)TF)rs   r‡   r   )r\   r­   Úvaluer   Úimplieds   &    r   Ú_full_implications_linesÚ"FactRules._full_implications_linesí  s—   é € Ø+Ò+Ü˜4×-Ñ-Ö.ˆDÛ&�Ø.¨t¨f°C¸°w¸aÐ@Ò@Ø˜t™h b¨©	°Ð;Ò;Ø#×5Ñ5°t°mÕD�Ü% lÖ3�GØ$ W¡K¨qÐ1Ô1ñ  4à#Ò#Ø”ó 'ñ /ð )Ô(ùs   ‚A?Bc              #  óæ   "  € R x € Rx € \        V P                  4       FG  pRV 2x € RV: R2x € \        V P                  V,          4       F  pRV: R2x € K  	  Rx € Rx € KI  	  Rx € R	# 5i)
z
prereq = {r£   z.    # facts that could determine the value of r«   z: {r´   r¬   z    },z
} # prereqN)rs   rJ   )r\   r­   Úpfacts   &  r   Ú_prereq_linesÚFactRules._prereq_linesú  sx   é € ØÒØŠÜ˜4Ÿ;™;Ö'ˆDØBÀ4À&ÐIÒIØ˜™ Ð%Ò%Ü §¡¨DÕ 1Ö2�Ø  ¡	¨Ð+Ô+ñ 3àŠNØŒHñ (ð Ôùs   ‚A/A1c           
   #  ó€  "  € \        \        4      p\        V P                  4       F   w  pw  r4W,          P	                  W234       K"  	  R x € Rx € Rx € ^ p/ p\        V4       Fl  pVw  rxRV RV 2x € W,           FK  w  r2WVV&   V^,          pRP                  \        \        \        V4      4      4      p	RV	 R2x € RV: R	2x € KM  	  Rx € Kn  	  R
x € Rx € \        V P                  4       F<  p
V
w  rxV P                  V
,           Uu. uF  q&V,          NK  	  ppRV
: RV: R2x € K>  	  Rx € R# u upi 5i)z@# Note: the order of the beta rules is used in the beta_triggerszbeta_rules = [r£   z    # Rules implying r±   r³   z    ({z},r´   z),z] # beta_ruleszbeta_triggers = {r«   z: r¬   z} # beta_triggersN)
r   Úlistr8   r<   r:   rs   r›   r   rt   rˆ   )r\   Úreverse_implicationsÚnÚprer¶   ÚmÚindicesr­   rµ   ÚsetstrÚqueryÚtriggerss   &           r   Ú_beta_rules_linesÚFactRules._beta_rules_lines  sW  é € Ü*¬4Ó0ÐÜ!*¨4¯?©?Ö!;ÑˆA‰~�Ø Õ)×0Ñ0°#°Ö:ñ "<ð QÒPØÒØŠØˆØˆÜÐ2Ö3ˆGØ!‰KˆDØ)¨$¨¨s°5°'Ð:Ò:Ø.×7Ð7‘�Ø˜‘
Ø�Q•�ØŸ™¤3¤s¬F°3«KÓ#8Ó9�Ø ˜x sÐ+Ò+Ø  ¡¨2Ð.Ô.ñ 8ð ŒHñ 4ð Òà!Ò!Ü˜D×.Ñ.Ö/ˆEØ‰KˆDØ,0×,>Ñ,>¸uÖ,EÓFÑ,E q Ÿ
˜
Ñ,EˆHÐFØ˜™	  H¡<¨qÐ1Ô1ñ 0ð "Ô!ùò Gùs   ‚DD>ÄD9Ä D>c                ó0   <€ V ^8„  d   QhRS[ S[,          /# r“   )r   rt   )r–   r€   s   "€r   r—   r˜   #  s   ø€ ÷ kñ k™X¡c�]ñ kr   c              #  ó.  "  € V P                  4        Rj  x€L
  Rx € Rx € V P                  4        Rj  x€L
  Rx € Rx € V P                  4        Rj  x€L
  Rx € Rx € V P                  4        Rj  x€L
  Rx € Rx € Rx € Rx € R#  Lv LX L: L5i)z@Returns a generator with lines to represent the facts and rules Nr£   z`generated_assumptions = {'defined_facts': defined_facts, 'full_implications': full_implications,zZ               'prereq': prereq, 'beta_rules': beta_rules, 'beta_triggers': beta_triggers})r®   r·   r»   rÇ   r[   s   &r   rœ   ÚFactRules.print_rules#  s•   é € à×,Ñ,Ó.×.Ð.ØŠØŠØ×0Ñ0Ó2×2Ð2ØŠØŠØ×%Ñ%Ó'×'Ð'ØŠØŠØ×)Ñ)Ó+×+Ð+ØŠØŠØpÒpØjÔjñ 	/ñ 	3ñ 	(ñ 	,ùsC   ‚B–B—B¶B·BÁBÁBÁ6BÁ7BÂBÂBÂB)r<   rˆ   r‡   r   rJ   N)rP   rQ   rR   rS   rT   r]   r�   Úclassmethodr¨   r®   r·   r»   rÇ   rœ   rU   r~   r   s   @r   r‚   r‚   |  sN   ø‡ € ñò<9÷v-ð -ð ÷
ó ð
ò"ò)ò
ò"÷:kö kr   r‚   c                   ó&   a € ] tR tRt o R tRtV tR# )ÚInconsistentAssumptionsi5  c                ó:   € V P                   w  rpV: R V: RV: 2# )r³   Ú=)r4   )r\   Úkbr­   rµ   s   &   r   Ú__str__ÚInconsistentAssumptions.__str__6  s   € ØŸ)™)‰ˆ�%Û £$ªÐ.Ð.r   rO   N)rP   rQ   rR   rS   rÒ   rU   r~   r   s   @r   rÎ   rÎ   5  s   ø‡ € ÷/ð /r   rÎ   c                   ó<   a € ] tR tRt o RtR tR tR tR tRt	V t
R# )	ÚFactKBi;  zL
A simple propositional knowledge base relying on compiled inference rules.
c                ó˜   € R RP                  \        V P                  4       4       Uu. uF  pRV,          NK  	  up4      ,          # u upi )z{
%s}z,
z	%s: %s)r›   rs   r!   )r\   r   s   & r   rÒ   ÚFactKB.__str__?  sB   € Ø˜%Ÿ*™*Ü%+¨D¯J©J«LÔ%9Ó:Ñ%9 ˆZ˜!�^ˆ^Ñ%9Ñ:ó<õ <ð 	<ùÚ:s   ¨A
c                ó   € Wn         R # r,   ©rI   )r\   rI   s   &&r   r]   ÚFactKB.__init__C  s   € ØŽ
r   c                ód   € W9   d&   W,          e   W,          V8X  d   R# \        WV4      hW V&   R# )zhAdd fact k=v to the knowledge base.

Returns True if the KB has actually been updated, False otherwise.
FT)rÎ   )r\   r   Úvs   &&&r   Ú_tellÚFactKB._tellF  s3   € ð
 Œ9˜�Ò,Ø�w˜!Œ|Ùä-¨d°qÓ9Ð9à�‰GÙr   c                óš  a € S P                   P                  pS P                   P                  pS P                   P                  p\	        V\
        4      '       d   VP                  4       pV'       dÚ   \        4       pV F_  w  rgS P                  Wg4      '       d   Vf   K"  W&V3,           F  w  r‰S P                  W‰4       K  	  VP                  W6V3,          4       Ka  	  . pV F`  p
WJ,          w  r¼\        ;QJ d    V 3R lV 4       F  '       d   K   RM	  RM! V 3R lV 4       4      '       g   KO  VP                  V4       Kb  	  Ká  R# )z‰
Update the KB with all the implications of a list of facts.

Facts can be specified as a dictionary or as a list of (key, value)
pairs.
Nc              3   óN   <"  € T F  w  rSP                  V4      VJ x € K  	  R # 5ir,   )r7   )r-   r   rÜ   r\   s   &  €r   r1   Ú*FactKB.deduce_all_facts.<locals>.<genexpr>y  s    øé € Ð:±E©D¨A�t—x‘x “{ aÕ'³Eùs   ƒ"%FT)rI   r   rˆ   r<   r
   r¡   r!   r   rÝ   r¤   Úallr:   )r\   Úfactsr   rˆ   r<   Úbeta_maytriggerr   rÜ   rr   rµ   rF   r?   r0   s   f&           r   Údeduce_all_factsÚFactKB.deduce_all_factsW  s  ø€ ð !ŸJ™J×8Ñ8ÐØŸ
™
×0Ñ0ˆØ—Z‘Z×*Ñ*ˆ
ä�eœT×"Ò"Ø—K‘K“MˆEçÜ!›eˆOó ‘�Ø—z‘z !×'Ò'¨1ª9Ùð #4°q°D×"9Ð"9‘J�CØ—J‘J˜sÖ*ñ #:ð  ×&Ñ& }¸°TÕ':Ö;ñ ð ˆEÛ'�Ø)Õ/‘�ß“3Ô:±EÓ:—3—3’3Ô:±EÓ:×:Ô:Ø—L‘L Ö'ó (ñ! r   rÙ   N)rP   rQ   rR   rS   rT   rÒ   r]   rÝ   rå   rU   r~   r   s   @r   rÕ   rÕ   ;  s#   ø‡ € ñò<òò÷"#(ð #(r   rÕ   N)rT   Úcollectionsr   Útypingr   Úlogicr   r   r   r   r   r   r   r)   rG   rL   Ú	ExceptionrN   rW   r‚   r#   rÎ   r¡   rÕ   rO   r   r   Ú<module>rë      s{   ðñ.õ` $Ý ç &Ó &òòòò(%òPLò^ôL	˜	ô 	÷
v7ñ v7÷vvkñ vkôr/˜jô /ô?(ˆTö ?(r   