Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 45894
Kernel: Python 3

expression.info(key=None)

A dictionary of facts about an expression.

The keys of the dictionary are:

  • length, size: the number of nodes in the syntax tree

  • width, atom: the number of letter occurrences

  • depth: the depth of the syntax tree (the depth of aa is 0, not 1)

  • type: the implementation type

  • add, complement, etc.: the number of occurrences of these operators (+, {c}, etc.) in the expression

Arguments:

  • key: if specified, return just the corresponding result.

See also:

Examples

import vcsn e = vcsn.Q.expression('[ab]*a[ab]') e

(a+b)a(a+b)\left(a + b\right)^{*} \, a \, \left(a + b\right)

e.SVG()
Image in a Jupyter notebook
e.info()
{'add': 2, 'atom': 5, 'complement': 0, 'compose': 0, 'conjunction': 0, 'depth': 3, 'infiltrate': 0, 'ldivide': 0, 'length': 10, 'lweight': 0, 'mul': 1, 'one': 0, 'rweight': 0, 'shuffle': 0, 'size': 10, 'star': 1, 'transposition': 0, 'tuple': 0, 'type': 'expressionset<letterset<char_letters(ab)>, q>', 'width': 5, 'zero': 0}
e.info('type')
'expressionset<letterset<char_letters(ab)>, q>'

Note that, although the expression uses a variadic product (the . node features three children), the length corresponds to the usual definition of expressions based on binary node. Hence the tree features 9 nodes, but the length of the expression is 10. This applies to all the variadic operators.

e.info('length')
10
e.info('depth')
3
e = vcsn.Q.expression('[ab]*a[ab]{2} & [ab]*a[ab]{4}') e

(a+b)a(a+b)2&(a+b)a(a+b)4\left(a + b\right)^{*} \, a \, \left(a + b\right)^{2} \& \left(a + b\right)^{*} \, a \, \left(a + b\right)^{4}

e.SVG()
Image in a Jupyter notebook
e.info()
{'add': 8, 'atom': 18, 'complement': 0, 'compose': 0, 'conjunction': 1, 'depth': 4, 'infiltrate': 0, 'ldivide': 0, 'length': 37, 'lweight': 0, 'mul': 2, 'one': 0, 'rweight': 0, 'shuffle': 0, 'size': 37, 'star': 2, 'transposition': 0, 'tuple': 0, 'type': 'expressionset<letterset<char_letters(ab)>, q>', 'width': 18, 'zero': 0}
vcsn.Q.expression('[ab]a[ab]').info()
{'add': 2, 'atom': 5, 'complement': 0, 'compose': 0, 'conjunction': 0, 'depth': 2, 'infiltrate': 0, 'ldivide': 0, 'length': 9, 'lweight': 0, 'mul': 1, 'one': 0, 'rweight': 0, 'shuffle': 0, 'size': 9, 'star': 0, 'transposition': 0, 'tuple': 0, 'type': 'expressionset<letterset<char_letters(ab)>, q>', 'width': 5, 'zero': 0}