JL iJdZddlZddlZddlmZmZGddeZGddeZGd d eZGd d eZ Gd deZ GddeZ Gdde e Z Gdde e Z GddeZGddee ZGddee ZGddeeZGdde e ZGdd ej&Zy)!a Interfaces and base classes for theorem provers and model builders. ``Prover`` is a standard interface for a theorem prover which tries to prove a goal from a list of assumptions. ``ModelBuilder`` is a standard interface for a model builder. Given just a set of assumptions. the model builder tries to build a model for the assumptions. Given a set of assumptions and a goal *G*, the model builder tries to find a counter-model, in the sense of a model that will satisfy the assumptions plus the negation of *G*. N)ABCMetaabstractmethodc*eZdZdZddZeddZy)Proverz Interface for trying to prove a goal from assumptions. Both the goal and the assumptions are constrained to be formulas of ``logic.Expression``. Nc.|j|||dS)zX :return: Whether the proof was successful or not. :rtype: bool r)_proveselfgoal assumptionsverboses X/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/nltk/inference/api.pyprovez Prover.prove s {{4g6q99cy)z{ :return: Whether the proof was successful or not, along with the proof :rtype: tuple: (bool, str) Nr s rrz Prover._prove'rNNF)__name__ __module__ __qualname____doc__rrrrrrrrs  :  rr) metaclassc*eZdZdZddZeddZy) ModelBuilderz Interface for trying to build a model of set of formulas. Open formulas are assumed to be universally quantified. Both the goal and the assumptions are constrained to be formulas of ``logic.Expression``. Nc.|j|||dS)zx Perform the actual model building. :return: Whether a model was generated :rtype: bool r) _build_modelr s r build_modelzModelBuilder.build_model7s   {Gz.s AY,>rz&Assumptions list has not been changed:N)setrTfilterrSprintWarningr5rU)r r+r, result_lists ` rr-z*BaseTheoremToolCommand.retract_assumptionss_ N 6">@Q@QRS [D$5$55 'BC D  " " $' rc|jS)r/)rSr0s rr z"BaseTheoremToolCommand.assumptionss    rc|jS)r2)rRr0s rr zBaseTheoremToolCommand.goals zzrcD|jD] }t|yr4)r r_)r r[s rr5z(BaseTheoremToolCommand.print_assumptionss#!!# A !H rNNr6) rrrrrVr'r-r r r5rrrrPrPs& I$(!rrPc6eZdZdZddZd dZd dZd dZdZy) BaseProverCommandr9NcP||_ tj|||d|_y)z :param prover: The theorem tool to execute with the assumptions :type prover: Prover :see: ``BaseTheoremToolCommand`` N)_proverrPrV_proof)r proverr r s rrVzBaseProverCommand.__init__ s'  >''dK@ rc|jF|jj|j|j |\|_|_|jS)zh Perform the actual proof. Store the result to prevent unnecessary re-proving. )rUrirr r rjr;s rrzBaseProverCommand.provesM << (, (;(; T--/) %DL$+||rch|j td|j|j|Sr=z.You have to call prove() first to get a proof!rU LookupErrordecorate_proofrjr>s rr@zBaseProverCommand.proof"1 << NO O&&t{{H= =rc|Sz Modify and return the proof string :param proof_string: str the proof to decorate :param simplify: bool simplify the proof? :return: str rr proof_stringr?s rrqz BaseProverCommand.decorate_proof-s rc|jSrN)rir0s rrBzBaseProverCommand.get_prover6s ||rrer6rC rrrrrVrr@rqrBrrrrgrgs    >rrgc6eZdZdZddZd dZd dZd dZdZy) BaseModelBuilderCommandz This class holds a ``ModelBuilder``, a goal, and a list of assumptions. When build_model() is called, the ``ModelBuilder`` is executed with the goal and assumptions. NcP||_ tj|||d|_y)z :param modelbuilder: The theorem tool to execute with the assumptions :type modelbuilder: ModelBuilder :see: ``BaseTheoremToolCommand`` N) _modelbuilderrPrV_model)r modelbuilderr r s rrVz BaseModelBuilderCommand.__init__As( *>''dK@ rc|jF|jj|j|j |\|_|_|jSzi Attempt to build a model. Store the result to prevent unnecessary re-building. )rUr|rr r r}r;s rrz#BaseModelBuilderCommand.build_modelNsO << (,(:(:(G(G T--/) %DL$+||rch|j td|j|j|SrHz4You have to call build_model() first to get a model!rUrp_decorate_modelr}rIs rrKzBaseModelBuilderCommand.modelY1 << WX X'' V< tj||d|_y)zE :param proverCommand: ``ProverCommand`` to decorate N)rrVrj)r proverCommands rrVzProverCommandDecorator.__init__s $,,T=A rc|jL|j}|j|j|j |\|_|_|jSrN)rUrBrr r rj)r r rks rrzProverCommandDecorator.provesQ << __&F(.  T--/) %DL$+||rch|j td|j|j|Srnror>s rr@zProverCommandDecorator.proofrrrc:|jj||Srt)rrqrus rrqz%ProverCommandDecorator.decorate_proofs}}++L(CCrc6|jjSrNrrBr0s rrBz!ProverCommandDecorator.get_prover}}''))rNr6rCrxrrrrrs!  >D*rrc4eZdZdZdZddZd dZd dZdZy) ModelBuilderCommandDecoratorz{ A base decorator for the ``ModelBuilderCommand`` class from which other prover command decorators can extend. c>tj||d|_y)zQ :param modelBuilderCommand: ``ModelBuilderCommand`` to decorate N)rrVr})r modelBuilderCommands rrVz%ModelBuilderCommandDecorator.__init__s $,,T3FG rc|jL|j}|j|j|j |\|_|_|jSr)rUrMrr r r})r r r~s rrz(ModelBuilderCommandDecorator.build_modelsW << 113L(4(A(A T--/) %DL$+||rNch|j td|j|j|SrrrIs rrKz"ModelBuilderCommandDecorator.modelrrc:|jj||S)z Modify and return the proof string :param valuation_str: str with the model builder's output :param format: str indicating the format for displaying :return: str )rrrs rrz,ModelBuilderCommandDecorator._decorate_models}},,]FCCrc6|jjSrNrr0s rrMz.ModelBuilderCommandDecorator.get_model_builderrrr6rNrrrrrrs!   =D*rrc,eZdZdZdZddZddZdZy)ParallelProverBuildera This class stores both a prover and a model builder and when either prove() or build_model() is called, then both theorem tools are run in parallel. Whichever finishes first, the prover or the model builder, is the result that will be used. c ||_||_yrN)rir|)r rkr~s rrVzParallelProverBuilder.__init__s )rNc,|j|||dfSN_runr s rrzParallelProverBuilder._provesyy{G4b88rc.|j||| dfSrrr s rrz"ParallelProverBuilder._build_models99T;88"<jjSrN)rirr r r r srr\z,ParallelProverBuilder._run.. sDLL&&t['BrTPc>jjSrN)r|rrsrr\z,ParallelProverBuilder._run..sD&&224gNrMB)TheoremToolThreadstartis_aliveresult)r r r r tp_thread mb_threads```` rrzParallelProverBuilder._run s% BGT & N     "y'9'9';   "y'9'9';    '## #    ) ''' 'rr)rrrrrVrrrrrrrrs*9=rrc.eZdZdZddZddZddZdZy) ParallelProverBuilderCommanda This command stores both a prover and a model builder and when either prove() or build_model() is called, then both theorem tools are run in parallel. Whichever finishes first, the prover or the model builder, is the result that will be used. Because the theorem prover result is the opposite of the model builder result, we will treat self._result as meaning "proof found/no model found". Ncdtj||||tj||||yrN)rgrVrz)r rkr~r r s rrVz%ParallelProverBuilderCommand.__init__/s*""4{C((|T;Orc$|j|SrNrr;s rrz"ParallelProverBuilderCommand.prove3syy!!rc&|j| SrNrr;s rrz(ParallelProverBuilderCommand.build_model6s99W%%%rctfdd}tfdd}|j|j|jr2|jr" |jr|jr"|j|j_jS|j|j _jS)Nc0tjSrN)rgrr;srr\z3ParallelProverBuilderCommand._run..<s%++D':rrc0tjSrN)rzrr;srr\z3ParallelProverBuilderCommand._run..?s+77gFrr)rrrrrU)r r rrs`` rrz!ParallelProverBuilderCommand._run9s% :GT & FQU    "y'9'9';   "y'9'9';    '$++DL||   )(///DL||rrer6)rrrrrVrrrrrrrr$sP"&rrc*eZdZddZdZedZy)rNcztjj|||_d|_||_||_yrN) threadingThreadrVrrU_verbose_name)r rr names rrVzTheoremToolThread.__init__Qs2!!$'    rc V |j|_|jrNtd|jd|jdt j t j yy#t$r-}t|td|jzYd}~yd}~wwxYw)NzThread z finished with result z at zThread %s completed abnormally)rrUrr_rtime localtime Exception)r es rrunzTheoremToolThread.runXs} C==?DL}}zz4<< 1LN  C !H 2djjA B B CsA.A22 B(;#B##B(c|jSrN)rUr0s rrzTheoremToolThread.resultds ||rrN)rrrrVrpropertyrrrrrrPs! Crr)rrrabcrrrrr!r8rErPrgrzrrrrrrrrrrrs  ' w * W 2/ 7/ d & 8 , @K/K\3. 3l4"46I4"n*"4*D-*8--*`2*#>@S2*j)FL)X)#46M)X ((r