a
    ¬<bµ  ã                   @   s¢   d Z 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mZmZmZmZ ddlmZ edd	„ ƒZeddd„ƒZdd„ Zedd„ ƒZdd„ Zdd„ Zd
S )zÓ
Known facts in assumptions module.

This module defines the facts between unary predicates in ``get_known_facts()``,
and supports functions to generate the contents in
``sympy.assumptions.ask_generated`` file.
é    )ÚQ)ÚAppliedPredicate)Úcacheit)ÚSymbol)Úto_cnfÚAndÚNotÚImpliesÚ
EquivalentÚ	Exclusive)Úsatisfiablec                   C   sÜ   t jt jt jB t jB t jt jt jB t jt jt jB t j	t jt jB t j
t jt jB t jt jt jB t jB t jB t jB t jt jt jB t jt jt jB t jt jt jB t jB t jB t jt jt jB t jB t jt jt jB t jB t jt jt jB iS ©N)r   ÚrealÚnegativeÚzeroÚpositiveÚintegerÚevenÚoddÚnonpositiveZnonzeroZnonnegativeZextended_realÚnegative_infiniteÚpositive_infiniteZextended_positiveZextended_negativeZextended_nonzeroZextended_nonpositiveZextended_nonnegativeÚcomplexÚ	algebraicÚtranscendental© r   r   úg/Users/vegardjervell/Documents/master/model/venv/lib/python3.9/site-packages/sympy/assumptions/facts.pyÚget_composite_predicates   s     ôr   Nc              0   C   s  | du rt dƒ} ttt | ¡t | ¡t | ¡t | ¡t | ¡ƒtt 	| ¡t 
| ¡ƒtt 	| ¡t 
| ¡B t | ¡ƒtt | ¡t | ¡ƒtt 	| ¡t | ¡t | ¡B ƒtt | ¡t | ¡ƒtt | ¡t | ¡ƒtt | ¡t | ¡ƒtt | ¡t | ¡ƒtt | ¡t | ¡ƒtt | ¡t | ¡ƒtt | ¡t | ¡B t | ¡t | ¡@ ƒtt | ¡t | ¡@ t | ¡ @ t | ¡ƒtt 	| ¡t | ¡ƒtt 
| ¡t | ¡ƒtt | ¡t | ¡t | ¡B ƒtt | ¡t | ¡ƒtt | ¡t | ¡ƒtt | ¡t | ¡B t | ¡ƒtt | ¡t | ¡B t | ¡ƒtt | ¡t | ¡ƒtt | ¡t | ¡ƒtt | ¡t | ¡@ t | ¡ƒtt | ¡t  | ¡ƒtt | ¡t !| ¡ƒtt  | ¡t "| ¡ƒtt #| ¡t  | ¡ƒtt | ¡t !| ¡ƒtt #| ¡t $| ¡ƒtt #| ¡t %| ¡ƒtt %| ¡t &| ¡ƒtt $| ¡t &| ¡ƒtt &| ¡t $| ¡t %| ¡B ƒtt $| ¡t %| ¡@ t #| ¡ƒtt #| ¡t '| ¡ƒtt (| ¡t &| ¡ƒtt !| ¡t )| ¡ƒtt !| ¡t "| ¡ƒtt '| ¡t "| ¡ƒtt )| ¡t "| ¡@ t !| ¡ƒtt !| ¡t *| ¡ ƒtt +| ¡t | ¡ƒtt | ¡t ,| ¡ƒƒ+}|S )z÷
    Facts between unary predicates.

    Parameters
    ==========

    x : Symbol, optional
        Placeholder symbol for unary facts. Default is ``Symbol('x')``.

    Returns
    =======

    fact : Known facts in conjugated normal form.

    NÚx)-r   r   r   r   r   r   r   r   r   r   Z	imaginaryr	   r   r   r   r
   ZrationalZ
irrationalr   r   r   Z	compositeÚprimeZ	hermitianZantihermitianZinfiniteZfiniteZcommutativeZ
orthogonalZpositive_definiteZunitaryZreal_elementsÚnormalZ
invertibleZsquareZdiagonalZupper_triangularZlower_triangularÚ
triangularZ	symmetricZunit_triangularZfullrankZsingularZinteger_elementsZcomplex_elements)r   Úfactr   r   r   Úget_known_facts&   sd    ÿ(*Å=r#   c                 C   sˆ   t |ƒ}t| |ƒ}i }| ¡ D ]d\}}tƒ }tƒ }|D ]<}	t|	tƒrR| |	j¡ q6t|	tƒr6|	j	d }
| |
j¡ q6||f||j< q|S )a  
    Computes and returns a dictionary which contains the relations between
    unary predicates.

    Each key is a predicate, and item is two groups of predicates.
    First group contains the predicates which are implied by the key, and
    second group contains the predicates which are rejected by the key.

    All predicates in *keys* and *fact* must be unary and have same placeholder
    symbol.

    Parameters
    ==========

    keys : list of AppliedPredicate instances.

    fact : Fact between predicates in conjugated normal form.

    Examples
    ========

    >>> from sympy import Q, And, Implies
    >>> from sympy.assumptions.facts import generate_known_facts_dict
    >>> from sympy.abc import x
    >>> keys = [Q.even(x), Q.odd(x), Q.zero(x)]
    >>> fact = And(Implies(Q.even(x), ~Q.odd(x)),
    ...     Implies(Q.zero(x), Q.even(x)))
    >>> generate_known_facts_dict(keys, fact)
    {Q.even: ({Q.even}, {Q.odd}),
     Q.odd: ({Q.odd}, {Q.even, Q.zero}),
     Q.zero: ({Q.even, Q.zero}, {Q.odd})}
    r   )
r   Úsingle_fact_lookupÚitemsÚsetÚ
isinstancer   ÚaddÚfunctionr   Úargs)Úkeysr"   Zfact_cnfÚmappingÚretÚkeyÚvalueZimpliedZrejectedÚexprÚpredr   r   r   Úgenerate_known_facts_dictz   s    !



r2   c                  C   sr   t ƒ } tjtjtjtjtjtjfD ]}|  |¡ q"g }tj	j
D ].}| d¡rNq>tt|ƒ}|| v rbq>| |¡ q>|S )z”
    Return every unary predicates registered to ``Q``.

    This function is used to generate the keys for
    ``generate_known_facts_dict``.

    Ú__)r&   r   ÚeqÚneÚgtÚltÚgeÚler(   Ú	__class__Ú__dict__Ú
startswithÚgetattrÚappend)Úexcluder1   ÚresultÚattrr   r   r   Úget_known_facts_keys¬   s    	 

rB   c                 C   sf   i }| D ]X}|h||< | D ]D}||krt |||ƒr@||  |¡ t | ||ƒr||  | ¡ qq|S r   )Úask_full_inferencer(   )Zknown_facts_keysÚknown_facts_cnfr,   r.   Z	other_keyr   r   r   r$   Å   s    
r$   c                 C   s0   t t||| ƒƒsdS t t||t| ƒƒƒs,dS dS )z9
    Method for inferring properties about objects.

    FTN)r   r   r   )ZpropositionZassumptionsrD   r   r   r   rC   Ó   s
    rC   )N)Ú__doc__Zsympy.assumptionsr   Zsympy.assumptions.assumer   Zsympy.core.cacher   Zsympy.core.symbolr   Zsympy.logic.boolalgr   r   r   r	   r
   r   Zsympy.logic.inferencer   r   r#   r2   rB   r$   rC   r   r   r   r   Ú<module>   s    
S2
