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 $a$ 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

In [1]:
import vcsn
e = vcsn.Q.expression('[ab]*a[ab]')
e
Out[1]:
$\left(a + b\right)^{*} \, a \, \left(a + b\right)$
In [2]:
e.SVG()
Out[2]:
%3 3 a 4 b 2 + 2->3 2->4 1 * 1->2 5 a 7 a 8 b 6 + 6->7 6->8 0 . 0->1 0->5 0->6
In [3]:
e.info()
Out[3]:
{'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}
In [4]:
e.info('type')
Out[4]:
'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.

In [5]:
e.info('length')
Out[5]:
10
In [6]:
e.info('depth')
Out[6]:
3
In [7]:
e = vcsn.Q.expression('[ab]*a[ab]{2} & [ab]*a[ab]{4}')
e
Out[7]:
$\left(a + b\right)^{*} \, a \, \left(a + b\right)^{2} \& \left(a + b\right)^{*} \, a \, \left(a + b\right)^{4}$
In [8]:
e.SVG()
Out[8]:
%3 4 a 5 b 3 + 3->4 3->5 2 * 2->3 6 a 8 a 9 b 7 + 7->8 7->9 11 a 12 b 10 + 10->11 10->12 1 . 1->2 1->6 1->7 1->10 16 a 17 b 15 + 15->16 15->17 14 * 14->15 18 a 20 a 21 b 19 + 19->20 19->21 23 a 24 b 22 + 22->23 22->24 26 a 27 b 25 + 25->26 25->27 29 a 30 b 28 + 28->29 28->30 13 . 13->14 13->18 13->19 13->22 13->25 13->28 0 & 0->1 0->13
In [9]:
e.info()
Out[9]:
{'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}
In [10]:
vcsn.Q.expression('[ab]a[ab]').info()
Out[10]:
{'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}