{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "code",
      "execution_count": 1,
      "metadata": {
        "id": "mdDWpLfhLAxD"
      },
      "outputs": [],
      "source": [
        "#@title Carga de paquetes\n",
        "from sympy.abc import *\n",
        "from sympy import *\n",
        "from IPython.display import *\n",
        "from sympy.series.formal import rational_algorithm as ra"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "#@title Definición de símbolos\n",
        "n, k = symbols('n k', integer=True, nonnegative=True)\n",
        "a, A = symbols('a A', cls=Function)"
      ],
      "metadata": {
        "id": "Wz_4JdEELSQr"
      },
      "execution_count": 2,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "#@title Definición de funciones\n",
        "def vertexto(texto):\n",
        "  \"\"\"Muestra texto en formato Markdown con MathJax.\"\"\"\n",
        "  return display(Markdown(texto))\n",
        "\n",
        "def termsum(term, n, a):\n",
        "  \"\"\"Descompone un término de la forma k*n^p*b^n*a_{n+q}.\"\"\"\n",
        "  factors = Mul.make_args(term)\n",
        "  k_val, p, q, b, ea = 1, 0, None, 1, 0\n",
        "  for f in factors:\n",
        "    if f.has(a):\n",
        "      q = simplify(f.args[0] - n)\n",
        "      ea = 1\n",
        "    elif f == n:\n",
        "      p = 1\n",
        "    elif f.is_Pow and f.base == n:\n",
        "      p = f.exp\n",
        "    elif f.is_Pow and f.exp == n:\n",
        "      b = f.base\n",
        "    else:\n",
        "      k_val *= f\n",
        "  return k_val, p, q, b, ea\n",
        "\n",
        "def derivada(expr, var=x, orden=1):\n",
        "  \"\"\"Calcula la derivada de una expresión o suma respecto a una variable.\"\"\"\n",
        "  if isinstance(expr, Eq):\n",
        "    return Eq(*[derivada(j, var, orden) for j in [expr.lhs, expr.rhs]])\n",
        "  elif isinstance(expr, Sum):\n",
        "    rr = expr.args\n",
        "    re = rr[1][0]\n",
        "    ato = diff(rr[0], var, orden)\n",
        "    return Sum(ato, rr[1])\n",
        "  return diff(expr, var, orden)\n",
        "\n",
        "def nthetado(expr, var=x, n=1):\n",
        "  \"\"\"Aplica el operador theta (x * d/dx) n veces.\"\"\"\n",
        "  if isinstance(expr, Eq):\n",
        "    return Eq(*[nthetado(j, var, n) for j in [expr.lhs, expr.rhs]])\n",
        "  elif isinstance(expr, Sum):\n",
        "    rr = expr.args\n",
        "    re = rr[1][0]\n",
        "    return Sum((rr[0] * re**n).simplify(), rr[1])\n",
        "\n",
        "  for _ in range(n):\n",
        "    expr = var * diff(expr, var)\n",
        "  return simplify(expr)\n",
        "\n",
        "def sumudu_transform(f, t, s):\n",
        "  \"\"\"Calcula la transformada de Sumudu.\"\"\"\n",
        "  if isinstance(f, Eq):\n",
        "    return Eq(sumudu_transform(f.lhs, t, s), sumudu_transform(f.rhs, t, s))\n",
        "  elif isinstance(f, Sum):\n",
        "    term = f.args[0]\n",
        "    return Sum(sumudu_transform(term, t, s), f.args[1]).doit()\n",
        "\n",
        "  tmp= integrate(f.subs(x, s*x)/exp(x), (x, 0, oo))\n",
        "  rta= tmp.args[0][0] if isinstance(tmp, Piecewise) else tmp\n",
        "  return simplify(rta.cancel())\n",
        "\n",
        "def dertheta(expr, var, k=0, m=0):\n",
        "  \"\"\"Aplica theta^k a la m-ésima derivada de expr.\"\"\"\n",
        "  return nthetado(derivada(expr, var, m), var, k)\n",
        "\n",
        "def serie_fgo(expr, acort=A(x), var=x):\n",
        "  \"\"\"Representa la Función Generadora Ordinaria (FGO).\"\"\"\n",
        "  return Eq(acort, Sum(expr * var**n, (n, 0, oo)))\n",
        "\n",
        "def serie_fge(expr, acort=A(x), var=x):\n",
        "  \"\"\"Representa la Función Generadora Exponencial (FGE).\"\"\"\n",
        "  return Eq(acort, Sum(expr * var**n / factorial(n), (n, 0, oo)))\n",
        "\n",
        "def combfge(expr, an=a(n), acort=A(x), var=x):\n",
        "  \"\"\"Combina términos para la FGE.\"\"\"\n",
        "  C = termsum(expr, an.args[0], an.func)\n",
        "  if C[4] == 1:\n",
        "    rmp = C[0] * dertheta(acort, var, C[1], C[2]).subs(var, var * C[3])\n",
        "  else:\n",
        "    rmp = C[0] * dertheta(exp(var), var, C[1], 0).subs(var, var * C[3])\n",
        "  lmp = serie_fge(expr, acort, var)\n",
        "  return Eq(lmp.rhs, simplify(rmp), evaluate=False)\n",
        "\n",
        "def combfgo(expr, an=a(n), acort=A(x), var=x):\n",
        "  \"\"\"Combina términos para la FGO.\"\"\"\n",
        "  C = termsum(expr, an.args[0], an.func)\n",
        "  if C[4] == 1:\n",
        "    tmp = (acort - sum(an.subs(n, j) * var**j for j in range(C[2]))) / var**C[2]\n",
        "  else:\n",
        "    tmp = 1 / (1 - var)\n",
        "  rmp = C[0] * nthetado(tmp, var, C[1]).subs(var, var * C[3])\n",
        "  lmp = serie_fgo(expr, acort, var)\n",
        "  return Eq(lmp.rhs, simplify(rmp, ratio=oo), evaluate=False)\n",
        "\n",
        "def sumeqs(*listeqs):\n",
        "  \"\"\"Suma los miembros de una lista de ecuaciones.\"\"\"\n",
        "  return Eq(sum(j.lhs for j in listeqs), sum(j.rhs for j in listeqs), evaluate=False)\n",
        "\n",
        "def apart2(f, x=None, **options):\n",
        "  \"\"\"Descomposición en fracciones parciales para denominadores de la forma (1-r*x)^m.\"\"\"\n",
        "  num, den = f.as_numer_denom()\n",
        "  rts = roots(den, x)\n",
        "  if not rts:\n",
        "    return Eq(f, f)\n",
        "\n",
        "  m = {1/r: mult for r, mult in rts.items()}\n",
        "  dens = {r: [[(1 - r*x)**j for j in range(1, m[r]+1)], []] for r in m}\n",
        "  for r, (pows, coeffs) in dens.items():\n",
        "    gij = simplify(f * pows[-1], ratio=oo)\n",
        "    for j in range(1, m[r]+1):\n",
        "      k = m[r] - j\n",
        "      val = limit(diff(gij, x, k), x, 1/r) / (factorial(k) * (-r)**k)\n",
        "      coeffs.append(cancel(val))\n",
        "  terms = [ UnevaluatedExpr(coeffs[j]) / pows[j]\n",
        "    for pows, coeffs in dens.values()\n",
        "    for j in range(len(pows)) ]\n",
        "  return Eq(f, Add(*terms, evaluate=False))\n",
        "\n",
        "def exabc(term, x):\n",
        "  \"\"\"Extrae componentes de un término para la extracción de coeficientes.\"\"\"\n",
        "  ta, resto = term.as_independent(x, as_Add=False)\n",
        "  tb = resto.base.coeff(x) * -1\n",
        "  tc = -resto.exp\n",
        "  return (ta, tb, tc)\n",
        "\n",
        "def extcoef(expr, x, n, **options):\n",
        "  \"\"\"Extrae el coeficiente n-ésimo de una función racional.\"\"\"\n",
        "  if expr.is_rational_function(x):\n",
        "    dfpe = apart2(expr, x)\n",
        "    lista = [list(Add.make_args(dfpe.rhs)), [], []]\n",
        "    for j in lista[0]:\n",
        "      a_val, b_val, c_val = exabc(j, x)\n",
        "      lista[1].append((a_val, b_val, c_val))\n",
        "      # Coeficiente de [x^n] en a / (1 - b*x)^c\n",
        "      term_coef = a_val * b_val**n * rf(c_val, n) / factorial(n)\n",
        "      lista[2].append(term_coef)\n",
        "    return simplify(sum(lista[2])).doit()\n",
        "  raise ValueError(f'El término expr={expr} debe ser una expresión racional.')\n",
        "\n",
        "def rsolgen(expr, an=a(n), ics=None, method='rsolve', **options):\n",
        "  \"\"\"Resuelve recursiones usando rsolve, FGO o FGE.\"\"\"\n",
        "  metodos = ['rsolve', 'fgo', 'fge']\n",
        "  if method not in metodos:\n",
        "    raise ValueError(f'El método {method} no es válido. Solo son válidos {metodos}.')\n",
        "\n",
        "  normal = expand(expr.lhs - expr.rhs) if isinstance(expr, Eq) else expand(expr)\n",
        "  vertexto(f'Resolviendo la recursión ${latex(Eq(normal, 0, evaluate=False))}$ con ${latex(ics)}$ mediante {method}:')\n",
        "\n",
        "  if method == 'rsolve':\n",
        "    return rsolve(normal, an, ics, **options)\n",
        "\n",
        "  A_func = symbols('A', cls=Function)\n",
        "  expandido = normal.expand()\n",
        "  sumandos = Add.make_args(expandido)\n",
        "  sumy = Eq(0, 0, evaluate=False)\n",
        "\n",
        "  if method == 'fge':\n",
        "    for j in sumandos:\n",
        "      eq_term = combfge(j, an, A_func(x), x)\n",
        "      sumy = Eq(sumy.lhs + eq_term.lhs, sumy.rhs + eq_term.rhs, evaluate=False)\n",
        "    eqc = Eq(sumy.lhs.simplify(), sumy.rhs)\n",
        "    vertexto(f'FGE del miembro izquierdo de la recursión: $${latex(eqc)}.$$')\n",
        "\n",
        "    ica = {diff(A_func(x), x, i.args[0]).subs(x, 0): ics[i] for i in ics} if ics else None\n",
        "    vertexto(f'Diccionario nuevo: ${latex(ica)}$')\n",
        "\n",
        "    tmp = dsolve(eqc.rhs, A_func(x), ics=ica)\n",
        "    vertexto(f'Solución provisional: ${latex(tmp)}$')\n",
        "\n",
        "    amp = sumudu_transform(tmp.rhs, x, s)\n",
        "    vertexto(f'Trans. Sumudu de esa solución: ${latex(amp)}$')\n",
        "\n",
        "    cmp = extcoef(amp, s, n)\n",
        "    vertexto(f'$$\\\\therefore {latex(cmp)}.$$')\n",
        "    return cmp\n",
        "\n",
        "  # method == 'fgo'\n",
        "  for j in sumandos:\n",
        "    eq_term = combfgo(j, an, A_func(x), x)\n",
        "    sumy = Eq(sumy.lhs + eq_term.lhs, sumy.rhs + eq_term.rhs, evaluate=False)\n",
        "  eqc = Eq(sumy.lhs.simplify(), sumy.rhs)\n",
        "  vertexto(f'FGO del miembro izquierdo de la recursión: $${latex(eqc)}.$$')\n",
        "\n",
        "  tmp = solve(eqc.rhs, A_func(x))[0]\n",
        "  tmp = tmp.subs(ics) if ics else tmp\n",
        "  vertexto(f'Solución de la ecuación ${latex(Eq(eqc.rhs, 0, evaluate=False))}$: $${latex(tmp)}.$$')\n",
        "\n",
        "  cmp = Eq(an, extcoef(tmp, x, n))\n",
        "  vertexto(f'$$\\\\therefore {latex(cmp)}.$$')\n",
        "  return cmp\n",
        "\n",
        "def sumav1(an, n, a, b):\n",
        "  \"\"\"Sumas finitas aplicando FGO.\"\"\"\n",
        "  fun = combfgo(an).rhs\n",
        "  ask = simplify(fun / (1 - x)).doit()\n",
        "  rta = extcoef(ask, x, n)\n",
        "  return Eq( Sum(an, (n, a,b)), rta.subs(n, b) - rta.subs(n, a - 1) )\n",
        "\n",
        "def sumav2(an, n, a, b):\n",
        "  \"\"\"Sumas finitas aplicando FGE.\"\"\"\n",
        "  fun = combfge(an).rhs\n",
        "  ask = simplify(fun + exp(x) * integrate(fun.subs(x, t) * exp(-t), (t, 0, x)))\n",
        "  tmp = sumudu_transform(ask, x, s)\n",
        "  rta = extcoef(tmp, s, n)\n",
        "  return Eq( Sum(an, (n, a,b)), rta.subs(n, b) - rta.subs(n, a - 1) )"
      ],
      "metadata": {
        "id": "81Wyr1HHLa7V"
      },
      "execution_count": 3,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "#@title Aplicación a descomposición en fracciones parciales\n",
        "fracciones= [1/(1-x**3), 1/((1-4*x)**4*(1-2*x)**3), x/(1-x**6)]\n",
        "for j in fracciones:\n",
        "  display(apart2(j, x))"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 165
        },
        "id": "bJzq7qArMS5n",
        "outputId": "a1b2036d-7c71-4216-9809-ee4ad7c77447"
      },
      "execution_count": 4,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "Eq(1/(1 - x**3), (1/3)/(-x/(-1/2 + sqrt(3)*I/2) + 1) + (1/3)/(-x/(-1/2 - sqrt(3)*I/2) + 1) + (1/3)/(1 - x))"
            ],
            "text/latex": "$\\displaystyle \\frac{1}{1 - x^{3}} = \\frac{\\frac{1}{3}}{- \\frac{x}{- \\frac{1}{2} + \\frac{\\sqrt{3} i}{2}} + 1} + \\frac{\\frac{1}{3}}{- \\frac{x}{- \\frac{1}{2} - \\frac{\\sqrt{3} i}{2}} + 1} + \\frac{\\frac{1}{3}}{1 - x}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "Eq(1/((1 - 4*x)**4*(1 - 2*x)**3), 40/(1 - 2*x) + 8/(1 - 2*x)**2 + 1/(1 - 2*x)**3 + (-80)/(1 - 4*x) + 48/(1 - 4*x)**2 + (-24)/(1 - 4*x)**3 + 8/(1 - 4*x)**4)"
            ],
            "text/latex": "$\\displaystyle \\frac{1}{\\left(1 - 4 x\\right)^{4} \\left(1 - 2 x\\right)^{3}} = \\frac{40}{1 - 2 x} + \\frac{8}{\\left(1 - 2 x\\right)^{2}} + \\frac{1}{\\left(1 - 2 x\\right)^{3}} + \\frac{-80}{1 - 4 x} + \\frac{48}{\\left(1 - 4 x\\right)^{2}} + \\frac{-24}{\\left(1 - 4 x\\right)^{3}} + \\frac{8}{\\left(1 - 4 x\\right)^{4}}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "Eq(x/(1 - x**6), (I/(3*sqrt(3) + 3*I))/(-x/(1/2 + sqrt(3)*I/2) + 1) + (-I/(3*sqrt(3) - 3*I))/(-x/(1/2 - sqrt(3)*I/2) + 1) + (I/(3*sqrt(3) - 3*I))/(-x/(-1/2 + sqrt(3)*I/2) + 1) + (-I/(3*sqrt(3) + 3*I))/(-x/(-1/2 - sqrt(3)*I/2) + 1) + (-1/6)/(x + 1) + (1/6)/(1 - x))"
            ],
            "text/latex": "$\\displaystyle \\frac{x}{1 - x^{6}} = \\frac{\\frac{i}{3 \\sqrt{3} + 3 i}}{- \\frac{x}{\\frac{1}{2} + \\frac{\\sqrt{3} i}{2}} + 1} + \\frac{- \\frac{i}{3 \\sqrt{3} - 3 i}}{- \\frac{x}{\\frac{1}{2} - \\frac{\\sqrt{3} i}{2}} + 1} + \\frac{\\frac{i}{3 \\sqrt{3} - 3 i}}{- \\frac{x}{- \\frac{1}{2} + \\frac{\\sqrt{3} i}{2}} + 1} + \\frac{- \\frac{i}{3 \\sqrt{3} + 3 i}}{- \\frac{x}{- \\frac{1}{2} - \\frac{\\sqrt{3} i}{2}} + 1} + \\frac{- \\frac{1}{6}}{x + 1} + \\frac{\\frac{1}{6}}{1 - x}$"
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "#@title Ejemplos de la transformada de Sumudu\n",
        "funciones= [x**6, exp(3*x), x**4*exp(6*x)]\n",
        "for j in funciones:\n",
        "  display(sumudu_transform(j, x, s))"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 112
        },
        "id": "4Qv3u1xaNkWg",
        "outputId": "2f0e919f-8672-43fe-efce-67397b59d51b"
      },
      "execution_count": 5,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "720*s**6"
            ],
            "text/latex": "$\\displaystyle 720 s^{6}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "-1/(3*s - 1)"
            ],
            "text/latex": "$\\displaystyle - \\frac{1}{3 s - 1}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "-24*s**4/(7776*s**5 - 6480*s**4 + 2160*s**3 - 360*s**2 + 30*s - 1)"
            ],
            "text/latex": "$\\displaystyle - \\frac{24 s^{4}}{7776 s^{5} - 6480 s^{4} + 2160 s^{3} - 360 s^{2} + 30 s - 1}$"
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "#@title Funciones generadoras ordinarias de sucesiones\n",
        "sucs= [n**2, 6**n, 7*n**3*4**n]\n",
        "for an in sucs:\n",
        "  display(combfgo(an, a(n), A(x), x))"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 174
        },
        "id": "3i5bEoTtN_nq",
        "outputId": "020d2b5d-508b-4109-d212-3d180a36a94b"
      },
      "execution_count": 6,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "Eq(Sum(n**2*x**n, (n, 0, oo)), -x*(x + 1)/(x - 1)**3)"
            ],
            "text/latex": "$\\displaystyle \\sum_{n=0}^{\\infty} n^{2} x^{n} = - \\frac{x \\left(x + 1\\right)}{\\left(x - 1\\right)^{3}}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "Eq(Sum(6**n*x**n, (n, 0, oo)), -1/(6*x - 1))"
            ],
            "text/latex": "$\\displaystyle \\sum_{n=0}^{\\infty} 6^{n} x^{n} = - \\frac{1}{6 x - 1}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "Eq(Sum(7*4**n*n**3*x**n, (n, 0, oo)), 28*x*(24*x + (4*x - 1)**2)/(4*x - 1)**4)"
            ],
            "text/latex": "$\\displaystyle \\sum_{n=0}^{\\infty} 7 \\cdot 4^{n} n^{3} x^{n} = \\frac{28 x \\left(24 x + \\left(4 x - 1\\right)^{2}\\right)}{\\left(4 x - 1\\right)^{4}}$"
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "#@title Funciones generadoras exponenciales de sucesiones\n",
        "sucs= [n**2, 6**n, 7*n**3*4**n]\n",
        "for an in sucs:\n",
        "  display(combfge(an, a(n), A(x), x))"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 165
        },
        "id": "CPp4d0FgPROG",
        "outputId": "bb83d6e6-9b06-4522-ee84-83d6e0d1a4c5"
      },
      "execution_count": 7,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "Eq(Sum(n**2*x**n/factorial(n), (n, 0, oo)), x*(x + 1)*exp(x))"
            ],
            "text/latex": "$\\displaystyle \\sum_{n=0}^{\\infty} \\frac{n^{2} x^{n}}{n!} = x \\left(x + 1\\right) e^{x}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "Eq(Sum(6**n*x**n/factorial(n), (n, 0, oo)), exp(6*x))"
            ],
            "text/latex": "$\\displaystyle \\sum_{n=0}^{\\infty} \\frac{6^{n} x^{n}}{n!} = e^{6 x}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "Eq(Sum(7*4**n*n**3*x**n/factorial(n), (n, 0, oo)), 28*x*(16*x**2 + 12*x + 1)*exp(4*x))"
            ],
            "text/latex": "$\\displaystyle \\sum_{n=0}^{\\infty} \\frac{7 \\cdot 4^{n} n^{3} x^{n}}{n!} = 28 x \\left(16 x^{2} + 12 x + 1\\right) e^{4 x}$"
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "#@title Coeficiente extraído de la serie de potencias de una función analítica\n",
        "funciones= [(1-5*x)**(-6), (1-x)**3/(1-6*x)**5, (3-5*x)**(-4)]\n",
        "for f in funciones:\n",
        "  display(extcoef(f, x, n))"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 127
        },
        "id": "Y-DiDHRkPcak",
        "outputId": "532f6c3a-6cc3-432b-a4e2-61ca36a63b44"
      },
      "execution_count": 8,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "5**n*(n + 1)*(n + 2)*(n + 3)*(n + 4)*(n + 5)/120"
            ],
            "text/latex": "$\\displaystyle \\frac{5^{n} \\left(n + 1\\right) \\left(n + 2\\right) \\left(n + 3\\right) \\left(n + 4\\right) \\left(n + 5\\right)}{120}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "6**n*(n + 1)*(125*n**3 + 1425*n**2 + 4930*n + 5184)/5184"
            ],
            "text/latex": "$\\displaystyle \\frac{6^{n} \\left(n + 1\\right) \\left(125 n^{3} + 1425 n^{2} + 4930 n + 5184\\right)}{5184}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "5**n*(n + 1)*(n + 2)*(n + 3)/(486*3**n)"
            ],
            "text/latex": "$\\displaystyle \\frac{3^{- n} 5^{n} \\left(n + 1\\right) \\left(n + 2\\right) \\left(n + 3\\right)}{486}$"
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "#@title Resolución de recursiones\n",
        "recursiones= [ Eq( a(n+1), a(n)+ (1-n)**3),\n",
        "               Eq( a(n+3)-8*a(n+2)+21*a(n+1)-18*a(n), 4**n+n*2**n),\n",
        "               Eq( a(n+2), a(n+1)-ln(4)-a(n) ) ]\n",
        "for rec in recursiones:\n",
        "  display( rsolgen(rec, a(n), method='fge') )"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 796
        },
        "id": "3PxFvmOcQYow",
        "outputId": "39f2fc00-c99e-46d7-b266-35f6ac89108b"
      },
      "execution_count": 9,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "Resolviendo la recursión $n^{3} - 3 n^{2} + 3 n - a{\\left(n \\right)} + a{\\left(n + 1 \\right)} - 1 = 0$ con $\\text{None}$ mediante fge:"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "FGE del miembro izquierdo de la recursión: $$\\sum_{n=0}^{\\infty} x^{n} \\left(\\frac{n^{2}}{\\left(n - 1\\right)!} - \\frac{3 n}{\\left(n - 1\\right)!} - \\frac{a{\\left(n \\right)} + 1}{n!} + \\frac{a{\\left(n + 1 \\right)}}{n!} + \\frac{3}{\\left(n - 1\\right)!}\\right) = - 3 x \\left(x + 1\\right) e^{x} + x \\left(x \\left(x + 2\\right) + x + 1\\right) e^{x} + 3 x e^{x} - A{\\left(x \\right)} - e^{x} + \\frac{d}{d x} A{\\left(x \\right)}.$$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "Diccionario nuevo: $\\text{None}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "Solución provisional: $A{\\left(x \\right)} = \\left(C_{1} - \\frac{x^{4}}{4} - \\frac{x^{2}}{2} + x\\right) e^{x}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "Trans. Sumudu de esa solución: $\\frac{- C_{1} s^{4} + 4 C_{1} s^{3} - 6 C_{1} s^{2} + 4 C_{1} s - C_{1} + 8 s^{4} - 5 s^{3} + 4 s^{2} - s}{s^{5} - 5 s^{4} + 10 s^{3} - 10 s^{2} + 5 s - 1}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "$$\\therefore C_{1} - \\frac{n^{4}}{4} + \\frac{3 n^{3}}{2} - \\frac{13 n^{2}}{4} + 3 n.$$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "C1 - n**4/4 + 3*n**3/2 - 13*n**2/4 + 3*n"
            ],
            "text/latex": "$\\displaystyle C_{1} - \\frac{n^{4}}{4} + \\frac{3 n^{3}}{2} - \\frac{13 n^{2}}{4} + 3 n$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "Resolviendo la recursión $- 2^{n} n - 4^{n} - 18 a{\\left(n \\right)} + 21 a{\\left(n + 1 \\right)} - 8 a{\\left(n + 2 \\right)} + a{\\left(n + 3 \\right)} = 0$ con $\\text{None}$ mediante fge:"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "FGE del miembro izquierdo de la recursión: $$\\sum_{n=0}^{\\infty} x^{n} \\left(- \\frac{2^{n}}{\\left(n - 1\\right)!} - \\frac{4^{n}}{n!} - \\frac{18 a{\\left(n \\right)}}{n!} + \\frac{21 a{\\left(n + 1 \\right)}}{n!} - \\frac{8 a{\\left(n + 2 \\right)}}{n!} + \\frac{a{\\left(n + 3 \\right)}}{n!}\\right) = - 2 x e^{2 x} - 18 A{\\left(x \\right)} - e^{4 x} + 21 \\frac{d}{d x} A{\\left(x \\right)} - 8 \\frac{d^{2}}{d x^{2}} A{\\left(x \\right)} + \\frac{d^{3}}{d x^{3}} A{\\left(x \\right)}.$$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "Diccionario nuevo: $\\text{None}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "Solución provisional: $A{\\left(x \\right)} = \\left(C_{1} + x^{2} + 4 x + \\left(C_{2} + C_{3} x\\right) e^{x} + \\frac{e^{2 x}}{2}\\right) e^{2 x}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "Trans. Sumudu de esa solución: $\\frac{- 144 C_{1} s^{5} + 276 C_{1} s^{4} - 208 C_{1} s^{3} + 77 C_{1} s^{2} - 14 C_{1} s + C_{1} - 96 C_{2} s^{5} + 200 C_{2} s^{4} - 164 C_{2} s^{3} + 66 C_{2} s^{2} - 13 C_{2} s + C_{2} + 32 C_{3} s^{5} - 56 C_{3} s^{4} + 36 C_{3} s^{3} - 10 C_{3} s^{2} + C_{3} s + 180 s^{5} - 264 s^{4} + 125 s^{3} - \\frac{35 s^{2}}{2} - 2 s + \\frac{1}{2}}{288 s^{6} - 696 s^{5} + 692 s^{4} - 362 s^{3} + 105 s^{2} - 16 s + 1}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "$$\\therefore 2^{n} C_{1} + \\frac{2^{n} n^{2}}{4} + \\frac{7 \\cdot 2^{n} n}{4} + 3^{n} C_{2} + \\frac{3^{n} C_{3} n}{3} + \\frac{4^{n}}{2}.$$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "2**n*C1 + 2**n*n**2/4 + 7*2**n*n/4 + 3**n*C2 + 3**n*C3*n/3 + 4**n/2"
            ],
            "text/latex": "$\\displaystyle 2^{n} C_{1} + \\frac{2^{n} n^{2}}{4} + \\frac{7 \\cdot 2^{n} n}{4} + 3^{n} C_{2} + \\frac{3^{n} C_{3} n}{3} + \\frac{4^{n}}{2}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "Resolviendo la recursión $a{\\left(n \\right)} - a{\\left(n + 1 \\right)} + a{\\left(n + 2 \\right)} + 2 \\log{\\left(2 \\right)} = 0$ con $\\text{None}$ mediante fge:"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "FGE del miembro izquierdo de la recursión: $$\\sum_{n=0}^{\\infty} \\frac{x^{n} \\left(a{\\left(n \\right)} - a{\\left(n + 1 \\right)} + a{\\left(n + 2 \\right)} + 2 \\log{\\left(2 \\right)}\\right)}{n!} = A{\\left(x \\right)} + e^{x} \\log{\\left(4 \\right)} - \\frac{d}{d x} A{\\left(x \\right)} + \\frac{d^{2}}{d x^{2}} A{\\left(x \\right)}.$$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "Diccionario nuevo: $\\text{None}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "Solución provisional: $A{\\left(x \\right)} = \\left(C_{1} \\sin{\\left(\\frac{\\sqrt{3} x}{2} \\right)} + C_{2} \\cos{\\left(\\frac{\\sqrt{3} x}{2} \\right)}\\right) e^{\\frac{x}{2}} - 2 e^{x} \\log{\\left(2 \\right)}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "Trans. Sumudu de esa solución: $\\frac{\\sqrt{3} C_{1} s^{2} - \\sqrt{3} C_{1} s - C_{2} s^{2} + 3 C_{2} s - 2 C_{2} + s^{2} \\log{\\left(16 \\right)} - s \\log{\\left(16 \\right)} + \\log{\\left(16 \\right)}}{2 \\left(s^{3} - 2 s^{2} + 2 s - 1\\right)}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "$$\\therefore \\frac{4^{- n} \\left(- 4 \\cdot 4^{n} \\log{\\left(2 \\right)} + i C_{1} \\left(2 - 2 \\sqrt{3} i\\right)^{n} - i C_{1} \\left(2 + 2 \\sqrt{3} i\\right)^{n} + C_{2} \\left(2 - 2 \\sqrt{3} i\\right)^{n} + C_{2} \\left(2 + 2 \\sqrt{3} i\\right)^{n}\\right)}{2}.$$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "(-4*4**n*log(2) + I*C1*(2 - 2*sqrt(3)*I)**n - I*C1*(2 + 2*sqrt(3)*I)**n + C2*(2 - 2*sqrt(3)*I)**n + C2*(2 + 2*sqrt(3)*I)**n)/(2*4**n)"
            ],
            "text/latex": "$\\displaystyle \\frac{4^{- n} \\left(- 4 \\cdot 4^{n} \\log{\\left(2 \\right)} + i C_{1} \\left(2 - 2 \\sqrt{3} i\\right)^{n} - i C_{1} \\left(2 + 2 \\sqrt{3} i\\right)^{n} + C_{2} \\left(2 - 2 \\sqrt{3} i\\right)^{n} + C_{2} \\left(2 + 2 \\sqrt{3} i\\right)^{n}\\right)}{2}$"
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "for rec in recursiones:\n",
        "  display( rsolgen(rec, a(n), method='fgo') )"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 837
        },
        "id": "rhFFnuNMRDxT",
        "outputId": "7dda5394-a425-4ace-b6fd-257db465cbb6"
      },
      "execution_count": 10,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "Resolviendo la recursión $n^{3} - 3 n^{2} + 3 n - a{\\left(n \\right)} + a{\\left(n + 1 \\right)} - 1 = 0$ con $\\text{None}$ mediante fgo:"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "FGO del miembro izquierdo de la recursión: $$\\sum_{n=0}^{\\infty} x^{n} \\left(n^{3} - 3 n^{2} + 3 n - a{\\left(n \\right)} + a{\\left(n + 1 \\right)} - 1\\right) = \\frac{3 x}{\\left(x - 1\\right)^{2}} + \\frac{3 x \\left(x + 1\\right)}{\\left(x - 1\\right)^{3}} + \\frac{x \\left(6 x + \\left(x - 1\\right)^{2}\\right)}{\\left(x - 1\\right)^{4}} - A{\\left(x \\right)} + \\frac{1}{x - 1} + \\frac{A{\\left(x \\right)} - a{\\left(0 \\right)}}{x}.$$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "Solución de la ecuación $\\frac{3 x}{\\left(x - 1\\right)^{2}} + \\frac{3 x \\left(x + 1\\right)}{\\left(x - 1\\right)^{3}} + \\frac{x \\left(6 x + \\left(x - 1\\right)^{2}\\right)}{\\left(x - 1\\right)^{4}} - A{\\left(x \\right)} + \\frac{1}{x - 1} + \\frac{A{\\left(x \\right)} - a{\\left(0 \\right)}}{x} = 0$: $$\\frac{3 x^{3} \\left(x - 1\\right) + 6 x^{3} + 4 x^{2} \\left(x - 1\\right)^{2} + 3 x^{2} \\left(x - 1\\right) + x \\left(x - 1\\right)^{3} - \\left(x - 1\\right)^{4} a{\\left(0 \\right)}}{\\left(x - 1\\right)^{5}}.$$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "$$\\therefore a{\\left(n \\right)} = - \\frac{n^{4}}{4} + \\frac{3 n^{3}}{2} - \\frac{13 n^{2}}{4} + 3 n + a{\\left(0 \\right)}.$$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "Eq(a(n), -n**4/4 + 3*n**3/2 - 13*n**2/4 + 3*n + a(0))"
            ],
            "text/latex": "$\\displaystyle a{\\left(n \\right)} = - \\frac{n^{4}}{4} + \\frac{3 n^{3}}{2} - \\frac{13 n^{2}}{4} + 3 n + a{\\left(0 \\right)}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "Resolviendo la recursión $- 2^{n} n - 4^{n} - 18 a{\\left(n \\right)} + 21 a{\\left(n + 1 \\right)} - 8 a{\\left(n + 2 \\right)} + a{\\left(n + 3 \\right)} = 0$ con $\\text{None}$ mediante fgo:"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "FGO del miembro izquierdo de la recursión: $$\\sum_{n=0}^{\\infty} x^{n} \\left(- 2^{n} n - 4^{n} - 18 a{\\left(n \\right)} + 21 a{\\left(n + 1 \\right)} - 8 a{\\left(n + 2 \\right)} + a{\\left(n + 3 \\right)}\\right) = - \\frac{2 x}{\\left(2 x - 1\\right)^{2}} - 18 A{\\left(x \\right)} + \\frac{1}{4 x - 1} + \\frac{21 \\left(A{\\left(x \\right)} - a{\\left(0 \\right)}\\right)}{x} + \\frac{8 \\left(x a{\\left(1 \\right)} - A{\\left(x \\right)} + a{\\left(0 \\right)}\\right)}{x^{2}} + \\frac{- x^{2} a{\\left(2 \\right)} - x a{\\left(1 \\right)} + A{\\left(x \\right)} - a{\\left(0 \\right)}}{x^{3}}.$$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "Solución de la ecuación $- \\frac{2 x}{\\left(2 x - 1\\right)^{2}} - 18 A{\\left(x \\right)} + \\frac{1}{4 x - 1} + \\frac{21 \\left(A{\\left(x \\right)} - a{\\left(0 \\right)}\\right)}{x} + \\frac{8 \\left(x a{\\left(1 \\right)} - A{\\left(x \\right)} + a{\\left(0 \\right)}\\right)}{x^{2}} + \\frac{- x^{2} a{\\left(2 \\right)} - x a{\\left(1 \\right)} + A{\\left(x \\right)} - a{\\left(0 \\right)}}{x^{3}} = 0$: $$\\frac{- 336 x^{5} a{\\left(0 \\right)} + 128 x^{5} a{\\left(1 \\right)} - 16 x^{5} a{\\left(2 \\right)} - 4 x^{5} + 548 x^{4} a{\\left(0 \\right)} - 176 x^{4} a{\\left(1 \\right)} + 20 x^{4} a{\\left(2 \\right)} - 2 x^{4} - 344 x^{3} a{\\left(0 \\right)} + 84 x^{3} a{\\left(1 \\right)} - 8 x^{3} a{\\left(2 \\right)} + x^{3} + 105 x^{2} a{\\left(0 \\right)} - 16 x^{2} a{\\left(1 \\right)} + x^{2} a{\\left(2 \\right)} - 16 x a{\\left(0 \\right)} + x a{\\left(1 \\right)} + a{\\left(0 \\right)}}{288 x^{6} - 696 x^{5} + 692 x^{4} - 362 x^{3} + 105 x^{2} - 16 x + 1}.$$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "$$\\therefore a{\\left(n \\right)} = \\frac{2^{n} n^{2}}{4} + \\frac{7 \\cdot 2^{n} n}{4} + 9 \\cdot 2^{n} a{\\left(0 \\right)} - 6 \\cdot 2^{n} a{\\left(1 \\right)} + 2^{n} a{\\left(2 \\right)} + \\frac{11 \\cdot 2^{n}}{2} + 2 \\cdot 3^{n} n a{\\left(0 \\right)} - \\frac{5 \\cdot 3^{n} n a{\\left(1 \\right)}}{3} + \\frac{3^{n} n a{\\left(2 \\right)}}{3} + \\frac{3^{n} n}{3} - 8 \\cdot 3^{n} a{\\left(0 \\right)} + 6 \\cdot 3^{n} a{\\left(1 \\right)} - 3^{n} a{\\left(2 \\right)} - 6 \\cdot 3^{n} + \\frac{4^{n}}{2}.$$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "Eq(a(n), 2**n*n**2/4 + 7*2**n*n/4 + 9*2**n*a(0) - 6*2**n*a(1) + 2**n*a(2) + 11*2**n/2 + 2*3**n*n*a(0) - 5*3**n*n*a(1)/3 + 3**n*n*a(2)/3 + 3**n*n/3 - 8*3**n*a(0) + 6*3**n*a(1) - 3**n*a(2) - 6*3**n + 4**n/2)"
            ],
            "text/latex": "$\\displaystyle a{\\left(n \\right)} = \\frac{2^{n} n^{2}}{4} + \\frac{7 \\cdot 2^{n} n}{4} + 9 \\cdot 2^{n} a{\\left(0 \\right)} - 6 \\cdot 2^{n} a{\\left(1 \\right)} + 2^{n} a{\\left(2 \\right)} + \\frac{11 \\cdot 2^{n}}{2} + 2 \\cdot 3^{n} n a{\\left(0 \\right)} - \\frac{5 \\cdot 3^{n} n a{\\left(1 \\right)}}{3} + \\frac{3^{n} n a{\\left(2 \\right)}}{3} + \\frac{3^{n} n}{3} - 8 \\cdot 3^{n} a{\\left(0 \\right)} + 6 \\cdot 3^{n} a{\\left(1 \\right)} - 3^{n} a{\\left(2 \\right)} - 6 \\cdot 3^{n} + \\frac{4^{n}}{2}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "Resolviendo la recursión $a{\\left(n \\right)} - a{\\left(n + 1 \\right)} + a{\\left(n + 2 \\right)} + 2 \\log{\\left(2 \\right)} = 0$ con $\\text{None}$ mediante fgo:"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "FGO del miembro izquierdo de la recursión: $$\\sum_{n=0}^{\\infty} x^{n} \\left(a{\\left(n \\right)} - a{\\left(n + 1 \\right)} + a{\\left(n + 2 \\right)} + 2 \\log{\\left(2 \\right)}\\right) = A{\\left(x \\right)} - \\frac{\\log{\\left(4 \\right)}}{x - 1} + \\frac{- A{\\left(x \\right)} + a{\\left(0 \\right)}}{x} + \\frac{- x a{\\left(1 \\right)} + A{\\left(x \\right)} - a{\\left(0 \\right)}}{x^{2}}.$$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "Solución de la ecuación $A{\\left(x \\right)} - \\frac{\\log{\\left(4 \\right)}}{x - 1} + \\frac{- A{\\left(x \\right)} + a{\\left(0 \\right)}}{x} + \\frac{- x a{\\left(1 \\right)} + A{\\left(x \\right)} - a{\\left(0 \\right)}}{x^{2}} = 0$: $$\\frac{- x^{2} a{\\left(0 \\right)} + x^{2} a{\\left(1 \\right)} + x^{2} \\log{\\left(4 \\right)} + 2 x a{\\left(0 \\right)} - x a{\\left(1 \\right)} - a{\\left(0 \\right)}}{x^{3} - 2 x^{2} + 2 x - 1}.$$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "$$\\therefore a{\\left(n \\right)} = \\frac{\\left(\\frac{1}{\\left(1 - \\sqrt{3} i\\right) \\left(1 + \\sqrt{3} i\\right)}\\right)^{n} \\left(- \\left(\\left(1 - \\sqrt{3} i\\right) \\left(1 + \\sqrt{3} i\\right)\\right)^{n} \\log{\\left(4096 \\right)} + \\sqrt{3} \\left(2 - 2 \\sqrt{3} i\\right)^{n} \\left(\\sqrt{3} a{\\left(0 \\right)} - i a{\\left(0 \\right)} + 2 i a{\\left(1 \\right)} + \\log{\\left(2^{2 \\sqrt{3}} \\right)} + i \\log{\\left(4 \\right)}\\right) + \\sqrt{3} \\left(2 + 2 \\sqrt{3} i\\right)^{n} \\left(\\sqrt{3} a{\\left(0 \\right)} + i a{\\left(0 \\right)} - 2 i a{\\left(1 \\right)} + \\log{\\left(2^{2 \\sqrt{3}} \\right)} - i \\log{\\left(4 \\right)}\\right)\\right)}{6}.$$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "Eq(a(n), (1/((1 - sqrt(3)*I)*(1 + sqrt(3)*I)))**n*(-((1 - sqrt(3)*I)*(1 + sqrt(3)*I))**n*log(4096) + sqrt(3)*(2 - 2*sqrt(3)*I)**n*(sqrt(3)*a(0) - I*a(0) + 2*I*a(1) + log(2**(2*sqrt(3))) + I*log(4)) + sqrt(3)*(2 + 2*sqrt(3)*I)**n*(sqrt(3)*a(0) + I*a(0) - 2*I*a(1) + log(2**(2*sqrt(3))) - I*log(4)))/6)"
            ],
            "text/latex": "$\\displaystyle a{\\left(n \\right)} = \\frac{\\left(\\frac{1}{\\left(1 - \\sqrt{3} i\\right) \\left(1 + \\sqrt{3} i\\right)}\\right)^{n} \\left(- \\left(\\left(1 - \\sqrt{3} i\\right) \\left(1 + \\sqrt{3} i\\right)\\right)^{n} \\log{\\left(4096 \\right)} + \\sqrt{3} \\left(2 - 2 \\sqrt{3} i\\right)^{n} \\left(\\sqrt{3} a{\\left(0 \\right)} - i a{\\left(0 \\right)} + 2 i a{\\left(1 \\right)} + \\log{\\left(2^{2 \\sqrt{3}} \\right)} + i \\log{\\left(4 \\right)}\\right) + \\sqrt{3} \\left(2 + 2 \\sqrt{3} i\\right)^{n} \\left(\\sqrt{3} a{\\left(0 \\right)} + i a{\\left(0 \\right)} - 2 i a{\\left(1 \\right)} + \\log{\\left(2^{2 \\sqrt{3}} \\right)} - i \\log{\\left(4 \\right)}\\right)\\right)}{6}$"
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "for rec in recursiones:\n",
        "  display( rsolgen(rec, a(n), method='rsolve') )"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 229
        },
        "id": "G7mVtSAuRhO2",
        "outputId": "49929c22-58aa-425e-d309-70183d6e9fd8"
      },
      "execution_count": 11,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "Resolviendo la recursión $n^{3} - 3 n^{2} + 3 n - a{\\left(n \\right)} + a{\\left(n + 1 \\right)} - 1 = 0$ con $\\text{None}$ mediante rsolve:"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "C0 + n*(-n**3 + 6*n**2 - 13*n + 12)/4"
            ],
            "text/latex": "$\\displaystyle C_{0} + \\frac{n \\left(- n^{3} + 6 n^{2} - 13 n + 12\\right)}{4}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "Resolviendo la recursión $- 2^{n} n - 4^{n} - 18 a{\\left(n \\right)} + 21 a{\\left(n + 1 \\right)} - 8 a{\\left(n + 2 \\right)} + a{\\left(n + 3 \\right)} = 0$ con $\\text{None}$ mediante rsolve:"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "2**n*C0 + 2**(n - 2)*(2**(n + 1) + n*(n + 7)) + 3**n*C1 + 3**(n - 1)*C2*n"
            ],
            "text/latex": "$\\displaystyle 2^{n} C_{0} + 2^{n - 2} \\left(2^{n + 1} + n \\left(n + 7\\right)\\right) + 3^{n} C_{1} + 3^{n - 1} C_{2} n$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "Resolviendo la recursión $a{\\left(n \\right)} - a{\\left(n + 1 \\right)} + a{\\left(n + 2 \\right)} + 2 \\log{\\left(2 \\right)} = 0$ con $\\text{None}$ mediante rsolve:"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "C0*(1/2 - sqrt(3)*I/2)**n + C1*(1/2 + sqrt(3)*I/2)**n - log(4)"
            ],
            "text/latex": "$\\displaystyle C_{0} \\left(\\frac{1}{2} - \\frac{\\sqrt{3} i}{2}\\right)^{n} + C_{1} \\left(\\frac{1}{2} + \\frac{\\sqrt{3} i}{2}\\right)^{n} - \\log{\\left(4 \\right)}$"
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Ejercicios del documento"
      ],
      "metadata": {
        "id": "NJyV6vhBz2Ay"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "eq001= Eq(a(n+3), 8*a(n+2)-21*a(n+1)+18*a(n))\n",
        "ics= {a(0): 4, a(1): 4, a(2): 4}\n",
        "display( rsolgen(eq001, a(n), ics, method='fgo') )"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 216
        },
        "id": "qZE5Vxn10DiC",
        "outputId": "d5627f79-fc47-4c82-ce97-77e8a62792a6"
      },
      "execution_count": 12,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "Resolviendo la recursión $- 18 a{\\left(n \\right)} + 21 a{\\left(n + 1 \\right)} - 8 a{\\left(n + 2 \\right)} + a{\\left(n + 3 \\right)} = 0$ con $\\left\\{ a{\\left(0 \\right)} : 4, \\  a{\\left(1 \\right)} : 4, \\  a{\\left(2 \\right)} : 4\\right\\}$ mediante fgo:"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "FGO del miembro izquierdo de la recursión: $$\\sum_{n=0}^{\\infty} x^{n} \\left(- 18 a{\\left(n \\right)} + 21 a{\\left(n + 1 \\right)} - 8 a{\\left(n + 2 \\right)} + a{\\left(n + 3 \\right)}\\right) = - 18 A{\\left(x \\right)} + \\frac{21 \\left(A{\\left(x \\right)} - a{\\left(0 \\right)}\\right)}{x} + \\frac{8 \\left(x a{\\left(1 \\right)} - A{\\left(x \\right)} + a{\\left(0 \\right)}\\right)}{x^{2}} + \\frac{- x^{2} a{\\left(2 \\right)} - x a{\\left(1 \\right)} + A{\\left(x \\right)} - a{\\left(0 \\right)}}{x^{3}}.$$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "Solución de la ecuación $- 18 A{\\left(x \\right)} + \\frac{21 \\left(A{\\left(x \\right)} - a{\\left(0 \\right)}\\right)}{x} + \\frac{8 \\left(x a{\\left(1 \\right)} - A{\\left(x \\right)} + a{\\left(0 \\right)}\\right)}{x^{2}} + \\frac{- x^{2} a{\\left(2 \\right)} - x a{\\left(1 \\right)} + A{\\left(x \\right)} - a{\\left(0 \\right)}}{x^{3}} = 0$: $$\\frac{- 56 x^{2} + 28 x - 4}{18 x^{3} - 21 x^{2} + 8 x - 1}.$$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "$$\\therefore a{\\left(n \\right)} = 16 \\cdot 2^{n} + \\frac{8 \\cdot 3^{n} n}{3} - 12 \\cdot 3^{n}.$$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "Eq(a(n), 16*2**n + 8*3**n*n/3 - 12*3**n)"
            ],
            "text/latex": "$\\displaystyle a{\\left(n \\right)} = 16 \\cdot 2^{n} + \\frac{8 \\cdot 3^{n} n}{3} - 12 \\cdot 3^{n}$"
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "display( rsolgen(eq001, a(n), method='fge') )"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 230
        },
        "id": "41CPDQUZ0rIu",
        "outputId": "d87f7f7f-0d1e-4983-8faf-56558a57b0ab"
      },
      "execution_count": 13,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "Resolviendo la recursión $- 18 a{\\left(n \\right)} + 21 a{\\left(n + 1 \\right)} - 8 a{\\left(n + 2 \\right)} + a{\\left(n + 3 \\right)} = 0$ con $\\text{None}$ mediante fge:"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "FGE del miembro izquierdo de la recursión: $$\\sum_{n=0}^{\\infty} \\frac{x^{n} \\left(- 18 a{\\left(n \\right)} + 21 a{\\left(n + 1 \\right)} - 8 a{\\left(n + 2 \\right)} + a{\\left(n + 3 \\right)}\\right)}{n!} = - 18 A{\\left(x \\right)} + 21 \\frac{d}{d x} A{\\left(x \\right)} - 8 \\frac{d^{2}}{d x^{2}} A{\\left(x \\right)} + \\frac{d^{3}}{d x^{3}} A{\\left(x \\right)}.$$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "Diccionario nuevo: $\\text{None}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "Solución provisional: $A{\\left(x \\right)} = \\left(C_{1} + \\left(C_{2} + C_{3} x\\right) e^{x}\\right) e^{2 x}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "Trans. Sumudu de esa solución: $\\frac{- 9 C_{1} s^{2} + 6 C_{1} s - C_{1} - 6 C_{2} s^{2} + 5 C_{2} s - C_{2} + 2 C_{3} s^{2} - C_{3} s}{18 s^{3} - 21 s^{2} + 8 s - 1}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "$$\\therefore 2^{n} C_{1} + 3^{n} C_{2} + 3^{n - 1} C_{3} n.$$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "2**n*C1 + 3**n*C2 + 3**(n - 1)*C3*n"
            ],
            "text/latex": "$\\displaystyle 2^{n} C_{1} + 3^{n} C_{2} + 3^{n - 1} C_{3} n$"
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "y, Y= symbols('y Y', cls= Function)\n",
        "eq001= Eq(y(n+3), 7*y(n+1)-6*y(n))\n",
        "ics= {y(0): 24, y(1): 8, y(2): 6}\n",
        "display( rsolgen(eq001, y(n), ics, method='fgo') )"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 220
        },
        "id": "6rosKpiN1rQG",
        "outputId": "11f8231a-325b-4bd0-dab8-cbe98d243c37"
      },
      "execution_count": 14,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "Resolviendo la recursión $6 y{\\left(n \\right)} - 7 y{\\left(n + 1 \\right)} + y{\\left(n + 3 \\right)} = 0$ con $\\left\\{ y{\\left(0 \\right)} : 24, \\  y{\\left(1 \\right)} : 8, \\  y{\\left(2 \\right)} : 6\\right\\}$ mediante fgo:"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "FGO del miembro izquierdo de la recursión: $$\\sum_{n=0}^{\\infty} x^{n} \\left(6 y{\\left(n \\right)} - 7 y{\\left(n + 1 \\right)} + y{\\left(n + 3 \\right)}\\right) = 6 A{\\left(x \\right)} + \\frac{7 \\left(- A{\\left(x \\right)} + y{\\left(0 \\right)}\\right)}{x} + \\frac{- x^{2} y{\\left(2 \\right)} - x y{\\left(1 \\right)} + A{\\left(x \\right)} - y{\\left(0 \\right)}}{x^{3}}.$$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "Solución de la ecuación $6 A{\\left(x \\right)} + \\frac{7 \\left(- A{\\left(x \\right)} + y{\\left(0 \\right)}\\right)}{x} + \\frac{- x^{2} y{\\left(2 \\right)} - x y{\\left(1 \\right)} + A{\\left(x \\right)} - y{\\left(0 \\right)}}{x^{3}} = 0$: $$\\frac{- 162 x^{2} + 8 x + 24}{6 x^{3} - 7 x^{2} + 1}.$$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "$$\\therefore y{\\left(n \\right)} = \\frac{3 \\left(-3\\right)^{n}}{2} - 10 \\cdot 2^{n} + \\frac{65}{2}.$$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "Eq(y(n), 3*(-3)**n/2 - 10*2**n + 65/2)"
            ],
            "text/latex": "$\\displaystyle y{\\left(n \\right)} = \\frac{3 \\left(-3\\right)^{n}}{2} - 10 \\cdot 2^{n} + \\frac{65}{2}$"
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "eq001= Eq(a(n+5), 5*a(n+4)-10*a(n+3)+10*a(n+2)-5*a(n+1)+a(n))\n",
        "ics={a(i): i**4 for i in range(5)}\n",
        "display( rsolgen(eq001, a(n), ics, method='fge') )"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 277
        },
        "id": "fFGszqAU3Lr3",
        "outputId": "6a70361e-74a7-4b0a-b48f-b2abec500b3d"
      },
      "execution_count": 15,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "Resolviendo la recursión $- a{\\left(n \\right)} + 5 a{\\left(n + 1 \\right)} - 10 a{\\left(n + 2 \\right)} + 10 a{\\left(n + 3 \\right)} - 5 a{\\left(n + 4 \\right)} + a{\\left(n + 5 \\right)} = 0$ con $\\left\\{ a{\\left(0 \\right)} : 0, \\  a{\\left(1 \\right)} : 1, \\  a{\\left(2 \\right)} : 16, \\  a{\\left(3 \\right)} : 81, \\  a{\\left(4 \\right)} : 256\\right\\}$ mediante fge:"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "FGE del miembro izquierdo de la recursión: $$\\sum_{n=0}^{\\infty} \\frac{x^{n} \\left(- a{\\left(n \\right)} + 5 a{\\left(n + 1 \\right)} - 10 a{\\left(n + 2 \\right)} + 10 a{\\left(n + 3 \\right)} - 5 a{\\left(n + 4 \\right)} + a{\\left(n + 5 \\right)}\\right)}{n!} = - A{\\left(x \\right)} + 5 \\frac{d}{d x} A{\\left(x \\right)} - 10 \\frac{d^{2}}{d x^{2}} A{\\left(x \\right)} + 10 \\frac{d^{3}}{d x^{3}} A{\\left(x \\right)} - 5 \\frac{d^{4}}{d x^{4}} A{\\left(x \\right)} + \\frac{d^{5}}{d x^{5}} A{\\left(x \\right)}.$$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "Diccionario nuevo: $\\left\\{ A{\\left(0 \\right)} : 0, \\  \\left. \\frac{d}{d x} A{\\left(x \\right)} \\right|_{\\substack{ x=0 }} : 1, \\  \\left. \\frac{d^{2}}{d x^{2}} A{\\left(x \\right)} \\right|_{\\substack{ x=0 }} : 16, \\  \\left. \\frac{d^{3}}{d x^{3}} A{\\left(x \\right)} \\right|_{\\substack{ x=0 }} : 81, \\  \\left. \\frac{d^{4}}{d x^{4}} A{\\left(x \\right)} \\right|_{\\substack{ x=0 }} : 256\\right\\}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "Solución provisional: $A{\\left(x \\right)} = x \\left(x \\left(x \\left(x + 6\\right) + 7\\right) + 1\\right) e^{x}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "Trans. Sumudu de esa solución: $\\frac{s \\left(- s^{3} - 11 s^{2} - 11 s - 1\\right)}{s^{5} - 5 s^{4} + 10 s^{3} - 10 s^{2} + 5 s - 1}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.Markdown object>"
            ],
            "text/markdown": "$$\\therefore n^{4}.$$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "n**4"
            ],
            "text/latex": "$\\displaystyle n^{4}$"
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "#@title Sumas finitas\n",
        "sucesiones= [ n**2,\n",
        "              n**2*3**n,\n",
        "              5**n,\n",
        "              n*(n+1)*(n+2)*6 ]\n",
        "for an in sucesiones:\n",
        "  display( sumav1(an, n, 0, w) )"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 215
        },
        "id": "lU736NWdR5t4",
        "outputId": "81629d07-5a85-40c4-f496-cd49f2154e9f"
      },
      "execution_count": 16,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "Eq(Sum(n**2, (n, 0, w)), w*(w + 1)*(2*w + 1)/6)"
            ],
            "text/latex": "$\\displaystyle \\sum_{n=0}^{w} n^{2} = \\frac{w \\left(w + 1\\right) \\left(2 w + 1\\right)}{6}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "Eq(Sum(3**n*n**2, (n, 0, w)), 3*3**w*w**2/2 - 3*3**w*w/2 + 3*3**w/2 - 3/2)"
            ],
            "text/latex": "$\\displaystyle \\sum_{n=0}^{w} 3^{n} n^{2} = \\frac{3 \\cdot 3^{w} w^{2}}{2} - \\frac{3 \\cdot 3^{w} w}{2} + \\frac{3 \\cdot 3^{w}}{2} - \\frac{3}{2}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "Eq(Sum(5**n, (n, 0, w)), 5*5**w/4 - 1/4)"
            ],
            "text/latex": "$\\displaystyle \\sum_{n=0}^{w} 5^{n} = \\frac{5 \\cdot 5^{w}}{4} - \\frac{1}{4}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "Eq(Sum(6*n*(n + 1)*(n + 2), (n, 0, w)), 3*w*(w + 1)**2*(w + 2))"
            ],
            "text/latex": "$\\displaystyle \\sum_{n=0}^{w} 6 n \\left(n + 1\\right) \\left(n + 2\\right) = 3 w \\left(w + 1\\right)^{2} \\left(w + 2\\right)$"
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "f= x*(2*x**2+9*x+6)*exp(x)/6\n",
        "integrate(f.subs(x, s*x)/exp(x), (x, 0, oo)).args[0][0] #sumudu_transform( , x, s)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 61
        },
        "id": "eIAE6e2xeovA",
        "outputId": "94b9a9ae-fd07-4e02-851e-8d6f01490850"
      },
      "execution_count": 17,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "2*s**3/(1 - s)**4 + 3*s**2/(1 - s)**3 + s/(1 - s)**2"
            ],
            "text/latex": "$\\displaystyle \\frac{2 s^{3}}{\\left(1 - s\\right)^{4}} + \\frac{3 s^{2}}{\\left(1 - s\\right)^{3}} + \\frac{s}{\\left(1 - s\\right)^{2}}$"
          },
          "metadata": {},
          "execution_count": 17
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "for an in sucesiones:\n",
        "  display( sumav2(an, n, 0, w) )"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 215
        },
        "id": "DHBYTpO1VJUZ",
        "outputId": "542c692e-a891-4393-ce0c-50d99d885c77"
      },
      "execution_count": 18,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "Eq(Sum(n**2, (n, 0, w)), w*(w + 1)*(2*w + 1)/6)"
            ],
            "text/latex": "$\\displaystyle \\sum_{n=0}^{w} n^{2} = \\frac{w \\left(w + 1\\right) \\left(2 w + 1\\right)}{6}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "Eq(Sum(3**n*n**2, (n, 0, w)), 3*3**w*w**2/2 - 3*3**w*w/2 + 3*3**w/2 - 3/2)"
            ],
            "text/latex": "$\\displaystyle \\sum_{n=0}^{w} 3^{n} n^{2} = \\frac{3 \\cdot 3^{w} w^{2}}{2} - \\frac{3 \\cdot 3^{w} w}{2} + \\frac{3 \\cdot 3^{w}}{2} - \\frac{3}{2}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "Eq(Sum(5**n, (n, 0, w)), 5*5**w/4 - 1/4)"
            ],
            "text/latex": "$\\displaystyle \\sum_{n=0}^{w} 5^{n} = \\frac{5 \\cdot 5^{w}}{4} - \\frac{1}{4}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "Eq(Sum(6*n*(n + 1)*(n + 2), (n, 0, w)), 3*w*(w + 1)**2*(w + 2))"
            ],
            "text/latex": "$\\displaystyle \\sum_{n=0}^{w} 6 n \\left(n + 1\\right) \\left(n + 2\\right) = 3 w \\left(w + 1\\right)^{2} \\left(w + 2\\right)$"
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "for an in sucesiones:\n",
        "  display( Sum(an, (n, 0, w)).doit() )"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 164
        },
        "id": "bBmJJKGwgev4",
        "outputId": "97f385c0-ea5d-479d-b4b7-9a104047c629"
      },
      "execution_count": 19,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "w**3/3 + w**2/2 + w/6"
            ],
            "text/latex": "$\\displaystyle \\frac{w^{3}}{3} + \\frac{w^{2}}{2} + \\frac{w}{6}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "3*3**w*w**2/2 - 3*3**w*w/2 + 3*3**w/2 - 3/2"
            ],
            "text/latex": "$\\displaystyle \\frac{3 \\cdot 3^{w} w^{2}}{2} - \\frac{3 \\cdot 3^{w} w}{2} + \\frac{3 \\cdot 3^{w}}{2} - \\frac{3}{2}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "5**(w + 1)/4 - 1/4"
            ],
            "text/latex": "$\\displaystyle \\frac{5^{w + 1}}{4} - \\frac{1}{4}$"
          },
          "metadata": {}
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "3*w**4/2 + 9*w**3 + 33*w**2/2 + 9*w"
            ],
            "text/latex": "$\\displaystyle \\frac{3 w^{4}}{2} + 9 w^{3} + \\frac{33 w^{2}}{2} + 9 w$"
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "sumav2(n**4*6**n, n, 0, j)"
      ],
      "metadata": {
        "id": "DzMKUWunsaPC",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 72
        },
        "outputId": "0ec14df9-369d-4256-d3be-3cfdf09d3e09"
      },
      "execution_count": 20,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "Eq(Sum(6**n*n**4, (n, 0, x**4*exp(6*x))), 6*6**(x**4*exp(6*x))*x**16*exp(24*x)/5 - 24*6**(x**4*exp(6*x))*x**12*exp(18*x)/25 + 252*6**(x**4*exp(6*x))*x**8*exp(12*x)/125 - 1464*6**(x**4*exp(6*x))*x**4*exp(6*x)/625 + 4074*6**(x**4*exp(6*x))/3125 - 4074/3125)"
            ],
            "text/latex": "$\\displaystyle \\sum_{n=0}^{x^{4} e^{6 x}} 6^{n} n^{4} = \\frac{6 \\cdot 6^{x^{4} e^{6 x}} x^{16} e^{24 x}}{5} - \\frac{24 \\cdot 6^{x^{4} e^{6 x}} x^{12} e^{18 x}}{25} + \\frac{252 \\cdot 6^{x^{4} e^{6 x}} x^{8} e^{12 x}}{125} - \\frac{1464 \\cdot 6^{x^{4} e^{6 x}} x^{4} e^{6 x}}{625} + \\frac{4074 \\cdot 6^{x^{4} e^{6 x}}}{3125} - \\frac{4074}{3125}$"
          },
          "metadata": {},
          "execution_count": 20
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "combfge(n**4*6**n)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 66
        },
        "id": "RZAz5Scd_QXY",
        "outputId": "9a53a9e9-c91c-491f-a4d4-2a5986e0486f"
      },
      "execution_count": 21,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "Eq(Sum(6**n*n**4*x**n/factorial(n), (n, 0, oo)), 6*x*(216*x**3 + 216*x**2 + 42*x + 1)*exp(6*x))"
            ],
            "text/latex": "$\\displaystyle \\sum_{n=0}^{\\infty} \\frac{6^{n} n^{4} x^{n}}{n!} = 6 x \\left(216 x^{3} + 216 x^{2} + 42 x + 1\\right) e^{6 x}$"
          },
          "metadata": {},
          "execution_count": 21
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "simplify(_.rhs + exp(x) * integrate(_.rhs.subs(x, t) * exp(-t), (t, 0, x)))"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 56
        },
        "id": "wfYEXKabAQnh",
        "outputId": "ab306612-5302-4bc2-f92c-dc6d43b206fd"
      },
      "execution_count": 22,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "6*(810000*x**4*exp(5*x) + 702000*x**3*exp(5*x) + 141300*x**2*exp(5*x) - 270*x*exp(5*x) + 679*exp(5*x) - 679)*exp(x)/3125"
            ],
            "text/latex": "$\\displaystyle \\frac{6 \\left(810000 x^{4} e^{5 x} + 702000 x^{3} e^{5 x} + 141300 x^{2} e^{5 x} - 270 x e^{5 x} + 679 e^{5 x} - 679\\right) e^{x}}{3125}$"
          },
          "metadata": {},
          "execution_count": 22
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "expand(_)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 54
        },
        "id": "kvRJ96NEAeQM",
        "outputId": "09d73857-04a7-4eb8-8b94-55324bd2ab55"
      },
      "execution_count": 23,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "7776*x**4*exp(6*x)/5 + 33696*x**3*exp(6*x)/25 + 33912*x**2*exp(6*x)/125 - 324*x*exp(6*x)/625 + 4074*exp(6*x)/3125 - 4074*exp(x)/3125"
            ],
            "text/latex": "$\\displaystyle \\frac{7776 x^{4} e^{6 x}}{5} + \\frac{33696 x^{3} e^{6 x}}{25} + \\frac{33912 x^{2} e^{6 x}}{125} - \\frac{324 x e^{6 x}}{625} + \\frac{4074 e^{6 x}}{3125} - \\frac{4074 e^{x}}{3125}$"
          },
          "metadata": {},
          "execution_count": 23
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "sumudu_transform(_, x, s)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 57
        },
        "id": "E2NXPJoAAqa0",
        "outputId": "4b02c645-bb04-420c-fb7d-354faca24aaf"
      },
      "execution_count": 24,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "6*s*(216*s**3 + 396*s**2 + 66*s + 1)/(7776*s**6 - 14256*s**5 + 8640*s**4 - 2520*s**3 + 390*s**2 - 31*s + 1)"
            ],
            "text/latex": "$\\displaystyle \\frac{6 s \\left(216 s^{3} + 396 s^{2} + 66 s + 1\\right)}{7776 s^{6} - 14256 s^{5} + 8640 s^{4} - 2520 s^{3} + 390 s^{2} - 31 s + 1}$"
          },
          "metadata": {},
          "execution_count": 24
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "extcoef(_, s, n)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 54
        },
        "id": "7sHa-iteAvAz",
        "outputId": "30e3443e-db68-4e67-e9f4-abc919c14e05"
      },
      "execution_count": 25,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "6*6**n*n**4/5 - 24*6**n*n**3/25 + 252*6**n*n**2/125 - 1464*6**n*n/625 + 4074*6**n/3125 - 4074/3125"
            ],
            "text/latex": "$\\displaystyle \\frac{6 \\cdot 6^{n} n^{4}}{5} - \\frac{24 \\cdot 6^{n} n^{3}}{25} + \\frac{252 \\cdot 6^{n} n^{2}}{125} - \\frac{1464 \\cdot 6^{n} n}{625} + \\frac{4074 \\cdot 6^{n}}{3125} - \\frac{4074}{3125}$"
          },
          "metadata": {},
          "execution_count": 25
        }
      ]
    }
  ]
}