{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# _`expression`_`.info(key=None)`\n",
"\n",
"A dictionary of facts about an expression.\n",
"\n",
"The keys of the dictionary are:\n",
"- `length`, `size`: the number of nodes in the syntax tree\n",
"- `width`, `atom`: the number of letter occurrences\n",
"- `depth`: the depth of the syntax tree (the depth of $a$ is 0, not 1)\n",
"- `type`: the implementation type\n",
"- `add`, `complement`, etc.: the number of occurrences of these operators (`+`, `{c}`, etc.) in the expression\n",
"\n",
"Arguments:\n",
"- `key`: if specified, return just the corresponding result.\n",
"\n",
"See also:\n",
"- [expression.context](expression.context.ipynb)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Examples"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/latex": [
"$\\left(a + b\\right)^{*} \\, a \\, \\left(a + b\\right)$"
],
"text/plain": [
"(a+b)*a(a+b)"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import vcsn\n",
"e = vcsn.Q.expression('[ab]*a[ab]')\n",
"e"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"e.SVG()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"{'add': 2,\n",
" 'atom': 5,\n",
" 'complement': 0,\n",
" 'compose': 0,\n",
" 'conjunction': 0,\n",
" 'depth': 3,\n",
" 'infiltrate': 0,\n",
" 'ldivide': 0,\n",
" 'length': 10,\n",
" 'lweight': 0,\n",
" 'mul': 1,\n",
" 'one': 0,\n",
" 'rweight': 0,\n",
" 'shuffle': 0,\n",
" 'size': 10,\n",
" 'star': 1,\n",
" 'transposition': 0,\n",
" 'tuple': 0,\n",
" 'type': 'expressionset, q>',\n",
" 'width': 5,\n",
" 'zero': 0}"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"e.info()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"'expressionset, q>'"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"e.info('type')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"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."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"10"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"e.info('length')"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"3"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"e.info('depth')"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/latex": [
"$\\left(a + b\\right)^{*} \\, a \\, \\left(a + b\\right)^{2} \\& \\left(a + b\\right)^{*} \\, a \\, \\left(a + b\\right)^{4}$"
],
"text/plain": [
"(a+b)*a(a+b){2}&(a+b)*a(a+b){4}"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"e = vcsn.Q.expression('[ab]*a[ab]{2} & [ab]*a[ab]{4}')\n",
"e"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"e.SVG()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"{'add': 8,\n",
" 'atom': 18,\n",
" 'complement': 0,\n",
" 'compose': 0,\n",
" 'conjunction': 1,\n",
" 'depth': 4,\n",
" 'infiltrate': 0,\n",
" 'ldivide': 0,\n",
" 'length': 37,\n",
" 'lweight': 0,\n",
" 'mul': 2,\n",
" 'one': 0,\n",
" 'rweight': 0,\n",
" 'shuffle': 0,\n",
" 'size': 37,\n",
" 'star': 2,\n",
" 'transposition': 0,\n",
" 'tuple': 0,\n",
" 'type': 'expressionset, q>',\n",
" 'width': 18,\n",
" 'zero': 0}"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"e.info()"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"{'add': 2,\n",
" 'atom': 5,\n",
" 'complement': 0,\n",
" 'compose': 0,\n",
" 'conjunction': 0,\n",
" 'depth': 2,\n",
" 'infiltrate': 0,\n",
" 'ldivide': 0,\n",
" 'length': 9,\n",
" 'lweight': 0,\n",
" 'mul': 1,\n",
" 'one': 0,\n",
" 'rweight': 0,\n",
" 'shuffle': 0,\n",
" 'size': 9,\n",
" 'star': 0,\n",
" 'transposition': 0,\n",
" 'tuple': 0,\n",
" 'type': 'expressionset, q>',\n",
" 'width': 5,\n",
" 'zero': 0}"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"vcsn.Q.expression('[ab]a[ab]').info()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.1"
},
"widgets": {
"state": {},
"version": "1.1.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
}