import vcsn
import pandas as pd
pd.options.display.max_colwidth = 0

a = vcsn.B.expression('ab*c').standard()
a

a.expression(algo = "naive")

a.expression(algo = "best")

"""
Explanation: automaton.expression(identities="default",algo="auto")
Apply the Brzozowski-McCluskey procedure, to compute a (basic) expression from an automaton.
Arguments:
- identities: the identities of the resulting expression
- algo: a heuristics to choose the order in which states are eliminated
  - "auto": same as "best"
  - "best": run all the heuristics, and return the shortest result
  - "naive": a simple heuristics which eliminates states with few incoming/outgoing transitions
  - "delgado": choose a state whose removal would add a small expression (number of nodes) to the result
  - "delgado_label": choose a state whose removal would add a small expression (number of labels in the expression) to the result
See also:
- automaton.eliminate_state
- automaton.lift
Examples
End of explanation
"""


def latex(e):
    return '$' + e.format('latex') + '$'
def example(*es):
    res = [[latex(e),
            latex(e.standard().expression(algo="naive")),
            latex(e.derived_term().expression(algo="naive"))]
           for e in [vcsn.Q.expression(e) for e in es]]
    return pd.DataFrame(res, columns=['Input', 'Via Standard', 'Via Derived Term'])
example('a', 'a+b+a', 'a+b+a', 'ab*c', '[ab]{2}')

"""
Explanation: Unfortunately there is no guarantee that the resulting expression is as simple as one could hope for.  Note also that expression.derived_term tends to build automata which give nicer results than expression.standard.
End of explanation
"""


a

a.expression('trivial')

a.expression('linear')

"""
Explanation: Identities
You may pass the desired identities as an argument.
End of explanation
"""


