
    sg                     8    d Z ddlmZ ddlmZmZ  G d d      Zy)a(  

Module for the DomainScalar class.

A DomainScalar represents an element which is in a particular
Domain. The idea is that the DomainScalar class provides the
convenience routines for unifying elements with different domains.

It assists in Scalar Multiplication and getitem for DomainMatrix.

   )construct_domain    )DomainZZc                        e Zd ZdZd Ze fd       Zd Zed        Zd Z	d Z
d Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z xZS )DomainScalarz
    docstring
    c                     t        |t              st        d      |j                  |      st        d|d|      | j	                  ||      S )Nzdomain should be of type Domainzelement z should be in domain )
isinstancer   	TypeErrorof_typenew)clselementdomains      T/var/www/html/venv/lib/python3.12/site-packages/sympy/polys/matrices/domainscalar.py__new__zDomainScalar.__new__   sE    &&)=>>~~g&7FSTTwww''    c                 B    t         |   |       }||_        ||_        |S N)superr   r   r   )r   r   r   obj	__class__s       r   r   zDomainScalar.new   s$    goc"

r   c                 ,    t        | j                        S r   )reprr   selfs    r   __repr__zDomainScalar.__repr__$       DLL!!r   c                 H    t        |g      \  }\  }| j                  ||      S r   )r   r   )r   exprr   r   s       r   
from_sympyzDomainScalar.from_sympy'   s&    .v6'www''r   c                 L    | j                   j                  | j                        S r   )r   to_sympyr   r   s    r   r#   zDomainScalar.to_sympy,   s    {{##DLL11r   c                 r    |j                  | j                  | j                        }| j                  ||      S r   )convert_fromr   r   r   )r   r   r   s      r   	to_domainzDomainScalar.to_domain/   s-    %%dllDKK@xx((r   c                 $    | j                  |      S r   )r&   )r   r   s     r   
convert_tozDomainScalar.convert_to3   s    ~~f%%r   c                     | j                   j                  |j                         }| j                  |      |j                  |      fS r   )r   unifyr&   )r   otherr   s      r   r*   zDomainScalar.unify6   s7    ""5<<0~~f%uv'>>>r   c                 ,    t        | j                        S r   )boolr   r   s    r   __bool__zDomainScalar.__bool__:   r   r   c                     t        |t              st        S | j                  |      \  } }| j	                  | j
                  |j
                  z   | j                        S r   r
   r   NotImplementedr*   r   r   r   r   r+   s     r   __add__zDomainScalar.__add__=   F    %.!!jj'exxu}}4dkkBBr   c                     t        |t              st        S | j                  |      \  } }| j	                  | j
                  |j
                  z
  | j                        S r   r0   r2   s     r   __sub__zDomainScalar.__sub__C   r4   r   c                    t        |t              s0t        |t              rt        t        |      t              }nt        S | j                  |      \  } }| j                  | j                  |j                  z  | j                        S r   )	r
   r   intr   r1   r*   r   r   r   r2   s     r   __mul__zDomainScalar.__mul__I   s`    %.%%$RY3%%jj'exxu}}4dkkBBr   c                     t        |t              st        S | j                  |      \  } }| j	                  | j
                  j                  | j                  |j                        | j
                        S r   )r
   r   r1   r*   r   r   quor   r2   s     r   __floordiv__zDomainScalar.__floordiv__S   P    %.!!jj'exxemmDdkkRRr   c                     t        |t              st        S | j                  |      \  } }| j	                  | j
                  j                  | j                  |j                        | j
                        S r   )r
   r   r1   r*   r   r   remr   r2   s     r   __mod__zDomainScalar.__mod__Y   r=   r   c                 ,   t        |t              st        S | j                  |      \  } }| j                  j                  | j                  |j                        \  }}| j                  || j                        | j                  || j                        fS r   )r
   r   r1   r*   r   divr   r   )r   r+   qrs       r   
__divmod__zDomainScalar.__divmod___   sm    %.!!jj'e{{t||U]];1DKK($((1dkk*BCCr   c                     t        |t              st        S | j                  | j                  |z  | j
                        S r   )r
   r8   r1   r   r   r   )r   ns     r   __pow__zDomainScalar.__pow__f   s/    !S!!!xxa55r   c                 P    | j                  | j                  | j                        S r   r   r   r   r   s    r   __pos__zDomainScalar.__pos__k       xxt{{33r   c                 P    | j                  | j                   | j                        S r   rJ   r   s    r   __neg__zDomainScalar.__neg__n   rL   r   c                     t        |t              st        S | j                  |j                  k(  xr | j                  |j                  k(  S r   )r
   r   r1   r   r   r2   s     r   __eq__zDomainScalar.__eq__q   s7    %.!!||u}},L1LLr   c                 H    | j                   | j                  j                  k(  S r   )r   r   zeror   s    r   is_zerozDomainScalar.is_zerov   s    ||t{{////r   c                 H    | j                   | j                  j                  k(  S r   )r   r   oner   s    r   is_onezDomainScalar.is_oney   s    ||t{{..r   )__name__
__module____qualname____doc__r   classmethodr   r   r!   r#   r&   r(   r*   r.   r3   r6   r9   r<   r@   rE   rH   rK   rN   rP   rS   rV   __classcell__)r   s   @r   r   r      s    (  " ( (2)&?"CCCSSD6
44M
0/r   r   N)rZ   constructorr   sympy.polys.domainsr   r   r    r   r   <module>r`      s   
 + *i/ i/r   