
    \hz                         S SK JrJrJrJrJrJr  S SKJr  S SK	J
r
JrJr  S SKJr   " S S\
5      r " S S\5      r " S	 S
\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      rg)    )SBasicDictSymbolTuplesympify)Str)Set	FiniteSetEmptySet)iterablec                       \ rS rSrSrSrSrg)Class   a   
The base class for any kind of class in the set-theoretic sense.

Explanation
===========

In axiomatic set theories, everything is a class.  A class which
can be a member of another class is a set.  A class which is not a
member of another class is a proper class.  The class `\{1, 2\}`
is a set; the class of all sets is a proper class.

This class is essentially a synonym for :class:`sympy.core.Set`.
The goal of this class is to assure easier migration to the
eventual proper implementation of set theory.
F N)__name__
__module____qualname____firstlineno____doc__	is_proper__static_attributes__r       T/var/www/auris/envauris/lib/python3.13/site-packages/sympy/categories/baseclasses.pyr   r      s     Ir   r   c                       \ rS rSrSrSrg)Object   z
The base class for any kind of object in an abstract category.

Explanation
===========

While technically any instance of :class:`~.Basic` will do, this
class is the recommended way to create abstract objects in
abstract categories.
r   N)r   r   r   r   r   r   r   r   r   r   r      s    	r   r   c                   J    \ rS rSrSrS r\S 5       r\S 5       rS r	S r
Srg	)
Morphism'   ae  
The base class for any morphism in an abstract category.

Explanation
===========

In abstract categories, a morphism is an arrow between two
category objects.  The object where the arrow starts is called the
domain, while the object where the arrow ends is called the
codomain.

Two morphisms between the same pair of objects are considered to
be the same morphisms.  To distinguish between morphisms between
the same objects use :class:`NamedMorphism`.

It is prohibited to instantiate this class.  Use one of the
derived classes instead.

See Also
========

IdentityMorphism, NamedMorphism, CompositeMorphism
c                     [        S5      e)Nz:Cannot instantiate Morphism.  Use derived classes instead.NotImplementedError)clsdomaincodomains      r   __new__Morphism.__new__?   s    !HJ 	Kr   c                      U R                   S   $ )z
Returns the domain of the morphism.

Examples
========

>>> from sympy.categories import Object, NamedMorphism
>>> A = Object("A")
>>> B = Object("B")
>>> f = NamedMorphism(A, B, "f")
>>> f.domain
Object("A")

r   argsselfs    r   r%   Morphism.domainC         yy|r   c                      U R                   S   $ )z
Returns the codomain of the morphism.

Examples
========

>>> from sympy.categories import Object, NamedMorphism
>>> A = Object("A")
>>> B = Object("B")
>>> f = NamedMorphism(A, B, "f")
>>> f.codomain
Object("B")

   r*   r,   s    r   r&   Morphism.codomainU   r/   r   c                     [        X5      $ )a!  
Composes self with the supplied morphism.

The order of elements in the composition is the usual order,
i.e., to construct `g\circ f` use ``g.compose(f)``.

Examples
========

>>> from sympy.categories import Object, NamedMorphism
>>> A = Object("A")
>>> B = Object("B")
>>> C = Object("C")
>>> f = NamedMorphism(A, B, "f")
>>> g = NamedMorphism(B, C, "g")
>>> g * f
CompositeMorphism((NamedMorphism(Object("A"), Object("B"), "f"),
NamedMorphism(Object("B"), Object("C"), "g")))
>>> (g * f).domain
Object("A")
>>> (g * f).codomain
Object("C")

)CompositeMorphismr-   others     r   composeMorphism.composeg   s    2 !--r   c                 $    U R                  U5      $ )z
Composes self with the supplied morphism.

The semantics of this operation is given by the following
equation: ``g * f == g.compose(f)`` for composable morphisms
``g`` and ``f``.

See Also
========

compose
)r7   r5   s     r   __mul__Morphism.__mul__   s     ||E""r   r   N)r   r   r   r   r   r'   propertyr%   r&   r7   r:   r   r   r   r   r   r   '   s?    .K  "  ".6#r   r   c                   .    \ rS rSrSrS r\S 5       rSrg)IdentityMorphism   a  
Represents an identity morphism.

Explanation
===========

An identity morphism is a morphism with equal domain and codomain,
which acts as an identity with respect to composition.

