human
Complete this python program:
def best_origin(a, b, lineseg, expr):
assistant
#Here is the Python program you requested.

    """Helper method for polytope_integrate.
    Returns a point on the lineseg whose vector inner product with the
    divergence of `expr` yields an expression with the least maximum
    total power.
    Parameters
    a : Hyperplane parameter denoting direction.
    b : Hyperplane parameter denoting distance.
    lineseg : Line segment on which to find the origin.
    expr : The expression which determines the best point.
    Algorithm(currently works only for 2D use case)
    1 > Firstly, check for edge cases. Here that would refer to vertical
    or horizontal lines.
    2 > If input expression is a polynomial containing more than one generator
    then find out the total power of each of the generators.
    x**2 + 3 + x*y + x**4*y**5 ---> {x: 7, y: 6}
    If expression is a constant value then pick the first boundary point
    of the line segment.
    3 > First check if a point exists on the line segment where the value of
    the highest power generator becomes 0. If not check if the value of
    the next highest becomes 0. If none becomes 0 within line segment
    constraints then pick the first boundary point of the line segement.
    Actually, any point lying on the segment can be picked as best origin
    in the last case.
    Examples
    >>> from sympy.integrals.intpoly import best_origin
    >>> from sympy.abc import x, y
    >>> from sympy.geometry.line import Segment2D
    >>> from sympy.geometry.point import Point
    >>> l = Segment2D(Point(0, 3), Point(1, 1))
    >>> expr = x**3*y**7
    >>> best_origin((2, 1), 3, l, expr)
    (0, 3.0)
    """
    (a1, b1) = lineseg.points[0]
    def x_axis_cut(ls):
        'Returns    the    point    where    the    input    line    segment\n                                intersects    the    x-axis.\n                                Parameters:\n                                ===========\n                                ls    :    Line    segment\n                                '
        (p, q) = ls.points
        if (p.y == S.Zero):
            return tuple(p)
        elif (q.y == S.Zero):
            return tuple(q)
        elif ((p.y / q.y) < S.Zero):
            return ((((p.y * (p.x - q.x)) / (q.y - p.y)) + p.x), S.Zero)
        else:
            return ()
    def y_axis_cut(ls):
        'Returns    the    point    where    the    input    line    segment\n                                intersects    the    y-axis.\n                                Parameters:\n                                ===========\n                                ls    :    Line    segment\n                                '
        (p, q) = ls.points
        if (p.x == S.Zero):
            return tuple(p)
        elif (q.x == S.Zero):
            return tuple(q)
        elif ((p.x / q.x) < S.Zero):
            return (S.Zero, (((p.x * (p.y - q.y)) / (q.x - p.x)) + p.y))
        else:
            return ()
    gens = (x, y)
    power_gens = {}
    for i in gens:
        power_gens[i] = S.Zero
    if (len(gens) > 1):
        if (len(gens) == 2):
            if (a[0] == S.Zero):
                if y_axis_cut(lineseg):
                    return (S.Zero, (b / a[1]))
                else:
                    return (a1, b1)
            elif (a[1] == S.Zero):
                if x_axis_cut(lineseg):
                    return ((b / a[0]), S.Zero)
                else:
                    return (a1, b1)
        if isinstance(expr, Expr):
            if expr.is_Add:
                for monomial in expr.args:
                    if monomial.is_Pow:
                        if (monomial.args[0] in gens):
                           ...