{ "cells": [ { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "# Pullback with large symbolic expressions\n", "## exp version\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": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "We enforce the use of the $\\exp$ representation of $\\cosh$ and $\\sinh$:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": true, "deletable": true, "editable": true }, "outputs": [], "source": [ "cosh_e(x) = (exp(x) + exp(-x))/2\n", "sinh_e(x) = (exp(x) - exp(-x))/2" ] }, { "cell_type": "code", "execution_count": 5, "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(-1/2*z*(e^(2*sqrt(x^2 + y^2 + z^2)*t) - e^(-2*sqrt(x^2 + y^2 + z^2)*t)) + 1/2*sqrt(x^2 + y^2 + z^2)*(e^(2*sqrt(x^2 + y^2 + z^2)*t) + e^(-2*sqrt(x^2 + y^2 + z^2)*t))), 1/2*x*(e^(2*sqrt(x^2 + y^2 + z^2)*t) - e^(-2*sqrt(x^2 + y^2 + z^2)*t))/((x^2 + y^2 + z^2)^(1/4)*sqrt(-1/2*z*(e^(2*sqrt(x^2 + y^2 + z^2)*t) - e^(-2*sqrt(x^2 + y^2 + z^2)*t)) + 1/2*sqrt(x^2 + y^2 + z^2)*(e^(2*sqrt(x^2 + y^2 + z^2)*t) + e^(-2*sqrt(x^2 + y^2 + z^2)*t)))), 1/2*y*(e^(2*sqrt(x^2 + y^2 + z^2)*t) - e^(-2*sqrt(x^2 + y^2 + z^2)*t))/((x^2 + y^2 + z^2)^(1/4)*sqrt(-1/2*z*(e^(2*sqrt(x^2 + y^2 + z^2)*t) - e^(-2*sqrt(x^2 + y^2 + z^2)*t)) + 1/2*sqrt(x^2 + y^2 + z^2)*(e^(2*sqrt(x^2 + y^2 + z^2)*t) + e^(-2*sqrt(x^2 + y^2 + z^2)*t)))))" ] }, "execution_count": 5, "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_e(2*r*t) - z*sinh_e(2*r*t))^(-1/2)\n", "STSb1 = (x*sinh_e(2*r*t)/r)*STSa\n", "STSb2 = (y*sinh_e(2*r*t)/r)*STSa\n", "\n", "STS = M.diffeomorphism(N, [STSa, STSb1, STSb2])\n", "STS.display()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CPU times: user 5.1 s, sys: 100 ms, total: 5.2 s\n", "Wall time: 5.17 s\n" ] }, { "data": { "text/html": [ "" ], "text/plain": [ "(2*(t*x*z^3 + (t*x^3 + t*x*y^2)*z)*e^(5*sqrt(x^2 + y^2 + z^2)*t) + 2*(t*x*z^3 + (t*x^3 + t*x*y^2)*z)*e^(sqrt(x^2 + y^2 + z^2)*t) - sqrt(x^2 + y^2 + z^2)*((2*t*x^3 + 2*t*x*y^2 + 2*t*x*z^2 + x*z)*e^(5*sqrt(x^2 + y^2 + z^2)*t) - (2*t*x^3 + 2*t*x*y^2 + 2*t*x*z^2 + x*z)*e^(sqrt(x^2 + y^2 + z^2)*t)))/(sqrt(-z*e^(4*sqrt(x^2 + y^2 + z^2)*t) + sqrt(x^2 + y^2 + z^2)*(e^(4*sqrt(x^2 + y^2 + z^2)*t) + 1) + z)*((sqrt(2)*x^2 + sqrt(2)*y^2 + sqrt(2)*z^2 + (sqrt(2)*x^2 + sqrt(2)*y^2 + sqrt(2)*z^2)*e^(4*sqrt(x^2 + y^2 + z^2)*t))*(x^2 + y^2 + z^2)^(3/4) + (sqrt(2)*z^3 + (sqrt(2)*x^2 + sqrt(2)*y^2)*z - (sqrt(2)*z^3 + (sqrt(2)*x^2 + sqrt(2)*y^2)*z)*e^(4*sqrt(x^2 + y^2 + z^2)*t))*(x^2 + y^2 + z^2)^(1/4)))" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%time STS.jacobian_matrix()[0,0]" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false, "deletable": true, "editable": true, "scrolled": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CPU times: user 4min 49s, sys: 1.18 s, total: 4min 50s\n", "Wall time: 4min 49s\n" ] }, { "data": { "text/html": [ "" ], "text/plain": [ "2-form on the 3-dimensional differentiable manifold M" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%time s = STS.pullback(omega)\n", "s" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The number of characters in each of the non-vanishing components of $s$:" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "[85610, 30001, 30002]" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "[len(str(s[ind])) for ind in [(0,1), (0,2), (1,2)]] " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The first 1000 characters of $s_{01}$:" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "-1/2*(131072*z^20 + 655360*(x^2 + y^2)*z^18 + 1384448*(x^4 + 2*x^2*y^2 + y^4)*z^16 + 1605632*(x^6 + 3*x^4*y^2 + 3*x^2*y^4 + y^6)*z^14 + 1111552*(x^8 + 4*x^6*y^2 + 6*x^4*y^4 + 4*x^2*y^6 + y^8)*z^12 + 467456*(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^10 + 116160*(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^8 + 15744*(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^6 + 978*(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^4 + 18*(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^2 + 2*(65536*z^20 + 327680*(x^2 + y^2)*z^18 + 692224*(x^4 + 2*x^2*y^2 + y^4)*z^16 + 802816*(x^6 + 3*x^4*y^2 + 3*x^2*y^4 + y^6)*z^14 + 555776*(x^8 + 4*x^6*y^2 + 6*x^4*y^4 + 4*x^2*y^6 + y^8)*z^12 + 233728*(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^10 + 5\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 }