#NEWLINE# def parse_mul_tree( root ) : #NEWLINE# #INDENT# '\n    Parse a tree of multiplications starting at the given root.\n\n    Parameters\n    ----------\n    root\n        The variable at the root of the tree.\n\n    Returns\n    -------\n    object\n        A tree where each non-leaf node corresponds to a multiplication\n        in the computation of `root`, represented by the list of its inputs.\n        Each input is a pair [n, x] with `n` a boolean value indicating whether\n        sub-tree `x` should be negated.\n\n    Examples\n    --------\n        x * y               -> [False, [[False, x], [False, y]]]\n        -(x * y)            -> [True, [[False, x], [False, y]]]\n        -x * y              -> [False, [[True, x], [False, y]]]\n        -x                  -> [True, x]\n        (x * y) * -z        -> [False, [[False, [[False, x], [False, y]]],\n                                        [True, z]]]\n\n    ' #NEWLINE# mul_info = is_mul ( root ) #NEWLINE# if ( mul_info is None ) : #NEWLINE# #INDENT# neg_info = is_neg ( root ) #NEWLINE# if ( neg_info is None ) : #NEWLINE# #INDENT# return [ False , root ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ( neg , sub_tree ) = parse_mul_tree ( neg_info ) #NEWLINE# return [ ( not neg ) , sub_tree ] #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# return [ False , list ( map ( parse_mul_tree , mul_info ) ) ]