Examples
========

>>> from sympy.categories import Object, NamedMorphism, IdentityMorphism
>>> A = Object("A")
>>> B = Object("B")
>>> f = NamedMorphism(A, B, "f")
>>> id_A = IdentityMorphism(A)
>>> id_B = IdentityMorphism(B)
>>> f * id_A == f
True
>>> id_B * f == f
True

See Also
========

Morphism
c                 .    [         R                  " X5      $ N)r   r'   )r$   r%   s     r   r'   IdentityMorphism.__new__   s    }}S))r   c                     U R                   $ rA   )r%   r,   s    r   r&   IdentityMorphism.codomain   s    {{r   r   N)	r   r   r   r   r   r'   r<   r&   r   r   r   r   r>   r>      s     8*  r   r>   c                   .    \ rS rSrSrS r\S 5       rSrg)NamedMorphism   a  
Represents a morphism which has a name.

Explanation
===========

Names are used to distinguish between morphisms which have the
same domain and codomain: two named morphisms are equal if they
have the same domains, codomains, and names.

Examples
========

>>> from sympy.categories import Object, NamedMorphism
>>> A = Object("A")
>>> B = Object("B")
>>> f = NamedMorphism(A, B, "f")
>>> f
NamedMorphism(Object("A"), Object("B"), "f")
>>> f.name
'f'

See Also
========

Morphism
c                     U(       d  [        S5      e[        U[        5      (       d  [        U5      n[        R                  " XX#5      $ )Nz!Empty morphism names not allowed.)
ValueError
isinstancer	   r   r'   )r$   r%   r&   names       r   r'   NamedMorphism.__new__   s8    @AA$$$t9D}}S(99r   c                 4    U R                   S   R                  $ )z
Returns the name of the morphism.

Examples
========

>>> from sympy.categories import Object, NamedMorphism
>>> A = Object("A")
>>> B = Object("B")
>>> f = NamedMorphism(A, B, "f")
>>> f.name
'f'

   r+   rK   r,   s    r   rK   NamedMorphism.name   s      yy|   r   r   N)	r   r   r   r   r   r'   r<   rK   r   r   r   r   rF   rF      s     6: ! !r   rF   c                   d    \ rS rSrSr\S 5       rS r\S 5       r	\S 5       r
\S 5       rS rS	rg
)r4      a7  
Represents a morphism which is a composition of other morphisms.

Explanation
===========

Two composite morphisms are equal if the morphisms they were
obtained from (components) are the same and were listed in the
same order.

The arguments to the constructor for this class should be listed
in diagram order: to obtain the composition `g\circ f` from the
instances of :class:`Morphism` ``g`` and ``f`` use
``CompositeMorphism(f, g)``.

Examples
========

>>> from sympy.categories import Object, NamedMorphism, CompositeMorphism
>>> A = Object("A")
>>> B = Object("B")
>>> C = Object("C")
>>> f = NamedMorphism(A, B, "f")
>>> g = NamedMorphism(B, C, "g")
>>> g * f
CompositeMorphism((NamedMorphism(Object("A"), Object("B"), "f"),
NamedMorphism(Object("B"), Object("C"), "g")))
>>> CompositeMorphism(f, g) == g * f
True

c                     [        U[        5      (       a  XR                  -   $ [        U[        5      (       a  U $ U [	        U5      -   $ )a  
Intelligently adds ``morphism`` to tuple ``t``.

Explanation
===========

If ``morphism`` is a composite morphism, its components are
added to the tuple.  If ``morphism`` is an identity, nothing
is added to the tuple.

No composability checks are performed.
)rJ   r4   
componentsr>   r   )tmorphisms     r   _add_morphismCompositeMorphism._add_morphism  sE     h 122 ****"233HuX&&r   c                 0   U(       a2  [        US   [        5      (       d  [        R                  " U /US   Q76 $ [	        5       n[        XSS  5       Ht  u  p4[        U[        5      (       a  [        U[        5      (       d  [        S5      eUR                  UR                  :w  a  [        S5      e[        R                  X#5      nMv     [        R                  X!S   5      nU(       d  US   $ [        U5      S:X  a  US   $ [        R                  " X5      $ )Nr   r1   z!All components must be morphisms.zUncomposable morphisms.)rJ   r   r4   r'   r   zip	TypeErrorr&   r%   rI   rW   lenr   )r$   rT   normalised_componentscurrent	followings        r   r'   CompositeMorphism.__new__'  s    jAAA %,,SA:a=AA %"%jQR."AGgx00"9h77 CDD9#3#33 !:;;$5$C$C%%0! #B !2 ? ?!b>!3 % a= &'1,(++}}S88r   c                      U R                   S   $ )ar  
Returns the components of this composite morphism.

Examples
========

>>> from sympy.categories import Object, NamedMorphism
>>> A = Object("A")
>>> B = Object("B")
>>> C = Object("C")
>>> f = NamedMorphism(A, B, "f")
>>> g = NamedMorphism(B, C, "g")
>>> (g * f).components
(NamedMorphism(Object("A"), Object("B"), "f"),
NamedMorphism(Object("B"), Object("C"), "g"))

r   r*   r,   s    r   rT   CompositeMorphism.componentsJ  s    & yy|r   c                 4    U R                   S   R                  $ )ae  
Returns the domain of this composite morphism.

The domain of the composite morphism is the domain of its
first component.

Examples
========

>>> from sympy.categories import Object, NamedMorphism
>>> A = Object("A")
>>> B = Object("B")
>>> C = Object("C")
>>> f = NamedMorphism(A, B, "f")
>>> g = NamedMorphism(B, C, "g")
>>> (g * f).domain
Object("A")

r   )rT   r%   r,   s    r   r%   CompositeMorphism.domain_  s    * q!(((r   c                 4    U R                   S   R                  $ )al  
Returns the codomain of this composite morphism.

The codomain of the composite morphism is the codomain of its
last component.

Examples
========

>>> from sympy.categories import Object, NamedMorphism
>>> A = Object("A")
>>> B = Object("B")
>>> C = Object("C")
>>> f = NamedMorphism(A, B, "f")
>>> g = NamedMorphism(B, C, "g")
>>> (g * f).codomain
Object("C")

rZ   )rT   r&   r,   s    r   r&   CompositeMorphism.codomainv  s    * r"+++r   c                 D    [        U R                  U R                  U5      $ )a  
Forgets the composite structure of this morphism.

Explanation
===========

If ``new_name`` is not empty, returns a :class:`NamedMorphism`
with the supplied name, otherwise returns a :class:`Morphism`.
In both cases the domain of the new morphism is the domain of
this composite morphism and the codomain of the new morphism
is the codomain of this composite morphism.

Examples
========

>>> from sympy.categories import Object, NamedMorphism
>>> A = Object("A")
>>> B = Object("B")
>>> C = Object("C")
>>> f = NamedMorphism(A, B, "f")
>>> g = NamedMorphism(B, C, "g")
>>> (g * f).flatten("h")
NamedMorphism(Object("A"), Object("C"), "h")

)rF   r%   r&   )r-   new_names     r   flattenCompositeMorphism.flatten  s    4 T[[$--BBr   r   N)r   r   r   r   r   staticmethodrW   r'   r<   rT   r%   r&   rj   r   r   r   r   r4   r4      sc    > ' '.!9F  ( ) ), , ,,Cr   r4   c                   b    \ rS rSrSr\\4S jr\S 5       r\S 5       r	\S 5       r
S rS rS	rg
)Categoryi  a  
An (abstract) category.

Explanation
===========

A category [JoyOfCats] is a quadruple `\mbox{K} = (O, \hom, id,
\circ)` consisting of

* a (set-theoretical) class `O`, whose members are called
  `K`-objects,

* for each pair `(A, B)` of `K`-objects, a set `\hom(A, B)` whose
  members are called `K`-morphisms from `A` to `B`,

* for a each `K`-object `A`, a morphism `id:A\rightarrow A`,
  called the `K`-identity of `A`,

* a composition law `\circ` associating with every `K`-morphisms
  `f:A\rightarrow B` and `g:B\rightarrow C` a `K`-morphism `g\circ
  f:A\rightarrow C`, called the composite of `f` and `g`.

Composition is associative, `K`-identities are identities with
respect to composition, and the sets `\hom(A, B)` are pairwise
disjoint.

This class knows nothing about its objects and morphisms.
Concrete cases of (abstract) categories should be implemented as
classes derived from this one.

Certain instances of :class:`Diagram` can be asserted to be
commutative in a :class:`Category` by supplying the argument
``commutative_diagrams`` in the constructor.

Examples
========

>>> from sympy.categories import Object, NamedMorphism, Diagram, Category
>>> from sympy import FiniteSet
>>> A = Object("A")
>>> B = Object("B")
>>> C = Object("C")
>>> f = NamedMorphism(A, B, "f")
>>> g = NamedMorphism(B, C, "g")
>>> d = Diagram([f, g])
>>> K = Category("K", commutative_diagrams=[d])
>>> K.commutative_diagrams == FiniteSet(d)
True

See Also
========

Diagram
c                     U(       d  [        S5      e[        U[        5      (       d  [        U5      n[        U[        5      (       d  [        U5      n[        R
                  " XU[        U6 5      nU$ )Nz%A Category cannot have an empty name.)rI   rJ   r	   r   r   r'   r   )r$   rK   objectscommutative_diagramsnew_categorys        r   r'   Category.__new__  s_    DEE$$$t9D'5))GnG}}S%.0D%EGr   c                 4    U R                   S   R                  $ )z
Returns the name of this category.

Examples
========

>>> from sympy.categories import Category
>>> K = Category("K")
>>> K.name
'K'

r   rO   r,   s    r   rK   Category.name  s     yy|   r   c                      U R                   S   $ )a  
Returns the class of objects of this category.

Examples
========

>>> from sympy.categories import Object, Category
>>> from sympy import FiniteSet
>>> A = Object("A")
>>> B = Object("B")
>>> K = Category("K", FiniteSet(A, B))
>>> K.objects
Class({Object("A"), Object("B")})

r1   r*   r,   s    r   rp   Category.objects  s    " yy|r   c                      U R                   S   $ )a  
Returns the :class:`~.FiniteSet` of diagrams which are known to
be commutative in this category.

Examples
========

>>> from sympy.categories import Object, NamedMorphism, Diagram, Category
>>> from sympy import FiniteSet
>>> A = Object("A")
>>> B = Object("B")
>>> C = Object("C")
>>> f = NamedMorphism(A, B, "f")
>>> g = NamedMorphism(B, C, "g")
>>> d = Diagram([f, g])
>>> K = Category("K", commutative_diagrams=[d])
>>> K.commutative_diagrams == FiniteSet(d)
True

rN   r*   r,   s    r   rq   Category.commutative_diagrams  s    , yy|r   c                     [        S5      e)Nz)hom-sets are not implemented in Category.r"   )r-   ABs      r   homCategory.hom*  s    !79 	9r   c                     [        S5      e)Nz@Obtaining the class of morphisms is not implemented in Category.r"   r,   s    r   all_morphismsCategory.all_morphisms.  s    !NP 	Pr   r   N)r   r   r   r   r   r   r'   r<   rK   rp   rq   r}   r   r   r   r   r   rn   rn     s[    5l $,(  ! !  $  .9Pr   rn   c                       \ rS rSrSr\S 5       r\  SS j5       rS r\	S 5       r
\	S 5       r\	S 5       rS	 rS
 rS rSrg)Diagrami3  a  
Represents a diagram in a certain category.

Explanation
===========

Informally, a diagram is a collection of objects of a category and
certain morphisms between them.  A diagram is still a monoid with
respect to morphism composition; i.e., identity morphisms, as well
as all composites of morphisms included in the diagram belong to
the diagram.  For a more formal approach to this notion see
[Pare1970].

The components of composite morphisms are also added to the
diagram.  No properties are assigned to such morphisms by default.

A commutative diagram is often accompanied by a statement of the
following kind: "if such morphisms with such properties exist,
then such morphisms which such properties exist and the diagram is
commutative".  To represent this, an instance of :class:`Diagram`
includes a collection of morphisms which are the premises and
another collection of conclusions.  ``premises`` and
``conclusions`` associate morphisms belonging to the corresponding
categories with the :class:`~.FiniteSet`'s of their properties.

The set of properties of a composite morphism is the intersection
of the sets of properties of its components.  The domain and
codomain of a conclusion morphism should be among the domains and
codomains of the morphisms listed as the premises of a diagram.

No checks are carried out of whether the supplied object and
morphisms do belong to one and the same category.

Examples
========

>>> from sympy.categories import Object, NamedMorphism, Diagram
>>> from sympy import pprint, default_sort_key
>>> A = Object("A")
>>> B = Object("B")
>>> C = Object("C")
>>> f = NamedMorphism(A, B, "f")
>>> g = NamedMorphism(B, C, "g")
>>> d = Diagram([f, g])
>>> premises_keys = sorted(d.premises.keys(), key=default_sort_key)
>>> pprint(premises_keys, use_unicode=False)
[g*f:A-->C, id:A-->A, id:B-->B, id:C-->C, f:A-->B, g:B-->C]
>>> pprint(d.premises, use_unicode=False)
{g*f:A-->C: EmptySet, id:A-->A: EmptySet, id:B-->B: EmptySet,
 id:C-->C: EmptySet, f:A-->B: EmptySet, g:B-->C: EmptySet}
>>> d = Diagram([f, g], {g * f: "unique"})
>>> pprint(d.conclusions,use_unicode=False)
{g*f:A-->C: {unique}}

References
==========

[Pare1970] B. Pareigis: Categories and functors.  Academic Press, 1970.

c                 *    X;   a
  X   U-  X'   gX U'   g)z
If ``key`` is in ``dictionary``, set the new value of ``key``
to be the union between the old value and ``value``.
Otherwise, set the value of ``key`` to ``value.

Returns ``True`` if the key already was in the dictionary and
``False`` otherwise.
TFr   )
dictionarykeyvalues      r   _set_dict_unionDiagram._set_dict_unionp  s%     (o5JO#sOr   c                    [         R                  XU5      (       Gdj  [        U[        5      (       a  U(       a  [	        S5      egU(       a\  [
        n[        UR                  5      n[        UR                  5      n[         R                  XU5        [         R                  XU5        [        U R                  5       5       Hs  u  pX-  n
UR                  UR                  :X  a  X-  n[         R                  XU
5        UR                  UR                  :X  d  MY  X-  n[         R                  XU
5        Mu     [        U[        5      (       a9  U(       a1  [
        nUR                   H  n[         R                  XUU5        M     gggg)z
Adds a morphism and its attributes to the supplied dictionary
``morphisms``.  If ``add_identities`` is True, also adds the
identity morphisms for the domain and the codomain of
``morphism``.
z5Instances of IdentityMorphism cannot have properties.N)r   r   rJ   r>   rI   r   r%   r&   listitemsr4   rT   _add_morphism_closure)	morphismsrV   propsadd_identitiesrecurse_compositesemptyid_domid_codexisting_morphismexisting_props	new_propsleftright	components                 r   r   Diagram._add_morphism_closure  sR    &&yEBB ($455 %OQ Q )(//:)(*;*;<''	5A''	5A59)//:K5L1!*2	??&7&@&@@#7D++IYG$$(9(@(@@-8E++IiH 6M ($566;M !!)!4!4I11)2@B "5	 <N6A Cr   c           	         0 n0 n[         n[        U5      S:  a  US   n[        U[        5      (       aI  [         nU H<  nU[	        UR
                  UR                  5      -  n[        R                  X'U5        M>     O[        U[        [        45      (       as  UR                  5        H_  u  pxU[	        UR
                  UR                  5      -  n[        R                  X'[        U5      (       a  [	        U6 O
[	        U5      5        Ma     [        U5      S:  Ga=  US   n	[        U	[        5      (       a  [         nU	 H  n[        UR                  UR
                  5      5      [        R                   L d  M:  [        UR                  UR                  5      5      [        R                   L d  Mq  [        R                  X7USSS9  M     O[        U	[        [        45      (       at  U	R                  5        H`  u  pxUR
                  U;   d  M  UR                  U;   d  M)  [        R                  X7[        U5      (       a  [	        U6 O
[	        U5      SSS9  Mb     ["        R$                  " U [        U5      [        U5      U5      $ )a  
Construct a new instance of Diagram.

Explanation
===========

If no arguments are supplied, an empty diagram is created.

If at least an argument is supplied, ``args[0]`` is
interpreted as the premises of the diagram.  If ``args[0]`` is
a list, it is interpreted as a list of :class:`Morphism`'s, in
which each :class:`Morphism` has an empty set of properties.
If ``args[0]`` is a Python dictionary or a :class:`Dict`, it
is interpreted as a dictionary associating to some
:class:`Morphism`'s some properties.

If at least two arguments are supplied ``args[1]`` is
interpreted as the conclusions of the diagram.  The type of
``args[1]`` is interpreted in exactly the same way as the type
of ``args[0]``.  If only one argument is supplied, the diagram
has no conclusions.

Examples
========

>>> from sympy.categories import Object, NamedMorphism
>>> from sympy.categories import IdentityMorphism, Diagram
>>> A = Object("A")
>>> B = Object("B")
>>> C = Object("C")
>>> f = NamedMorphism(A, B, "f")
>>> g = NamedMorphism(B, C, "g")
>>> d = Diagram([f, g])
>>> IdentityMorphism(A) in d.premises.keys()
True
>>> g * f in d.premises.keys()
True
>>> d = Diagram([f, g], {g * f: "unique"})
>>> d.conclusions[g * f]
{unique}

r1   r   rN   F)r   r   )r   r]   rJ   r   r   r%   r&   r   r   dictr   r   r   r   containsr   truer   r'   )
r$   r+   premisesconclusionsrp   premises_argr   rV   r   conclusions_args
             r   r'   Diagram.__new__  s   V  t9>7L,-- ! ,Hy(:K:KLLG11(eL !- L4,77 (4'9'9';OHy(:K:KLLG11 %Iu,=V_`eVfh (<
 t9>"1gO/400 ! /H !1!1(//!BCqvvM !1!1(2C2C!DEO  55'5/4 6 6 !0 OdD\:: (7'<'<'>OH 72 ))W4  55'QV9e3D]fgl]m+0U 6 L (? }}S$x.${2CWMMr   c                      U R                   S   $ )a  
Returns the premises of this diagram.

Examples
========

>>> from sympy.categories import Object, NamedMorphism
>>> from sympy.categories import IdentityMorphism, Diagram
>>> from sympy import pretty
>>> A = Object("A")
>>> B = Object("B")
>>> f = NamedMorphism(A, B, "f")
>>> id_A = IdentityMorphism(A)
>>> id_B = IdentityMorphism(B)
>>> d = Diagram([f])
>>> print(pretty(d.premises, use_unicode=False))
{id:A-->A: EmptySet, id:B-->B: EmptySet, f:A-->B: EmptySet}

r   r*   r,   s    r   r   Diagram.premises  s    * yy|r   c                      U R                   S   $ )a  
Returns the conclusions of this diagram.

Examples
========

>>> from sympy.categories import Object, NamedMorphism
>>> from sympy.categories import IdentityMorphism, Diagram
>>> from sympy import FiniteSet
>>> A = Object("A")
>>> B = Object("B")
>>> C = Object("C")
>>> f = NamedMorphism(A, B, "f")
>>> g = NamedMorphism(B, C, "g")
>>> d = Diagram([f, g])
>>> IdentityMorphism(A) in d.premises.keys()
True
>>> g * f in d.premises.keys()
True
>>> d = Diagram([f, g], {g * f: "unique"})
>>> d.conclusions[g * f] == FiniteSet("unique")
True

r1   r*   r,   s    r   r   Diagram.conclusions0  s    4 yy|r   c                      U R                   S   $ )ak  
Returns the :class:`~.FiniteSet` of objects that appear in this
diagram.

Examples
========

>>> from sympy.categories import Object, NamedMorphism, Diagram
>>> A = Object("A")
>>> B = Object("B")
>>> C = Object("C")
>>> f = NamedMorphism(A, B, "f")
>>> g = NamedMorphism(B, C, "g")
>>> d = Diagram([f, g])
>>> d.objects
{Object("A"), Object("B"), Object("C")}

rN   r*   r,   s    r   rp   Diagram.objectsL  s    ( yy|r   c                 l   [         n[         nU R                  R                  5        H5  nUR                  U:X  d  M  UR                  U:X  d  M'  U[        U5      -  nM7     U R                  R                  5        H5  nUR                  U:X  d  M  UR                  U:X  d  M'  U[        U5      -  nM7     X44$ )a3  
Returns a 2-tuple of sets of morphisms between objects ``A`` and
``B``: one set of morphisms listed as premises, and the other set
of morphisms listed as conclusions.

Examples
========

>>> from sympy.categories import Object, NamedMorphism, Diagram
>>> from sympy import pretty
>>> A = Object("A")
>>> B = Object("B")
>>> C = Object("C")
>>> f = NamedMorphism(A, B, "f")
>>> g = NamedMorphism(B, C, "g")
>>> d = Diagram([f, g], {g * f: "unique"})
>>> print(pretty(d.hom(A, C), use_unicode=False))
({g*f:A-->C}, {g*f:A-->C})

See Also
========
Object, Morphism
)r   r   keysr%   r&   r   r   )r-   r{   r|   r   r   rV   s         r   r}   Diagram.homb  s    0 **,H1$8+<+<+AIh// - ((--/H1$8+<+<+Ay22 0 &&r   c                    ^ ^ [        UU 4S jTR                   5       5      nU(       d  g[        UU 4S jTR                   5       5      nU$ )aw  
Checks whether ``diagram`` is a subdiagram of ``self``.
Diagram `D'` is a subdiagram of `D` if all premises
(conclusions) of `D'` are contained in the premises
(conclusions) of `D`.  The morphisms contained
both in `D'` and `D` should have the same properties for `D'`
to be a subdiagram of `D`.

Examples
========

>>> from sympy.categories import Object, NamedMorphism, Diagram
>>> A = Object("A")
>>> B = Object("B")
>>> C = Object("C")
>>> f = NamedMorphism(A, B, "f")
>>> g = NamedMorphism(B, C, "g")
>>> d = Diagram([f, g], {g * f: "unique"})
>>> d1 = Diagram([f])
>>> d.is_subdiagram(d1)
True
>>> d1.is_subdiagram(d)
False
c              3      >#    U  H:  nUTR                   ;   =(       a    TR                   U   TR                   U   :H  v   M<     g 7frA   )r   .0mdiagramr-   s     r   	<genexpr>(Diagram.is_subdiagram.<locals>.<genexpr>  sI      2 01 T]]* A((+t}}Q/??A 0   AAFc              3      >#    U  H:  nUTR                   ;   =(       a    TR                   U   TR                   U   :H  v   M<     g 7frA   )r   r   s     r   r   r     sM      8#6a  0 00 J"..q1T5E5Ea5HHJ#6r   )allr   r   )r-   r   r   r   s   ``  r   is_subdiagramDiagram.is_subdiagram  sO    2  2 ' 0 02 2  8#*#6#68 8
 r   c                    UR                  U R                  5      (       d  [        S5      e0 nU R                  R	                  5        Hw  u  p4[        UR                  UR                  5      5      [        R                  L d  M<  [        UR                  UR                  5      5      [        R                  L d  Ms  XBU'   My     0 nU R                  R	                  5        Hw  u  p4[        UR                  UR                  5      5      [        R                  L d  M<  [        UR                  UR                  5      5      [        R                  L d  Ms  XEU'   My     [        X%5      $ )ar  
If ``objects`` is a subset of the objects of ``self``, returns
a diagram which has as premises all those premises of ``self``
which have a domains and codomains in ``objects``, likewise
for conclusions.  Properties are preserved.

Examples
========

>>> from sympy.categories import Object, NamedMorphism, Diagram
>>> from sympy import FiniteSet
>>> A = Object("A")
>>> B = Object("B")
>>> C = Object("C")
>>> f = NamedMorphism(A, B, "f")
>>> g = NamedMorphism(B, C, "g")
>>> d = Diagram([f, g], {f: "unique", g*f: "veryunique"})
>>> d1 = d.subdiagram_from_objects(FiniteSet(A, B))
>>> d1 == Diagram([f], {f: "unique"})
True
z2Supplied objects should all belong to the diagram.)	is_subsetrp   rI   r   r   r   r   r%   r   r   r&   r   r   )r-   rp   new_premisesrV   r   new_conclusionss         r   subdiagram_from_objectsDiagram.subdiagram_from_objects  s   ,   ..DF F #}}224OH))(//:;qvvE))(*;*;<=G).X&  5
 #//557OH))(//:;qvvE))(*;*;<=G,1)  8
 |55r   r   N)TT)r   r   r   r   r   rl   r   r   r'   r<   r   r   rp   r}   r   r   r   r   r   r   r   r   3  s    ;x    IM15.B .B`eNN  ,  6  *"'H$L&6r   r   N)
sympy.corer   r   r   r   r   r   sympy.core.symbolr	   
sympy.setsr
   r   r   sympy.utilities.iterablesr   r   r   r   r>   rF   r4   rn   r   r   r   r   <module>r      s    = = ! / / .C &
V 
h#u h#V"x "J5!H 5!pxC xCvFPu FPR_6e _6r   