{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# The latest version of ore_algebra should be used, run the following command if you need it\n", "# sage -pip install git+https://github.com/mkauers/ore_algebra/" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# Create the differential algebra to encode linear differential equation\n", "# (and shift algebra which expresses linear recurrence for coefficients)\n", "from ore_algebra import *\n", "Pols. = PolynomialRing(QQ)\n", "Diff. = OreAlgebra(Pols)\n", "Ind. = PolynomialRing(QQ)\n", "Shift. = OreAlgebra(Ind)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "@CachedFunction \n", "def NSEW(i,j,n):\n", " if i<0 or j<0:\n", " return 0\n", " elif n==0 and i==0 and j==0:\n", " return 1\n", " elif n==0:\n", " return 0\n", " else:\n", " return NSEW(i-1,j,n-1) + NSEW(i,j-1,n-1) + NSEW(i+1,j,n-1) + NSEW(i,j+1,n-1)" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[1, 2, 10, 70, 588, 5544, 56628, 613470, 6952660, 81662152, 987369656, 12228193432, 154532114800, 1986841476000, 25928281261800, 342787130211150, 4583937702039300, 61923368957373000, 844113292629453000, 11600528392993339800]\n" ] } ], "source": [ "LST = [ NSEW(0,0,2*n) for n in range(20)]\n", "print LST" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0: Also equal to the number of standard tableaux of 2n cells with height less than or equal to 4. A005817(2n) - _Mike Zabrocki_, Feb 22 2007\n", "1: Also equal to Sum binomial(2n,2i)C(i)C(n-i) = (4/pi^2) Integral_{0..Pi} Integral_{0..Pi} (2cos(x)+2cos(y))^{2n} sin^2(x)sin^2(y) dx dy, since this counts walks of 2n steps in the nonnegative quadrant of an integer lattice that return to the origin (cf. R. K. Guy link below). - _Andrew V. Sutherland_, Nov 29 2007\n", "2: Also, number of walks within N^2 (the first quadrant of Z^2) starting at (0,0), ending on the vertical axis and consisting of 2 n steps taken from {(-1, 0), (-1, 1), (1, -1), (1, 0)}. - _Manuel Kauers_, Nov 18 2008 - _Manuel Kauers_, Nov 18 2008\n", "3: Also, number of walks within N^2 (the first quadrant of Z^2) starting and ending at (0,0) and consisting of 2 n steps taken from {(-1, 0), (0, -1), (0, 1), (1, 0)}. - _Manuel Kauers_, Nov 18 2008\n", "4: a(2n-2) is also the sum of the numbers of standard Young tableaux of size 2n of (2,2) rectangular hook shapes (k+2,k+2,2^{n-2-k}, 0 <= k <= n-2. - Amitai Regev (amitai.regev(AT)weizmann.ac.il), Mar 10 2010\n", "5: Also, number of tree-rooted planar maps with n edges. - _Noam Zeilberger_, Aug 18 2017\n" ] } ], "source": [ "print oeis(LST)[0].comments()" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(-n^2 - 5*n - 6)*Sn + 16*n^2 + 32*n + 12\n" ] } ], "source": [ "rec = guess(LST,Shift)\n", "print rec" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(16*z^3 - z^2)*Dz^3 + (96*z^2 - 6*z)*Dz^2 + (108*z - 6)*Dz + 12\n" ] } ], "source": [ "annDiff = guess(LST,Diff)\n", "print annDiff" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1,\n", " 2,\n", " 10,\n", " 70,\n", " 588,\n", " 5544,\n", " 56628,\n", " 613470,\n", " 6952660,\n", " 81662152,\n", " 987369656,\n", " 12228193432,\n", " 154532114800,\n", " 1986841476000,\n", " 25928281261800,\n", " 342787130211150,\n", " 4583937702039300,\n", " 61923368957373000,\n", " 844113292629453000,\n", " 11600528392993339800]" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rec.to_list([1],20)" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[16^n*n^(-3)*(1 - 15/4*n^(-1) + 317/32*n^(-2) - 2925/128*n^(-3) + 101123/2048*n^(-4) + O(n^(-5)))]" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "show(rec.generalized_series_solutions())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "SageMath 8.4", "language": "", "name": "sagemath" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.15" } }, "nbformat": 4, "nbformat_minor": 1 }