§
    PŠtjº  ã                   ót   — d dl mZ d dlmZmZ d dlmZ d dlmc m	Z	 d dlm
Z
 efd„Zefd„Ze
fd„Zefd	„ZdS )
é    )Úpartial)ÚchainÚminimize)ÚidentityN)Úyieldifyc           
      ó¢   — |D ]B}t          | |¦  «        r0 ||         t          t          t          ||¬¦  «        | ¦  «        Ž c S ŒC || ¦  «        S )a�   Apply functions onto recursive containers (tree).

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

    join - a dictionary mapping container types to functions
      e.g. ``{list: minimize, tuple: chain}``

    Keys are containers/iterables.  Values are functions [a] -> a.

    Examples
    ========

    >>> from sympy.strategies.tree import treeapply
    >>> tree = [(3, 2), (4, 1)]
    >>> treeapply(tree, {list: max, tuple: min})
    2

    >>> add = lambda *args: sum(args)
    >>> def mul(*args):
    ...     total = 1
    ...     for arg in args:
    ...         total *= arg
    ...     return total
    >>> treeapply(tree, {list: mul, tuple: add})
    25
    )ÚjoinÚleaf)Ú
isinstanceÚmapr   Ú	treeapply)Útreer	   r
   Útyps       úS/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sympy/strategies/tree.pyr   r      sw   € ð8 ð )ð )ˆÝ�d˜CÑ Ô ð 	)Ø�4˜”9�c¥'­)¸$ÀTÐ"JÑ"JÔ"JØ"&ñ(ô (ð )ð )ð )ð )ð	)ð ˆ4�‰:Œ:Ðó    c                 óp   — t          t          |¬¦  «        }t          | t          |t          t
          ifi |¤ŽS )aÕ   Execute a strategic tree.  Select alternatives greedily

    Trees
    -----

    Nodes in a tree can be either

    function - a leaf
    list     - a selection among operations
    tuple    - a sequence of chained operations

    Textual examples
    ----------------

    Text: Run f, then run g, e.g. ``lambda x: g(f(x))``
    Code: ``(f, g)``

    Text: Run either f or g, whichever minimizes the objective
    Code: ``[f, g]``

    Textx: Run either f or g, whichever is better, then run h
    Code: ``([f, g], h)``

    Text: Either expand then simplify or try factor then foosimp. Finally print
    Code: ``([(expand, simplify), (factor, foosimp)], print)``

    Objective
    ---------

    "Better" is determined by the objective keyword.  This function makes
    choices to minimize the objective.  It defaults to the identity.

    Examples
    ========

    >>> from sympy.strategies.tree import greedy
    >>> inc    = lambda x: x + 1
    >>> dec    = lambda x: x - 1
    >>> double = lambda x: 2*x

    >>> tree = [inc, (dec, double)] # either inc or dec-then-double
    >>> fn = greedy(tree)
    >>> fn(4)  # lowest value comes from the inc
    5
    >>> fn(1)  # lowest value comes from dec then double
    0

    This function selects between options in a tuple.  The result is chosen
    that minimizes the objective function.

    >>> fn = greedy(tree, objective=lambda x: -x)  # maximize
    >>> fn(4)  # highest value comes from the dec then double
    6
    >>> fn(1)  # highest value comes from the inc
    2

    Greediness
    ----------

    This is a greedy algorithm.  In the example:

        ([a, b], c)  # do either a or b, then do c

    the choice between running ``a`` or ``b`` is made without foresight to c
    )Ú	objective)r   r   r   ÚlistÚtupler   )r   r   ÚkwargsÚoptimizes       r   Úgreedyr   +   s8   € õD •x¨9Ð5Ñ5Ô5€HÝ�T�D (­Eµ5Ð9ÐDÐD¸VÐDÐDÐDr   c                 ój   — t          | t          t          j        t          t          j        i|¬¦  «        S )aœ   Execute a strategic tree.  Return all possibilities.

    Returns a lazy iterator of all possible results

    Exhaustiveness
    --------------

    This is an exhaustive algorithm.  In the example

        ([a, b], [c, d])

    All of the results from

        (a, c), (b, c), (a, d), (b, d)

    are returned.  This can lead to combinatorial blowup.

    See sympy.strategies.greedy for details on input
    )r
   )r   r   ÚbranchÚ	multiplexr   r   )r   r
   s     r   Ú
allresultsr   q   s0   € õ( �T�D¥&Ô"2µE½6¼<ÐHØð ñ  ô  ð  r   c                 ó   ‡ ‡‡— ˆˆˆ fd„S )Nc           
      óh   •— t          t           t          ‰fi ‰¤Ž| ¦  «        ¦  «        ‰¬¦  «        S )N)Úkey)Úminr   r   )Úexprr   r   r   s    €€€r   ú<lambda>zbrute.<locals>.<lambda>Š   s>   ø€ ��EÐ"<¥*¨TÐ"<Ð"<°VÐ"<Ð"<¸TÑ"BÔ"BÑCÔCØ )ð+ñ +ô +€ r   © )r   r   r   s   ```r   Úbruter$   ‰   s(   øøø€ ð+ð +ð +ð +ð +ð +ð +r   )Ú	functoolsr   Úsympy.strategiesr   r   Úsympy.strategies.corer   Úsympy.strategies.branchÚ
strategiesr   r   r   r   r   r$   r#   r   r   ú<module>r*      sæ   ðØ Ð Ð Ð Ð Ð Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø *Ð *Ð *Ð *Ð *Ð *Ø (Ð (Ð (Ð (Ð (Ð (Ð (Ð (Ð (Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,ð  (ð  ð  ð  ð  ðF $ð CEð CEð CEð CEðL #ð  ð  ð  ð  ð0 #ð +ð +ð +ð +ð +ð +r   