(e)
If ``e`` is a sum that can be written as ``g*(a + s)`` where
    ``s`` is ``+/-1``, return ``g``, ``a``, and ``s`` where ``a`` does
    not have a leading negative coefficient.

    Examples
    ========

    >>> from sympy.simplify.fu import as_f_sign_1
    >>> from sympy.abc import x
    >>> as_f_sign_1(x + 1)
    (1, x, 1)
    >>> as_f_sign_1(x - 1)
    (1, x, -1)
    >>> as_f_sign_1(-x + 1)
    (-1, x, -1)
    >>> as_f_sign_1(-x - 1)
    (-1, x, 1)
    >>> as_f_sign_1(2*x + 2)
    (2, x, 1)
If ``e`` is a sum that can be written as ``g*(a + s)`` where
    ``s`` is ``+/-1``, return ``g``, ``a``, and ``s`` where ``a`` does
    not have a leading negative coefficient.
If e is a sum that can be written as g * ( a + s ) where s is + / - 1 return g a and s where a does not have a leading negative coefficient .
def as_f_sign_1(e):
    """If ``e`` is a sum that can be written as ``g*(a + s)`` where
    ``s`` is ``+/-1``, return ``g``, ``a``, and ``s`` where ``a`` does
    not have a leading negative coefficient.

    Examples
    ========

    >>> from sympy.simplify.fu import as_f_sign_1
    >>> from sympy.abc import x
    >>> as_f_sign_1(x + 1)
    (1, x, 1)
    >>> as_f_sign_1(x - 1)
    (1, x, -1)
    >>> as_f_sign_1(-x + 1)
    (-1, x, -1)
    >>> as_f_sign_1(-x - 1)
    (-1, x, 1)
    >>> as_f_sign_1(2*x + 2)
    (2, x, 1)
    """
    if not e.is_Add or len(e.args) != 2:
        return
    # exact match
    a, b = e.args
    if a in (S.NegativeOne, S.One):
        g = S.One
        if b.is_Mul and b.args[0].is_Number and b.args[0] < 0:
            a, b = -a, -b
            g = -g
        return g, b, a
    # gcd match
    a, b = [Factors(i) for i in e.args]
    ua, ub = a.normal(b)
    gcd = a.gcd(b).as_expr()
    if S.NegativeOne in ua.factors:
        ua = ua.quo(S.NegativeOne)
        n1 = -1
        n2 = 1
    elif S.NegativeOne in ub.factors:
        ub = ub.quo(S.NegativeOne)
        n1 = 1
        n2 = -1
    else:
        n1 = n2 = 1
    a, b = [i.as_expr() for i in (ua, ub)]
    if a is S.One:
        a, b = b, a
        n1, n2 = n2, n1
    if n1 == -1:
        gcd = -gcd
        n2 = -n2

    if b is S.One:
        return gcd, a, n2
def as_f_sign_1 ( e ) : if not e . is_Add or len ( e . args ) != 2 : return # exact match a , b = e . args if a in ( S . NegativeOne , S . One ) : g = S . One if b . is_Mul and b . args [ 0 ] . is_Number and b . args [ 0 ] < 0 : a , b = - a , - b g = - g return g , b , a # gcd match a , b = [ Factors ( i ) for i in e . args ] ua , ub = a . normal ( b ) gcd = a . gcd ( b ) . as_expr ( ) if S . NegativeOne in ua . factors : ua = ua . quo ( S . NegativeOne ) n1 = - 1 n2 = 1 elif S . NegativeOne in ub . factors : ub = ub . quo ( S . NegativeOne ) n1 = 1 n2 = - 1 else : n1 = n2 = 1 a , b = [ i . as_expr ( ) for i in ( ua , ub ) ] if a is S . One : a , b = b , a n1 , n2 = n2 , n1 if n1 == - 1 : gcd = - gcd n2 = - n2 if b is S . One : return gcd , a , n2