{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# PyQNormaliz: First example\n", "\n", "For computations over real embedded number fields with QNormaliz, first load the PyQNormaliz_cpp module" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import PyQNormaliz_cpp" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we enter a dodecahedron" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "dodec = PyQNormaliz_cpp.NmzCone( number_field = \"min_poly (a^2 - 5) embedding [2.236067977499789 +/- 8.06e-16]\",\n", " cone = [\n", "[ \"-a + 3\", \"-a + 3\", \"-a + 3\", 1 ],\n", "[ \"2*a - 4\", 0, \"a - 1\", 1 ],\n", "[ \"-a + 3\", \"a - 3\", \"-a + 3\", 1 ],\n", "[ \"a - 1\", \"2*a - 4\", 0, 1 ],\n", "[ \"a - 1\", \"-2*a + 4\", 0, 1 ],\n", "[ 0, \"a - 1\", \"2*a - 4\", 1 ],\n", "[ 0, \"-a + 1\", \"2*a - 4\", 1 ],\n", "[ \"-2*a + 4\", 0, \"a - 1\", 1 ],\n", "[ \"a - 3\", \"-a + 3\", \"-a + 3\", 1 ],\n", "[ \"a - 3\", \"a - 3\", \"-a + 3\", 1 ],\n", "[ \"-a + 3\", \"-a + 3\", \"a - 3\", 1 ],\n", "[ 0, \"a - 1\", \"-2*a + 4\", 1 ],\n", "[ \"-a + 3\", \"a - 3\", \"a - 3\", 1 ],\n", "[ 0, \"-a + 1\", \"-2*a + 4\", 1 ],\n", "[ \"2*a - 4\", 0, \"-a + 1\", 1 ],\n", "[ \"-a + 1\", \"2*a - 4\", 0, 1 ],\n", "[ \"-a + 1\", \"-2*a + 4\", 0, 1 ],\n", "[ \"a - 3\", \"-a + 3\", \"a - 3\", 1 ],\n", "[ \"a - 3\", \"a - 3\", \"a - 3\", 1 ],\n", "[ \"-2*a + 4\", 0, \"-a + 1\", 1 ] ] )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The input for number field elements can be given as strings, or as a list of pairs of integers. The polynomial\n", "```\n", "a^2+1/2a-3/5\n", "```\n", "would be the list\n", "```\n", "[[-3,5],[1,2],[1,1]]\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we can compute the support hyperplanes of the dodecahedron" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[[[[-1, 4], [-1, 4]], [[0, 1]], [[-1, 2]], [[1, 1]]],\n", " [[[-1, 4], [-1, 4]], [[0, 1]], [[1, 2]], [[1, 1]]],\n", " [[[-1, 2]], [[-1, 4], [-1, 4]], [[0, 1]], [[1, 1]]],\n", " [[[-1, 2]], [[1, 4], [1, 4]], [[0, 1]], [[1, 1]]],\n", " [[[0, 1]], [[-1, 2]], [[-1, 4], [-1, 4]], [[1, 1]]],\n", " [[[0, 1]], [[-1, 2]], [[1, 4], [1, 4]], [[1, 1]]],\n", " [[[0, 1]], [[1, 2]], [[-1, 4], [-1, 4]], [[1, 1]]],\n", " [[[0, 1]], [[1, 2]], [[1, 4], [1, 4]], [[1, 1]]],\n", " [[[1, 2]], [[-1, 4], [-1, 4]], [[0, 1]], [[1, 1]]],\n", " [[[1, 2]], [[1, 4], [1, 4]], [[0, 1]], [[1, 1]]],\n", " [[[1, 4], [1, 4]], [[0, 1]], [[-1, 2]], [[1, 1]]],\n", " [[[1, 4], [1, 4]], [[0, 1]], [[1, 2]], [[1, 1]]]]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "PyQNormaliz_cpp.NmzResult(dodec,\"SupportHyperplanes\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The output might be a bit hard to read. Therefore one can pass functions to the result function." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "def rational_handler(list):\n", " return list[0]/list[1]" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[[[-0.25, -0.25], [0.0], [-0.5], [1.0]],\n", " [[-0.25, -0.25], [0.0], [0.5], [1.0]],\n", " [[-0.5], [-0.25, -0.25], [0.0], [1.0]],\n", " [[-0.5], [0.25, 0.25], [0.0], [1.0]],\n", " [[0.0], [-0.5], [-0.25, -0.25], [1.0]],\n", " [[0.0], [-0.5], [0.25, 0.25], [1.0]],\n", " [[0.0], [0.5], [-0.25, -0.25], [1.0]],\n", " [[0.0], [0.5], [0.25, 0.25], [1.0]],\n", " [[0.5], [-0.25, -0.25], [0.0], [1.0]],\n", " [[0.5], [0.25, 0.25], [0.0], [1.0]],\n", " [[0.25, 0.25], [0.0], [-0.5], [1.0]],\n", " [[0.25, 0.25], [0.0], [0.5], [1.0]]]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "PyQNormaliz_cpp.NmzResult(dodec,\"SupportHyperplanes\",RationalHandler=rational_handler)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The resulting number field elements are displayed as lists. One might want to display them as polynomial strings" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "def polynomial_string(list):\n", " string = str(list[0][0]) + \"/\" + str(list[0][1])\n", " for i in range(1,len(list)):\n", " string += \" + \" + str(list[i][0]) + \"/\" + str(list[i][1]) + \"*a^\" + str(i)\n", " return string\n" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[['-1/4 + -1/4*a^1', '0/1', '-1/2', '1/1'],\n", " ['-1/4 + -1/4*a^1', '0/1', '1/2', '1/1'],\n", " ['-1/2', '-1/4 + -1/4*a^1', '0/1', '1/1'],\n", " ['-1/2', '1/4 + 1/4*a^1', '0/1', '1/1'],\n", " ['0/1', '-1/2', '-1/4 + -1/4*a^1', '1/1'],\n", " ['0/1', '-1/2', '1/4 + 1/4*a^1', '1/1'],\n", " ['0/1', '1/2', '-1/4 + -1/4*a^1', '1/1'],\n", " ['0/1', '1/2', '1/4 + 1/4*a^1', '1/1'],\n", " ['1/2', '-1/4 + -1/4*a^1', '0/1', '1/1'],\n", " ['1/2', '1/4 + 1/4*a^1', '0/1', '1/1'],\n", " ['1/4 + 1/4*a^1', '0/1', '-1/2', '1/1'],\n", " ['1/4 + 1/4*a^1', '0/1', '1/2', '1/1']]" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "PyQNormaliz_cpp.NmzResult(dodec,\"SupportHyperplanes\",NumberfieldElementHandler=polynomial_string)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Furthermore, `RationalHandler` and `MatrixHandler` can also be used." ] } ], "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.6.4" } }, "nbformat": 4, "nbformat_minor": 2 }