{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"# Pullback with large symbolic expressions\n",
"\n",
"This worksheet is relative the `ask.sagemath` question [*Pullback computation hanging*](https://ask.sagemath.org/question/40852/pullback-computation-hanging/)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"text/plain": [
"'SageMath version 8.1, Release Date: 2017-12-07'"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"version()"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true,
"deletable": true,
"editable": true
},
"outputs": [],
"source": [
"%display latex"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
"2*b2/a^3 da/\\db1 - 2*b1/a^3 da/\\db2 - 2/a^2 db1/\\db2"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"M = Manifold(3, 'M')\n",
"X. = M.chart()\n",
"\n",
"N = Manifold(3, 'N')\n",
"XN. = N.chart()\n",
"\n",
"omega = N.diff_form(2)\n",
"omega[0,1] = 2*b2/a^3\n",
"omega[0,2] = -2*b1/a^3\n",
"omega[1,2] = -2/a^2\n",
"omega.display()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
"M --> N\n",
" (x, y, z) |--> (a, b1, b2) = ((x^2 + y^2 + z^2)^(1/4)/sqrt(-z*sinh(2*sqrt(x^2 + y^2 + z^2)*t) + sqrt(x^2 + y^2 + z^2)*cosh(2*sqrt(x^2 + y^2 + z^2)*t)), x*sinh(2*sqrt(x^2 + y^2 + z^2)*t)/((x^2 + y^2 + z^2)^(1/4)*sqrt(-z*sinh(2*sqrt(x^2 + y^2 + z^2)*t) + sqrt(x^2 + y^2 + z^2)*cosh(2*sqrt(x^2 + y^2 + z^2)*t))), y*sinh(2*sqrt(x^2 + y^2 + z^2)*t)/((x^2 + y^2 + z^2)^(1/4)*sqrt(-z*sinh(2*sqrt(x^2 + y^2 + z^2)*t) + sqrt(x^2 + y^2 + z^2)*cosh(2*sqrt(x^2 + y^2 + z^2)*t))))"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"r = sqrt(x^2+y^2+z^2)\n",
"t = var('t', domain='real')\n",
"STSa = r^(1/2)*(r*cosh(2*r*t) - z*sinh(2*r*t))^(-1/2)\n",
"STSb1 = (x*sinh(2*r*t)/r)*STSa\n",
"STSb2 = (y*sinh(2*r*t)/r)*STSa\n",
"\n",
"STS = M.diffeomorphism(N, [STSa, STSb1, STSb2])\n",
"STS.display()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 8.43 s, sys: 28 ms, total: 8.46 s\n",
"Wall time: 8.44 s\n"
]
},
{
"data": {
"text/html": [
""
],
"text/plain": [
"((2*t*x^3 + 2*t*x*y^2 + 2*t*x*z^2 + x*z)*cosh(sqrt(x^2 + y^2 + z^2)*t)*sinh(sqrt(x^2 + y^2 + z^2)*t) - (2*t*x*z*sinh(sqrt(x^2 + y^2 + z^2)*t)^2 + t*x*z)*sqrt(x^2 + y^2 + z^2))*sqrt(-2*z*cosh(sqrt(x^2 + y^2 + z^2)*t)*sinh(sqrt(x^2 + y^2 + z^2)*t) + sqrt(x^2 + y^2 + z^2)*(2*sinh(sqrt(x^2 + y^2 + z^2)*t)^2 + 1))/(4*(2*(z^3 + (x^2 + y^2)*z)*cosh(sqrt(x^2 + y^2 + z^2)*t)^3 - (z^3 + (x^2 + y^2)*z)*cosh(sqrt(x^2 + y^2 + z^2)*t))*(x^2 + y^2 + z^2)^(1/4)*sinh(sqrt(x^2 + y^2 + z^2)*t) - (4*(x^2 + y^2 + 2*z^2)*cosh(sqrt(x^2 + y^2 + z^2)*t)^4 - 4*(x^2 + y^2 + 2*z^2)*cosh(sqrt(x^2 + y^2 + z^2)*t)^2 + x^2 + y^2 + z^2)*(x^2 + y^2 + z^2)^(3/4))"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%time STS.jacobian_matrix()[0,0]"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 19min 52s, sys: 2.72 s, total: 19min 54s\n",
"Wall time: 19min 51s\n"
]
},
{
"data": {
"text/html": [
""
],
"text/plain": [
"2-form on the 3-dimensional differentiable manifold M"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%time s = STS.pullback(omega)\n",
"s"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"The number of characters in each of the non-vanishing components of $s$:"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
"[400626, 116291, 116292]"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"[len(str(s[ind])) for ind in [(0,1), (0,2), (1,2)]] "
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"The first 1000 characters of $s_{01}$:"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-8*((536870912*(268435456*z^31 + 2080374784*(x^2 + y^2)*z^29 + 7264534528*(x^4 + 2*x^2*y^2 + y^4)*z^27 + 15099494400*(x^6 + 3*x^4*y^2 + 3*x^2*y^4 + y^6)*z^25 + 20789067776*(x^8 + 4*x^6*y^2 + 6*x^4*y^4 + 4*x^2*y^6 + y^8)*z^23 + 19963052032*(x^10 + 5*x^8*y^2 + 10*x^6*y^4 + 10*x^4*y^6 + 5*x^2*y^8 + y^10)*z^21 + 13710721024*(x^12 + 6*x^10*y^2 + 15*x^8*y^4 + 20*x^6*y^6 + 15*x^4*y^8 + 6*x^2*y^10 + y^12)*z^19 + 6794969088*(x^14 + 7*x^12*y^2 + 21*x^10*y^4 + 35*x^8*y^6 + 35*x^6*y^8 + 21*x^4*y^10 + 7*x^2*y^12 + y^14)*z^17 + 2421104640*(x^16 + 8*x^14*y^2 + 28*x^12*y^4 + 56*x^10*y^6 + 70*x^8*y^8 + 56*x^6*y^10 + 28*x^4*y^12 + 8*x^2*y^14 + y^16)*z^15 + 610568192*(x^18 + 9*x^16*y^2 + 36*x^14*y^4 + 84*x^12*y^6 + 126*x^10*y^8 + 126*x^8*y^10 + 84*x^6*y^12 + 36*x^4*y^14 + 9*x^2*y^16 + y^18)*z^13 + 105797120*(x^20 + 10*x^18*y^2 + 45*x^16*y^4 + 120*x^14*y^6 + 210*x^12*y^8 + 252*x^10*y^10 + 210*x^8*y^12 + 120*x^6*y^14 + 45*x^4*y^16 + 10*x^2*y^18 + y^20)*z^11 + 11994112*(x^22 + 11*x^20*y^2 + 55*x^18*y^4 + 16\n"
]
}
],
"source": [
"print(str(s[0,1])[:1000])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"deletable": true,
"editable": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "SageMath 8.1",
"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.14"
}
},
"nbformat": 4,
"nbformat_minor": 2
}