o
    h                     @   s  d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	m
Z
 d dlmZmZmZmZmZ d dlmZ d dlmZ d d	lmZmZ d d
lmZmZmZmZ d dlmZmZ d dlm Z m!Z!m"Z"m#Z#m$Z$ d dl%m&Z& d)ddZ'dd Z(dd Z)dd Z*i e	de
dededededede$ de# de" de! de  dededed ed!ed"ed#ed$ed%ed&ed'iZ+d(S )*    )smtlib_code)AppliedPredicate)
EncodedCNF)Q)AddMul)EqualityLessThanGreaterThanStrictLessThanStrictGreaterThan)Abs)Pow)MinMax)AndOrXorImplies)NotITE)StrictGreaterThanPredicateStrictLessThanPredicateGreaterThanPredicateLessThanPredicateEqualityPredicate)import_moduleFc                 C   sr   t | tst }||  |} td}|d u rtdt| |}t| }|dkr,dS |dkr7t|	 | S d S )Nz3zz3 is not installedZunsatFsat)

isinstancer   Zadd_propr   ImportErrorencoded_cnf_to_z3_solverstrcheckz3_model_to_sympy_modelmodel)exprZ
all_modelsZexprsr   sres r)   g/home/www/facesmatcher.com/frenv_anti/lib/python3.10/site-packages/sympy/logic/algorithms/z3_wrapper.pyz3_satisfiable   s   


r+   c                    s(   dd |j  D   fddD S )Nc                 S   s   i | ]\}}||qS r)   r)   ).0keyvaluer)   r)   r*   
<dictcomp>&   s    z+z3_model_to_sympy_model.<locals>.<dictcomp>c                    s.   i | ]} t | d d  t| qS )   N)intnameboolr,   varZrev_encz3_modelr)   r*   r/   '   s   . )encodingitems)r7   enc_cnfr)   r6   r*   r$   %   s   r$   c                 C   s    dd | D }dd | d S )Nc                 S   s2   g | ]}|d krdt | ndt | dqS )r   dz(not d))abs)r,   Zlitr)   r)   r*   
<listcomp>+   s   2 z'clause_to_assertion.<locals>.<listcomp>z(assert (or  z)))join)clauseZclause_stringsr)   r)   r*   clause_to_assertion*   s   rB   c                 C   s4  dd }|  }dd | jD }dd | jD }t }| j D ]U\}}t|ts*q |jt	j
t	jt	jt	jt	jt	jt	jt	jt	jt	jt	jt	jt	jt	jt	jt	jt	jfvrRq t|ddtd}	||jO }|	}d| d	| d
}
d|
 d
 }|| q |D ]}|d| d qxd|}d|}| | | | |S )Nc                 S   s   dS )NF)r   r   functionr   positivenegativezero)predr)   r)   r*   dummify_bool0   s   z.encoded_cnf_to_z3_solver.<locals>.dummify_boolc                 S   s   g | ]}d | dqS )z(declare-const dz Bool)r)   r4   r)   r)   r*   r>   ;   s    z,encoded_cnf_to_z3_solver.<locals>.<listcomp>c                 S   s   g | ]}t |qS r)   )rB   )r,   rA   r)   r)   r*   r>   <   s    F)Zauto_declareZauto_assertknown_functionsz
(implies dr?   r<   z(assert z(declare-const z Real)
)!ZSolver	variablesdatasetr8   r9   r   r   rC   r   gtltgeleneeqrD   rE   Zextended_negativeZextended_positiverF   ZnonzeroZnonnegativenonpositiveZextended_nonzeroZextended_nonnegativeZextended_nonpositiver   rI   Zfree_symbolsappendr@   Zfrom_string)r:   r   rH   r'   ZdeclarationsZ
assertionssymbolsrG   encZpred_strrA   Z	assertionZsymr)   r)   r*   r!   /   s.   	
N




r!   +*=z<=z>=<>r=   minmax^andorxornotZitez=>N)F),Zsympy.printing.smtlibr   Zsympy.assumptions.assumer   Zsympy.assumptions.cnfr   Zsympy.assumptions.askr   Z
sympy.corer   r   Zsympy.core.relationalr   r	   r
   r   r   Z$sympy.functions.elementary.complexesr   Z&sympy.functions.elementary.exponentialr   Z(sympy.functions.elementary.miscellaneousr   r   Zsympy.logic.boolalgr   r   r   r   r   r   Z#sympy.assumptions.relation.equalityr   r   r   r   r   Zsympy.externalr   r+   r$   rB   r!   rI   r)   r)   r)   r*   <module>   st    
)

