{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Helmholtz energy conversion of cubics"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As in Michelsen's book, PR and SRK can be given the common form:\n",
    "$$ p = \\frac{RT}{v-b}-\\frac{a(T)}{(v+\\Delta_1b)(v+\\Delta_2b)} $$\n",
    "which can be ultimately converted to\n",
    "$$ \\alpha^r = - \\log{\\left (- b \\delta \\rho_{r} + 1 \\right )} - \\frac{\\tau a{\\left (\\tau \\right )}}{R T_{c} b \\left(\\Delta_{1} - \\Delta_{2}\\right)} \\log{\\left (\\frac{\\Delta_{1} b \\delta \\rho_{r} + 1}{\\Delta_{2} b \\delta \\rho_{r} + 1} \\right )} $$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "IPython console for SymPy 0.7.6 (Python 2.7.10-64-bit) (ground types: python)\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from sympy import *\n",
    "from IPython.display import display, Math, Latex\n",
    "from IPython.core.display import display_html\n",
    "init_session(quiet=True, use_latex='mathjax')\n",
    "init_printing()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "b,rho_r,tau,delta,T_c,R,Delta_1,Delta_2 = symbols('b,rho_r,tau,delta,T_c,R,Delta_1,Delta_2')\n",
    "a = symbols('a', cls=Function)(tau)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAVsAAAApCAYAAACbUoqTAAAABHNCSVQICAgIfAhkiAAADZVJREFU\neJztnXm8FlUZx7/3XhZF2RHIBQFFo1gKTcpEQUnLJclcECxNDQqXj+KumRd3K8wSl1LxuqSmSYtl\noUaYSx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RNplEdJc2DUszyCMpk4AzAvsuIdzRV092QxEB3cslTEDY\nPSeliGuQDUaRHmnj5i2WQjENzyZbjmaycSwtzSCPJPRFWr1JM9Kmish8NLioGsLuOQ2HULogp5n3\nQvyTqNeCm0i2OrfFUmgux1tivB/x8zuAwm7CYknTsLTK85NyDNIUu+OZWg7GC4MqGj2RTb2a+g27\n5zScT3SsfRPwswrLVSmHES38LZZOxUTkAJlM+NwVYRxOZRPRbIwcLStRVEKeITwzkHNoFZojYwxy\nGB2U4zWzoC+aOaySlUfC7jlLtqd6zTsNo1FURRamFYvFYrFYLBaLxWKxWCwWi8VisdSA/wM0c1JY\ny04SRwAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$$- \\log{\\left (- b \\delta \\rho_{r} + 1 \\right )} - \\frac{\\tau a{\\left (\\tau \\right )}}{R T_{c} b \\left(\\Delta_{1} - \\Delta_{2}\\right)} \\log{\\left (\\frac{\\Delta_{1} b \\delta \\rho_{r} + 1}{\\Delta_{2} b \\delta \\rho_{r} + 1} \\right )}$$"
      ],
      "text/plain": [
       "                              ⎛Δ₁⋅b⋅δ⋅ρᵣ + 1⎞\n",
       "                    τ⋅a(τ)⋅log⎜─────────────⎟\n",
       "                              ⎝Δ₂⋅b⋅δ⋅ρᵣ + 1⎠\n",
       "-log(-b⋅δ⋅ρᵣ + 1) - ─────────────────────────\n",
       "                        R⋅T_c⋅b⋅(Δ₁ - Δ₂)    "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "alphar = -log(1-b*rho_r*delta)-a*tau/(R*b*T_c*(Delta_1-Delta_2))*log((1+Delta_1*b*rho_r*delta)/(1+Delta_2*b*rho_r*delta))\n",
    "display(alphar)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "def format_deriv(arg, itau, idel, RHS):\n",
    "    \"\"\" \n",
    "    A function for giving a nice latex representation of \n",
    "    the partial derivative in question \n",
    "    \"\"\"\n",
    "    if itau+idel == 1:\n",
    "        numexp = ''\n",
    "    else:\n",
    "        numexp = '^{{{s:d}}}'.format(s=itau+idel)\n",
    "        \n",
    "    if itau == 0:\n",
    "        tau = ''\n",
    "    elif itau == 1:\n",
    "        tau = '\\\\partial \\\\tau'\n",
    "    else:\n",
    "        tau = '\\\\partial \\\\tau^{{{s:d}}}'.format(s=itau)\n",
    "        \n",
    "    if idel == 0:\n",
    "        delta = ''\n",
    "    elif idel == 1:\n",
    "        delta = '\\\\partial \\\\delta'\n",
    "    else:\n",
    "        delta = '\\\\partial \\\\delta^{{{s:d}}}'.format(s=idel)\n",
    "        \n",
    "    temp = '\\\\frac{{\\\\partial{{{numexp:s}}} {arg:s}}}{{{{{tau:s}}}{{{delta:s}}}}} = '\n",
    "    return Math(temp.format(**locals()) + latex(RHS))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\frac{\\partial{} \\alpha^r}{{}{\\partial \\delta}} = \\frac{b \\rho_{r}}{- b \\delta \\rho_{r} + 1} - \\frac{\\tau a{\\left (\\tau \\right )}}{R T_{c} b \\left(\\Delta_{1} - \\Delta_{2}\\right) \\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right)} \\left(\\frac{\\Delta_{1} b \\rho_{r}}{\\Delta_{2} b \\delta \\rho_{r} + 1} - \\frac{\\Delta_{2} b \\rho_{r} \\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right)}{\\left(\\Delta_{2} b \\delta \\rho_{r} + 1\\right)^{2}}\\right) \\left(\\Delta_{2} b \\delta \\rho_{r} + 1\\right)$$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$$\\frac{\\partial{} \\alpha^r}{{\\partial \\tau}{}} = - \\frac{\\tau \\frac{d}{d \\tau} a{\\left (\\tau \\right )}}{R T_{c} b \\left(\\Delta_{1} - \\Delta_{2}\\right)} \\log{\\left (\\frac{\\Delta_{1} b \\delta \\rho_{r} + 1}{\\Delta_{2} b \\delta \\rho_{r} + 1} \\right )} - \\frac{a{\\left (\\tau \\right )}}{R T_{c} b \\left(\\Delta_{1} - \\Delta_{2}\\right)} \\log{\\left (\\frac{\\Delta_{1} b \\delta \\rho_{r} + 1}{\\Delta_{2} b \\delta \\rho_{r} + 1} \\right )}$$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$$\\frac{\\partial{^{2}} \\alpha^r}{{}{\\partial \\delta^{2}}} = b \\rho_{r}^{2} \\left(\\frac{\\Delta_{1} \\tau \\left(\\Delta_{1} - \\frac{\\Delta_{2} \\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right)}{\\Delta_{2} b \\delta \\rho_{r} + 1}\\right) a{\\left (\\tau \\right )}}{R T_{c} \\left(\\Delta_{1} - \\Delta_{2}\\right) \\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right)^{2}} + \\frac{\\Delta_{2} \\tau \\left(\\Delta_{1} - \\frac{\\Delta_{2} \\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right)}{\\Delta_{2} b \\delta \\rho_{r} + 1}\\right) a{\\left (\\tau \\right )}}{R T_{c} \\left(\\Delta_{1} - \\Delta_{2}\\right) \\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right) \\left(\\Delta_{2} b \\delta \\rho_{r} + 1\\right)} + \\frac{b}{\\left(b \\delta \\rho_{r} - 1\\right)^{2}}\\right)$$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$$\\frac{\\partial{^{2}} \\alpha^r}{{\\partial \\tau}{\\partial \\delta}} = - \\frac{\\tau \\frac{d}{d \\tau} a{\\left (\\tau \\right )}}{R T_{c} b \\left(\\Delta_{1} - \\Delta_{2}\\right) \\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right)} \\left(\\frac{\\Delta_{1} b \\rho_{r}}{\\Delta_{2} b \\delta \\rho_{r} + 1} - \\frac{\\Delta_{2} b \\rho_{r} \\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right)}{\\left(\\Delta_{2} b \\delta \\rho_{r} + 1\\right)^{2}}\\right) \\left(\\Delta_{2} b \\delta \\rho_{r} + 1\\right) - \\frac{a{\\left (\\tau \\right )}}{R T_{c} b \\left(\\Delta_{1} - \\Delta_{2}\\right) \\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right)} \\left(\\frac{\\Delta_{1} b \\rho_{r}}{\\Delta_{2} b \\delta \\rho_{r} + 1} - \\frac{\\Delta_{2} b \\rho_{r} \\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right)}{\\left(\\Delta_{2} b \\delta \\rho_{r} + 1\\right)^{2}}\\right) \\left(\\Delta_{2} b \\delta \\rho_{r} + 1\\right)$$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$$\\frac{\\partial{^{2}} \\alpha^r}{{\\partial \\tau^{2}}{}} = - \\frac{1}{R T_{c} b \\left(\\Delta_{1} - \\Delta_{2}\\right)} \\left(\\tau \\frac{d^{2}}{d \\tau^{2}}  a{\\left (\\tau \\right )} + 2 \\frac{d}{d \\tau} a{\\left (\\tau \\right )}\\right) \\log{\\left (\\frac{\\Delta_{1} b \\delta \\rho_{r} + 1}{\\Delta_{2} b \\delta \\rho_{r} + 1} \\right )}$$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$$\\frac{\\partial{^{3}} \\alpha^r}{{}{\\partial \\delta^{3}}} = 2 b^{2} \\rho_{r}^{3} \\left(- \\frac{\\Delta_{1}^{2} \\tau \\left(\\Delta_{1} - \\frac{\\Delta_{2} \\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right)}{\\Delta_{2} b \\delta \\rho_{r} + 1}\\right) a{\\left (\\tau \\right )}}{R T_{c} \\left(\\Delta_{1} - \\Delta_{2}\\right) \\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right)^{3}} - \\frac{\\Delta_{1} \\Delta_{2} \\tau \\left(\\Delta_{1} - \\frac{\\Delta_{2} \\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right)}{\\Delta_{2} b \\delta \\rho_{r} + 1}\\right) a{\\left (\\tau \\right )}}{R T_{c} \\left(\\Delta_{1} - \\Delta_{2}\\right) \\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right)^{2} \\left(\\Delta_{2} b \\delta \\rho_{r} + 1\\right)} - \\frac{\\Delta_{2}^{2} \\tau \\left(\\Delta_{1} - \\frac{\\Delta_{2} \\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right)}{\\Delta_{2} b \\delta \\rho_{r} + 1}\\right) a{\\left (\\tau \\right )}}{R T_{c} \\left(\\Delta_{1} - \\Delta_{2}\\right) \\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right) \\left(\\Delta_{2} b \\delta \\rho_{r} + 1\\right)^{2}} - \\frac{b}{\\left(b \\delta \\rho_{r} - 1\\right)^{3}}\\right)$$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$$\\frac{\\partial{^{3}} \\alpha^r}{{\\partial \\tau}{\\partial \\delta^{2}}} = \\frac{b \\rho_{r}^{2}}{R T_{c} \\left(\\Delta_{1} - \\Delta_{2}\\right) \\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right)} \\left(\\Delta_{1} - \\frac{\\Delta_{2} \\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right)}{\\Delta_{2} b \\delta \\rho_{r} + 1}\\right) \\left(\\frac{\\Delta_{1} \\tau \\frac{d}{d \\tau} a{\\left (\\tau \\right )}}{\\Delta_{1} b \\delta \\rho_{r} + 1} + \\frac{\\Delta_{1} a{\\left (\\tau \\right )}}{\\Delta_{1} b \\delta \\rho_{r} + 1} + \\frac{\\Delta_{2} \\tau \\frac{d}{d \\tau} a{\\left (\\tau \\right )}}{\\Delta_{2} b \\delta \\rho_{r} + 1} + \\frac{\\Delta_{2} a{\\left (\\tau \\right )}}{\\Delta_{2} b \\delta \\rho_{r} + 1}\\right)$$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$$\\frac{\\partial{^{3}} \\alpha^r}{{\\partial \\tau^{2}}{\\partial \\delta}} = - \\frac{1}{R T_{c} b \\left(\\Delta_{1} - \\Delta_{2}\\right) \\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right)} \\left(\\tau \\frac{d^{2}}{d \\tau^{2}}  a{\\left (\\tau \\right )} + 2 \\frac{d}{d \\tau} a{\\left (\\tau \\right )}\\right) \\left(\\frac{\\Delta_{1} b \\rho_{r}}{\\Delta_{2} b \\delta \\rho_{r} + 1} - \\frac{\\Delta_{2} b \\rho_{r} \\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right)}{\\left(\\Delta_{2} b \\delta \\rho_{r} + 1\\right)^{2}}\\right) \\left(\\Delta_{2} b \\delta \\rho_{r} + 1\\right)$$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$$\\frac{\\partial{^{3}} \\alpha^r}{{\\partial \\tau^{3}}{}} = - \\frac{1}{R T_{c} b \\left(\\Delta_{1} - \\Delta_{2}\\right)} \\left(\\tau \\frac{d^{3}}{d \\tau^{3}}  a{\\left (\\tau \\right )} + 3 \\frac{d^{2}}{d \\tau^{2}}  a{\\left (\\tau \\right )}\\right) \\log{\\left (\\frac{\\Delta_{1} b \\delta \\rho_{r} + 1}{\\Delta_{2} b \\delta \\rho_{r} + 1} \\right )}$$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$$\\frac{\\partial{^{4}} \\alpha^r}{{}{\\partial \\delta^{4}}} = 6 b^{3} \\rho_{r}^{4} \\left(\\frac{\\Delta_{1}^{3} \\tau \\left(\\Delta_{1} - \\frac{\\Delta_{2} \\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right)}{\\Delta_{2} b \\delta \\rho_{r} + 1}\\right) a{\\left (\\tau \\right )}}{R T_{c} \\left(\\Delta_{1} - \\Delta_{2}\\right) \\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right)^{4}} + \\frac{\\Delta_{1}^{2} \\Delta_{2} \\tau \\left(\\Delta_{1} - \\frac{\\Delta_{2} \\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right)}{\\Delta_{2} b \\delta \\rho_{r} + 1}\\right) a{\\left (\\tau \\right )}}{R T_{c} \\left(\\Delta_{1} - \\Delta_{2}\\right) \\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right)^{3} \\left(\\Delta_{2} b \\delta \\rho_{r} + 1\\right)} + \\frac{\\Delta_{1} \\Delta_{2}^{2} \\tau \\left(\\Delta_{1} - \\frac{\\Delta_{2} \\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right)}{\\Delta_{2} b \\delta \\rho_{r} + 1}\\right) a{\\left (\\tau \\right )}}{R T_{c} \\left(\\Delta_{1} - \\Delta_{2}\\right) \\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right)^{2} \\left(\\Delta_{2} b \\delta \\rho_{r} + 1\\right)^{2}} + \\frac{\\Delta_{2}^{3} \\tau \\left(\\Delta_{1} - \\frac{\\Delta_{2} \\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right)}{\\Delta_{2} b \\delta \\rho_{r} + 1}\\right) a{\\left (\\tau \\right )}}{R T_{c} \\left(\\Delta_{1} - \\Delta_{2}\\right) \\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right) \\left(\\Delta_{2} b \\delta \\rho_{r} + 1\\right)^{3}} + \\frac{b}{\\left(b \\delta \\rho_{r} - 1\\right)^{4}}\\right)$$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$$\\frac{\\partial{^{4}} \\alpha^r}{{\\partial \\tau}{\\partial \\delta^{3}}} = \\frac{2 b^{2} \\rho_{r}^{3}}{R T_{c} \\left(\\Delta_{1} - \\Delta_{2}\\right) \\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right)} \\left(\\Delta_{1} - \\frac{\\Delta_{2} \\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right)}{\\Delta_{2} b \\delta \\rho_{r} + 1}\\right) \\left(- \\frac{\\Delta_{1}^{2} \\tau \\frac{d}{d \\tau} a{\\left (\\tau \\right )}}{\\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right)^{2}} - \\frac{\\Delta_{1}^{2} a{\\left (\\tau \\right )}}{\\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right)^{2}} - \\frac{\\Delta_{1} \\Delta_{2} \\tau \\frac{d}{d \\tau} a{\\left (\\tau \\right )}}{\\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right) \\left(\\Delta_{2} b \\delta \\rho_{r} + 1\\right)} - \\frac{\\Delta_{1} \\Delta_{2} a{\\left (\\tau \\right )}}{\\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right) \\left(\\Delta_{2} b \\delta \\rho_{r} + 1\\right)} - \\frac{\\Delta_{2}^{2} \\tau \\frac{d}{d \\tau} a{\\left (\\tau \\right )}}{\\left(\\Delta_{2} b \\delta \\rho_{r} + 1\\right)^{2}} - \\frac{\\Delta_{2}^{2} a{\\left (\\tau \\right )}}{\\left(\\Delta_{2} b \\delta \\rho_{r} + 1\\right)^{2}}\\right)$$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$$\\frac{\\partial{^{4}} \\alpha^r}{{\\partial \\tau^{2}}{\\partial \\delta^{2}}} = \\frac{b \\rho_{r}^{2}}{R T_{c} \\left(\\Delta_{1} - \\Delta_{2}\\right) \\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right)} \\left(\\Delta_{1} - \\frac{\\Delta_{2} \\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right)}{\\Delta_{2} b \\delta \\rho_{r} + 1}\\right) \\left(\\frac{\\Delta_{1}}{\\Delta_{1} b \\delta \\rho_{r} + 1} + \\frac{\\Delta_{2}}{\\Delta_{2} b \\delta \\rho_{r} + 1}\\right) \\left(\\tau \\frac{d^{2}}{d \\tau^{2}}  a{\\left (\\tau \\right )} + 2 \\frac{d}{d \\tau} a{\\left (\\tau \\right )}\\right)$$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$$\\frac{\\partial{^{4}} \\alpha^r}{{\\partial \\tau^{3}}{\\partial \\delta}} = - \\frac{1}{R T_{c} b \\left(\\Delta_{1} - \\Delta_{2}\\right) \\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right)} \\left(\\tau \\frac{d^{3}}{d \\tau^{3}}  a{\\left (\\tau \\right )} + 3 \\frac{d^{2}}{d \\tau^{2}}  a{\\left (\\tau \\right )}\\right) \\left(\\frac{\\Delta_{1} b \\rho_{r}}{\\Delta_{2} b \\delta \\rho_{r} + 1} - \\frac{\\Delta_{2} b \\rho_{r} \\left(\\Delta_{1} b \\delta \\rho_{r} + 1\\right)}{\\left(\\Delta_{2} b \\delta \\rho_{r} + 1\\right)^{2}}\\right) \\left(\\Delta_{2} b \\delta \\rho_{r} + 1\\right)$$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$$\\frac{\\partial{^{4}} \\alpha^r}{{\\partial \\tau^{4}}{}} = - \\frac{1}{R T_{c} b \\left(\\Delta_{1} - \\Delta_{2}\\right)} \\left(\\tau \\frac{d^{4}}{d \\tau^{4}}  a{\\left (\\tau \\right )} + 4 \\frac{d^{3}}{d \\tau^{3}}  a{\\left (\\tau \\right )}\\right) \\log{\\left (\\frac{\\Delta_{1} b \\delta \\rho_{r} + 1}{\\Delta_{2} b \\delta \\rho_{r} + 1} \\right )}$$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "for deriv_count in range(1,5):\n",
    "    for dtau in range(deriv_count+1):\n",
    "        ddelta = deriv_count-dtau\n",
    "        #print dtau, ddelta\n",
    "        display(format_deriv('\\\\alpha^r', dtau, ddelta, diff(diff(alphar,tau,dtau),delta,ddelta)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "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.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
