import vcsn
def aut(e, ctx_exp):
    ctx = vcsn.context(ctx_exp)
    return ctx.expression(e).standard()

"""
Explanation: automaton.has_negative_cycle
Whether an automaton has negative cycles (i.e. contains at least one negative path between a state and itself).
Uses the Bellman-Ford algorithm.
End of explanation
"""


aut('\e', 'lal_char, zmin').has_negative_cycle()

aut('(<-1>a)*', 'lal_char, zmin').has_negative_cycle()

aut('a*', 'lal_char, zmin').has_negative_cycle()

"""
Explanation: Examples
In tropical weightsets
Negative loops can appear when the weight of the path from a state to itself is negative.
End of explanation
"""


aut('(<0.5>a)*', 'lal_char, r').has_negative_cycle()

aut('(<1.5>a)*', 'lal_char, r').has_negative_cycle()

"""
Explanation: In regular weightsets
Negative loops can appear when the weight of the path from a state to itself is between 0 and 1.
End of explanation
"""


