Created
October 25, 2018 16:48
-
-
Save moskytw/2beed4309a541b4ad8b0918361c4c4ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import sympy as sym\n", | |
"sym.init_printing()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"frac = sym.Rational\n", | |
"\n", | |
"x, y, a = sym.symbols('x y a')\n", | |
"\n", | |
"x_nn = sym.symbols('x_nn', nonnegative=True)\n", | |
"assert sym.ask(sym.Q.nonnegative(x_nn))\n", | |
"\n", | |
"x_n, y_n = sym.symbols('x_n y_n', negative=True)\n", | |
"assert sym.ask(sym.Q.negative(x_n)) and sym.ask(sym.Q.negative(y_n))\n", | |
"\n", | |
"m, n, k = sym.symbols('m n k', integer=True)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"The two expressions should be equivalent:\n" | |
] | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAE8AAAAYCAYAAAC7v6DJAAAABHNCSVQICAgIfAhkiAAAA3tJREFUWIXtmEtIFWEUx39XSTQjkQhJsAeZD4IehEmkgSQIRUGWi1xYUbhJF9kmJchNZWCL7IW2yFZRFkURhrQxkp6L0Mo2FRVmaWRkJD1tcc50x3Fm7r0zVyW4/81wz/l//3O++53v+84MxDCl2A90A1+BQaAVSHLgngMGgORJycwdK4BRYJcLJ5K5eUI9sBqYBxQDfUCtDS8P+APURDF2GvAbOO5x/BWgH5jh4K8nvLlFDS1IhVnRAXwmuitXiVRPkcfxK3V8XZh8p7l5QgbQBPQAn5Dy/gkctPCykKpriVZgRTvwEYj3odELvAbiLPZw5/YPHchKbLbYA8h+HwUa1DYLeA9cBEqAxUAOMAyUWcY36Ni1NjFr1LfXIads4Dtw22KfqfazHvM3cEDtJSZbJHP7h6XIGfKMsat5VAM0m2wVyDYMmGzblLfIovsI+IX9RZGvY9occurQsUss9nIdt9Fj/gaK1ddoskUytzFoVdJ2/V2nvy8wtrTX66Q2AZlANXL4frEETVZej0O8acA34I2Nr0xjH7PxtSFbKdFj/gZS1P/AZAt3buOQAYwAr4AqFb4JJFh4AeCkCg4g50MjcMfCy1KNDpeYncqZY7IlA2+BDzpBMxKRLWRXreHmb8YIsk0NhDs3WxzWoKNAFzA9nEEOWEVw5Z1wSDmlJtsRxlaQGRvUV+6gF2n+fUilRQS7MgZpCA3sRLaVV4zo07q9zOjSZ74+c4A9wF3sW4NS4Adww0Ev0vyTTHn6QjnSVvQjK3fap1666riVfKrG7NTft5CDf7kNNx5pT9odtCLNP075L0LwQmIdsqLdwGzgOdLbZPvQDCDnxmAI3lPkAjBu0VMOvCL1V9r4vOSfq3qXQ+TnigKkvF8SPLi3qPBVP8LAJdXJdOE0K2cY+aNTHXhNSFWmWexe89+hnCoXjiuWIX1NP7DQ4nuo4oVexYGtqrHbhVNB8JB3elkPIC2N9Qjwk/955LLIcMnNEZnINT3E+EYUgk3kPS/iigSk5bjvwikk2G859VJ5yjF/XPCTfwpyUfjdWROOWmQSdpcAwDVkO+a5aBgtzYIo5VStegVR0pswJCIv4NdtfMYlcSKERi/wOEr5JAHvkPP4v8Aa5EU8GZgL7APOIC/4T/DXjEeKXOR73fxJjBk1GN/ihpCvF+lTm04MMcQQQwxu+As0bhHG9blUKwAAAABJRU5ErkJggg==\n", | |
"text/latex": [ | |
"$$x^{a} \\left(\\frac{y}{x}\\right)^{a}$$" | |
], | |
"text/plain": [ | |
" a\n", | |
" a ⎛y⎞ \n", | |
"x ⋅⎜─⎟ \n", | |
" ⎝x⎠ " | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAABcAAAAYCAYAAAARfGZ1AAAABHNCSVQICAgIfAhkiAAAAVJJREFUSInt1L9L1VEYx/HXDRvMQS5NCjkpCYLgEE2O4eCkcAcdtEAEh0ByaXAWLrQUFaiLrro5iosRDo5q/4AG+QNMvCEYmg7nKF++3AvJPUhDn+35cJ73ec7zHB7+cU1jC79whAU0woME8AZMoAtDeIHJBNyqmsMi9Vf+BB+wjWOhNa/wPX/wDa4wVQP0FOf4EuPH2McS+oS2dKKCUj75eYQv14Cv4gLdMR7BCQqZM6OR0ZFPfogz7FYBl2LS+4zXHy8bQDte4wdOcxfeaj1CWjJeE/ZwgOaMX8CnCDsUev8OX6uBYSbCBzNeOXovayX9rfojqBzjTvzGhhpPvYuK+CO0B9ZwiZ56wTf6JvzXYeEVn1OBYTZCK8KuKKaEj0T4FcZSgqE3gjclGGJeK8IQn6UG3wzxYypgG95iXlhMO3iUCj4uVPtT2HCtqcD/df+6Bux/Sk1+DzraAAAAAElFTkSuQmCC\n", | |
"text/latex": [ | |
"$$y^{a}$$" | |
], | |
"text/plain": [ | |
" a\n", | |
"y " | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n", | |
"Try to simplify:\n" | |
] | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAE8AAAAYCAYAAAC7v6DJAAAABHNCSVQICAgIfAhkiAAAA3tJREFUWIXtmEtIFWEUx39XSTQjkQhJsAeZD4IehEmkgSQIRUGWi1xYUbhJF9kmJchNZWCL7IW2yFZRFkURhrQxkp6L0Mo2FRVmaWRkJD1tcc50x3Fm7r0zVyW4/81wz/l//3O++53v+84MxDCl2A90A1+BQaAVSHLgngMGgORJycwdK4BRYJcLJ5K5eUI9sBqYBxQDfUCtDS8P+APURDF2GvAbOO5x/BW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 \n", | |
"x ⋅⎜─⎟ \n", | |
" ⎝x⎠ " | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAABcAAAAYCAYAAAARfGZ1AAAABHNCSVQICAgIfAhkiAAAAVJJREFUSInt1L9L1VEYx/HXDRvMQS5NCjkpCYLgEE2O4eCkcAcdtEAEh0ByaXAWLrQUFaiLrro5iosRDo5q/4AG+QNMvCEYmg7nKF++3AvJPUhDn+35cJ73ec7zHB7+cU1jC79whAU0woME8AZMoAtDeIHJBNyqmsMi9Vf+BB+wjWOhNa/wPX/wDa4wVQP0FOf4EuPH2McS+oS2dKKCUj75eYQv14Cv4gLdMR7BCQqZM6OR0ZFPfogz7FYBl2LS+4zXHy8bQDte4wdOcxfeaj1CWjJeE/ZwgOaMX8CnCDsUev8OX6uBYSbCBzNeOXovayX9rfojqBzjTvzGhhpPvYuK+CO0B9ZwiZ56wTf6JvzXYeEVn1OBYTZCK8KuKKaEj0T4FcZSgqE3gjclGGJeK8IQn6UG3wzxYypgG95iXlhMO3iUCj4uVPtT2HCtqcD/df+6Bux/Sk1+DzraAAAAAElFTkSuQmCC\n", | |
"text/latex": [ | |
"$$y^{a}$$" | |
], | |
"text/plain": [ | |
" a\n", | |
"y " | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n", | |
"Hm?\n" | |
] | |
} | |
], | |
"source": [ | |
"exp_1 = x**a * (y/x)**a\n", | |
"exp_2 = y**a\n", | |
"\n", | |
"print('The two expressions should be equivalent:')\n", | |
"display(exp_1, exp_2)\n", | |
"\n", | |
"print()\n", | |
"print('Try to simplify:')\n", | |
"display(*map(sym.simplify, [exp_1, exp_2]))\n", | |
"\n", | |
"print()\n", | |
"print('Hm?')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Let's assume x is nonnegative:\n" | |
] | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAGkAAAAaCAYAAAC0NHJVAAAABHNCSVQICAgIfAhkiAAABDVJREFUaIHtmVmIFFcUhr9WHGZsUUSCC44LjhuBqMhExAWGDAgRlbg8OBCTkCAB9UF9cQnEPLiBQmISRfOQyYviRlwIypCHjERcEkjQRMWgkriMOuISkwxZdHw4p+g7NXWr69bc6SjW99Ld5/x96tzb5946txoyngveA84AfwDNQD1QkTLWF8BtIO8ls6eH8UAr8E6Mxuc8tmMNMAkYDNQC14GVKeJUA4+BZb4SA/oCj4CPPcZMy5dAE9DD4l+Dn3lMxA5kRbjSANzHY/UAC5EKrvEYMy0vI7msSqhPO4/tqAS2AGeBu8hS/RdY6xhnBLKKdvhIyuAIcAfo6jluWs4DvwJdQnaneWxAfu05IXsO2SNbgQ1q6wPcBPYA04AXgVHAQ2CeY/IbNPYrEb5l6ltu+e5I4G/gWMjeU+2fh+wuY/TN+xp/mmFznscxyB5+jrbVt1mDbzdsC5DtKWfY3lDdcMfkvwf+I7phmKAx91q+26DffSlkr9PvzQzZXcbom1q9xibDlmoe61Xwpn5epZ9303aZTkcm5zWgCliC3Bh/D12wGHmNc9bi7wb8BfwW4ZunuX0U4duLbBvlEb56ko3RN730OqcNW6p5rARagCvAYg16FCgL6XLApxrsNrKnbgK+dUx8hF6jIUbTqJr+hi0PXAVuIYM3KUe2C9vqSzrGzqAF2d4CUs/jeiTxVuA40N13pgYTKVSxjXWqmW3YNtJ2NZjMUF9dTMxSjtHkOrJyEmNb2s3G+7eR7aazaNHXqG0p4Li+TtDXUcBS4ATRbeps4B/gq5iYpRyjSQWFMaemDmmHm5Aq29bRgEUYoNeJW969NadG/fw1cvMfF6HtirTdR2LilXqMAV30upc6EuRVpALPAC8AF5B+fWRHs4shh+zFzUV0PyONQNC1bbXoatS/0OJPOsaBGmcWcr/6E5ncGkeNyWjV77f4izIZWfKXKdyg52rQA2mDJmSfXqcqRrNdNQ+RH7S3RbcFWWV9I3wuY5yu9kakda4CDgI/OGpM3lL9Yos/lrFIr94EDAv5vtPAU0J2n5U2X3WLYnJcQOFGb3tQmUNa9ait03WMq4EHQD/D9jpwzVFjsgtpGiotfitVSEt4j/YHQigcwE6G7D4rrQxppU/F5DmFwhnDdn6oVk34IW2aMe4BdoZ0HwDfOGoCeiENQ2fvSm3wXWkrkYmKagYADiHbWHVMTkGrPjQu8YRcRA6W4Rw+dNQELNHcJnvILTG+K60cefh4OMIXNAufFMnpPPBjEU0S8khBhCf0KoVzWRJNQAVwA7n3lhTflQYwFXkImQcGASuAz5AHpT9RugPnROQHMP/76YMUylgHTcBo5P+iIf5TteO70qII/gu6h6zIAelSTcW7SGtuUou07mUOmv8V35WWEUPaJ75jgF+Qw2XAOORQeM5Bk5GRkZGRkfEM8QQvWnMYOFdVUgAAAABJRU5ErkJggg==\n", | |
"text/latex": [ | |
"$$x_{nn}^{a} \\left(\\frac{y}{x_{nn}}\\right)^{a}$$" | |
], | |
"text/plain": [ | |
" a\n", | |
" a ⎛ y ⎞ \n", | |
"xₙₙ ⋅⎜───⎟ \n", | |
" ⎝xₙₙ⎠ " | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAABcAAAAYCAYAAAARfGZ1AAAABHNCSVQICAgIfAhkiAAAAVJJREFUSInt1L9L1VEYx/HXDRvMQS5NCjkpCYLgEE2O4eCkcAcdtEAEh0ByaXAWLrQUFaiLrro5iosRDo5q/4AG+QNMvCEYmg7nKF++3AvJPUhDn+35cJ73ec7zHB7+cU1jC79whAU0woME8AZMoAtDeIHJBNyqmsMi9Vf+BB+wjWOhNa/wPX/wDa4wVQP0FOf4EuPH2McS+oS2dKKCUj75eYQv14Cv4gLdMR7BCQqZM6OR0ZFPfogz7FYBl2LS+4zXHy8bQDte4wdOcxfeaj1CWjJeE/ZwgOaMX8CnCDsUev8OX6uBYSbCBzNeOXovayX9rfojqBzjTvzGhhpPvYuK+CO0B9ZwiZ56wTf6JvzXYeEVn1OBYTZCK8KuKKaEj0T4FcZSgqE3gjclGGJeK8IQn6UG3wzxYypgG95iXlhMO3iUCj4uVPtT2HCtqcD/df+6Bux/Sk1+DzraAAAAAElFTkSuQmCC\n", | |
"text/latex": [ | |
"$$y^{a}$$" | |
], | |
"text/plain": [ | |
" a\n", | |
"y " | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n", | |
"Try to simplify:\n" | |
] | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAABcAAAAYCAYAAAARfGZ1AAAABHNCSVQICAgIfAhkiAAAAVJJREFUSInt1L9L1VEYx/HXDRvMQS5NCjkpCYLgEE2O4eCkcAcdtEAEh0ByaXAWLrQUFaiLrro5iosRDo5q/4AG+QNMvCEYmg7nKF++3AvJPUhDn+35cJ73ec7zHB7+cU1jC79whAU0woME8AZMoAtDeIHJBNyqmsMi9Vf+BB+wjWOhNa/wPX/wDa4wVQP0FOf4EuPH2McS+oS2dKKCUj75eYQv14Cv4gLdMR7BCQqZM6OR0ZFPfogz7FYBl2LS+4zXHy8bQDte4wdOcxfeaj1CWjJeE/ZwgOaMX8CnCDsUev8OX6uBYSbCBzNeOXovayX9rfojqBzjTvzGhhpPvYuK+CO0B9ZwiZ56wTf6JvzXYeEVn1OBYTZCK8KuKKaEj0T4FcZSgqE3gjclGGJeK8IQn6UG3wzxYypgG95iXlhMO3iUCj4uVPtT2HCtqcD/df+6Bux/Sk1+DzraAAAAAElFTkSuQmCC\n", | |
"text/latex": [ | |
"$$y^{a}$$" | |
], | |
"text/plain": [ | |
" a\n", | |
"y " | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAABcAAAAYCAYAAAARfGZ1AAAABHNCSVQICAgIfAhkiAAAAVJJREFUSInt1L9L1VEYx/HXDRvMQS5NCjkpCYLgEE2O4eCkcAcdtEAEh0ByaXAWLrQUFaiLrro5iosRDo5q/4AG+QNMvCEYmg7nKF++3AvJPUhDn+35cJ73ec7zHB7+cU1jC79whAU0woME8AZMoAtDeIHJBNyqmsMi9Vf+BB+wjWOhNa/wPX/wDa4wVQP0FOf4EuPH2McS+oS2dKKCUj75eYQv14Cv4gLdMR7BCQqZM6OR0ZFPfogz7FYBl2LS+4zXHy8bQDte4wdOcxfeaj1CWjJeE/ZwgOaMX8CnCDsUev8OX6uBYSbCBzNeOXovayX9rfojqBzjTvzGhhpPvYuK+CO0B9ZwiZ56wTf6JvzXYeEVn1OBYTZCK8KuKKaEj0T4FcZSgqE3gjclGGJeK8IQn6UG3wzxYypgG95iXlhMO3iUCj4uVPtT2HCtqcD/df+6Bux/Sk1+DzraAAAAAElFTkSuQmCC\n", | |
"text/latex": [ | |
"$$y^{a}$$" | |
], | |
"text/plain": [ | |
" a\n", | |
"y " | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n", | |
"OK.\n" | |
] | |
} | |
], | |
"source": [ | |
"exp_1 = x_nn**a * (y/x_nn)**a\n", | |
"exp_2 = y**a\n", | |
"\n", | |
"print(\"Let's assume x is nonnegative:\")\n", | |
"display(exp_1, exp_2)\n", | |
"\n", | |
"print()\n", | |
"print('Try to simplify:')\n", | |
"display(*map(sym.simplify, [exp_1, exp_2]))\n", | |
"\n", | |
"print()\n", | |
"print('OK.')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"The identity 2 won't work without assumptions:\n" | |
] | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAC0AAAAYCAYAAABurXSEAAAABHNCSVQICAgIfAhkiAAAAfFJREFUWIXt1jlolEEUwPFfvEAtJIiFQmyMGBA8CrExnSKYyiOFKaKCCIKCaCNirQZioXgQbWKpNmIlwSaiItrFAysFFeIBRowonmsxL+bbJXHdfJtswPy7eTvzf7Mz8+Yb/lOOog+f8A7dmD2e3mlVkM/AXizHdmzAgUnsHZELuDSe3rwr3YDTeIj30lbuwquJ9PaggK0l8TrpTBVwImLz8RpXsFHaxiYMojUz9mCMOzTKBJfhK25V6P3DSvzEE0zPxE9G4q5MrB0f4g8NsSP6Lc3E1kbs6iiT7sEPrKjQW0R3dNgZ7SPRvqz4OLVEss1oxH7042NJwpn4jBcj5GoN96kxeItowBc8x76Q3sCskn51OBuyt9IZ7MTtEZy94VmYic3FS7zBvDF6izgeSQq4gznlBpThWLi2ZGIdinc0N0PFU5CKIC8t4eqIdhO+4a6/bHkltOGXdI4KOF8FZ304e6N9Uyr41VVw2yStQB8W4Cm+S9dSXh5L922btBjnquC0TqryZ4YLZlskuFYFf1e4BqW3RH1e4SrpbuzHkpLfHkSy5pw52g3Xye6cLo3SF2jA8AWfZX0kupczT3N47qtS8U0E16XiW1PrifwrQ8V3ptYTKcdiHMZF6UH0SP6P1LizR1rdAenFtqi205liisnLb1Izj3GG8CkAAAAAAElFTkSuQmCC\n", | |
"text/latex": [ | |
"$$x^{a} y^{a}$$" | |
], | |
"text/plain": [ | |
" a a\n", | |
"x ⋅y " | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAADIAAAAYCAYAAAC4CK7hAAAABHNCSVQICAgIfAhkiAAAAt1JREFUWIXt1zuMVVUUBuDvYiDCkBBCTNBk0ITh1QhGkRAZK2y0UqGQYkQ0NEABWAgx0UbRBAuJj4CNVoqPaLQxExqMEwUsCPhq0KCBUSYRo8bxyVisNd4z13POvRcGY8z8zbn73/9ea5299lr7XP7neAnn0PMv+bsRY3igRvMwTuAnjOBFzKwzuhIXsGNSQuwcb2IYsyvmH8UtuBZrcQa76gwO4ntt3vYy4GaRld0d6g+Ik1OKxSIbBy49rovCZziNaS18L/bhJL4Tx+t3PDYuaF2wCQ0cLHEyKHbs7ha+Ic7rGJ5IbkeOd1YEvAS/4r0W/hUswG0Fbh6OYT4eRD9uwi84XmHfR/hDeZEvx5/4FFcU+Kcy6P0FblVyr1X4GUw/17fwa3Pd3gI3II56o8Ddm7pFZcZ70vjJCuc0d35jjnfn+KCJ2Z2On/FViY31uebpkrk5OXe0wN2Rcd2JPmwTTeEHE1/ubyxOI4M1L9KLUXyJral/FzNKtIdz/uoC14Ov8W0GXYZRfFMYN/BsBn5O1MpevF8V5GrN3a3DntSNYQizKnSPp+auAvekiRktwxmRga5QPA6j+byyzZqRwu/7xREqw1A+V+VzKbbjAzVtU7T90Zr5trhG7FZlyrBBtOfh1D5fo52b2sM5PiSaxQ01a6blmlOdhVyOhjiDIxXzt+M38ZlwFT4XvXxJjc1PRM/fIF78uTYxLEvdGx1HXYHX01BfC79GHKEvNIt3XWrfqrG3PzU/ig2a28b/fanf2lXUJbgnDW0pcCtEHx/Gwhb9sdT3V9gb0GwMdR+E43hZFHpv5yGXY4ZojUdy3Cda4Xn/vLxoXmAfVtjr17wXSnt+AXNEkddluCvsSud1Rdkp3hYFvrID7bb0u2YS/CLa72m8c4l2xgv8mQ60M3FW1Oik4lY8ovs/VgvwEF4QH4Ufq74wi1gm/m9c16W/y4bNIgvn8aq4m6YwhSn8B/AXK6OvvLADPFMAAAAASUVORK5CYII=\n", | |
"text/latex": [ | |
"$$\\left(x y\\right)^{a}$$" | |
], | |
"text/plain": [ | |
" a\n", | |
"(x⋅y) " | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n", | |
"Subs x→-1, y→-1, a→1/2:\n" | |
] | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAB4AAAASCAYAAABM8m7ZAAAABHNCSVQICAgIfAhkiAAAAJVJREFUSInt1KENAjEUh/Ef5IZgAYbAcWEBBKMwADuwwAn2QLAADkVyCoUCgwNBFaLpXUpDyH3JSyte+4n+X/kTVtjigBue2JUQH4PsjlNJcY0pRpjHxFVm8T61cZxZnMwgbr0DkVq9E/sZrjMeHc5fcokXfS/qys+8cTFyfyDLUDAJ6wxN2F+xzuwEG/EpaL8hHYjyAqjXJ2KDRzE8AAAAAElFTkSuQmCC\n", | |
"text/latex": [ | |
"$$-1$$" | |
], | |
"text/plain": [ | |
"-1" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAA0AAAASCAYAAACAa1QyAAAABHNCSVQICAgIfAhkiAAAAHZJREFUKJFjYKACCGFgYJjMwMBwmIGB4RMDA8N/BgaGJYQ0XYAq/MzAwHCdWE2ODAwMqgwMDIwMDAwOuDSxoPH3EzKVgYGBgYkYRaOaBlwTeuQGQDEDAwODBJS2ZGBgWABlv2FgYChBN6SBAZJ0cOEH5LiMzgAA6XoX52TB9a4AAAAASUVORK5CYII=\n", | |
"text/latex": [ | |
"$$1$$" | |
], | |
"text/plain": [ | |
"1" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n", | |
"Or force:\n" | |
] | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAADIAAAAYCAYAAAC4CK7hAAAABHNCSVQICAgIfAhkiAAAAt1JREFUWIXt1zuMVVUUBuDvYiDCkBBCTNBk0ITh1QhGkRAZK2y0UqGQYkQ0NEABWAgx0UbRBAuJj4CNVoqPaLQxExqMEwUsCPhq0KCBUSYRo8bxyVisNd4z13POvRcGY8z8zbn73/9ea5299lr7XP7neAnn0PMv+bsRY3igRvMwTuAnjOBFzKwzuhIXsGNSQuwcb2IYsyvmH8UtuBZrcQa76gwO4ntt3vYy4GaRld0d6g+Ik1OKxSIbBy49rovCZziNaS18L/bhJL4Tx+t3PDYuaF2wCQ0cLHEyKHbs7ha+Ic7rGJ5IbkeOd1YEvAS/4r0W/hUswG0Fbh6OYT4eRD9uwi84XmHfR/hDeZEvx5/4FFcU+Kcy6P0FblVyr1X4GUw/17fwa3Pd3gI3II56o8Ddm7pFZcZ70vjJCuc0d35jjnfn+KCJ2Z2On/FViY31uebpkrk5OXe0wN2Rcd2JPmwTTeEHE1/ubyxOI4M1L9KLUXyJral/FzNKtIdz/uoC14Ov8W0GXYZRfFMYN/BsBn5O1MpevF8V5GrN3a3DntSNYQizKnSPp+auAvekiRktwxmRga5QPA6j+byyzZqRwu/7xREqw1A+V+VzKbbjAzVtU7T90Zr5trhG7FZlyrBBtOfh1D5fo52b2sM5PiSaxQ01a6blmlOdhVyOhjiDIxXzt+M38ZlwFT4XvXxJjc1PRM/fIF78uTYxLEvdGx1HXYHX01BfC79GHKEvNIt3XWrfqrG3PzU/ig2a28b/fanf2lXUJbgnDW0pcCtEHx/Gwhb9sdT3V9gb0GwMdR+E43hZFHpv5yGXY4ZojUdy3Cda4Xn/vLxoXmAfVtjr17wXSnt+AXNEkddluCvsSud1Rdkp3hYFvrID7bb0u2YS/CLa72m8c4l2xgv8mQ60M3FW1Oik4lY8ovs/VgvwEF4QH4Ufq74wi1gm/m9c16W/y4bNIgvn8aq4m6YwhSn8B/AXK6OvvLADPFMAAAAASUVORK5CYII=\n", | |
"text/latex": [ | |
"$$\\left(x y\\right)^{a}$$" | |
], | |
"text/plain": [ | |
" a\n", | |
"(x⋅y) " | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAADIAAAAYCAYAAAC4CK7hAAAABHN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
"text/plain": [ | |
" a\n", | |
"(x⋅y) " | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"# https://docs.sympy.org/latest/tutorial/simplification.html#powers\n", | |
"\n", | |
"exp_1 = x**a * y**a\n", | |
"exp_2 = (x*y)**a\n", | |
"\n", | |
"print(\"The identity 2 won't work without assumptions:\")\n", | |
"display(exp_1, exp_2)\n", | |
"\n", | |
"print()\n", | |
"print('Subs x→-1, y→-1, a→1/2:')\n", | |
"display(*(e.subs(dict(x=-1, y=-1, a=frac(1, 2))) for e in [exp_1, exp_2]))\n", | |
"\n", | |
"print()\n", | |
"print('Or force:')\n", | |
"display(*(e.powsimp(force=True) for e in [exp_1, exp_2]))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Let's assume x and y is negative:\n" | |
] | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAGIAAAAaCAYAAABM1ImiAAAABHNCSVQICAgIfAhkiAAABEFJREFUaIHtmV2IVVUUgL+rJKM3EpEwxcmiSR2EHIlRJA3EASGpyPLBgaxIJNB5UF/SAu3Bn8CgzB/UB6eXIi36I4yhB0cc0hSUGX8iUTEdRx3Jyp/BSseHtY73zO7sffa+584l5H4v99511l5r7X3W3nvtfaHCfcO7QDtwHegGmoHBFt1PgMtAviyRlY+ngV5ggUMnZJyKYhXwDDAGaAA6geUJevXAHWBpKZ17MAK4DXzcz36+ArqABy3PV+E3TiVjG5L5Ji3AH5Q4CzxYiGTrjH72M1n9rPDUt41TUVQDG4AO4Hdk2v0DrDb0xiKzYVupHAewG7gCDCyDrxPAWWCAIfcdp3u0IG/1ZUOeQ9a0XmCdyoYDF4GdwCxgAjAeuAbMNdqv07YzE3wu1WfLLDGNA24Be21BO3hI2+4w5CH9DGGltp0Vk4WM0z0mIuvpcfpm0Afq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{x_{n}}\\right)^{a}$$" | |
], | |
"text/plain": [ | |
" a\n", | |
" a ⎛yₙ⎞ \n", | |
"xₙ ⋅⎜──⎟ \n", | |
" ⎝xₙ⎠ " | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAABcAAAAaCAYAAABctMd+AAAABHNCSVQICAgIfAhkiAAAAbVJREFUSInt1UuIj1EYx/HPiAWjNM0GYTUypYxZSIqFIotJomZhyqCkLJTYKNZqysIohA1bVqaUZDOSBQvltnDZGOVWboNyHYvzvDq9/f/vjJl3YeG3O7+e53vOec45z+Ef12HcxSe8wTnMhGk1wKdjD5ZiK9ZjXw3chjqD80x95QtxHPfwVirNTjwvB+7HGA40AS3BV1yPcTte4gI2SGXpxCh6y8krA36xCfwqfmBZjPvxHi1ZzPZgLC4nz8AXPGsA7o2kwczrick2owN78QIfSxP+0XBA5mVeK0bwCnMyvwUnAvZaqv1R3GgEhiMB35J5A+HtaJY0UfUEaCDGnfiGm5ps9W/Uhl9SeeAafqJ7quBCD6T72ift4mRdYDgd0FGpV7TVCe8P+Bh2VcQtiJhNuILPeIq1VfA1kXRL9SEWhz+MddJdv4Q7VfAh6RBXVAXhED5gbuZtk/WVcuPqw0acwu1x4F24LPWXQh14kgctwkGclRrTfcwaBwyPpCefawjHcmO3VLt3UoebPwFwq1S61SV/RA0veVXAZ2deeyxyeWFM9rPowmPpsRXqxnc8nCTzv2rQbxWFY7q9+1pZAAAAAElFTkSuQmCC\n", | |
"text/latex": [ | |
"$$y_{n}^{a}$$" | |
], | |
"text/plain": [ | |
" a\n", | |
"yₙ " | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n", | |
"Try to simplify:\n" | |
] | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAABcAAAAaCAYAAABctMd+AAAABHNCSVQICAgIfAhkiAAAAbVJREFUSInt1UuIj1EYx/HPiAWjNM0GYTUypYxZSIqFIotJomZhyqCkLJTYKNZqysIohA1bVqaUZDOSBQvltnDZGOVWboNyHYvzvDq9/f/vjJl3YeG3O7+e53vOec45z+Ef12HcxSe8wTnMhGk1wKdjD5ZiK9ZjXw3chjqD80x95QtxHPfwVirNTjwvB+7HGA40AS3BV1yPcTte4gI2SGXpxCh6y8krA36xCfwqfmBZjPvxHi1ZzPZgLC4nz8AXPGsA7o2kwczrick2owN78QIfSxP+0XBA5mVeK0bwCnMyvwUnAvZaqv1R3GgEhiMB35J5A+HtaJY0UfUEaCDGnfiGm5ps9W/Uhl9SeeAafqJ7quBCD6T72ift4mRdYDgd0FGpV7TVCe8P+Bh2VcQtiJhNuILPeIq1VfA1kXRL9SEWhz+MddJdv4Q7VfAh6RBXVAXhED5gbuZtk/WVcuPqw0acwu1x4F24LPWXQh14kgctwkGclRrTfcwaBwyPpCefawjHcmO3VLt3UoebPwFwq1S61SV/RA0veVXAZ2deeyxyeWFM9rPowmPpsRXqxnc8nCTzv2rQbxWFY7q9+1pZAAAAAElFTkSuQmCC\n", | |
"text/latex": [ | |
"$$y_{n}^{a}$$" | |
], | |
"text/plain": [ | |
" a\n", | |
"yₙ " | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAABcAAAAaCAYAAABctMd+AAAABHNCSVQICAgIfAhkiAAAAbVJREFUSInt1UuIj1EYx/HPiAWjNM0GYTUypYxZSIqFIotJomZhyqCkLJTYKNZqysIohA1bVqaUZDOSBQvltnDZGOVWboNyHYvzvDq9/f/vjJl3YeG3O7+e53vOec45z+Ef12HcxSe8wTnMhGk1wKdjD5ZiK9ZjXw3chjqD80x95QtxHPfwVirNTjwvB+7HGA40AS3BV1yPcTte4gI2SGXpxCh6y8krA36xCfwqfmBZjPvxHi1ZzPZgLC4nz8AXPGsA7o2kwczrick2owN78QIfSxP+0XBA5mVeK0bwCnMyvwUnAvZaqv1R3GgEhiMB35J5A+HtaJY0UfUEaCDGnfiGm5ps9W/Uhl9SeeAafqJ7quBCD6T72ift4mRdYDgd0FGpV7TVCe8P+Bh2VcQtiJhNuILPeIq1VfA1kXRL9SEWhz+MddJdv4Q7VfAh6RBXVAXhED5gbuZtk/WVcuPqw0acwu1x4F24LPWXQh14kgctwkGclRrTfcwaBwyPpCefawjHcmO3VLt3UoebPwFwq1S61SV/RA0veVXAZ2deeyxyeWFM9rPowmPpsRXqxnc8nCTzv2rQbxWFY7q9+1pZAAAAAElFTkSuQmCC\n", | |
"text/latex": [ | |
"$$y_{n}^{a}$$" | |
], | |
"text/plain": [ | |
" a\n", | |
"yₙ " | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n", | |
"OK.\n" | |
] | |
} | |
], | |
"source": [ | |
"exp_1 = x_n**a * (y_n/x_n)**a\n", | |
"exp_2 = y_n**a\n", | |
"\n", | |
"print(\"Let's assume x and y is negative:\")\n", | |
"display(exp_1, exp_2)\n", | |
"\n", | |
"print()\n", | |
"print('Try to simplify:')\n", | |
"display(*map(sym.simplify, [exp_1, exp_2]))\n", | |
"\n", | |
"print()\n", | |
"print('OK.')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"The two expressions should be equivalent:\n" | |
] | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAF8AAAAaCAYAAADR2YAqAAAABHNCSVQICAgIfAhkiAAAA9dJREFUaIHt2V1oHUUUB/BfWloTk1i/QEGsVaRFEW1Soi1opaJQkArqk61PIiKIIAqivigoKuqbT/omaI0fMbX1A1pRERGr/ZBWCQpiFWps1GqtGEjV+DCz3JvN7M29t3eTR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FeGviXCRrulIMZ5gweFBPTN1LEGHo82zm9JRDPj7ujvylnyVxo6hQOqbcdhY8Ts/TXrwo94fZb8lY61eNj8+JlyER4xSz9G2mijjTbamP/4D3daL4hYfSwAAAAAAElFTkSuQmCC\n", | |
"text/latex": [ | |
"$$m^{k} \\left(\\frac{n}{m}\\right)^{k}$$" | |
], | |
"text/plain": [ | |
" k\n", | |
" k ⎛n⎞ \n", | |
"m ⋅⎜─⎟ \n", | |
" ⎝m⎠ " | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAABkAAAAYCAYAAAAPtVbGAAAABHNCSVQICAgIfAhkiAAAAVRJREFUSInt1DtLXFEUBeDPF+KrsQrYBAsFsRhHxDQhlSCkTOkfSGkl9gqKv0NkELQQrOwFIZoQCCFpTJNiAgqCJBCfxd2Dcjmj4+QiBF3NYZ+9zlr7cbn8J1jGzl2E1gJMSvj0GCYfC9Cpixe4wkjEPajgAC+LMpnGb7RhGF+wiq6iDGAee3iHI8wWKV5DBcc4wZt6pPzip2QzXsIo1lDFKXYxmeOXsIkO9Dda2VyYbOAPtrCC7bivoi+43bjABGaikHIjJpUQ+5V4sBG51xG/wrmbJS/gJwbuM/kWQm8TucXITUX8Hl9v5Vuwjn1Zl0n04hI/4kEea2EyeF+ledxefCnEd0Isj7LsKzr8F5PaDvYTvD4MyX4fqQIaNhmL80OCNybrMlXAg0zK+IvPCd54nAfNmNTQiTP1K12VjWm4GfFaJ6Nolx4VWSen+N6MyTOeKK4B2JtDRhglL9UAAAAASUVORK5CYII=\n", | |
"text/latex": [ | |
"$$n^{k}$$" | |
], | |
"text/plain": [ | |
" k\n", | |
"n " | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n", | |
"\n", | |
"Try to simplify:\n" | |
] | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAABkAAAAYCAYAAAAPtVbGAAAABHNCSVQICAgIfAhkiAAAAVRJREFUSInt1DtLXFEUBeDPF+KrsQrYBAsFsRhHxDQhlSCkTOkfSGkl9gqKv0NkELQQrOwFIZoQCCFpTJNiAgqCJBCfxd2Dcjmj4+QiBF3NYZ+9zlr7cbn8J1jGzl2E1gJMSvj0GCYfC9Cpixe4wkjEPajgAC+LMpnGb7RhGF+wiq6iDGAee3iHI8wWKV5DBcc4wZt6pPzip2QzXsIo1lDFKXYxmeOXsIkO9Dda2VyYbOAPtrCC7bivoi+43bjABGaikHIjJpUQ+5V4sBG51xG/wrmbJS/gJwbuM/kWQm8TucXITUX8Hl9v5Vuwjn1Zl0n04hI/4kEea2EyeF+ledxefCnEd0Isj7LsKzr8F5PaDvYTvD4MyX4fqQIaNhmL80OCNybrMlXAg0zK+IvPCd54nAfNmNTQiTP1K12VjWm4GfFaJ6Nolx4VWSen+N6MyTOeKK4B2JtDRhglL9UAAAAASUVORK5CYII=\n", | |
"text/latex": [ | |
"$$n^{k}$$" | |
], | |
"text/plain": [ | |
" k\n", | |
"n " | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAABkAAAAYCAYAAAAPtVbGAAAABHNCSVQICAgIfAhkiAAAAVRJREFUSInt1DtLXFEUBeDPF+KrsQrYBAsFsRhHxDQhlSCkTOkfSGkl9gqKv0NkELQQrOwFIZoQCCFpTJNiAgqCJBCfxd2Dcjmj4+QiBF3NYZ+9zlr7cbn8J1jGzl2E1gJMSvj0GCYfC9Cpixe4wkjEPajgAC+LMpnGb7RhGF+wiq6iDGAee3iHI8wWKV5DBcc4wZt6pPzip2QzXsIo1lDFKXYxmeOXsIkO9Dda2VyYbOAPtrCC7bivoi+43bjABGaikHIjJpUQ+5V4sBG51xG/wrmbJS/gJwbuM/kWQm8TucXITUX8Hl9v5Vuwjn1Zl0n04hI/4kEea2EyeF+ledxefCnEd0Isj7LsKzr8F5PaDvYTvD4MyX4fqQIaNhmL80OCNybrMlXAg0zK+IvPCd54nAfNmNTQiTP1K12VjWm4GfFaJ6Nolx4VWSen+N6MyTOeKK4B2JtDRhglL9UAAAAASUVORK5CYII=\n", | |
"text/latex": [ | |
"$$n^{k}$$" | |
], | |
"text/plain": [ | |
" k\n", | |
"n " | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n", | |
"OK.\n" | |
] | |
} | |
], | |
"source": [ | |
"exp_1 = m**k * (n/m)**k\n", | |
"exp_2 = n**k\n", | |
"\n", | |
"print('The two expressions should be equivalent:')\n", | |
"display(exp_1, exp_2)\n", | |
"print()\n", | |
"\n", | |
"print()\n", | |
"print('Try to simplify:')\n", | |
"display(*map(sym.simplify, [exp_1, exp_2]))\n", | |
"\n", | |
"print()\n", | |
"print('OK.')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"The two expressions should be equivalent:\n" | |
] | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAE8AAAAcCAYAAAAgLuLfAAAABHNCSVQICAgIfAhkiAAAA5RJREFUaIHtmEtsDVEYx3+XkFZFU4mgoiEaVQuK1CPxSIVEJCyKhUrEKyJRCbWhGxIJlbDwCCmbSiRa9YpGSNlUNN6PeG8QpKqKkorGsxbfN7nT6Zy5985MtYv728yd8/3Pd77vzplzvjOQpFspAy53dxBdhGduvUIYIA94EIKfnohnbmH9efdD8NMT6dLchgDtwFi9TwMqgXvACIf2GPBBNT2BSUjsawz2RHLzxTzgO9AbyAGeAMeBVIcuH/gLlIQxqDIY+AMcCODjLNAI9HexxZubb7YAN4FFwCdgo0FXC3wJc2BgLTIzCgL4mKw+Sl1s8ebmm0rgM/AVmGXQjEZm3ZGQx74IfERmRhCeAa/pvP7HzM3ZoRZ5Eosc7RGgQm1ltvY84AzQBxhoCG6V9q9ysZWoz82GvjnAD+Cqo30AMBuoQV5dv/GD/ElZwFxHezy5dWC8BvOUjk90rw5cbmvrp9p8YBnwDZjo4vMO8Bv3jWKK+q02xFOrfcc52ou038IA8VvMUdseW1u8uXWiQp2t0PtSva+i40ydiiRmrWM7gAZgmE2TpppHhrH6IIvyGxfbEh13n4utGkkoJUD8Fulqv2Vriyc3V4YDbcAroFgdXwL6OnTrkPXCIgKcBO4iTw5kvWtHZpCJOtUMtbWlAW+BJk3OTgrQinm2xhu/nTbgve0+ntyM7NJB24H6eDoYmEb0qZvYqZpCW9tuOs4eOwvUVuThM9H4G5CZlhCmE0az7fdq5NXyQ5te3V4vi3q9TtHrGGATcB0prJ0UAj+BCx4+E40/1RZrIIqQ0qIReXKHA/jKVB/XPDQZOl6d3l9BFusJLtreSHly0cNfovH3Uv2LGLqYzEee6kNgEPAc+IWUDH6IIEey5hi6J8gGYO2ihwy6ArWvNdj9xJ+rPk/HiNGT6cj0fkl08V6sjs8F8HtKfWR7aMpV04r80RkG3X5kVg52sfmNf6Vqij00nuQhx6dGYJTDdludz/Dpe6n2X++hWU50gTcd1CNISeO2BASJ/wSyWQz3iM9INrJNt9C5GIVoEXnDj3OkRGhCzokmZhCttSIGTb5qnB8XgsSfjmwUQd6sLmcrkoDbJgBwnmhFb8IqaUaGGNcG9Tk9RJ+hk4IcvmtcbNYmcTCGj2eE+8U6FXiHrMk9npnANuT0kIV88jmKHPwf478Q90susJ2QPmz+T6xvcS3IsSeze8NJkiRJkiRJupB/h18KXLwlLK4AAAAASUVORK5CYII=\n", | |
"text/latex": [ | |
"$$x^{k} \\left(\\frac{y}{x}\\right)^{k}$$" | |
], | |
"text/plain": [ | |
" k\n", | |
" k ⎛y⎞ \n", | |
"x ⋅⎜─⎟ \n", | |
" ⎝x⎠ " | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAABgAAAAcCAYAAAB75n/uAAAABHNCSVQICAgIfAhkiAAAAV5JREFUSInt1D1IXUEQhuHHiIW5RdBKIwQ7g4WoINqIbcDOYKMgFiKWYhp7QbQMhECwtRADKVImNloICv4Uir1iIaISIoISf4rdiwe59xqStRB9u5k5fN/MztnlETCFn8WKLxIYNGPzoQ02EugUpAbXaIxxDnNYR30Kg3c4QzkasI1ZVKYQh3Gs4D2OMJpKOM8cjvELXYU+yC55TDjPD0XEGnCOpUyuGd9Qger7ummPBl+L1H/gD5pi/BKXaEM/TtFayqBCWNhugVpvNP+YyXVEw/xCJ7CPulImi1GoNpPLYQ8HeJXJj2AnE5dhHmvCdAWZjAY9mdx0zA2W6uxv6Y5i0zF+iwssxw7/mypcCUcFC8IiW1KI59kW/og+YZrPKcXhSxT+jUNhqqQMRINrDKUWh84ovirRYu/y3e0NTU5+sZ9Sir4Rnt0Z4THbUuIm/gvDQtcnwlV/nVL8mSfADXaUSDdIPpvnAAAAAElFTkSuQmCC\n", | |
"text/latex": [ | |
"$$y^{k}$$" | |
], | |
"text/plain": [ | |
" k\n", | |
"y " | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n", | |
"\n", | |
"Try to simplify:\n" | |
] | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAABgAAAAcCAYAAAB75n/uAAAABHNCSVQICAgIfAhkiAAAAV5JREFUSInt1D1IXUEQhuHHiIW5RdBKIwQ7g4WoINqIbcDOYKMgFiKWYhp7QbQMhECwtRADKVImNloICv4Uir1iIaISIoISf4rdiwe59xqStRB9u5k5fN/MztnlETCFn8WKLxIYNGPzoQ02EugUpAbXaIxxDnNYR30Kg3c4QzkasI1ZVKYQh3Gs4D2OMJpKOM8cjvELXYU+yC55TDjPD0XEGnCOpUyuGd9Qger7ummPBl+L1H/gD5pi/BKXaEM/TtFayqBCWNhugVpvNP+YyXVEw/xCJ7CPulImi1GoNpPLYQ8HeJXJj2AnE5dhHmvCdAWZjAY9mdx0zA2W6uxv6Y5i0zF+iwssxw7/mypcCUcFC8IiW1KI59kW/og+YZrPKcXhSxT+jUNhqqQMRINrDKUWh84ovirRYu/y3e0NTU5+sZ9Sir4Rnt0Z4THbUuIm/gvDQtcnwlV/nVL8mSfADXaUSDdIPpvnAAAAAElFTkSuQmCC\n", | |
"text/latex": [ | |
"$$y^{k}$$" | |
], | |
"text/plain": [ | |
" k\n", | |
"y " | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAABgAAAAcCAYAAAB75n/uAAAABHNCSVQICAgIfAhkiAAAAV5JREFUSInt1D1IXUEQhuHHiIW5RdBKIwQ7g4WoINqIbcDOYKMgFiKWYhp7QbQMhECwtRADKVImNloICv4Uir1iIaISIoISf4rdiwe59xqStRB9u5k5fN/MztnlETCFn8WKLxIYNGPzoQ02EugUpAbXaIxxDnNYR30Kg3c4QzkasI1ZVKYQh3Gs4D2OMJpKOM8cjvELXYU+yC55TDjPD0XEGnCOpUyuGd9Qger7ummPBl+L1H/gD5pi/BKXaEM/TtFayqBCWNhugVpvNP+YyXVEw/xCJ7CPulImi1GoNpPLYQ8HeJXJj2AnE5dhHmvCdAWZjAY9mdx0zA2W6uxv6Y5i0zF+iwssxw7/mypcCUcFC8IiW1KI59kW/og+YZrPKcXhSxT+jUNhqqQMRINrDKUWh84ovirRYu/y3e0NTU5+sZ9Sir4Rnt0Z4THbUuIm/gvDQtcnwlV/nVL8mSfADXaUSDdIPpvnAAAAAElFTkSuQmCC\n", | |
"text/latex": [ | |
"$$y^{k}$$" | |
], | |
"text/plain": [ | |
" k\n", | |
"y " | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\n", | |
"OK.\n" | |
] | |
} | |
], | |
"source": [ | |
"exp_1 = x**k * (y/x)**k\n", | |
"exp_2 = y**k\n", | |
"\n", | |
"print('The two expressions should be equivalent:')\n", | |
"display(exp_1, exp_2)\n", | |
"print()\n", | |
"\n", | |
"print()\n", | |
"print('Try to simplify:')\n", | |
"display(*map(sym.simplify, [exp_1, exp_2]))\n", | |
"\n", | |
"print()\n", | |
"print('OK.')" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3 (data-lab)", | |
"language": "python", | |
"name": "python3-data-lab" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.5" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment