diff --git a/.ipynb_checkpoints/examples-checkpoint.ipynb b/.ipynb_checkpoints/examples-checkpoint.ipynb index 9b4ce1a..b8a7d20 100644 --- a/.ipynb_checkpoints/examples-checkpoint.ipynb +++ b/.ipynb_checkpoints/examples-checkpoint.ipynb @@ -1,22 +1,29 @@ { "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In this notebook there are presented examples of usage of shiroin, a python library for proving inequalities of multivariate polynomials." + ] + }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from shiroindev import *\n", - "sSeed=1\n", + "sVars.seed=1\n", "from IPython.display import Latex\n", - "sPrint=lambda x:display(Latex(x))" + "sVars.display=lambda x:display(Latex(x))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "The first line obviously loads this package. The second one sets a seed for proving functions. If you don't write it, you can get slightly different proof each time you run a function. \n", + "The first line obviously loads this package. The second one sets a seed for proving functions. If you don't write it, you can get a slightly different proof each time you run a function. The next two lines provide a nicer display of proofs, i.e. formulas will be shown instead of LaTeX code of these formulas. Note that this works on Jupyter, but not on the git page.\n", "\n", "Now let's make some proofs. We will use problems from https://www.imomath.com/index.php?options=593&lmm=0." ] @@ -38,21 +45,80 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 2, "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "numerator: $a^2-ab-ac+b^2-bc+c^2$\n", - "denominator: $1$\n", - "status: 0\n", - "From weighted AM-GM inequality:\n", - "\n", - "Program couldn't find a solution with integer coefficients. Try to multiple the formula by some integer and run this function again.\n", - "$$ ab+ac+bc \\le a^2+b^2+c^2 $$\n" - ] + "data": { + "text/latex": [ + "numerator: $a^2-ab-ac+b^2-bc+c^2$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $1$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "From weighted AM-GM inequality:" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Program couldn't find a solution with integer coefficients. Try to multiple the formula by some integer and run this function again." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ ab+ac+bc \\le a^2+b^2+c^2 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" }, { "data": { @@ -60,7 +126,7 @@ "0" ] }, - "execution_count": 8, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } @@ -89,21 +155,112 @@ "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "numerator: $$2a^2-2ab-2ac+2b^2-2bc+2c^2$$\n", - "denominator: $$1$$\n", - "status: 0\n", - "From weighted AM-GM inequality:\n", - "$$2ab \\le a^2+b^2$$\n", - "$$2ac \\le a^2+c^2$$\n", - "$$2bc \\le b^2+c^2$$\n", - "\n", - "$$ 0 \\le \n", - "0 $$\n", - "The sum of all inequalities gives us a proof of the inequality.\n" - ] + "data": { + "text/latex": [ + "numerator: $2a^2-2ab-2ac+2b^2-2bc+2c^2$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $1$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "From weighted AM-GM inequality:" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$2ab \\le a^2+b^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$2ac \\le a^2+c^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$2bc \\le b^2+c^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le 0 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" }, { "data": { @@ -141,17 +298,64 @@ "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "numerator: $$a^2-ab-ac-ad+b^2+c^2+d^2$$\n", - "denominator: $$1$$\n", - "status: 2\n", - "\n", - "Program couldn't find any proof.\n", - "$$ ab+ac+ad \\le \n", - "a^2+b^2+c^2+d^2 $$\n" - ] + "data": { + "text/latex": [ + "numerator: $a^2-ab-ac-ad+b^2+c^2+d^2$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $1$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 2" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Program couldn't find any proof." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ ab+ac+ad \\le a^2+b^2+c^2+d^2 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" }, { "data": { @@ -172,7 +376,12 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "This time `prove` didn't found the proof. But it doesn't mean that the inequality is not true! `prove` uses a list of values for which the formula should be small. There is no strict rule here, but the smaller that value is, the higher are chances to find a proof. List of values should correspond to the list of variables in alphabetical order. So let's try $a=2$ and $b=c=d=1$." + "This time `prove` didn't found the proof. But it doesn't mean that the inequality is not true! `prove` uses a list of $n$ positive values, where $n$ is a number of variables in the formula. List of values should correspond to the list of variables in alphabetical order. Here are a few tips how to choose the right values.\n", + "\n", + "1. Consider a function $pos(values)$ which is the sum of the positive addends in the formula after substitution of values to variables. Analogically, let $neg(values)$ be the sum of the negative addends. We should choose such values for which $quotient=pos(values)/|neg(values)|$ is small. \n", + "2. If the symmetry group of the formula is transitive (for example, the formula is cyclic or symmetric)\n", + "\n", + "So let's try $a=2$ and $b=c=d=1$." ] }, { @@ -181,22 +390,124 @@ "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "Substitute $ a \\to 2a $\n", - "numerator: $$4a^2-2ab-2ac-2ad+b^2+c^2+d^2$$\n", - "denominator: $$1$$\n", - "status: 0\n", - "From weighted AM-GM inequality:\n", - "$$2ab \\le a^2+b^2$$\n", - "$$2ac \\le a^2+c^2$$\n", - "$$2ad \\le a^2+d^2$$\n", - "\n", - "$$ 0 \\le \n", - "a^2 $$\n", - "The sum of all inequalities gives us a proof of the inequality.\n" - ] + "data": { + "text/latex": [ + "Substitute $a\\to 2a$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "numerator: $4a^2-2ab-2ac-2ad+b^2+c^2+d^2$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $1$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "From weighted AM-GM inequality:" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$2ab \\le a^2+b^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$2ac \\le a^2+c^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$2ad \\le a^2+d^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le a^2 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" }, { "data": { @@ -226,22 +537,124 @@ "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "Substitute $ a \\to 7a/4 $\n", - "numerator: $$49a^2-28ab-28ac-28ad+16b^2+16c^2+16d^2$$\n", - "denominator: $$16$$\n", - "status: 0\n", - "From weighted AM-GM inequality:\n", - "$$28ab \\le 14a^2+14b^2$$\n", - "$$28ac \\le 14a^2+14c^2$$\n", - "$$28ad \\le 14a^2+14d^2$$\n", - "\n", - "$$ 0 \\le \n", - "7a^2+2b^2+2c^2+2d^2 $$\n", - "The sum of all inequalities gives us a proof of the inequality.\n" - ] + "data": { + "text/latex": [ + "Substitute $a\\to 7a/4$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "numerator: $49a^2-28ab-28ac-28ad+16b^2+16c^2+16d^2$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $16$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "From weighted AM-GM inequality:" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$28ab \\le 14a^2+14b^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$28ac \\le 14a^2+14c^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$28ad \\le 14a^2+14d^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le 7a^2+2b^2+2c^2+2d^2 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" }, { "data": { @@ -277,19 +690,88 @@ "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "numerator: $$-x^3y+2x^2y^2-x^2-xy^3+2xy-y^2$$\n", - "denominator: $$x^3y^3-x^3y-x^2y^2+x^2-xy^3+xy+y^2-1$$\n", - "status: 2\n", - "\n", - "Program couldn't find any proof.\n", - "$$ x^3y+x^2+xy^3+y^2 \\le \n", - "2x^2y^2+2xy $$\n", - "It looks like the formula is symmetric. You can assume without loss of generality that x >= y Try\n", - "prove(makesubs(S(\" -x**3*y + 2*x**2*y**2 - x**2 - x*y**3 + 2*x*y - y**2 \"), [('y', 'inf')] )\n" - ] + "data": { + "text/latex": [ + "numerator: $-x^3y+2x^2y^2-x^2-xy^3+2xy-y^2$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $x^3y^3-x^3y-x^2y^2+x^2-xy^3+xy+y^2-1$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 2" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Program couldn't find any proof." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ x^3y+x^2+xy^3+y^2 \\le 2x^2y^2+2xy $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "It looks like the formula is symmetric. You can assume without loss of generality that x >= y. Try" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "prove(makesubs(S(\"-x**3*y + 2*x**2*y**2 - x**2 - x*y**3 + 2*x*y - y**2\"),[('y', 'oo')])" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" }, { "data": { @@ -322,24 +804,148 @@ "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "Substitute $ x \\to 1-1/(x+1) $\n", - "Substitute $ y \\to 1-1/(y+1) $\n", - "numerator: $$6x^3y+3x^3-12x^2y^2-3x^2y+3x^2+6xy^3-3xy^2-6xy+3y^3+3y^2$$\n", - "denominator: $$4x^2y+2x^2+4xy^2+8xy+3x+2y^2+3y+1$$\n", - "status: 0\n", - "From weighted AM-GM inequality:\n", - "$$12x^2y^2 \\le 6x^3y+6xy^3$$\n", - "$$3x^2y \\le 2x^3+y^3$$\n", - "$$3xy^2 \\le x^3+2y^3$$\n", - "$$6xy \\le 3x^2+3y^2$$\n", - "\n", - "$$ 0 \\le \n", - "0 $$\n", - "The sum of all inequalities gives us a proof of the inequality.\n" - ] + "data": { + "text/latex": [ + "Substitute $x\\to 1-1/(x+1)$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $y\\to 1-1/(y+1)$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "numerator: $6x^3y+3x^3-12x^2y^2-3x^2y+3x^2+6xy^3-3xy^2-6xy+3y^3+3y^2$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $4x^2y+2x^2+4xy^2+8xy+3x+2y^2+3y+1$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "From weighted AM-GM inequality:" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$12x^2y^2 \\le 6x^3y+6xy^3$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$3x^2y \\le 2x^3+y^3$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$3xy^2 \\le x^3+2y^3$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$6xy \\le 3x^2+3y^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le 0 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" }, { "data": { @@ -382,24 +988,148 @@ "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "Substitute $ x \\to -y+1+(y-1)/(x+1) $\n", - "Substitute $ y \\to 1-1/(y+1) $\n", - "Substitute $ y \\to y/2 $\n", - "numerator: $$x^4y^2+x^3y^2-2x^3y-4x^2y+4x^2+xy^2-2xy+y^2$$\n", - "denominator: $$x^3y^2+2x^3y+2x^2y^2+4x^2y+xy^2+2xy$$\n", - "status: 0\n", - "From weighted AM-GM inequality:\n", - "$$2x^3y \\le x^4y^2+x^2$$\n", - "$$4x^2y \\le x^3y^2+2x^2+xy^2$$\n", - "$$2xy \\le x^2+y^2$$\n", - "\n", - "$$ 0 \\le \n", - "0 $$\n", - "The sum of all inequalities gives us a proof of the inequality.\n" - ] + "data": { + "text/latex": [ + "Substitute $x\\to -y+1+(y-1)/(x+1)$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $y\\to 1-1/(y+1)$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $y\\to y/2$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "numerator: $x^4y^2+x^3y^2-2x^3y-4x^2y+4x^2+xy^2-2xy+y^2$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $x^3y^2+2x^3y+2x^2y^2+4x^2y+xy^2+2xy$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "From weighted AM-GM inequality:" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$2x^3y \\le x^4y^2+x^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$4x^2y \\le x^3y^2+2x^2+xy^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$2xy \\le x^2+y^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le 0 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" }, { "data": { @@ -435,21 +1165,112 @@ "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "numerator: $$2a^2-2ab-2ac+2b^2-2bc+2c^2$$\n", - "denominator: $$1$$\n", - "status: 0\n", - "From weighted AM-GM inequality:\n", - "$$2ab \\le a^2+b^2$$\n", - "$$2ac \\le a^2+c^2$$\n", - "$$2bc \\le b^2+c^2$$\n", - "\n", - "$$ 0 \\le \n", - "0 $$\n", - "The sum of all inequalities gives us a proof of the inequality.\n" - ] + "data": { + "text/latex": [ + "numerator: $2a^2-2ab-2ac+2b^2-2bc+2c^2$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $1$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "From weighted AM-GM inequality:" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$2ab \\le a^2+b^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$2ac \\le a^2+c^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$2bc \\le b^2+c^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le 0 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" }, { "data": { @@ -483,17 +1304,64 @@ "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "numerator: $$x^4-4x^3+6x^2-4x+1$$\n", - "denominator: $$1$$\n", - "status: 2\n", - "\n", - "Program couldn't find any proof.\n", - "$$ 4x^3+4x \\le \n", - "x^4+6x^2+1 $$\n" - ] + "data": { + "text/latex": [ + "numerator: $x^4-4x^3+6x^2-4x+1$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $1$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 2" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Program couldn't find any proof." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 4x^3+4x \\le x^4+6x^2+1 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" }, { "data": { @@ -523,18 +1391,76 @@ "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "Substitute $ x \\to x+1 $\n", - "numerator: $$x^4$$\n", - "denominator: $$1$$\n", - "status: 0\n", - "\n", - "$$ 0 \\le \n", - "x^4 $$\n", - "The sum of all inequalities gives us a proof of the inequality.\n" - ] + "data": { + "text/latex": [ + "Substitute $x\\to x+1$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "numerator: $x^4$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $1$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le x^4 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" }, { "data": { @@ -548,7 +1474,7 @@ } ], "source": [ - "prove(makesubs('(x-1)^4','(1,inf)'))" + "prove(makesubs('(x-1)^4','(1,oo)'))" ] }, { @@ -559,18 +1485,76 @@ }, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "Substitute $ x \\to 1-x $\n", - "numerator: $$x^4$$\n", - "denominator: $$1$$\n", - "status: 0\n", - "\n", - "$$ 0 \\le \n", - "x^4 $$\n", - "The sum of all inequalities gives us a proof of the inequality.\n" - ] + "data": { + "text/latex": [ + "Substitute $x\\to 1-x$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "numerator: $x^4$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $1$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le x^4 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" }, { "data": { @@ -584,7 +1568,7 @@ } ], "source": [ - "prove(makesubs('(x-1)^4','(-inf,1)'))" + "prove(makesubs('(x-1)^4','(-oo,1)'))" ] }, { @@ -629,17 +1613,64 @@ "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "numerator: $$a^3c+a^3d+a^2b^2-a^2bd-2a^2c^2-a^2cd+a^2d^2+ab^3-ab^2c-ab^2d-abc^2+ac^3-acd^2+b^3d+b^2c^2-2b^2d^2+bc^3-bc^2d-bcd^2+bd^3+c^2d^2+cd^3$$\n", - "denominator: $$a^2bc+a^2bd+a^2c^2+a^2cd+ab^2c+ab^2d+abc^2+2abcd+abd^2+ac^2d+acd^2+b^2cd+b^2d^2+bc^2d+bcd^2$$\n", - "status: 2\n", - "\n", - "Program couldn't find any proof.\n", - "$$ a^2bd+2a^2c^2+a^2cd+ab^2c+ab^2d+abc^2+acd^2+2b^2d^2+bc^2d+bcd^2 \\le \n", - "a^3c+a^3d+a^2b^2+a^2d^2+ab^3+ac^3+b^3d+b^2c^2+bc^3+bd^3+c^2d^2+cd^3 $$\n" - ] + "data": { + "text/latex": [ + "numerator: $a^3c+a^3d+a^2b^2-a^2bd-2a^2c^2-a^2cd+a^2d^2+ab^3-ab^2c-ab^2d-abc^2+ac^3-acd^2+b^3d+b^2c^2-2b^2d^2+bc^3-bc^2d-bcd^2+bd^3+c^2d^2+cd^3$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $a^2bc+a^2bd+a^2c^2+a^2cd+ab^2c+ab^2d+abc^2+2abcd+abd^2+ac^2d+acd^2+b^2cd+b^2d^2+bc^2d+bcd^2$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 2" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Program couldn't find any proof." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ a^2bd+2a^2c^2+a^2cd+ab^2c+ab^2d+abc^2+acd^2+2b^2d^2+bc^2d+bcd^2 \\le a^3c+a^3d+a^2b^2+a^2d^2+ab^3+ac^3+b^3d+b^2c^2+bc^3+bd^3+c^2d^2+cd^3 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" }, { "data": { @@ -669,20 +1700,100 @@ "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "Substitute $ a \\to a+c $\n", - "Substitute $ b \\to b+d $\n", - "numerator: $$a^3c+a^3d+a^2b^2+a^2bd+a^2c^2+2a^2cd+a^2d^2+ab^3+ab^2c+2ab^2d-abc^2+abd^2+b^3c+b^3d+b^2c^2+2b^2cd+b^2d^2$$\n", - "denominator: $$a^2bc+a^2bd+a^2c^2+2a^2cd+a^2d^2+ab^2c+ab^2d+3abc^2+6abcd+3abd^2+2ac^3+6ac^2d+6acd^2+2ad^3+b^2c^2+2b^2cd+b^2d^2+2bc^3+6bc^2d+6bcd^2+2bd^3+c^4+4c^3d+6c^2d^2+4cd^3+d^4$$\n", - "status: 0\n", - "From weighted AM-GM inequality:\n", - "\n", - "Program couldn't find a solution with integer coefficients. Try to multiple the formula by some integer and run this function again.\n", - "$$ abc^2 \\le \n", - "a^3c+a^3d+a^2b^2+a^2bd+a^2c^2+2a^2cd+a^2d^2+ab^3+ab^2c+2ab^2d+abd^2+b^3c+b^3d+b^2c^2+2b^2cd+b^2d^2 $$\n" - ] + "data": { + "text/latex": [ + "Substitute $a\\to a+c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $b\\to b+d$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "numerator: $a^3c+a^3d+a^2b^2+a^2bd+a^2c^2+2a^2cd+a^2d^2+ab^3+ab^2c+2ab^2d-abc^2+abd^2+b^3c+b^3d+b^2c^2+2b^2cd+b^2d^2$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $a^2bc+a^2bd+a^2c^2+2a^2cd+a^2d^2+ab^2c+ab^2d+3abc^2+6abcd+3abd^2+2ac^3+6ac^2d+6acd^2+2ad^3+b^2c^2+2b^2cd+b^2d^2+2bc^3+6bc^2d+6bcd^2+2bd^3+c^4+4c^3d+6c^2d^2+4cd^3+d^4$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "From weighted AM-GM inequality:" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Program couldn't find a solution with integer coefficients. Try to multiple the formula by some integer and run this function again." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ abc^2 \\le a^3c+a^3d+a^2b^2+a^2bd+a^2c^2+2a^2cd+a^2d^2+ab^3+ab^2c+2ab^2d+abd^2+b^3c+b^3d+b^2c^2+2b^2cd+b^2d^2 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" }, { "data": { @@ -696,7 +1807,7 @@ } ], "source": [ - "prove(makesubs(formula,'[c,inf],[d,inf]'))" + "prove(makesubs(formula,'[c,oo],[d,oo]'))" ] }, { @@ -705,21 +1816,112 @@ "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "Substitute $ a \\to a+c $\n", - "Substitute $ b \\to b+d $\n", - "numerator: $$2a^3c+2a^3d+2a^2b^2+2a^2bd+2a^2c^2+4a^2cd+2a^2d^2+2ab^3+2ab^2c+4ab^2d-2abc^2+2abd^2+2b^3c+2b^3d+2b^2c^2+4b^2cd+2b^2d^2$$\n", - "denominator: $$a^2bc+a^2bd+a^2c^2+2a^2cd+a^2d^2+ab^2c+ab^2d+3abc^2+6abcd+3abd^2+2ac^3+6ac^2d+6acd^2+2ad^3+b^2c^2+2b^2cd+b^2d^2+2bc^3+6bc^2d+6bcd^2+2bd^3+c^4+4c^3d+6c^2d^2+4cd^3+d^4$$\n", - "status: 0\n", - "From weighted AM-GM inequality:\n", - "$$2abc^2 \\le a^2c^2+b^2c^2$$\n", - "\n", - "$$ 0 \\le \n", - "2a^3c+2a^3d+2a^2b^2+2a^2bd+a^2c^2+4a^2cd+2a^2d^2+2ab^3+2ab^2c+4ab^2d+2abd^2+2b^3c+2b^3d+b^2c^2+4b^2cd+2b^2d^2 $$\n", - "The sum of all inequalities gives us a proof of the inequality.\n" - ] + "data": { + "text/latex": [ + "Substitute $a\\to a+c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $b\\to b+d$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "numerator: $2a^3c+2a^3d+2a^2b^2+2a^2bd+2a^2c^2+4a^2cd+2a^2d^2+2ab^3+2ab^2c+4ab^2d-2abc^2+2abd^2+2b^3c+2b^3d+2b^2c^2+4b^2cd+2b^2d^2$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $a^2bc+a^2bd+a^2c^2+2a^2cd+a^2d^2+ab^2c+ab^2d+3abc^2+6abcd+3abd^2+2ac^3+6ac^2d+6acd^2+2ad^3+b^2c^2+2b^2cd+b^2d^2+2bc^3+6bc^2d+6bcd^2+2bd^3+c^4+4c^3d+6c^2d^2+4cd^3+d^4$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "From weighted AM-GM inequality:" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$2abc^2 \\le a^2c^2+b^2c^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le 2a^3c+2a^3d+2a^2b^2+2a^2bd+a^2c^2+4a^2cd+2a^2d^2+2ab^3+2ab^2c+4ab^2d+2abd^2+2b^3c+2b^3d+b^2c^2+4b^2cd+2b^2d^2 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" }, { "data": { @@ -733,7 +1935,7 @@ } ], "source": [ - "prove(makesubs(formula,'[c,inf],[d,inf]')*2)" + "prove(makesubs(formula,'[c,oo],[d,oo]')*2)" ] }, { @@ -749,23 +1951,136 @@ "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "Substitute $ a \\to c-c/(a+1) $\n", - "Substitute $ b \\to d-d/(b+1) $\n", - "numerator: $$2a^3bc^2d^2+4a^3bcd^3+2a^3bd^4+2a^3c^2d^2+2a^3cd^3-2a^2b^2c^3d+2a^2b^2cd^3-4a^2bc^3d+4a^2bc^2d^2+12a^2bcd^3+6a^2bd^4-2a^2c^3d+4a^2c^2d^2+6a^2cd^3+2ab^3c^4+4ab^3c^3d+2ab^3c^2d^2+6ab^2c^4+8ab^2c^3d+4ab^2c^2d^2+4ab^2cd^3+6abc^4+4abc^3d+6abc^2d^2+12abcd^3+6abd^4+2ac^4+4ac^2d^2+6acd^3+2b^3c^3d+2b^3c^2d^2+4b^2c^3d+4b^2c^2d^2+2b^2cd^3+2bc^3d+4bc^2d^2+4bcd^3+2bd^4+2c^2d^2+2cd^3$$\n", - "denominator: $$a^3b^3c^4+4a^3b^3c^3d+6a^3b^3c^2d^2+4a^3b^3cd^3+a^3b^3d^4+3a^3b^2c^4+10a^3b^2c^3d+12a^3b^2c^2d^2+6a^3b^2cd^3+a^3b^2d^4+3a^3bc^4+8a^3bc^3d+7a^3bc^2d^2+2a^3bcd^3+a^3c^4+2a^3c^3d+a^3c^2d^2+a^2b^3c^4+6a^2b^3c^3d+12a^2b^3c^2d^2+10a^2b^3cd^3+3a^2b^3d^4+3a^2b^2c^4+15a^2b^2c^3d+24a^2b^2c^2d^2+15a^2b^2cd^3+3a^2b^2d^4+3a^2bc^4+12a^2bc^3d+14a^2bc^2d^2+5a^2bcd^3+a^2c^4+3a^2c^3d+2a^2c^2d^2+2ab^3c^3d+7ab^3c^2d^2+8ab^3cd^3+3ab^3d^4+5ab^2c^3d+14ab^2c^2d^2+12ab^2cd^3+3ab^2d^4+4abc^3d+8abc^2d^2+4abcd^3+ac^3d+ac^2d^2+b^3c^2d^2+2b^3cd^3+b^3d^4+2b^2c^2d^2+3b^2cd^3+b^2d^4+bc^2d^2+bcd^3$$\n", - "status: 0\n", - "From weighted AM-GM inequality:\n", - "$$2a^2b^2c^3d \\le a^3bc^2d^2+ab^3c^4$$\n", - "$$2a^2c^3d \\le a^3c^2d^2+ac^4$$\n", - "$$4a^2bc^3d \\le a^3bc^2d^2+a^3c^2d^2+ab^2c^4+abc^4$$\n", - "\n", - "$$ 0 \\le \n", - "4a^3bcd^3+2a^3bd^4+2a^3cd^3+2a^2b^2cd^3+4a^2bc^2d^2+12a^2bcd^3+6a^2bd^4+4a^2c^2d^2+6a^2cd^3+ab^3c^4+4ab^3c^3d+2ab^3c^2d^2+5ab^2c^4+8ab^2c^3d+4ab^2c^2d^2+4ab^2cd^3+5abc^4+4abc^3d+6abc^2d^2+12abcd^3+6abd^4+ac^4+4ac^2d^2+6acd^3+2b^3c^3d+2b^3c^2d^2+4b^2c^3d+4b^2c^2d^2+2b^2cd^3+2bc^3d+4bc^2d^2+4bcd^3+2bd^4+2c^2d^2+2cd^3 $$\n", - "The sum of all inequalities gives us a proof of the inequality.\n" - ] + "data": { + "text/latex": [ + "Substitute $a\\to c-c/(a+1)$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $b\\to d-d/(b+1)$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "numerator: $2a^3bc^2d^2+4a^3bcd^3+2a^3bd^4+2a^3c^2d^2+2a^3cd^3-2a^2b^2c^3d+2a^2b^2cd^3-4a^2bc^3d+4a^2bc^2d^2+12a^2bcd^3+6a^2bd^4-2a^2c^3d+4a^2c^2d^2+6a^2cd^3+2ab^3c^4+4ab^3c^3d+2ab^3c^2d^2+6ab^2c^4+8ab^2c^3d+4ab^2c^2d^2+4ab^2cd^3+6abc^4+4abc^3d+6abc^2d^2+12abcd^3+6abd^4+2ac^4+4ac^2d^2+6acd^3+2b^3c^3d+2b^3c^2d^2+4b^2c^3d+4b^2c^2d^2+2b^2cd^3+2bc^3d+4bc^2d^2+4bcd^3+2bd^4+2c^2d^2+2cd^3$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $a^3b^3c^4+4a^3b^3c^3d+6a^3b^3c^2d^2+4a^3b^3cd^3+a^3b^3d^4+3a^3b^2c^4+10a^3b^2c^3d+12a^3b^2c^2d^2+6a^3b^2cd^3+a^3b^2d^4+3a^3bc^4+8a^3bc^3d+7a^3bc^2d^2+2a^3bcd^3+a^3c^4+2a^3c^3d+a^3c^2d^2+a^2b^3c^4+6a^2b^3c^3d+12a^2b^3c^2d^2+10a^2b^3cd^3+3a^2b^3d^4+3a^2b^2c^4+15a^2b^2c^3d+24a^2b^2c^2d^2+15a^2b^2cd^3+3a^2b^2d^4+3a^2bc^4+12a^2bc^3d+14a^2bc^2d^2+5a^2bcd^3+a^2c^4+3a^2c^3d+2a^2c^2d^2+2ab^3c^3d+7ab^3c^2d^2+8ab^3cd^3+3ab^3d^4+5ab^2c^3d+14ab^2c^2d^2+12ab^2cd^3+3ab^2d^4+4abc^3d+8abc^2d^2+4abcd^3+ac^3d+ac^2d^2+b^3c^2d^2+2b^3cd^3+b^3d^4+2b^2c^2d^2+3b^2cd^3+b^2d^4+bc^2d^2+bcd^3$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "From weighted AM-GM inequality:" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$2a^2b^2c^3d \\le a^3bc^2d^2+ab^3c^4$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$2a^2c^3d \\le a^3c^2d^2+ac^4$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$4a^2bc^3d \\le a^3bc^2d^2+a^3c^2d^2+ab^3c^4+ac^4$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le 4a^3bcd^3+2a^3bd^4+2a^3cd^3+2a^2b^2cd^3+4a^2bc^2d^2+12a^2bcd^3+6a^2bd^4+4a^2c^2d^2+6a^2cd^3+4ab^3c^3d+2ab^3c^2d^2+6ab^2c^4+8ab^2c^3d+4ab^2c^2d^2+4ab^2cd^3+6abc^4+4abc^3d+6abc^2d^2+12abcd^3+6abd^4+4ac^2d^2+6acd^3+2b^3c^3d+2b^3c^2d^2+4b^2c^3d+4b^2c^2d^2+2b^2cd^3+2bc^3d+4bc^2d^2+4bcd^3+2bd^4+2c^2d^2+2cd^3 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" }, { "data": { @@ -791,36 +2106,178 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 19, "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "numerator: $$x^4-4x^3+6x^2-4x+1$$\n", - "denominator: $$1$$\n", - "\n", - "\\hline\n", - "\n", - "Substitute $x\\to 1+x$\n", - "Numerator after substitutions: x^4\n", - "status: 0\n", - "\n", - "$$ 0 \\le \n", - "x^4 $$\n", - "The sum of all inequalities gives us a proof of the inequality.\n", - "\n", - "\\hline\n", - "\n", - "Substitute $x\\to 1/(1+x)$\n", - "Numerator after substitutions: x^4\n", - "status: 0\n", - "\n", - "$$ 0 \\le \n", - "x^4 $$\n", - "The sum of all inequalities gives us a proof of the inequality.\n" - ] + "data": { + "text/latex": [ + "numerator: $x^4-4x^3+6x^2-4x+1$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $1$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "\n", + "\\hline\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $x\\to 1+x$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Numerator after substitutions: $x^4$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le x^4 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "\n", + "\\hline\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $x\\to 1/(1+x)$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Numerator after substitutions: $x^4$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le x^4 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" } ], "source": [ @@ -829,121 +2286,844 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 20, "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "numerator: $$4a^5+4a^4b+4a^4c-6a^4-4a^3b-2a^3c+4ab^3-9ab^2+4ac^2-18ac+9a+4b^4+4b^3c-6b^3-3b^2c+4bc^2-12bc+10b+4c^3-6c^2+11c$$\n", - "denominator: $$1$$\n", - "\n", - "\\hline\n", - "\n", - "Substitute $a\\to 1+a,b\\to 1+b,c\\to 1+c$\n", - "Numerator after substitutions: 4a^5+4a^4b+4a^4c+22a^4+12a^3b+14a^3c+42a^3+12a^2b+18a^2c+34a^2+4ab^3+3ab^2-2ab+4ac^2+4b^4+4b^3c+18b^3+9b^2c+18b^2+4bc^2+2bc+4c^3+14c^2\n", - "status: 0\n", - "From weighted AM-GM inequality:\n", - "$$2ab \\le a^2+b^2$$\n", - "\n", - "$$ 0 \\le \n", - "4a^5+4a^4b+4a^4c+22a^4+12a^3b+14a^3c+42a^3+12a^2b+18a^2c+33a^2+4ab^3+3ab^2+4ac^2+4b^4+4b^3c+18b^3+9b^2c+17b^2+4bc^2+2bc+4c^3+14c^2 $$\n", - "The sum of all inequalities gives us a proof of the inequality.\n", - "\n", - "\\hline\n", - "\n", - "Substitute $a\\to 1/(1+a),b\\to 1+b,c\\to 1+c$\n", - "Numerator after substitutions: 4a^5b^4+4a^5b^3c+14a^5b^3+9a^5b^2c+15a^5b^2+4a^5bc^2+2a^5bc+6a^5b+4a^5c^3+10a^5c^2+8a^5c+10a^5+20a^4b^4+20a^4b^3c+74a^4b^3+45a^4b^2c+78a^4b^2+20a^4bc^2+10a^4bc+24a^4b+20a^4c^3+54a^4c^2+30a^4c+40a^4+40a^3b^4+40a^3b^3c+156a^3b^3+90a^3b^2c+162a^3b^2+40a^3bc^2+20a^3bc+36a^3b+40a^3c^3+116a^3c^2+40a^3c+60a^3+40a^2b^4+40a^2b^3c+164a^2b^3+90a^2b^2c+168a^2b^2+40a^2bc^2+20a^2bc+20a^2b+40a^2c^3+124a^2c^2+18a^2c+34a^2+20ab^4+20ab^3c+86ab^3+45ab^2c+87ab^2+20abc^2+10abc+2ab+20ac^3+66ac^2+4b^4+4b^3c+18b^3+9b^2c+18b^2+4bc^2+2bc+4c^3+14c^2\n", - "status: 0\n", - "\n", - "$$ 0 \\le \n", - "4a^5b^4+4a^5b^3c+14a^5b^3+9a^5b^2c+15a^5b^2+4a^5bc^2+2a^5bc+6a^5b+4a^5c^3+10a^5c^2+8a^5c+10a^5+20a^4b^4+20a^4b^3c+74a^4b^3+45a^4b^2c+78a^4b^2+20a^4bc^2+10a^4bc+24a^4b+20a^4c^3+54a^4c^2+30a^4c+40a^4+40a^3b^4+40a^3b^3c+156a^3b^3+90a^3b^2c+162a^3b^2+40a^3bc^2+20a^3bc+36a^3b+40a^3c^3+116a^3c^2+40a^3c+60a^3+40a^2b^4+40a^2b^3c+164a^2b^3+90a^2b^2c+168a^2b^2+40a^2bc^2+20a^2bc+20a^2b+40a^2c^3+124a^2c^2+18a^2c+34a^2+20ab^4+20ab^3c+86ab^3+45ab^2c+87ab^2+20abc^2+10abc+2ab+20ac^3+66ac^2+4b^4+4b^3c+18b^3+9b^2c+18b^2+4bc^2+2bc+4c^3+14c^2 $$\n", - "The sum of all inequalities gives us a proof of the inequality.\n", - "\n", - "\\hline\n", - "\n", - "Substitute $a\\to 1+a,b\\to 1/(1+b),c\\to 1+c$\n", - "Numerator after substitutions: 4a^5b^4+16a^5b^3+24a^5b^2+16a^5b+4a^5+4a^4b^4c+18a^4b^4+16a^4b^3c+76a^4b^3+24a^4b^2c+120a^4b^2+16a^4bc+84a^4b+4a^4c+22a^4+14a^3b^4c+30a^3b^4+56a^3b^3c+132a^3b^3+84a^3b^2c+216a^3b^2+56a^3bc+156a^3b+14a^3c+42a^3+18a^2b^4c+22a^2b^4+72a^2b^3c+100a^2b^3+108a^2b^2c+168a^2b^2+72a^2bc+124a^2b+18a^2c+34a^2+4ab^4c^2+ab^4+16ab^3c^2+8ab^3+24ab^2c^2+9ab^2+16abc^2+2ab+4ac^2+4b^4c^3+10b^4c^2+3b^4c+4b^4+16b^3c^3+44b^3c^2+8b^3c+18b^3+24b^2c^3+72b^2c^2+3b^2c+18b^2+16bc^3+52bc^2-2bc+4c^3+14c^2\n", - "status: 0\n", - "From weighted AM-GM inequality:\n", - "$$2bc \\le b^2+c^2$$\n", - "\n", - "$$ 0 \\le \n", - "4a^5b^4+16a^5b^3+24a^5b^2+16a^5b+4a^5+4a^4b^4c+18a^4b^4+16a^4b^3c+76a^4b^3+24a^4b^2c+120a^4b^2+16a^4bc+84a^4b+4a^4c+22a^4+14a^3b^4c+30a^3b^4+56a^3b^3c+132a^3b^3+84a^3b^2c+216a^3b^2+56a^3bc+156a^3b+14a^3c+42a^3+18a^2b^4c+22a^2b^4+72a^2b^3c+100a^2b^3+108a^2b^2c+168a^2b^2+72a^2bc+124a^2b+18a^2c+34a^2+4ab^4c^2+ab^4+16ab^3c^2+8ab^3+24ab^2c^2+9ab^2+16abc^2+2ab+4ac^2+4b^4c^3+10b^4c^2+3b^4c+4b^4+16b^3c^3+44b^3c^2+8b^3c+18b^3+24b^2c^3+72b^2c^2+3b^2c+17b^2+16bc^3+52bc^2+4c^3+13c^2 $$\n", - "The sum of all inequalities gives us a proof of the inequality.\n", - "\n", - "\\hline\n", - "\n", - "Substitute $a\\to 1/(1+a),b\\to 1/(1+b),c\\to 1+c$\n", - "Numerator after substitutions: 4a^5b^4c^3+6a^5b^4c^2+11a^5b^4c+9a^5b^4+16a^5b^3c^3+28a^5b^3c^2+40a^5b^3c+38a^5b^3+24a^5b^2c^3+48a^5b^2c^2+51a^5b^2c+57a^5b^2+16a^5bc^3+36a^5bc^2+30a^5bc+34a^5b+4a^5c^3+10a^5c^2+8a^5c+10a^5+20a^4b^4c^3+34a^4b^4c^2+45a^4b^4c+40a^4b^4+80a^4b^3c^3+156a^4b^3c^2+160a^4b^3c+170a^4b^3+120a^4b^2c^3+264a^4b^2c^2+195a^4b^2c+246a^4b^2+80a^4bc^3+196a^4bc^2+110a^4bc+136a^4b+20a^4c^3+54a^4c^2+30a^4c+40a^4+40a^3b^4c^3+76a^3b^4c^2+70a^3b^4c+70a^3b^4+160a^3b^3c^3+344a^3b^3c^2+240a^3b^3c+300a^3b^3+240a^3b^2c^3+576a^3b^2c^2+270a^3b^2c+414a^3b^2+160a^3bc^3+424a^3bc^2+140a^3bc+204a^3b+40a^3c^3+116a^3c^2+40a^3c+60a^3+40a^2b^4c^3+84a^2b^4c^2+48a^2b^4c+58a^2b^4+160a^2b^3c^3+376a^2b^3c^2+152a^2b^3c+248a^2b^3+240a^2b^2c^3+624a^2b^2c^2+138a^2b^2c+312a^2b^2+160a^2bc^3+456a^2bc^2+52a^2bc+116a^2b+40a^2c^3+124a^2c^2+18a^2c+34a^2+20ab^4c^3+46ab^4c^2+15ab^4c+19ab^4+80ab^3c^3+204ab^3c^2+40ab^3c+82ab^3+120ab^2c^3+336ab^2c^2+15ab^2c+81ab^2+80abc^3+244abc^2-10abc-2ab+20ac^3+66ac^2+4b^4c^3+10b^4c^2+3b^4c+4b^4+16b^3c^3+44b^3c^2+8b^3c+18b^3+24b^2c^3+72b^2c^2+3b^2c+18b^2+16bc^3+52bc^2-2bc+4c^3+14c^2\n", - "status: 0\n", - "From weighted AM-GM inequality:\n", - "$$2ab \\le a^2+b^2$$\n", - "$$2bc \\le b^2+c^2$$\n", - "$$10abc \\le 2a^3c+2a^2+2b^3+4bc^2$$\n", - "\n", - "$$ 0 \\le \n", - "4a^5b^4c^3+6a^5b^4c^2+11a^5b^4c+9a^5b^4+16a^5b^3c^3+28a^5b^3c^2+40a^5b^3c+38a^5b^3+24a^5b^2c^3+48a^5b^2c^2+51a^5b^2c+57a^5b^2+16a^5bc^3+36a^5bc^2+30a^5bc+34a^5b+4a^5c^3+10a^5c^2+8a^5c+10a^5+20a^4b^4c^3+34a^4b^4c^2+45a^4b^4c+40a^4b^4+80a^4b^3c^3+156a^4b^3c^2+160a^4b^3c+170a^4b^3+120a^4b^2c^3+264a^4b^2c^2+195a^4b^2c+246a^4b^2+80a^4bc^3+196a^4bc^2+110a^4bc+136a^4b+20a^4c^3+54a^4c^2+30a^4c+40a^4+40a^3b^4c^3+76a^3b^4c^2+70a^3b^4c+70a^3b^4+160a^3b^3c^3+344a^3b^3c^2+240a^3b^3c+300a^3b^3+240a^3b^2c^3+576a^3b^2c^2+270a^3b^2c+414a^3b^2+160a^3bc^3+424a^3bc^2+140a^3bc+204a^3b+40a^3c^3+116a^3c^2+38a^3c+60a^3+40a^2b^4c^3+84a^2b^4c^2+48a^2b^4c+58a^2b^4+160a^2b^3c^3+376a^2b^3c^2+152a^2b^3c+248a^2b^3+240a^2b^2c^3+624a^2b^2c^2+138a^2b^2c+312a^2b^2+160a^2bc^3+456a^2bc^2+52a^2bc+116a^2b+40a^2c^3+124a^2c^2+18a^2c+31a^2+20ab^4c^3+46ab^4c^2+15ab^4c+19ab^4+80ab^3c^3+204ab^3c^2+40ab^3c+82ab^3+120ab^2c^3+336ab^2c^2+15ab^2c+81ab^2+80abc^3+244abc^2+20ac^3+66ac^2+4b^4c^3+10b^4c^2+3b^4c+4b^4+16b^3c^3+44b^3c^2+8b^3c+16b^3+24b^2c^3+72b^2c^2+3b^2c+16b^2+16bc^3+48bc^2+4c^3+13c^2 $$\n", - "The sum of all inequalities gives us a proof of the inequality.\n", - "\n", - "\\hline\n", - "\n", - "Substitute $a\\to 1+a,b\\to 1+b,c\\to 1/(1+c)$\n", - "Numerator after substitutions: 4a^5c^3+12a^5c^2+12a^5c+4a^5+4a^4bc^3+12a^4bc^2+12a^4bc+4a^4b+18a^4c^3+58a^4c^2+62a^4c+22a^4+12a^3bc^3+36a^3bc^2+36a^3bc+12a^3b+28a^3c^3+98a^3c^2+112a^3c+42a^3+12a^2bc^3+36a^2bc^2+36a^2bc+12a^2b+16a^2c^3+66a^2c^2+84a^2c+34a^2+4ab^3c^3+12ab^3c^2+12ab^3c+4ab^3+3ab^2c^3+9ab^2c^2+9ab^2c+3ab^2-2abc^3-6abc^2-6abc-2ab+4ac^3+4ac^2+4b^4c^3+12b^4c^2+12b^4c+4b^4+14b^3c^3+46b^3c^2+50b^3c+18b^3+9b^2c^3+36b^2c^2+45b^2c+18b^2+2bc^3-2bc+10c^3+14c^2\n", - "status: 0\n", - "From weighted AM-GM inequality:\n", - "$$2ab \\le a^2+b^2$$\n", - "$$2bc \\le b^2+c^2$$\n", - "$$6abc \\le 3a^2c+3b^2c$$\n", - "$$2abc^3 \\le a^2bc^3+bc^3$$\n", - "$$6abc^2 \\le a^4b+a^2c^3+b^4c^2+bc^3+2c^2$$\n", - "\n", - "$$ 0 \\le \n", - "4a^5c^3+12a^5c^2+12a^5c+4a^5+4a^4bc^3+12a^4bc^2+12a^4bc+3a^4b+18a^4c^3+58a^4c^2+62a^4c+22a^4+12a^3bc^3+36a^3bc^2+36a^3bc+12a^3b+28a^3c^3+98a^3c^2+112a^3c+42a^3+11a^2bc^3+36a^2bc^2+36a^2bc+12a^2b+15a^2c^3+66a^2c^2+81a^2c+33a^2+4ab^3c^3+12ab^3c^2+12ab^3c+4ab^3+3ab^2c^3+9ab^2c^2+9ab^2c+3ab^2+4ac^3+4ac^2+4b^4c^3+11b^4c^2+12b^4c+4b^4+14b^3c^3+46b^3c^2+50b^3c+18b^3+9b^2c^3+36b^2c^2+42b^2c+16b^2+10c^3+11c^2 $$\n", - "The sum of all inequalities gives us a proof of the inequality.\n", - "\n", - "\\hline\n", - "\n", - "Substitute $a\\to 1/(1+a),b\\to 1+b,c\\to 1/(1+c)$\n", - "Numerator after substitutions: 4a^5b^4c^3+12a^5b^4c^2+12a^5b^4c+4a^5b^4+10a^5b^3c^3+34a^5b^3c^2+38a^5b^3c+14a^5b^3+6a^5b^2c^3+27a^5b^2c^2+36a^5b^2c+15a^5b^2+8a^5bc^3+18a^5bc^2+16a^5bc+6a^5b+8a^5c^3+24a^5c^2+22a^5c+10a^5+20a^4b^4c^3+60a^4b^4c^2+60a^4b^4c+20a^4b^4+54a^4b^3c^3+182a^4b^3c^2+202a^4b^3c+74a^4b^3+33a^4b^2c^3+144a^4b^2c^2+189a^4b^2c+78a^4b^2+34a^4bc^3+72a^4bc^2+62a^4bc+24a^4b+44a^4c^3+114a^4c^2+90a^4c+40a^4+40a^3b^4c^3+120a^3b^4c^2+120a^3b^4c+40a^3b^4+116a^3b^3c^3+388a^3b^3c^2+428a^3b^3c+156a^3b^3+72a^3b^2c^3+306a^3b^2c^2+396a^3b^2c+162a^3b^2+56a^3bc^3+108a^3bc^2+88a^3bc+36a^3b+96a^3c^3+216a^3c^2+140a^3c+60a^3+40a^2b^4c^3+120a^2b^4c^2+120a^2b^4c+40a^2b^4+124a^2b^3c^3+412a^2b^3c^2+452a^2b^3c+164a^2b^3+78a^2b^2c^3+324a^2b^2c^2+414a^2b^2c+168a^2b^2+40a^2bc^3+60a^2bc^2+40a^2bc+20a^2b+100a^2c^3+190a^2c^2+84a^2c+34a^2+20ab^4c^3+60ab^4c^2+60ab^4c+20ab^4+66ab^3c^3+218ab^3c^2+238ab^3c+86ab^3+42ab^2c^3+171ab^2c^2+216ab^2c+87ab^2+12abc^3+6abc^2-4abc+2ab+46ac^3+66ac^2+4b^4c^3+12b^4c^2+12b^4c+4b^4+14b^3c^3+46b^3c^2+50b^3c+18b^3+9b^2c^3+36b^2c^2+45b^2c+18b^2+2bc^3-2bc+10c^3+14c^2\n", - "status: 0\n", - "From weighted AM-GM inequality:\n", - "$$2bc \\le b^2+c^2$$\n", - "$$4abc \\le a^2c^2+2ab^2+c^2$$\n", - "\n", - "$$ 0 \\le \n", - "4a^5b^4c^3+12a^5b^4c^2+12a^5b^4c+4a^5b^4+10a^5b^3c^3+34a^5b^3c^2+38a^5b^3c+14a^5b^3+6a^5b^2c^3+27a^5b^2c^2+36a^5b^2c+15a^5b^2+8a^5bc^3+18a^5bc^2+16a^5bc+6a^5b+8a^5c^3+24a^5c^2+22a^5c+10a^5+20a^4b^4c^3+60a^4b^4c^2+60a^4b^4c+20a^4b^4+54a^4b^3c^3+182a^4b^3c^2+202a^4b^3c+74a^4b^3+33a^4b^2c^3+144a^4b^2c^2+189a^4b^2c+78a^4b^2+34a^4bc^3+72a^4bc^2+62a^4bc+24a^4b+44a^4c^3+114a^4c^2+90a^4c+40a^4+40a^3b^4c^3+120a^3b^4c^2+120a^3b^4c+40a^3b^4+116a^3b^3c^3+388a^3b^3c^2+428a^3b^3c+156a^3b^3+72a^3b^2c^3+306a^3b^2c^2+396a^3b^2c+162a^3b^2+56a^3bc^3+108a^3bc^2+88a^3bc+36a^3b+96a^3c^3+216a^3c^2+140a^3c+60a^3+40a^2b^4c^3+120a^2b^4c^2+120a^2b^4c+40a^2b^4+124a^2b^3c^3+412a^2b^3c^2+452a^2b^3c+164a^2b^3+78a^2b^2c^3+324a^2b^2c^2+414a^2b^2c+168a^2b^2+40a^2bc^3+60a^2bc^2+40a^2bc+20a^2b+100a^2c^3+189a^2c^2+84a^2c+34a^2+20ab^4c^3+60ab^4c^2+60ab^4c+20ab^4+66ab^3c^3+218ab^3c^2+238ab^3c+86ab^3+42ab^2c^3+171ab^2c^2+216ab^2c+85ab^2+12abc^3+6abc^2+2ab+46ac^3+66ac^2+4b^4c^3+12b^4c^2+12b^4c+4b^4+14b^3c^3+46b^3c^2+50b^3c+18b^3+9b^2c^3+36b^2c^2+45b^2c+17b^2+2bc^3+10c^3+12c^2 $$\n", - "The sum of all inequalities gives us a proof of the inequality.\n", - "\n", - "\\hline\n", - "\n", - "Substitute $a\\to 1+a,b\\to 1/(1+b),c\\to 1/(1+c)$\n", - "Numerator after substitutions: 4a^5b^4c^3+12a^5b^4c^2+12a^5b^4c+4a^5b^4+16a^5b^3c^3+48a^5b^3c^2+48a^5b^3c+16a^5b^3+24a^5b^2c^3+72a^5b^2c^2+72a^5b^2c+24a^5b^2+16a^5bc^3+48a^5bc^2+48a^5bc+16a^5b+4a^5c^3+12a^5c^2+12a^5c+4a^5+14a^4b^4c^3+46a^4b^4c^2+50a^4b^4c+18a^4b^4+60a^4b^3c^3+196a^4b^3c^2+212a^4b^3c+76a^4b^3+96a^4b^2c^3+312a^4b^2c^2+336a^4b^2c+120a^4b^2+68a^4bc^3+220a^4bc^2+236a^4bc+84a^4b+18a^4c^3+58a^4c^2+62a^4c+22a^4+16a^3b^4c^3+62a^3b^4c^2+76a^3b^4c+30a^3b^4+76a^3b^3c^3+284a^3b^3c^2+340a^3b^3c+132a^3b^3+132a^3b^2c^3+480a^3b^2c^2+564a^3b^2c+216a^3b^2+100a^3bc^3+356a^3bc^2+412a^3bc+156a^3b+28a^3c^3+98a^3c^2+112a^3c+42a^3+4a^2b^4c^3+30a^2b^4c^2+48a^2b^4c+22a^2b^4+28a^2b^3c^3+156a^2b^3c^2+228a^2b^3c+100a^2b^3+60a^2b^2c^3+288a^2b^2c^2+396a^2b^2c+168a^2b^2+52a^2bc^3+228a^2bc^2+300a^2bc+124a^2b+16a^2c^3+66a^2c^2+84a^2c+34a^2+5ab^4c^3+7ab^4c^2+3ab^4c+ab^4+24ab^3c^3+40ab^3c^2+24ab^3c+8ab^3+33ab^2c^3+51ab^2c^2+27ab^2c+9ab^2+18abc^3+22abc^2+6abc+2ab+4ac^3+4ac^2+7b^4c^3+16b^4c^2+9b^4c+4b^4+38b^3c^3+82b^3c^2+46b^3c+18b^3+63b^2c^3+120b^2c^2+51b^2c+18b^2+38bc^3+56bc^2+2bc+10c^3+14c^2\n", - "status: 0\n", - "\n", - "$$ 0 \\le \n" - ] + "data": { + "text/latex": [ + "numerator: $4a^5+4a^4b+4a^4c-6a^4-4a^3b-2a^3c+4ab^3-9ab^2+4ac^2-18ac+9a+4b^4+4b^3c-6b^3-3b^2c+4bc^2-12bc+10b+4c^3-6c^2+11c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" }, { - "name": "stdout", - "output_type": "stream", - "text": [ - "4a^5b^4c^3+12a^5b^4c^2+12a^5b^4c+4a^5b^4+16a^5b^3c^3+48a^5b^3c^2+48a^5b^3c+16a^5b^3+24a^5b^2c^3+72a^5b^2c^2+72a^5b^2c+24a^5b^2+16a^5bc^3+48a^5bc^2+48a^5bc+16a^5b+4a^5c^3+12a^5c^2+12a^5c+4a^5+14a^4b^4c^3+46a^4b^4c^2+50a^4b^4c+18a^4b^4+60a^4b^3c^3+196a^4b^3c^2+212a^4b^3c+76a^4b^3+96a^4b^2c^3+312a^4b^2c^2+336a^4b^2c+120a^4b^2+68a^4bc^3+220a^4bc^2+236a^4bc+84a^4b+18a^4c^3+58a^4c^2+62a^4c+22a^4+16a^3b^4c^3+62a^3b^4c^2+76a^3b^4c+30a^3b^4+76a^3b^3c^3+284a^3b^3c^2+340a^3b^3c+132a^3b^3+132a^3b^2c^3+480a^3b^2c^2+564a^3b^2c+216a^3b^2+100a^3bc^3+356a^3bc^2+412a^3bc+156a^3b+28a^3c^3+98a^3c^2+112a^3c+42a^3+4a^2b^4c^3+30a^2b^4c^2+48a^2b^4c+22a^2b^4+28a^2b^3c^3+156a^2b^3c^2+228a^2b^3c+100a^2b^3+60a^2b^2c^3+288a^2b^2c^2+396a^2b^2c+168a^2b^2+52a^2bc^3+228a^2bc^2+300a^2bc+124a^2b+16a^2c^3+66a^2c^2+84a^2c+34a^2+5ab^4c^3+7ab^4c^2+3ab^4c+ab^4+24ab^3c^3+40ab^3c^2+24ab^3c+8ab^3+33ab^2c^3+51ab^2c^2+27ab^2c+9ab^2+18abc^3+22abc^2+6abc+2ab+4ac^3+4ac^2+7b^4c^3+16b^4c^2+9b^4c+4b^4+38b^3c^3+82b^3c^2+46b^3c+18b^3+63b^2c^3+120b^2c^2+51b^2c+18b^2+38bc^3+56bc^2+2bc+10c^3+14c^2 $$\n", - "The sum of all inequalities gives us a proof of the inequality.\n", - "\n", - "\\hline\n", - "\n", - "Substitute $a\\to 1/(1+a),b\\to 1/(1+b),c\\to 1/(1+c)$\n", - "Numerator after substitutions: 11a^5b^4c^2+16a^5b^4c+9a^5b^4+10a^5b^3c^3+62a^5b^3c^2+74a^5b^3c+38a^5b^3+30a^5b^2c^3+117a^5b^2c^2+120a^5b^2c+57a^5b^2+24a^5bc^3+78a^5bc^2+72a^5bc+34a^5b+8a^5c^3+24a^5c^2+22a^5c+10a^5+9a^4b^4c^3+64a^4b^4c^2+75a^4b^4c+40a^4b^4+86a^4b^3c^3+346a^4b^3c^2+350a^4b^3c+170a^4b^3+195a^4b^2c^3+612a^4b^2c^2+543a^4b^2c+246a^4b^2+142a^4bc^3+384a^4bc^2+298a^4bc+136a^4b+44a^4c^3+114a^4c^2+90a^4c+40a^4+36a^3b^4c^3+146a^3b^4c^2+140a^3b^4c+70a^3b^4+244a^3b^3c^3+764a^3b^3c^2+660a^3b^3c+300a^3b^3+480a^3b^2c^3+1278a^3b^2c^2+972a^3b^2c+414a^3b^2+328a^3bc^3+756a^3bc^2+472a^3bc+204a^3b+96a^3c^3+216a^3c^2+140a^3c+60a^3+54a^2b^4c^3+162a^2b^4c^2+126a^2b^4c+58a^2b^4+312a^2b^3c^3+816a^2b^3c^2+592a^2b^3c+248a^2b^3+558a^2b^2c^3+1284a^2b^2c^2+798a^2b^2c+312a^2b^2+360a^2bc^3+700a^2bc^2+296a^2bc+116a^2b+100a^2c^3+190a^2c^2+84a^2c+34a^2+30ab^4c^3+73ab^4c^2+42ab^4c+19ab^4+166ab^3c^3+370ab^3c^2+206ab^3c+82ab^3+282ab^2c^3+549ab^2c^2+228ab^2c+81ab^2+172abc^3+258abc^2+4abc-2ab+46ac^3+66ac^2+7b^4c^3+16b^4c^2+9b^4c+4b^4+38b^3c^3+82b^3c^2+46b^3c+18b^3+63b^2c^3+120b^2c^2+51b^2c+18b^2+38bc^3+56bc^2+2bc+10c^3+14c^2\n", - "status: 0\n", - "From weighted AM-GM inequality:\n", - "$$2ab \\le a^2+b^2$$\n", - "\n", - "$$ 0 \\le \n", - "11a^5b^4c^2+16a^5b^4c+9a^5b^4+10a^5b^3c^3+62a^5b^3c^2+74a^5b^3c+38a^5b^3+30a^5b^2c^3+117a^5b^2c^2+120a^5b^2c+57a^5b^2+24a^5bc^3+78a^5bc^2+72a^5bc+34a^5b+8a^5c^3+24a^5c^2+22a^5c+10a^5+9a^4b^4c^3+64a^4b^4c^2+75a^4b^4c+40a^4b^4+86a^4b^3c^3+346a^4b^3c^2+350a^4b^3c+170a^4b^3+195a^4b^2c^3+612a^4b^2c^2+543a^4b^2c+246a^4b^2+142a^4bc^3+384a^4bc^2+298a^4bc+136a^4b+44a^4c^3+114a^4c^2+90a^4c+40a^4+36a^3b^4c^3+146a^3b^4c^2+140a^3b^4c+70a^3b^4+244a^3b^3c^3+764a^3b^3c^2+660a^3b^3c+300a^3b^3+480a^3b^2c^3+1278a^3b^2c^2+972a^3b^2c+414a^3b^2+328a^3bc^3+756a^3bc^2+472a^3bc+204a^3b+96a^3c^3+216a^3c^2+140a^3c+60a^3+54a^2b^4c^3+162a^2b^4c^2+126a^2b^4c+58a^2b^4+312a^2b^3c^3+816a^2b^3c^2+592a^2b^3c+248a^2b^3+558a^2b^2c^3+1284a^2b^2c^2+798a^2b^2c+312a^2b^2+360a^2bc^3+700a^2bc^2+296a^2bc+116a^2b+100a^2c^3+190a^2c^2+84a^2c+33a^2+30ab^4c^3+73ab^4c^2+42ab^4c+19ab^4+166ab^3c^3+370ab^3c^2+206ab^3c+82ab^3+282ab^2c^3+549ab^2c^2+228ab^2c+81ab^2+172abc^3+258abc^2+4abc+46ac^3+66ac^2+7b^4c^3+16b^4c^2+9b^4c+4b^4+38b^3c^3+82b^3c^2+46b^3c+18b^3+63b^2c^3+120b^2c^2+51b^2c+17b^2+38bc^3+56bc^2+2bc+10c^3+14c^2 $$\n", - "The sum of all inequalities gives us a proof of the inequality.\n" - ] + "data": { + "text/latex": [ + "denominator: $1$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "\n", + "\\hline\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $a\\to 1+a,b\\to 1+b,c\\to 1+c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Numerator after substitutions: $4a^5+4a^4b+4a^4c+22a^4+12a^3b+14a^3c+42a^3+12a^2b+18a^2c+34a^2+4ab^3+3ab^2-2ab+4ac^2+4b^4+4b^3c+18b^3+9b^2c+18b^2+4bc^2+2bc+4c^3+14c^2$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "From weighted AM-GM inequality:" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$2ab \\le a^2+b^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le 4a^5+4a^4b+4a^4c+22a^4+12a^3b+14a^3c+42a^3+12a^2b+18a^2c+33a^2+4ab^3+3ab^2+4ac^2+4b^4+4b^3c+18b^3+9b^2c+17b^2+4bc^2+2bc+4c^3+14c^2 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "\n", + "\\hline\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $a\\to 1/(1+a),b\\to 1+b,c\\to 1+c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Numerator after substitutions: $4a^5b^4+4a^5b^3c+14a^5b^3+9a^5b^2c+15a^5b^2+4a^5bc^2+2a^5bc+6a^5b+4a^5c^3+10a^5c^2+8a^5c+10a^5+20a^4b^4+20a^4b^3c+74a^4b^3+45a^4b^2c+78a^4b^2+20a^4bc^2+10a^4bc+24a^4b+20a^4c^3+54a^4c^2+30a^4c+40a^4+40a^3b^4+40a^3b^3c+156a^3b^3+90a^3b^2c+162a^3b^2+40a^3bc^2+20a^3bc+36a^3b+40a^3c^3+116a^3c^2+40a^3c+60a^3+40a^2b^4+40a^2b^3c+164a^2b^3+90a^2b^2c+168a^2b^2+40a^2bc^2+20a^2bc+20a^2b+40a^2c^3+124a^2c^2+18a^2c+34a^2+20ab^4+20ab^3c+86ab^3+45ab^2c+87ab^2+20abc^2+10abc+2ab+20ac^3+66ac^2+4b^4+4b^3c+18b^3+9b^2c+18b^2+4bc^2+2bc+4c^3+14c^2$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le 4a^5b^4+4a^5b^3c+14a^5b^3+9a^5b^2c+15a^5b^2+4a^5bc^2+2a^5bc+6a^5b+4a^5c^3+10a^5c^2+8a^5c+10a^5+20a^4b^4+20a^4b^3c+74a^4b^3+45a^4b^2c+78a^4b^2+20a^4bc^2+10a^4bc+24a^4b+20a^4c^3+54a^4c^2+30a^4c+40a^4+40a^3b^4+40a^3b^3c+156a^3b^3+90a^3b^2c+162a^3b^2+40a^3bc^2+20a^3bc+36a^3b+40a^3c^3+116a^3c^2+40a^3c+60a^3+40a^2b^4+40a^2b^3c+164a^2b^3+90a^2b^2c+168a^2b^2+40a^2bc^2+20a^2bc+20a^2b+40a^2c^3+124a^2c^2+18a^2c+34a^2+20ab^4+20ab^3c+86ab^3+45ab^2c+87ab^2+20abc^2+10abc+2ab+20ac^3+66ac^2+4b^4+4b^3c+18b^3+9b^2c+18b^2+4bc^2+2bc+4c^3+14c^2 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "\n", + "\\hline\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $a\\to 1+a,b\\to 1/(1+b),c\\to 1+c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Numerator after substitutions: $4a^5b^4+16a^5b^3+24a^5b^2+16a^5b+4a^5+4a^4b^4c+18a^4b^4+16a^4b^3c+76a^4b^3+24a^4b^2c+120a^4b^2+16a^4bc+84a^4b+4a^4c+22a^4+14a^3b^4c+30a^3b^4+56a^3b^3c+132a^3b^3+84a^3b^2c+216a^3b^2+56a^3bc+156a^3b+14a^3c+42a^3+18a^2b^4c+22a^2b^4+72a^2b^3c+100a^2b^3+108a^2b^2c+168a^2b^2+72a^2bc+124a^2b+18a^2c+34a^2+4ab^4c^2+ab^4+16ab^3c^2+8ab^3+24ab^2c^2+9ab^2+16abc^2+2ab+4ac^2+4b^4c^3+10b^4c^2+3b^4c+4b^4+16b^3c^3+44b^3c^2+8b^3c+18b^3+24b^2c^3+72b^2c^2+3b^2c+18b^2+16bc^3+52bc^2-2bc+4c^3+14c^2$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "From weighted AM-GM inequality:" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$2bc \\le b^2+c^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le 4a^5b^4+16a^5b^3+24a^5b^2+16a^5b+4a^5+4a^4b^4c+18a^4b^4+16a^4b^3c+76a^4b^3+24a^4b^2c+120a^4b^2+16a^4bc+84a^4b+4a^4c+22a^4+14a^3b^4c+30a^3b^4+56a^3b^3c+132a^3b^3+84a^3b^2c+216a^3b^2+56a^3bc+156a^3b+14a^3c+42a^3+18a^2b^4c+22a^2b^4+72a^2b^3c+100a^2b^3+108a^2b^2c+168a^2b^2+72a^2bc+124a^2b+18a^2c+34a^2+4ab^4c^2+ab^4+16ab^3c^2+8ab^3+24ab^2c^2+9ab^2+16abc^2+2ab+4ac^2+4b^4c^3+10b^4c^2+3b^4c+4b^4+16b^3c^3+44b^3c^2+8b^3c+18b^3+24b^2c^3+72b^2c^2+3b^2c+17b^2+16bc^3+52bc^2+4c^3+13c^2 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "\n", + "\\hline\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $a\\to 1/(1+a),b\\to 1/(1+b),c\\to 1+c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Numerator after substitutions: $4a^5b^4c^3+6a^5b^4c^2+11a^5b^4c+9a^5b^4+16a^5b^3c^3+28a^5b^3c^2+40a^5b^3c+38a^5b^3+24a^5b^2c^3+48a^5b^2c^2+51a^5b^2c+57a^5b^2+16a^5bc^3+36a^5bc^2+30a^5bc+34a^5b+4a^5c^3+10a^5c^2+8a^5c+10a^5+20a^4b^4c^3+34a^4b^4c^2+45a^4b^4c+40a^4b^4+80a^4b^3c^3+156a^4b^3c^2+160a^4b^3c+170a^4b^3+120a^4b^2c^3+264a^4b^2c^2+195a^4b^2c+246a^4b^2+80a^4bc^3+196a^4bc^2+110a^4bc+136a^4b+20a^4c^3+54a^4c^2+30a^4c+40a^4+40a^3b^4c^3+76a^3b^4c^2+70a^3b^4c+70a^3b^4+160a^3b^3c^3+344a^3b^3c^2+240a^3b^3c+300a^3b^3+240a^3b^2c^3+576a^3b^2c^2+270a^3b^2c+414a^3b^2+160a^3bc^3+424a^3bc^2+140a^3bc+204a^3b+40a^3c^3+116a^3c^2+40a^3c+60a^3+40a^2b^4c^3+84a^2b^4c^2+48a^2b^4c+58a^2b^4+160a^2b^3c^3+376a^2b^3c^2+152a^2b^3c+248a^2b^3+240a^2b^2c^3+624a^2b^2c^2+138a^2b^2c+312a^2b^2+160a^2bc^3+456a^2bc^2+52a^2bc+116a^2b+40a^2c^3+124a^2c^2+18a^2c+34a^2+20ab^4c^3+46ab^4c^2+15ab^4c+19ab^4+80ab^3c^3+204ab^3c^2+40ab^3c+82ab^3+120ab^2c^3+336ab^2c^2+15ab^2c+81ab^2+80abc^3+244abc^2-10abc-2ab+20ac^3+66ac^2+4b^4c^3+10b^4c^2+3b^4c+4b^4+16b^3c^3+44b^3c^2+8b^3c+18b^3+24b^2c^3+72b^2c^2+3b^2c+18b^2+16bc^3+52bc^2-2bc+4c^3+14c^2$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "From weighted AM-GM inequality:" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$2ab \\le a^2+b^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$2bc \\le b^2+c^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$10abc \\le 2a^2+2ab^2c+4ac^2+2b^3$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le 4a^5b^4c^3+6a^5b^4c^2+11a^5b^4c+9a^5b^4+16a^5b^3c^3+28a^5b^3c^2+40a^5b^3c+38a^5b^3+24a^5b^2c^3+48a^5b^2c^2+51a^5b^2c+57a^5b^2+16a^5bc^3+36a^5bc^2+30a^5bc+34a^5b+4a^5c^3+10a^5c^2+8a^5c+10a^5+20a^4b^4c^3+34a^4b^4c^2+45a^4b^4c+40a^4b^4+80a^4b^3c^3+156a^4b^3c^2+160a^4b^3c+170a^4b^3+120a^4b^2c^3+264a^4b^2c^2+195a^4b^2c+246a^4b^2+80a^4bc^3+196a^4bc^2+110a^4bc+136a^4b+20a^4c^3+54a^4c^2+30a^4c+40a^4+40a^3b^4c^3+76a^3b^4c^2+70a^3b^4c+70a^3b^4+160a^3b^3c^3+344a^3b^3c^2+240a^3b^3c+300a^3b^3+240a^3b^2c^3+576a^3b^2c^2+270a^3b^2c+414a^3b^2+160a^3bc^3+424a^3bc^2+140a^3bc+204a^3b+40a^3c^3+116a^3c^2+40a^3c+60a^3+40a^2b^4c^3+84a^2b^4c^2+48a^2b^4c+58a^2b^4+160a^2b^3c^3+376a^2b^3c^2+152a^2b^3c+248a^2b^3+240a^2b^2c^3+624a^2b^2c^2+138a^2b^2c+312a^2b^2+160a^2bc^3+456a^2bc^2+52a^2bc+116a^2b+40a^2c^3+124a^2c^2+18a^2c+31a^2+20ab^4c^3+46ab^4c^2+15ab^4c+19ab^4+80ab^3c^3+204ab^3c^2+40ab^3c+82ab^3+120ab^2c^3+336ab^2c^2+13ab^2c+81ab^2+80abc^3+244abc^2+20ac^3+62ac^2+4b^4c^3+10b^4c^2+3b^4c+4b^4+16b^3c^3+44b^3c^2+8b^3c+16b^3+24b^2c^3+72b^2c^2+3b^2c+16b^2+16bc^3+52bc^2+4c^3+13c^2 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "\n", + "\\hline\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $a\\to 1+a,b\\to 1+b,c\\to 1/(1+c)$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Numerator after substitutions: $4a^5c^3+12a^5c^2+12a^5c+4a^5+4a^4bc^3+12a^4bc^2+12a^4bc+4a^4b+18a^4c^3+58a^4c^2+62a^4c+22a^4+12a^3bc^3+36a^3bc^2+36a^3bc+12a^3b+28a^3c^3+98a^3c^2+112a^3c+42a^3+12a^2bc^3+36a^2bc^2+36a^2bc+12a^2b+16a^2c^3+66a^2c^2+84a^2c+34a^2+4ab^3c^3+12ab^3c^2+12ab^3c+4ab^3+3ab^2c^3+9ab^2c^2+9ab^2c+3ab^2-2abc^3-6abc^2-6abc-2ab+4ac^3+4ac^2+4b^4c^3+12b^4c^2+12b^4c+4b^4+14b^3c^3+46b^3c^2+50b^3c+18b^3+9b^2c^3+36b^2c^2+45b^2c+18b^2+2bc^3-2bc+10c^3+14c^2$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "From weighted AM-GM inequality:" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$2abc^3 \\le a^2bc^3+bc^3$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$2ab \\le a^2+b^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$2bc \\le b^2+c^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$6abc \\le 2a^3b+2b^2c+2c^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$6abc^2 \\le 2ab^2c^3+ab^2+3ac^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le 4a^5c^3+12a^5c^2+12a^5c+4a^5+4a^4bc^3+12a^4bc^2+12a^4bc+4a^4b+18a^4c^3+58a^4c^2+62a^4c+22a^4+12a^3bc^3+36a^3bc^2+36a^3bc+10a^3b+28a^3c^3+98a^3c^2+112a^3c+42a^3+11a^2bc^3+36a^2bc^2+36a^2bc+12a^2b+16a^2c^3+66a^2c^2+84a^2c+33a^2+4ab^3c^3+12ab^3c^2+12ab^3c+4ab^3+ab^2c^3+9ab^2c^2+9ab^2c+2ab^2+4ac^3+ac^2+4b^4c^3+12b^4c^2+12b^4c+4b^4+14b^3c^3+46b^3c^2+50b^3c+18b^3+9b^2c^3+36b^2c^2+43b^2c+16b^2+bc^3+10c^3+11c^2 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "\n", + "\\hline\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $a\\to 1/(1+a),b\\to 1+b,c\\to 1/(1+c)$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Numerator after substitutions: $4a^5b^4c^3+12a^5b^4c^2+12a^5b^4c+4a^5b^4+10a^5b^3c^3+34a^5b^3c^2+38a^5b^3c+14a^5b^3+6a^5b^2c^3+27a^5b^2c^2+36a^5b^2c+15a^5b^2+8a^5bc^3+18a^5bc^2+16a^5bc+6a^5b+8a^5c^3+24a^5c^2+22a^5c+10a^5+20a^4b^4c^3+60a^4b^4c^2+60a^4b^4c+20a^4b^4+54a^4b^3c^3+182a^4b^3c^2+202a^4b^3c+74a^4b^3+33a^4b^2c^3+144a^4b^2c^2+189a^4b^2c+78a^4b^2+34a^4bc^3+72a^4bc^2+62a^4bc+24a^4b+44a^4c^3+114a^4c^2+90a^4c+40a^4+40a^3b^4c^3+120a^3b^4c^2+120a^3b^4c+40a^3b^4+116a^3b^3c^3+388a^3b^3c^2+428a^3b^3c+156a^3b^3+72a^3b^2c^3+306a^3b^2c^2+396a^3b^2c+162a^3b^2+56a^3bc^3+108a^3bc^2+88a^3bc+36a^3b+96a^3c^3+216a^3c^2+140a^3c+60a^3+40a^2b^4c^3+120a^2b^4c^2+120a^2b^4c+40a^2b^4+124a^2b^3c^3+412a^2b^3c^2+452a^2b^3c+164a^2b^3+78a^2b^2c^3+324a^2b^2c^2+414a^2b^2c+168a^2b^2+40a^2bc^3+60a^2bc^2+40a^2bc+20a^2b+100a^2c^3+190a^2c^2+84a^2c+34a^2+20ab^4c^3+60ab^4c^2+60ab^4c+20ab^4+66ab^3c^3+218ab^3c^2+238ab^3c+86ab^3+42ab^2c^3+171ab^2c^2+216ab^2c+87ab^2+12abc^3+6abc^2-4abc+2ab+46ac^3+66ac^2+4b^4c^3+12b^4c^2+12b^4c+4b^4+14b^3c^3+46b^3c^2+50b^3c+18b^3+9b^2c^3+36b^2c^2+45b^2c+18b^2+2bc^3-2bc+10c^3+14c^2$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "From weighted AM-GM inequality:" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$4abc \\le a^2c^2+2ab^2+c^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$2bc \\le b^2+c^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le 4a^5b^4c^3+12a^5b^4c^2+12a^5b^4c+4a^5b^4+10a^5b^3c^3+34a^5b^3c^2+38a^5b^3c+14a^5b^3+6a^5b^2c^3+27a^5b^2c^2+36a^5b^2c+15a^5b^2+8a^5bc^3+18a^5bc^2+16a^5bc+6a^5b+8a^5c^3+24a^5c^2+22a^5c+10a^5+20a^4b^4c^3+60a^4b^4c^2+60a^4b^4c+20a^4b^4+54a^4b^3c^3+182a^4b^3c^2+202a^4b^3c+74a^4b^3+33a^4b^2c^3+144a^4b^2c^2+189a^4b^2c+78a^4b^2+34a^4bc^3+72a^4bc^2+62a^4bc+24a^4b+44a^4c^3+114a^4c^2+90a^4c+40a^4+40a^3b^4c^3+120a^3b^4c^2+120a^3b^4c+40a^3b^4+116a^3b^3c^3+388a^3b^3c^2+428a^3b^3c+156a^3b^3+72a^3b^2c^3+306a^3b^2c^2+396a^3b^2c+162a^3b^2+56a^3bc^3+108a^3bc^2+88a^3bc+36a^3b+96a^3c^3+216a^3c^2+140a^3c+60a^3+40a^2b^4c^3+120a^2b^4c^2+120a^2b^4c+40a^2b^4+124a^2b^3c^3+412a^2b^3c^2+452a^2b^3c+164a^2b^3+78a^2b^2c^3+324a^2b^2c^2+414a^2b^2c+168a^2b^2+40a^2bc^3+60a^2bc^2+40a^2bc+20a^2b+100a^2c^3+189a^2c^2+84a^2c+34a^2+20ab^4c^3+60ab^4c^2+60ab^4c+20ab^4+66ab^3c^3+218ab^3c^2+238ab^3c+86ab^3+42ab^2c^3+171ab^2c^2+216ab^2c+85ab^2+12abc^3+6abc^2+2ab+46ac^3+66ac^2+4b^4c^3+12b^4c^2+12b^4c+4b^4+14b^3c^3+46b^3c^2+50b^3c+18b^3+9b^2c^3+36b^2c^2+45b^2c+17b^2+2bc^3+10c^3+12c^2 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "\n", + "\\hline\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $a\\to 1+a,b\\to 1/(1+b),c\\to 1/(1+c)$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Numerator after substitutions: $4a^5b^4c^3+12a^5b^4c^2+12a^5b^4c+4a^5b^4+16a^5b^3c^3+48a^5b^3c^2+48a^5b^3c+16a^5b^3+24a^5b^2c^3+72a^5b^2c^2+72a^5b^2c+24a^5b^2+16a^5bc^3+48a^5bc^2+48a^5bc+16a^5b+4a^5c^3+12a^5c^2+12a^5c+4a^5+14a^4b^4c^3+46a^4b^4c^2+50a^4b^4c+18a^4b^4+60a^4b^3c^3+196a^4b^3c^2+212a^4b^3c+76a^4b^3+96a^4b^2c^3+312a^4b^2c^2+336a^4b^2c+120a^4b^2+68a^4bc^3+220a^4bc^2+236a^4bc+84a^4b+18a^4c^3+58a^4c^2+62a^4c+22a^4+16a^3b^4c^3+62a^3b^4c^2+76a^3b^4c+30a^3b^4+76a^3b^3c^3+284a^3b^3c^2+340a^3b^3c+132a^3b^3+132a^3b^2c^3+480a^3b^2c^2+564a^3b^2c+216a^3b^2+100a^3bc^3+356a^3bc^2+412a^3bc+156a^3b+28a^3c^3+98a^3c^2+112a^3c+42a^3+4a^2b^4c^3+30a^2b^4c^2+48a^2b^4c+22a^2b^4+28a^2b^3c^3+156a^2b^3c^2+228a^2b^3c+100a^2b^3+60a^2b^2c^3+288a^2b^2c^2+396a^2b^2c+168a^2b^2+52a^2bc^3+228a^2bc^2+300a^2bc+124a^2b+16a^2c^3+66a^2c^2+84a^2c+34a^2+5ab^4c^3+7ab^4c^2+3ab^4c+ab^4+24ab^3c^3+40ab^3c^2+24ab^3c+8ab^3+33ab^2c^3+51ab^2c^2+27ab^2c+9ab^2+18abc^3+22abc^2+6abc+2ab+4ac^3+4ac^2+7b^4c^3+16b^4c^2+9b^4c+4b^4+38b^3c^3+82b^3c^2+46b^3c+18b^3+63b^2c^3+120b^2c^2+51b^2c+18b^2+38bc^3+56bc^2+2bc+10c^3+14c^2$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le 4a^5b^4c^3+12a^5b^4c^2+12a^5b^4c+4a^5b^4+16a^5b^3c^3+48a^5b^3c^2+48a^5b^3c+16a^5b^3+24a^5b^2c^3+72a^5b^2c^2+72a^5b^2c+24a^5b^2+16a^5bc^3+48a^5bc^2+48a^5bc+16a^5b+4a^5c^3+12a^5c^2+12a^5c+4a^5+14a^4b^4c^3+46a^4b^4c^2+50a^4b^4c+18a^4b^4+60a^4b^3c^3+196a^4b^3c^2+212a^4b^3c+76a^4b^3+96a^4b^2c^3+312a^4b^2c^2+336a^4b^2c+120a^4b^2+68a^4bc^3+220a^4bc^2+236a^4bc+84a^4b+18a^4c^3+58a^4c^2+62a^4c+22a^4+16a^3b^4c^3+62a^3b^4c^2+76a^3b^4c+30a^3b^4+76a^3b^3c^3+284a^3b^3c^2+340a^3b^3c+132a^3b^3+132a^3b^2c^3+480a^3b^2c^2+564a^3b^2c+216a^3b^2+100a^3bc^3+356a^3bc^2+412a^3bc+156a^3b+28a^3c^3+98a^3c^2+112a^3c+42a^3+4a^2b^4c^3+30a^2b^4c^2+48a^2b^4c+22a^2b^4+28a^2b^3c^3+156a^2b^3c^2+228a^2b^3c+100a^2b^3+60a^2b^2c^3+288a^2b^2c^2+396a^2b^2c+168a^2b^2+52a^2bc^3+228a^2bc^2+300a^2bc+124a^2b+16a^2c^3+66a^2c^2+84a^2c+34a^2+5ab^4c^3+7ab^4c^2+3ab^4c+ab^4+24ab^3c^3+40ab^3c^2+24ab^3c+8ab^3+33ab^2c^3+51ab^2c^2+27ab^2c+9ab^2+18abc^3+22abc^2+6abc+2ab+4ac^3+4ac^2+7b^4c^3+16b^4c^2+9b^4c+4b^4+38b^3c^3+82b^3c^2+46b^3c+18b^3+63b^2c^3+120b^2c^2+51b^2c+18b^2+38bc^3+56bc^2+2bc+10c^3+14c^2 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "\n", + "\\hline\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $a\\to 1/(1+a),b\\to 1/(1+b),c\\to 1/(1+c)$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Numerator after substitutions: $11a^5b^4c^2+16a^5b^4c+9a^5b^4+10a^5b^3c^3+62a^5b^3c^2+74a^5b^3c+38a^5b^3+30a^5b^2c^3+117a^5b^2c^2+120a^5b^2c+57a^5b^2+24a^5bc^3+78a^5bc^2+72a^5bc+34a^5b+8a^5c^3+24a^5c^2+22a^5c+10a^5+9a^4b^4c^3+64a^4b^4c^2+75a^4b^4c+40a^4b^4+86a^4b^3c^3+346a^4b^3c^2+350a^4b^3c+170a^4b^3+195a^4b^2c^3+612a^4b^2c^2+543a^4b^2c+246a^4b^2+142a^4bc^3+384a^4bc^2+298a^4bc+136a^4b+44a^4c^3+114a^4c^2+90a^4c+40a^4+36a^3b^4c^3+146a^3b^4c^2+140a^3b^4c+70a^3b^4+244a^3b^3c^3+764a^3b^3c^2+660a^3b^3c+300a^3b^3+480a^3b^2c^3+1278a^3b^2c^2+972a^3b^2c+414a^3b^2+328a^3bc^3+756a^3bc^2+472a^3bc+204a^3b+96a^3c^3+216a^3c^2+140a^3c+60a^3+54a^2b^4c^3+162a^2b^4c^2+126a^2b^4c+58a^2b^4+312a^2b^3c^3+816a^2b^3c^2+592a^2b^3c+248a^2b^3+558a^2b^2c^3+1284a^2b^2c^2+798a^2b^2c+312a^2b^2+360a^2bc^3+700a^2bc^2+296a^2bc+116a^2b+100a^2c^3+190a^2c^2+84a^2c+34a^2+30ab^4c^3+73ab^4c^2+42ab^4c+19ab^4+166ab^3c^3+370ab^3c^2+206ab^3c+82ab^3+282ab^2c^3+549ab^2c^2+228ab^2c+81ab^2+172abc^3+258abc^2+4abc-2ab+46ac^3+66ac^2+7b^4c^3+16b^4c^2+9b^4c+4b^4+38b^3c^3+82b^3c^2+46b^3c+18b^3+63b^2c^3+120b^2c^2+51b^2c+18b^2+38bc^3+56bc^2+2bc+10c^3+14c^2$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "From weighted AM-GM inequality:" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$2ab \\le a^2+b^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le 11a^5b^4c^2+16a^5b^4c+9a^5b^4+10a^5b^3c^3+62a^5b^3c^2+74a^5b^3c+38a^5b^3+30a^5b^2c^3+117a^5b^2c^2+120a^5b^2c+57a^5b^2+24a^5bc^3+78a^5bc^2+72a^5bc+34a^5b+8a^5c^3+24a^5c^2+22a^5c+10a^5+9a^4b^4c^3+64a^4b^4c^2+75a^4b^4c+40a^4b^4+86a^4b^3c^3+346a^4b^3c^2+350a^4b^3c+170a^4b^3+195a^4b^2c^3+612a^4b^2c^2+543a^4b^2c+246a^4b^2+142a^4bc^3+384a^4bc^2+298a^4bc+136a^4b+44a^4c^3+114a^4c^2+90a^4c+40a^4+36a^3b^4c^3+146a^3b^4c^2+140a^3b^4c+70a^3b^4+244a^3b^3c^3+764a^3b^3c^2+660a^3b^3c+300a^3b^3+480a^3b^2c^3+1278a^3b^2c^2+972a^3b^2c+414a^3b^2+328a^3bc^3+756a^3bc^2+472a^3bc+204a^3b+96a^3c^3+216a^3c^2+140a^3c+60a^3+54a^2b^4c^3+162a^2b^4c^2+126a^2b^4c+58a^2b^4+312a^2b^3c^3+816a^2b^3c^2+592a^2b^3c+248a^2b^3+558a^2b^2c^3+1284a^2b^2c^2+798a^2b^2c+312a^2b^2+360a^2bc^3+700a^2bc^2+296a^2bc+116a^2b+100a^2c^3+190a^2c^2+84a^2c+33a^2+30ab^4c^3+73ab^4c^2+42ab^4c+19ab^4+166ab^3c^3+370ab^3c^2+206ab^3c+82ab^3+282ab^2c^3+549ab^2c^2+228ab^2c+81ab^2+172abc^3+258abc^2+4abc+46ac^3+66ac^2+7b^4c^3+16b^4c^2+9b^4c+4b^4+38b^3c^3+82b^3c^2+46b^3c+18b^3+63b^2c^3+120b^2c^2+51b^2c+17b^2+38bc^3+56bc^2+2bc+10c^3+14c^2 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" } ], "source": [ @@ -965,25 +3145,116 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 21, "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "numerator: $$21f(-1,4,3)-21f(1,2,3)-21f(2,3,1)+21f(3,-1,4)-21f(3,1,2)+21f(4,3,-1)$$\n", - "denominator: $$1$$\n", - "status: 0\n", - "From Jensen inequality:\n", - "$$21f(1, 2, 3) \\le 11f(-1, 4, 3)+8f(3, -1, 4)+2f(4, 3, -1)$$\n", - "$$21f(2, 3, 1) \\le 8f(-1, 4, 3)+2f(3, -1, 4)+11f(4, 3, -1)$$\n", - "$$21f(3, 1, 2) \\le 2f(-1, 4, 3)+11f(3, -1, 4)+8f(4, 3, -1)$$\n", - "\n", - "$$ 0 \\le \n", - "0 $$\n", - "The sum of all inequalities gives us a proof of the inequality.\n" - ] + "data": { + "text/latex": [ + "numerator: $21f(-1,4,3)-21f(1,2,3)-21f(2,3,1)+21f(3,-1,4)-21f(3,1,2)+21f(4,3,-1)$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $1$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "From Jensen inequality:" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$21f(1, 2, 3) \\le 11f(-1, 4, 3)+8f(3, -1, 4)+2f(4, 3, -1)$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$21f(2, 3, 1) \\le 8f(-1, 4, 3)+2f(3, -1, 4)+11f(4, 3, -1)$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$21f(3, 1, 2) \\le 2f(-1, 4, 3)+11f(3, -1, 4)+8f(4, 3, -1)$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le 0 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" } ], "source": [ @@ -1000,9 +3271,9 @@ ], "metadata": { "kernelspec": { - "display_name": "SageMath 9.0", - "language": "sage", - "name": "sagemath" + "display_name": "Python 3", + "language": "python", + "name": "python3" }, "language_info": { "codemirror_mode": { diff --git a/.ipynb_checkpoints/sandbox-checkpoint.ipynb b/.ipynb_checkpoints/sandbox-checkpoint.ipynb index 2fd6442..8b7f55a 100644 --- a/.ipynb_checkpoints/sandbox-checkpoint.ipynb +++ b/.ipynb_checkpoints/sandbox-checkpoint.ipynb @@ -1,6 +1,7074 @@ { - "cells": [], - "metadata": {}, + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "def extrema(fr):\n", + " t=[]\n", + " for x in fr.free_symbols:\n", + " t+=[fr.diff(x)]\n", + " print(t)\n", + " return solve(t)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "from shiroindev import *\n", + "from sympy import *\n", + "from itertools import permutations, combinations\n", + "sVars.seed=1\n", + "from IPython.display import Latex\n", + "sVars.display=lambda x:display(Latex(x))" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "numerator: $12a^3-18a^2b+6a^2c+6ab^2-18ac^2+12b^3-18b^2c+6bc^2+12c^3$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $4a^2b+2a^2c+2ab^2+9abc+4ac^2+4b^2c+2bc^2$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "From weighted AM-GM inequality:" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$18a^2b \\le 10a^3+6ab^2+2b^3$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$18ac^2 \\le 2a^3+6a^2c+10c^3$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$18b^2c \\le 10b^3+6bc^2+2c^3$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le 0 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "formula=cyclize('(a+b)/(2*b+c)')-2\n", + "prove(formula*6)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "Substitute $a\\to s-s/(a+1)$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $b\\to s-s/(b+1)$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $c\\to s-s/(c+1)$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "numerator: $abcs^2+s^2$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $abc+ab+ac+a+bc+b+c+1$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le abcs^2+s^2 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "prove(makesubs(Sm('-a(s-b)-b(s-c)-c(s-a)+ s^2'),'[0,s],[0,s],[0,s]'))" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "def nonneg(formula):\n", + " formula=expand(formula)\n", + " for addend in formula.as_ordered_terms():\n", + " coef,facts=addend.as_coeff_mul()\n", + " if coef<0:\n", + " return False\n", + " return True" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "def symprove(formula,n):\n", + " formula=S(formula)\n", + " if n==0:\n", + " return\n", + " ls=list(formula.free_symbols)\n", + " for i in range(len(ls)):\n", + " a=ls[i]\n", + " for j in range(i+1,len(ls)):\n", + " b=ls[j]\n", + " if expand(formula-formula.subs({a:b, b:a}, simultaneous=True))==S(0):\n", + " formula=makesubs(formula,[[b,S('oo')]],variables=[a,b])\n", + " sVars.display('$$'+latex(formula)+'$$')\n", + " symprove(formula,n-1)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "Substitute $y\\to x+y$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$y^{2}$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "symprove('x^2-2*x*y+y^2',4)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "def provesym(formula,n):\n", + " formula=S(formula)\n", + " if n==0:\n", + " return\n", + " fs=list(formula.free_symbols)\n", + " print \n", + " for i in range(2,len(fs)+1):\n", + " for fs2 in combinations(fs,i):\n", + " for fsp in permutations(fs2[1:]):\n", + " if expand(formula-formula.subs(zip((fs2[0],)+fsp,fsp+(fs2[0],)), simultaneous=True))==S(0):\n", + " newformula=makesubs(formula,[[fs2[0],oo]]*(len(fsp)),variables=fsp)\n", + " sVars.display(str(n)+' $$'+latex(newformula)+'$$')\n", + " provesym(newformula,n-1)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "Substitute $x\\to x+z$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "4 $$x^{2} \\left(x + z\\right)^{t} - x y y^{t} + x y z^{t} - x y \\left(x + z\\right)^{t} + x y^{t} z - x z z^{t} + x z \\left(x + z\\right)^{t} + y^{2} y^{t} - 2 y y^{t} z + y^{t} z^{2}$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $y\\to y+z$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "4 $$x^{2} x^{t} - x x^{t} y - 2 x x^{t} z + x y z^{t} - x y \\left(y + z\\right)^{t} + x^{t} y z + x^{t} z^{2} + y^{2} \\left(y + z\\right)^{t} - y z z^{t} + y z \\left(y + z\\right)^{t}$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $y\\to x+y$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "4 $$x^{2} z^{t} - x x^{t} y + x y z^{t} + x y \\left(x + y\\right)^{t} - 2 x z z^{t} + x^{t} y z + y^{2} \\left(x + y\\right)^{t} - y z z^{t} - y z \\left(x + y\\right)^{t} + z^{2} z^{t}$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $x\\to x+z$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $y\\to y+z$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "4 $$x^{2} \\left(x + z\\right)^{t} + x y z^{t} - x y \\left(x + z\\right)^{t} - x y \\left(y + z\\right)^{t} + y^{2} \\left(y + z\\right)^{t}$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $y\\to x+y$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "3 $$x^{2} z^{t} + x y z^{t} - x y \\left(x + z\\right)^{t} + x y \\left(x + y + z\\right)^{t} + y^{2} \\left(x + y + z\\right)^{t}$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $y\\to y+z$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $x\\to x+z$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "4 $$x^{2} \\left(x + z\\right)^{t} + x y z^{t} - x y \\left(x + z\\right)^{t} - x y \\left(y + z\\right)^{t} + y^{2} \\left(y + z\\right)^{t}$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $y\\to x+y$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "3 $$x^{2} z^{t} + x y z^{t} - x y \\left(x + z\\right)^{t} + x y \\left(x + y + z\\right)^{t} + y^{2} \\left(x + y + z\\right)^{t}$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "provesym(Sm('x^t(x-y)(x-z) + y^t (y-z)(y-x) + z^t (z-x)(z-y)'),4)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "Substitute $x\\to x+y$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\displaystyle x^{2} \\left(x + y\\right)^{t} - x y y^{t} + x y z^{t} + x y \\left(x + y\\right)^{t} + x y^{t} z - x z z^{t} - x z \\left(x + y\\right)^{t} + y^{2} z^{t} - 2 y z z^{t} + z^{2} z^{t}$" + ], + "text/plain": [ + "x**2*(x + y)**t - x*y*y**t + x*y*z**t + x*y*(x + y)**t + x*y**t*z - x*z*z**t - x*z*(x + y)**t + y**2*z**t - 2*y*z*z**t + z**2*z**t" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "makesubs(Sm('x^t(x-y)(x-z) + y^t (y-z)(y-x) + z^t (z-x)(z-y)'),'[y,oo]',variables='x')" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "Substitute $x\\to x+y$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\displaystyle x^{2} \\left(x + y\\right)^{t} - x y y^{t} + x y z^{t} + x y \\left(x + y\\right)^{t} + x y^{t} z - x z z^{t} - x z \\left(x + y\\right)^{t} + y^{2} z^{t} - 2 y z z^{t} + z^{2} z^{t}$" + ], + "text/plain": [ + "x**2*(x + y)**t - x*y*y**t + x*y*z**t + x*y*(x + y)**t + x*y**t*z - x*z*z**t - x*z*(x + y)**t + y**2*z**t - 2*y*z*z**t + z**2*z**t" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "makesubs(Sm('x^t*(x-y)(x-z) + y^t*(y-z)(y-x) + z^t*(z-x)(z-y)'),'[y,oo]',variables='x')" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "Substitute $x\\to x+z$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "4 $$x^{2} \\left(x + z\\right)^{t} - x y y^{t} + x y z^{t} - x y \\left(x + z\\right)^{t} + x y^{t} z - x z z^{t} + x z \\left(x + z\\right)^{t} + y^{2} y^{t} - 2 y y^{t} z + y^{t} z^{2}$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $y\\to y+z$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "4 $$x^{2} x^{t} - x x^{t} y - 2 x x^{t} z + x y z^{t} - x y \\left(y + z\\right)^{t} + x^{t} y z + x^{t} z^{2} + y^{2} \\left(y + z\\right)^{t} - y z z^{t} + y z \\left(y + z\\right)^{t}$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $y\\to x+y$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "4 $$x^{2} z^{t} - x x^{t} y + x y z^{t} + x y \\left(x + y\\right)^{t} - 2 x z z^{t} + x^{t} y z + y^{2} \\left(x + y\\right)^{t} - y z z^{t} - y z \\left(x + y\\right)^{t} + z^{2} z^{t}$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $x\\to x+z$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $y\\to y+z$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "4 $$x^{2} \\left(x + z\\right)^{t} + x y z^{t} - x y \\left(x + z\\right)^{t} - x y \\left(y + z\\right)^{t} + y^{2} \\left(y + z\\right)^{t}$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $y\\to x+y$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "3 $$x^{2} z^{t} + x y z^{t} - x y \\left(x + z\\right)^{t} + x y \\left(x + y + z\\right)^{t} + y^{2} \\left(x + y + z\\right)^{t}$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $y\\to y+z$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $x\\to x+z$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "4 $$x^{2} \\left(x + z\\right)^{t} + x y z^{t} - x y \\left(x + z\\right)^{t} - x y \\left(y + z\\right)^{t} + y^{2} \\left(y + z\\right)^{t}$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $y\\to x+y$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "3 $$x^{2} z^{t} + x y z^{t} - x y \\left(x + z\\right)^{t} + x y \\left(x + y + z\\right)^{t} + y^{2} \\left(x + y + z\\right)^{t}$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "provesym(Sm('x^t(x-y)(x-z) + y^t (y-z)(y-x) + z^t (z-x)(z-y)'),4)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle x^{t} \\left(x - y\\right) \\left(x - z\\right) + y^{t} \\left(- x + y\\right) \\left(y - z\\right) + z^{t} \\left(- x + z\\right) \\left(- y + z\\right)$" + ], + "text/plain": [ + "x**t*(x - y)*(x - z) + y**t*(-x + y)*(y - z) + z**t*(-x + z)*(-y + z)" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Sm('x^t(x-y)(x-z) + y^t (y-z)(y-x) + z^t (z-x)(z-y)')" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle 3 x + y + 2 z$" + ], + "text/plain": [ + "3*x + y + 2*z" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "S('x+2*y+3*z').subs(zip(S('[x,y,z]'),S('[y,z,x]')),simultaneous=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[x, y, z]" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "S('[x,y,z]')" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle - t x y^{2} + t x z^{2} - x^{2} \\left(x + y\\right)^{t} + x^{2} \\left(x + z\\right)^{t} + x y y^{t} - x y \\left(x + y\\right)^{t} - x y \\left(x + z\\right)^{t} - x z z^{t} + x z \\left(x + y\\right)^{t} + x z \\left(x + z\\right)^{t} + y^{2} y^{t} - y^{2} z^{t} - 2 y y^{t} z + 2 y z z^{t} + y^{t} z^{2} - z^{2} z^{t}$" + ], + "text/plain": [ + "-t*x*y**2 + t*x*z**2 - x**2*(x + y)**t + x**2*(x + z)**t + x*y*y**t - x*y*(x + y)**t - x*y*(x + z)**t - x*z*z**t + x*z*(x + y)**t + x*z*(x + z)**t + y**2*y**t - y**2*z**t - 2*y*y**t*z + 2*y*z*z**t + y**t*z**2 - z**2*z**t" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "formula=Sm('x^2(x+y)^t-xyy^t+xyz^t+xy(x+y)^t+xy^tz-xzzt-xz(x+y)^t+y^2z^t-2yzz^t+z^2z^t')\n", + "expand(formula.subs(S('[y,z],[z,y]'),simultaneous=True)-formula)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [], + "source": [ + "def point(formula):\n", + " fs=list(formula.free_symbols)\n", + " il=1\n", + " for s in fs[1:]:\n", + " il*=s\n", + " fr=formula.subs(fs[0],1/il)\n", + " print(fr)\n", + " return(extrema(fr))\n", + "#point(Sm('(a^2+b^2+c^2+d^2)-a*(b+c+d)'))" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "Substitute $a\\to 11a/8$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $b\\to 4b/5$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $c\\to 4c/5$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $d\\to 4d/5$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "numerator: $3025a^2-1760ab-1760ac-1760ad+1024b^2+1024c^2+1024d^2$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $1600$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "From weighted AM-GM inequality:" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$1760ab \\le 880a^2+880b^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$1760ac \\le 880a^2+880c^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$1760ad \\le 880a^2+880d^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le 385a^2+144b^2+144c^2+144d^2 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "prove(Sm('(a^2+b^2+c^2+d^2)-a*(b+c+d)'),'11/8,4/5,4/5,4/5')" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.06133333333333324" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "216/125-5/3" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle - \\frac{2 \\sqrt{2} \\left(a - b\\right)}{c} + \\frac{\\left(a - b\\right)^{2}}{c^{2}} - \\frac{2 \\sqrt{2} \\left(- a + c\\right)}{b} + \\frac{\\left(- a + c\\right)^{2}}{b^{2}} - \\frac{2 \\sqrt{2} \\left(b - c\\right)}{a} + \\frac{\\left(b - c\\right)^{2}}{a^{2}}$" + ], + "text/plain": [ + "-2*sqrt(2)*(a - b)/c + (a - b)**2/c**2 - 2*sqrt(2)*(-a + c)/b + (-a + c)**2/b**2 - 2*sqrt(2)*(b - c)/a + (b - c)**2/a**2" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $a\\to a+b$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $b\\to b+c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Optimization terminated successfully.\n", + " Current function value: 0.000000\n", + " Iterations: 51\n", + " Function evaluations: 97\n", + "[1.17092486 1.170961 1.17093843]\n" + ] + }, + { + "data": { + "text/latex": [ + "$\\displaystyle \\frac{a^{4} b^{2} + 2 a^{4} b c + 2 a^{4} c^{2} + 2 a^{3} b^{3} - 2 \\sqrt{2} a^{3} b^{2} c + 6 a^{3} b^{2} c - 2 \\sqrt{2} a^{3} b c^{2} + 10 a^{3} b c^{2} + 4 a^{3} c^{3} + a^{2} b^{4} - 4 \\sqrt{2} a^{2} b^{3} c + 4 a^{2} b^{3} c - 6 \\sqrt{2} a^{2} b^{2} c^{2} + 12 a^{2} b^{2} c^{2} - 2 \\sqrt{2} a^{2} b c^{3} + 10 a^{2} b c^{3} + 2 a^{2} c^{4} - 2 \\sqrt{2} a b^{4} c - 4 \\sqrt{2} a b^{3} c^{2} + 4 a b^{3} c^{2} - 2 \\sqrt{2} a b^{2} c^{3} + 6 a b^{2} c^{3} + 2 a b c^{4} + 2 b^{4} c^{2} + 4 b^{3} c^{3} + 2 b^{2} c^{4}}{c^{2} \\left(a^{2} b^{2} + 2 a^{2} b c + a^{2} c^{2} + 2 a b^{3} + 6 a b^{2} c + 6 a b c^{2} + 2 a c^{3} + b^{4} + 4 b^{3} c + 6 b^{2} c^{2} + 4 b c^{3} + c^{4}\\right)}$" + ], + "text/plain": [ + "(a**4*b**2 + 2*a**4*b*c + 2*a**4*c**2 + 2*a**3*b**3 - 2*sqrt(2)*a**3*b**2*c + 6*a**3*b**2*c - 2*sqrt(2)*a**3*b*c**2 + 10*a**3*b*c**2 + 4*a**3*c**3 + a**2*b**4 - 4*sqrt(2)*a**2*b**3*c + 4*a**2*b**3*c - 6*sqrt(2)*a**2*b**2*c**2 + 12*a**2*b**2*c**2 - 2*sqrt(2)*a**2*b*c**3 + 10*a**2*b*c**3 + 2*a**2*c**4 - 2*sqrt(2)*a*b**4*c - 4*sqrt(2)*a*b**3*c**2 + 4*a*b**3*c**2 - 2*sqrt(2)*a*b**2*c**3 + 6*a*b**2*c**3 + 2*a*b*c**4 + 2*b**4*c**2 + 4*b**3*c**3 + 2*b**2*c**4)/(c**2*(a**2*b**2 + 2*a**2*b*c + a**2*c**2 + 2*a*b**3 + 6*a*b**2*c + 6*a*b*c**2 + 2*a*c**3 + b**4 + 4*b**3*c + 6*b**2*c**2 + 4*b*c**3 + c**4))" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "formula=cyclize(Sm('((a-b)/c)^2-8**(1/2)*(a-b)/c'))\n", + "display(formula)\n", + "from scipy.optimize import fmin\n", + "import numpy as np\n", + "def f(x):\n", + " num,den=fraction(cancel(formula))\n", + " fs=sorted(newformula.free_symbols,key=str)\n", + " return num.subs(zip(fs,x))\n", + "newformula=(makesubs(formula,'[b,oo],[c,oo]'))\n", + "print(fmin(f,np.array([2,1,1])))\n", + "display(simplify(newformula))\n", + "#prove(newformula)\n", + "#prove(makesubs(formula,'[b,oo],[a,oo]',variables='c,b,a'))" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Warning: Maximum number of function evaluations has been exceeded.\n" + ] + }, + { + "data": { + "text/plain": [ + "array([-1.62831265e+41, -1.93382892e+41])" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def g(x):\n", + " return x[0]+x[1]\n", + "fmin(g,[0,0])" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\frac{a^{2} + b^{2} + c^{2} + d^{2}}{a \\left(b + c + d\\right)}$" + ], + "text/plain": [ + "(a**2 + b**2 + c**2 + d**2)/(a*(b + c + d))" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Optimization terminated successfully.\n", + " Current function value: 1.154701\n", + " Iterations: 80\n", + " Function evaluations: 144\n" + ] + }, + { + "data": { + "text/latex": [ + "$\\displaystyle \\left( \\frac{11}{8}, \\ \\frac{4}{5}, \\ \\frac{4}{5}, \\ \\frac{4}{5}\\right)$" + ], + "text/plain": [ + "(11/8, 4/5, 4/5, 4/5)" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "formula=Sm('(a^2+b^2+c^2+d^2)/(a*(b+c+d))')\n", + "display(formula)\n", + "def f(x):\n", + " fs=sorted(formula.free_symbols,key=str)\n", + " return formula.subs(zip(fs,x))\n", + "nsimplify(tuple(fmin(f,(1,1,1,1))),tolerance=0.1,rational=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\frac{55}{32}$" + ], + "text/plain": [ + "55/32" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "_[0]/_[1]" + ] + }, + { + "cell_type": "code", + "execution_count": 107, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "Substitute $a\\to a+b$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $b\\to b+c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\displaystyle a^{8} b^{4} + 2 a^{8} b^{2} c^{2} + 2 a^{8} c^{4} + 2 a^{6} b^{6} - 2 \\sqrt{2} a^{6} b^{4} c^{2} + 6 a^{6} b^{4} c^{2} - 2 \\sqrt{2} a^{6} b^{2} c^{4} + 10 a^{6} b^{2} c^{4} + 4 a^{6} c^{6} + a^{4} b^{8} - 4 \\sqrt{2} a^{4} b^{6} c^{2} + 4 a^{4} b^{6} c^{2} - 6 \\sqrt{2} a^{4} b^{4} c^{4} + 12 a^{4} b^{4} c^{4} - 2 \\sqrt{2} a^{4} b^{2} c^{6} + 10 a^{4} b^{2} c^{6} + 2 a^{4} c^{8} - 2 \\sqrt{2} a^{2} b^{8} c^{2} - 4 \\sqrt{2} a^{2} b^{6} c^{4} + 4 a^{2} b^{6} c^{4} - 2 \\sqrt{2} a^{2} b^{4} c^{6} + 6 a^{2} b^{4} c^{6} + 2 a^{2} b^{2} c^{8} + 2 b^{8} c^{4} + 4 b^{6} c^{6} + 2 b^{4} c^{8}$" + ], + "text/plain": [ + "a**8*b**4 + 2*a**8*b**2*c**2 + 2*a**8*c**4 + 2*a**6*b**6 - 2*sqrt(2)*a**6*b**4*c**2 + 6*a**6*b**4*c**2 - 2*sqrt(2)*a**6*b**2*c**4 + 10*a**6*b**2*c**4 + 4*a**6*c**6 + a**4*b**8 - 4*sqrt(2)*a**4*b**6*c**2 + 4*a**4*b**6*c**2 - 6*sqrt(2)*a**4*b**4*c**4 + 12*a**4*b**4*c**4 - 2*sqrt(2)*a**4*b**2*c**6 + 10*a**4*b**2*c**6 + 2*a**4*c**8 - 2*sqrt(2)*a**2*b**8*c**2 - 4*sqrt(2)*a**2*b**6*c**4 + 4*a**2*b**6*c**4 - 2*sqrt(2)*a**2*b**4*c**6 + 6*a**2*b**4*c**6 + 2*a**2*b**2*c**8 + 2*b**8*c**4 + 4*b**6*c**6 + 2*b**4*c**8" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{a: 2, b: 2, c: 2}\n" + ] + }, + { + "data": { + "text/latex": [ + "$\\displaystyle \\frac{19 \\sqrt{2}}{12}$" + ], + "text/plain": [ + "19*sqrt(2)/12" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "x\n", + "Optimization terminated successfully.\n", + " Current function value: 1.000000\n", + " Iterations: 147\n", + " Function evaluations: 267\n" + ] + }, + { + "data": { + "text/plain": [ + "(4.4110810020775736e-12, 28.52020821072961, 3.1191098416324057e-12)" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\displaystyle \\left( 0, \\ \\frac{57}{2}, \\ 0\\right)$" + ], + "text/plain": [ + "(0, 57/2, 0)" + ] + }, + "execution_count": 107, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "formula=cyclize(Sm('((a-b)/c)^2-8**(1/2)*(a-b)/c'))\n", + "formula=(makesubs(formula,'[b,oo],[c,oo]'))\n", + "num,den=fraction(cancel(formula))\n", + "num=num.subs(zip(fs,list(map(lambda x:x**2,fs))))\n", + "display(num)\n", + "numm=0\n", + "nump=0\n", + "for addend in num.as_ordered_terms():\n", + " coef,facts=addend.as_coeff_mul()\n", + " if coef<0:\n", + " numm-=addend\n", + " else:\n", + " nump+=addend\n", + "num=nump/numm\n", + "fs=sorted(num.free_symbols,key=str)\n", + "numm,nump=Poly(numm),Poly(nump)\n", + "def f(x):\n", + " return nump.eval(dict(zip(fs,x)))/numm.eval(dict(zip(fs,x))) \n", + "print(dict(zip(fs,(2,2,2))))\n", + "display(f((2,2,2)))\n", + "print('x')\n", + "tup=tuple(fmin(f,(2,2,2)))\n", + "display(tuple([x*x for x in tup]))\n", + "nsimplify(tuple([x*x for x in tup]),tolerance=0.1,rational=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\left( 2, \\ \\frac{31}{3}, \\ \\frac{7}{4}\\right)$" + ], + "text/plain": [ + "(2, 31/3, 7/4)" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "nsimplify((2.1002573656763053, 10.340431462974655, 1.7661001788212371),tolerance=0.3,rational=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1.414211498165453" + ] + }, + "execution_count": 65, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(2.1002573656763053/1.7661001788212371)**2" + ] + }, + { + "cell_type": "code", + "execution_count": 111, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "Case $a\\ge c\\ge b$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $a\\to a+c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $c\\to b+c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "numerator: $2a^4b^2+2a^4bc+a^4c^2+4a^3b^3+2\\sqrt{2}a^3b^2c+10a^3b^2c+2\\sqrt{2}a^3bc^2+6a^3bc^2+2a^3c^3+2a^2b^4+2\\sqrt{2}a^2b^3c+10a^2b^3c+6\\sqrt{2}a^2b^2c^2+12a^2b^2c^2+4a^2bc^3+4\\sqrt{2}a^2bc^3+a^2c^4+2ab^4c+2\\sqrt{2}ab^3c^2+6ab^3c^2+4ab^2c^3+4\\sqrt{2}ab^2c^3+2\\sqrt{2}abc^4+2b^4c^2+4b^3c^3+2b^2c^4$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $a^2b^4+2a^2b^3c+a^2b^2c^2+2ab^5+6ab^4c+6ab^3c^2+2ab^2c^3+b^6+4b^5c+6b^4c^2+4b^3c^3+b^2c^4$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le 2a^4b^2+2a^4bc+a^4c^2+4a^3b^3+2\\sqrt{2}a^3b^2c+10a^3b^2c+2\\sqrt{2}a^3bc^2+6a^3bc^2+2a^3c^3+2a^2b^4+2\\sqrt{2}a^2b^3c+10a^2b^3c+6\\sqrt{2}a^2b^2c^2+12a^2b^2c^2+4\\sqrt{2}a^2bc^3+4a^2bc^3+a^2c^4+2ab^4c+2\\sqrt{2}ab^3c^2+6ab^3c^2+4\\sqrt{2}ab^2c^3+4ab^2c^3+2\\sqrt{2}abc^4+2b^4c^2+4b^3c^3+2b^2c^4 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Case $a\\ge b\\ge c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $a\\to a+b$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $b\\to b+c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $a\\to \\sqrt{2}a$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "numerator: $16a^4b^2+32a^4bc+32a^4c^2+16\\sqrt{2}a^3b^3-32a^3b^2c+48\\sqrt{2}a^3b^2c-32a^3bc^2+80\\sqrt{2}a^3bc^2+32\\sqrt{2}a^3c^3+8a^2b^4-32\\sqrt{2}a^2b^3c+32a^2b^3c-48\\sqrt{2}a^2b^2c^2+96a^2b^2c^2-16\\sqrt{2}a^2bc^3+80a^2bc^3+16a^2c^4-16ab^4c-32ab^3c^2+16\\sqrt{2}ab^3c^2-16ab^2c^3+24\\sqrt{2}ab^2c^3+8\\sqrt{2}abc^4+8b^4c^2+16b^3c^3+8b^2c^4$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $2a^2b^2c^2+4a^2bc^3+2a^2c^4+2\\sqrt{2}ab^3c^2+6\\sqrt{2}ab^2c^3+6\\sqrt{2}abc^4+2\\sqrt{2}ac^5+b^4c^2+4b^3c^3+6b^2c^4+4bc^5+c^6$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "From weighted AM-GM inequality:" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$32a^3b^2c \\le 16a^4b^2+16a^2b^2c^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$32\\sqrt{2}a^2b^3c \\le 16\\sqrt{2}a^3b^3+16\\sqrt{2}ab^3c^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$48\\sqrt{2}a^2b^2c^2 \\le 24\\sqrt{2}a^3b^2c+24\\sqrt{2}ab^2c^3$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$16\\sqrt{2}a^2bc^3 \\le 8\\sqrt{2}a^3bc^2+8\\sqrt{2}abc^4$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$16ab^4c \\le 8a^2b^4+8b^4c^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$32ab^3c^2 \\le 16a^2b^3c+16b^3c^3$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$32a^3bc^2 \\le 16a^4bc+16a^2bc^3$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$16ab^2c^3 \\le 8a^2b^2c^2+8b^2c^4$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le 16a^4bc+32a^4c^2+24\\sqrt{2}a^3b^2c+72\\sqrt{2}a^3bc^2+32\\sqrt{2}a^3c^3+16a^2b^3c+72a^2b^2c^2+64a^2bc^3+16a^2c^4 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 111, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "formula=cyclize(Sm('((a-b)/c)^2-8**(1/2)*(a-b)/c'))\n", + "display(Latex('Case $a\\ge c\\ge b$'))\n", + "formula1=makesubs(formula,'[c,oo],[b,oo]',variables='a,c,b')\n", + "prove(formula1)\n", + "display(Latex('Case $a\\ge b\\ge c$'))\n", + "formula2=makesubs(formula,'[b,oo],[c,oo]')\n", + "prove(formula2*4,values='2**(1/2),1,1')" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "Substitute $a\\to a+b$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $b\\to b+c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $a\\to\\sqrt{2}a$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "numerator: $4a^4b^2+8a^4bc+8a^4c^2+4\\sqrt{2}a^3b^3-8a^3b^2c+12\\sqrt{2}a^3b^2c-8a^3bc^2+20\\sqrt{2}a^3bc^2+8\\sqrt{2}a^3c^3+2a^2b^4-8\\sqrt{2}a^2b^3c+8a^2b^3c-12\\sqrt{2}a^2b^2c^2+24a^2b^2c^2-4\\sqrt{2}a^2bc^3+20a^2bc^3+4a^2c^4-4ab^4c-8ab^3c^2+4\\sqrt{2}ab^3c^2-4ab^2c^3+6\\sqrt{2}ab^2c^3+2\\sqrt{2}abc^4+2b^4c^2+4b^3c^3+2b^2c^4$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $1$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "From weighted AM-GM inequality:" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$8a^3b^2c \\le 4a^4b^2+4a^2b^2c^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$8\\sqrt{2}a^2b^3c \\le 4\\sqrt{2}a^3b^3+4\\sqrt{2}ab^3c^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$12\\sqrt{2}a^2b^2c^2 \\le 6\\sqrt{2}a^3b^2c+6\\sqrt{2}ab^2c^3$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$4\\sqrt{2}a^2bc^3 \\le 2\\sqrt{2}a^3bc^2+2\\sqrt{2}abc^4$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$4ab^4c \\le 2a^2b^4+2b^4c^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$8ab^3c^2 \\le 4a^2b^3c+4b^3c^3$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$8a^3bc^2 \\le 4a^4bc+4a^2bc^3$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$4ab^2c^3 \\le 2a^2b^2c^2+2b^2c^4$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le 4a^4bc+8a^4c^2+6\\sqrt{2}a^3b^2c+18\\sqrt{2}a^3bc^2+8\\sqrt{2}a^3c^3+4a^2b^3c+18a^2b^2c^2+16a^2bc^3+4a^2c^4 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "formula=cyclize(Sm('((a-b)/c)^2-8**(1/2)*(a-b)/c'))\n", + "formula=(makesubs(formula,'[b,oo],[c,oo]'))\n", + "formula,_=fraction(cancel(formula))\n", + "formula=formula.subs('a','2**(1/2)*a')\n", + "sVars.display(r'Substitute $a\\to\\sqrt{2}a$')\n", + "prove(formula)" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(1, (x, y, sqrt(2)))" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "S('2**(1/2)*x*y').as_coeff_mul()" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(1, (x, y, sqrt(2)))" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "S('sqrt(2)*x*y').as_coeff_mul()" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[(1, 1, 1), (0, 0, 0)]" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Poly('sqrt(2)*x*y+8').monoms()" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 58]" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Poly('sqrt(2)*x*y+58').coeffs()" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(x, y, sqrt(2), sqrt(3), sqrt(6))" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Poly('sqrt(2)*x*y+sqrt(3)+sqrt(2)*sqrt(3)').gens" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "([0], [(0, 0)], [1, 7], [(2, 0), (0, 1)], (x, y))" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def _formula2list(formula):\n", + " neg=pos=0\n", + " for addend in formula.as_ordered_terms():\n", + " coef,facts=addend.as_coeff_mul()\n", + " if coef<0:\n", + " neg-=addend\n", + " else:\n", + " pos+=addend\n", + " neg=Poly(neg,gens=Poly(formula).gens)\n", + " pos=Poly(pos,gens=Poly(formula).gens)\n", + " return neg.coeffs(),neg.monoms(),pos.coeffs(),pos.monoms(),Poly(formula).gens\n", + "_formula2list(S('x^2+7*y'))" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "numerator: $\\sqrt{2}x^2-2\\sqrt{2}xy+\\sqrt{2}y^2$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $1$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "From weighted AM-GM inequality:" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$2\\sqrt{2}xy \\le \\sqrt{2}x^2+\\sqrt{2}y^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le 0 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "prove(S('sqrt(2)*x^2-sqrt(8)*x*y+sqrt(2)*y^2'))" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[(1, 0), (0, 2), (0, 1), (0, 0)], [1, 1, 1, 1]]" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "[Poly('1+2**(1/3)+4**(1/3)+x').monoms(),Poly('1+2**(1/3)+4**(1/3)+x').coeffs()]" + ] + }, + { + "cell_type": "code", + "execution_count": 168, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\operatorname{Poly}{\\left( x + \\sqrt{x}, x, \\sqrt{x}, domain=\\mathbb{Z} \\right)}$" + ], + "text/plain": [ + "Poly(x + (sqrt(x)), x, sqrt(x), domain='ZZ')" + ] + }, + "execution_count": 168, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x=Symbol('x', positive=True)\n", + "Poly(x+sqrt(x))" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": {}, + "outputs": [], + "source": [ + "prove?" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\operatorname{Poly}{\\left( x^{2} + 1, x, domain=\\mathbb{Z} \\right)}$" + ], + "text/plain": [ + "Poly(x**2 + 1, x, domain='ZZ')" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Poly('x^2-1').abs()" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\operatorname{Poly}{\\left( x\\frac{1}{x + y}, x, \\frac{1}{x + y}, domain=\\mathbb{Z} \\right)}$" + ], + "text/plain": [ + "Poly(x*(1/(x + y)), x, 1/(x + y), domain='ZZ')" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Poly(Poly('x')/Poly('x+y'))" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\operatorname{Poly}{\\left( x + \\sqrt{x} + x^{\\frac{2}{3}} + \\sqrt[3]{x} + \\sqrt[4]{x} + \\sqrt{2}, x, \\sqrt{x}, \\sqrt[3]{x}, \\sqrt[4]{x}, domain=QQ \\right)}$" + ], + "text/plain": [ + "Poly(x + (sqrt(x)) + (x**(1/3))**2 + (x**(1/3)) + (x**(1/4)) + sqrt(2), x, sqrt(x), x**(1/3), x**(1/4), domain='QQ')" + ] + }, + "execution_count": 44, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Poly('sqrt(2)+x+sqrt(x)+x**(1/4)+x**(1/3)+x**(2/3)',extension=1)" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, sqrt(6)]" + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Poly('x+sqrt(6)',S('x'),S('sqrt(2)'),S('sqrt(3)')).coeffs()" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, x]" + ] + }, + "execution_count": 47, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Poly('x+sqrt(x)',S('sqrt(x)')).coeffs()" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "In file: /home/grzegorz/Pobrane/SageMath/local/lib/python3.7/site-packages/sympy/polys/polytools.py\n", + "class Poly(Expr):\n", + " \"\"\"\n", + " Generic class for representing and operating on polynomial expressions.\n", + " Subclasses Expr class.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y\n", + "\n", + " Create a univariate polynomial:\n", + "\n", + " >>> Poly(x*(x**2 + x - 1)**2)\n", + " Poly(x**5 + 2*x**4 - x**3 - 2*x**2 + x, x, domain='ZZ')\n", + "\n", + " Create a univariate polynomial with specific domain:\n", + "\n", + " >>> from sympy import sqrt\n", + " >>> Poly(x**2 + 2*x + sqrt(3), domain='R')\n", + " Poly(1.0*x**2 + 2.0*x + 1.73205080756888, x, domain='RR')\n", + "\n", + " Create a multivariate polynomial:\n", + "\n", + " >>> Poly(y*x**2 + x*y + 1)\n", + " Poly(x**2*y + x*y + 1, x, y, domain='ZZ')\n", + "\n", + " Create a univariate polynomial, where y is a constant:\n", + "\n", + " >>> Poly(y*x**2 + x*y + 1,x)\n", + " Poly(y*x**2 + y*x + 1, x, domain='ZZ[y]')\n", + "\n", + " You can evaluate the above polynomial as a function of y:\n", + "\n", + " >>> Poly(y*x**2 + x*y + 1,x).eval(2)\n", + " 6*y + 1\n", + "\n", + " See Also\n", + " ========\n", + "\n", + " sympy.core.expr.Expr\n", + "\n", + " \"\"\"\n", + "\n", + " __slots__ = ['rep', 'gens']\n", + "\n", + " is_commutative = True\n", + " is_Poly = True\n", + " _op_priority = 10.001\n", + "\n", + " def __new__(cls, rep, *gens, **args):\n", + " \"\"\"Create a new polynomial instance out of something useful. \"\"\"\n", + " opt = options.build_options(gens, args)\n", + "\n", + " if 'order' in opt:\n", + " raise NotImplementedError(\"'order' keyword is not implemented yet\")\n", + "\n", + " if iterable(rep, exclude=str):\n", + " if isinstance(rep, dict):\n", + " return cls._from_dict(rep, opt)\n", + " else:\n", + " return cls._from_list(list(rep), opt)\n", + " else:\n", + " rep = sympify(rep)\n", + "\n", + " if rep.is_Poly:\n", + " return cls._from_poly(rep, opt)\n", + " else:\n", + " return cls._from_expr(rep, opt)\n", + "\n", + " @classmethod\n", + " def new(cls, rep, *gens):\n", + " \"\"\"Construct :class:`Poly` instance from raw representation. \"\"\"\n", + " if not isinstance(rep, DMP):\n", + " raise PolynomialError(\n", + " \"invalid polynomial representation: %s\" % rep)\n", + " elif rep.lev != len(gens) - 1:\n", + " raise PolynomialError(\"invalid arguments: %s, %s\" % (rep, gens))\n", + "\n", + " obj = Basic.__new__(cls)\n", + "\n", + " obj.rep = rep\n", + " obj.gens = gens\n", + "\n", + " return obj\n", + "\n", + " @classmethod\n", + " def from_dict(cls, rep, *gens, **args):\n", + " \"\"\"Construct a polynomial from a ``dict``. \"\"\"\n", + " opt = options.build_options(gens, args)\n", + " return cls._from_dict(rep, opt)\n", + "\n", + " @classmethod\n", + " def from_list(cls, rep, *gens, **args):\n", + " \"\"\"Construct a polynomial from a ``list``. \"\"\"\n", + " opt = options.build_options(gens, args)\n", + " return cls._from_list(rep, opt)\n", + "\n", + " @classmethod\n", + " def from_poly(cls, rep, *gens, **args):\n", + " \"\"\"Construct a polynomial from a polynomial. \"\"\"\n", + " opt = options.build_options(gens, args)\n", + " return cls._from_poly(rep, opt)\n", + "\n", + " @classmethod\n", + " def from_expr(cls, rep, *gens, **args):\n", + " \"\"\"Construct a polynomial from an expression. \"\"\"\n", + " opt = options.build_options(gens, args)\n", + " return cls._from_expr(rep, opt)\n", + "\n", + " @classmethod\n", + " def _from_dict(cls, rep, opt):\n", + " \"\"\"Construct a polynomial from a ``dict``. \"\"\"\n", + " gens = opt.gens\n", + "\n", + " if not gens:\n", + " raise GeneratorsNeeded(\n", + " \"can't initialize from 'dict' without generators\")\n", + "\n", + " level = len(gens) - 1\n", + " domain = opt.domain\n", + "\n", + " if domain is None:\n", + " domain, rep = construct_domain(rep, opt=opt)\n", + " else:\n", + " for monom, coeff in rep.items():\n", + " rep[monom] = domain.convert(coeff)\n", + "\n", + " return cls.new(DMP.from_dict(rep, level, domain), *gens)\n", + "\n", + " @classmethod\n", + " def _from_list(cls, rep, opt):\n", + " \"\"\"Construct a polynomial from a ``list``. \"\"\"\n", + " gens = opt.gens\n", + "\n", + " if not gens:\n", + " raise GeneratorsNeeded(\n", + " \"can't initialize from 'list' without generators\")\n", + " elif len(gens) != 1:\n", + " raise MultivariatePolynomialError(\n", + " \"'list' representation not supported\")\n", + "\n", + " level = len(gens) - 1\n", + " domain = opt.domain\n", + "\n", + " if domain is None:\n", + " domain, rep = construct_domain(rep, opt=opt)\n", + " else:\n", + " rep = list(map(domain.convert, rep))\n", + "\n", + " return cls.new(DMP.from_list(rep, level, domain), *gens)\n", + "\n", + " @classmethod\n", + " def _from_poly(cls, rep, opt):\n", + " \"\"\"Construct a polynomial from a polynomial. \"\"\"\n", + " if cls != rep.__class__:\n", + " rep = cls.new(rep.rep, *rep.gens)\n", + "\n", + " gens = opt.gens\n", + " field = opt.field\n", + " domain = opt.domain\n", + "\n", + " if gens and rep.gens != gens:\n", + " if set(rep.gens) != set(gens):\n", + " return cls._from_expr(rep.as_expr(), opt)\n", + " else:\n", + " rep = rep.reorder(*gens)\n", + "\n", + " if 'domain' in opt and domain:\n", + " rep = rep.set_domain(domain)\n", + " elif field is True:\n", + " rep = rep.to_field()\n", + "\n", + " return rep\n", + "\n", + " @classmethod\n", + " def _from_expr(cls, rep, opt):\n", + " \"\"\"Construct a polynomial from an expression. \"\"\"\n", + " rep, opt = _dict_from_expr(rep, opt)\n", + " return cls._from_dict(rep, opt)\n", + "\n", + " def _hashable_content(self):\n", + " \"\"\"Allow SymPy to hash Poly instances. \"\"\"\n", + " return (self.rep, self.gens)\n", + "\n", + " def __hash__(self):\n", + " return super(Poly, self).__hash__()\n", + "\n", + " @property\n", + " def free_symbols(self):\n", + " \"\"\"\n", + " Free symbols of a polynomial expression.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y, z\n", + "\n", + " >>> Poly(x**2 + 1).free_symbols\n", + " {x}\n", + " >>> Poly(x**2 + y).free_symbols\n", + " {x, y}\n", + " >>> Poly(x**2 + y, x).free_symbols\n", + " {x, y}\n", + " >>> Poly(x**2 + y, x, z).free_symbols\n", + " {x, y}\n", + "\n", + " \"\"\"\n", + " symbols = set()\n", + " gens = self.gens\n", + " for i in range(len(gens)):\n", + " for monom in self.monoms():\n", + " if monom[i]:\n", + " symbols |= gens[i].free_symbols\n", + " break\n", + "\n", + " return symbols | self.free_symbols_in_domain\n", + "\n", + " @property\n", + " def free_symbols_in_domain(self):\n", + " \"\"\"\n", + " Free symbols of the domain of ``self``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y\n", + "\n", + " >>> Poly(x**2 + 1).free_symbols_in_domain\n", + " set()\n", + " >>> Poly(x**2 + y).free_symbols_in_domain\n", + " set()\n", + " >>> Poly(x**2 + y, x).free_symbols_in_domain\n", + " {y}\n", + "\n", + " \"\"\"\n", + " domain, symbols = self.rep.dom, set()\n", + "\n", + " if domain.is_Composite:\n", + " for gen in domain.symbols:\n", + " symbols |= gen.free_symbols\n", + " elif domain.is_EX:\n", + " for coeff in self.coeffs():\n", + " symbols |= coeff.free_symbols\n", + "\n", + " return symbols\n", + "\n", + " @property\n", + " def args(self):\n", + " \"\"\"\n", + " Don't mess up with the core.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**2 + 1, x).args\n", + " (x**2 + 1,)\n", + "\n", + " \"\"\"\n", + " return (self.as_expr(),)\n", + "\n", + " @property\n", + " def gen(self):\n", + " \"\"\"\n", + " Return the principal generator.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**2 + 1, x).gen\n", + " x\n", + "\n", + " \"\"\"\n", + " return self.gens[0]\n", + "\n", + " @property\n", + " def domain(self):\n", + " \"\"\"Get the ground domain of ``self``. \"\"\"\n", + " return self.get_domain()\n", + "\n", + " @property\n", + " def zero(self):\n", + " \"\"\"Return zero polynomial with ``self``'s properties. \"\"\"\n", + " return self.new(self.rep.zero(self.rep.lev, self.rep.dom), *self.gens)\n", + "\n", + " @property\n", + " def one(self):\n", + " \"\"\"Return one polynomial with ``self``'s properties. \"\"\"\n", + " return self.new(self.rep.one(self.rep.lev, self.rep.dom), *self.gens)\n", + "\n", + " @property\n", + " def unit(self):\n", + " \"\"\"Return unit polynomial with ``self``'s properties. \"\"\"\n", + " return self.new(self.rep.unit(self.rep.lev, self.rep.dom), *self.gens)\n", + "\n", + " def unify(f, g):\n", + " \"\"\"\n", + " Make ``f`` and ``g`` belong to the same domain.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> f, g = Poly(x/2 + 1), Poly(2*x + 1)\n", + "\n", + " >>> f\n", + " Poly(1/2*x + 1, x, domain='QQ')\n", + " >>> g\n", + " Poly(2*x + 1, x, domain='ZZ')\n", + "\n", + " >>> F, G = f.unify(g)\n", + "\n", + " >>> F\n", + " Poly(1/2*x + 1, x, domain='QQ')\n", + " >>> G\n", + " Poly(2*x + 1, x, domain='QQ')\n", + "\n", + " \"\"\"\n", + " _, per, F, G = f._unify(g)\n", + " return per(F), per(G)\n", + "\n", + " def _unify(f, g):\n", + " g = sympify(g)\n", + "\n", + " if not g.is_Poly:\n", + " try:\n", + " return f.rep.dom, f.per, f.rep, f.rep.per(f.rep.dom.from_sympy(g))\n", + " except CoercionFailed:\n", + " raise UnificationFailed(\"can't unify %s with %s\" % (f, g))\n", + "\n", + " if isinstance(f.rep, DMP) and isinstance(g.rep, DMP):\n", + " gens = _unify_gens(f.gens, g.gens)\n", + "\n", + " dom, lev = f.rep.dom.unify(g.rep.dom, gens), len(gens) - 1\n", + "\n", + " if f.gens != gens:\n", + " f_monoms, f_coeffs = _dict_reorder(\n", + " f.rep.to_dict(), f.gens, gens)\n", + "\n", + " if f.rep.dom != dom:\n", + " f_coeffs = [dom.convert(c, f.rep.dom) for c in f_coeffs]\n", + "\n", + " F = DMP(dict(list(zip(f_monoms, f_coeffs))), dom, lev)\n", + " else:\n", + " F = f.rep.convert(dom)\n", + "\n", + " if g.gens != gens:\n", + " g_monoms, g_coeffs = _dict_reorder(\n", + " g.rep.to_dict(), g.gens, gens)\n", + "\n", + " if g.rep.dom != dom:\n", + " g_coeffs = [dom.convert(c, g.rep.dom) for c in g_coeffs]\n", + "\n", + " G = DMP(dict(list(zip(g_monoms, g_coeffs))), dom, lev)\n", + " else:\n", + " G = g.rep.convert(dom)\n", + " else:\n", + " raise UnificationFailed(\"can't unify %s with %s\" % (f, g))\n", + "\n", + " cls = f.__class__\n", + "\n", + " def per(rep, dom=dom, gens=gens, remove=None):\n", + " if remove is not None:\n", + " gens = gens[:remove] + gens[remove + 1:]\n", + "\n", + " if not gens:\n", + " return dom.to_sympy(rep)\n", + "\n", + " return cls.new(rep, *gens)\n", + "\n", + " return dom, per, F, G\n", + "\n", + " def per(f, rep, gens=None, remove=None):\n", + " \"\"\"\n", + " Create a Poly out of the given representation.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly, ZZ\n", + " >>> from sympy.abc import x, y\n", + "\n", + " >>> from sympy.polys.polyclasses import DMP\n", + "\n", + " >>> a = Poly(x**2 + 1)\n", + "\n", + " >>> a.per(DMP([ZZ(1), ZZ(1)], ZZ), gens=[y])\n", + " Poly(y + 1, y, domain='ZZ')\n", + "\n", + " \"\"\"\n", + " if gens is None:\n", + " gens = f.gens\n", + "\n", + " if remove is not None:\n", + " gens = gens[:remove] + gens[remove + 1:]\n", + "\n", + " if not gens:\n", + " return f.rep.dom.to_sympy(rep)\n", + "\n", + " return f.__class__.new(rep, *gens)\n", + "\n", + " def set_domain(f, domain):\n", + " \"\"\"Set the ground domain of ``f``. \"\"\"\n", + " opt = options.build_options(f.gens, {'domain': domain})\n", + " return f.per(f.rep.convert(opt.domain))\n", + "\n", + " def get_domain(f):\n", + " \"\"\"Get the ground domain of ``f``. \"\"\"\n", + " return f.rep.dom\n", + "\n", + " def set_modulus(f, modulus):\n", + " \"\"\"\n", + " Set the modulus of ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(5*x**2 + 2*x - 1, x).set_modulus(2)\n", + " Poly(x**2 + 1, x, modulus=2)\n", + "\n", + " \"\"\"\n", + " modulus = options.Modulus.preprocess(modulus)\n", + " return f.set_domain(FF(modulus))\n", + "\n", + " def get_modulus(f):\n", + " \"\"\"\n", + " Get the modulus of ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**2 + 1, modulus=2).get_modulus()\n", + " 2\n", + "\n", + " \"\"\"\n", + " domain = f.get_domain()\n", + "\n", + " if domain.is_FiniteField:\n", + " return Integer(domain.characteristic())\n", + " else:\n", + " raise PolynomialError(\"not a polynomial over a Galois field\")\n", + "\n", + " def _eval_subs(f, old, new):\n", + " \"\"\"Internal implementation of :func:`subs`. \"\"\"\n", + " if old in f.gens:\n", + " if new.is_number:\n", + " return f.eval(old, new)\n", + " else:\n", + " try:\n", + " return f.replace(old, new)\n", + " except PolynomialError:\n", + " pass\n", + "\n", + " return f.as_expr().subs(old, new)\n", + "\n", + " def exclude(f):\n", + " \"\"\"\n", + " Remove unnecessary generators from ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import a, b, c, d, x\n", + "\n", + " >>> Poly(a + x, a, b, c, d, x).exclude()\n", + " Poly(a + x, a, x, domain='ZZ')\n", + "\n", + " \"\"\"\n", + " J, new = f.rep.exclude()\n", + " gens = []\n", + "\n", + " for j in range(len(f.gens)):\n", + " if j not in J:\n", + " gens.append(f.gens[j])\n", + "\n", + " return f.per(new, gens=gens)\n", + "\n", + " def replace(f, x, y=None, *_ignore):\n", + " # XXX this does not match Basic's signature\n", + " \"\"\"\n", + " Replace ``x`` with ``y`` in generators list.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y\n", + "\n", + " >>> Poly(x**2 + 1, x).replace(x, y)\n", + " Poly(y**2 + 1, y, domain='ZZ')\n", + "\n", + " \"\"\"\n", + " if y is None:\n", + " if f.is_univariate:\n", + " x, y = f.gen, x\n", + " else:\n", + " raise PolynomialError(\n", + " \"syntax supported only in univariate case\")\n", + "\n", + " if x == y or x not in f.gens:\n", + " return f\n", + "\n", + " if x in f.gens and y not in f.gens:\n", + " dom = f.get_domain()\n", + "\n", + " if not dom.is_Composite or y not in dom.symbols:\n", + " gens = list(f.gens)\n", + " gens[gens.index(x)] = y\n", + " return f.per(f.rep, gens=gens)\n", + "\n", + " raise PolynomialError(\"can't replace %s with %s in %s\" % (x, y, f))\n", + "\n", + " def reorder(f, *gens, **args):\n", + " \"\"\"\n", + " Efficiently apply new order of generators.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y\n", + "\n", + " >>> Poly(x**2 + x*y**2, x, y).reorder(y, x)\n", + " Poly(y**2*x + x**2, y, x, domain='ZZ')\n", + "\n", + " \"\"\"\n", + " opt = options.Options((), args)\n", + "\n", + " if not gens:\n", + " gens = _sort_gens(f.gens, opt=opt)\n", + " elif set(f.gens) != set(gens):\n", + " raise PolynomialError(\n", + " \"generators list can differ only up to order of elements\")\n", + "\n", + " rep = dict(list(zip(*_dict_reorder(f.rep.to_dict(), f.gens, gens))))\n", + "\n", + " return f.per(DMP(rep, f.rep.dom, len(gens) - 1), gens=gens)\n", + "\n", + " def ltrim(f, gen):\n", + " \"\"\"\n", + " Remove dummy generators from ``f`` that are to the left of\n", + " specified ``gen`` in the generators as ordered. When ``gen``\n", + " is an integer, it refers to the generator located at that\n", + " position within the tuple of generators of ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y, z\n", + "\n", + " >>> Poly(y**2 + y*z**2, x, y, z).ltrim(y)\n", + " Poly(y**2 + y*z**2, y, z, domain='ZZ')\n", + " >>> Poly(z, x, y, z).ltrim(-1)\n", + " Poly(z, z, domain='ZZ')\n", + "\n", + " \"\"\"\n", + " rep = f.as_dict(native=True)\n", + " j = f._gen_to_level(gen)\n", + "\n", + " terms = {}\n", + "\n", + " for monom, coeff in rep.items():\n", + "\n", + " if any(i for i in monom[:j]):\n", + " # some generator is used in the portion to be trimmed\n", + " raise PolynomialError(\"can't left trim %s\" % f)\n", + "\n", + " terms[monom[j:]] = coeff\n", + "\n", + " gens = f.gens[j:]\n", + "\n", + " return f.new(DMP.from_dict(terms, len(gens) - 1, f.rep.dom), *gens)\n", + "\n", + " def has_only_gens(f, *gens):\n", + " \"\"\"\n", + " Return ``True`` if ``Poly(f, *gens)`` retains ground domain.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y, z\n", + "\n", + " >>> Poly(x*y + 1, x, y, z).has_only_gens(x, y)\n", + " True\n", + " >>> Poly(x*y + z, x, y, z).has_only_gens(x, y)\n", + " False\n", + "\n", + " \"\"\"\n", + " indices = set()\n", + "\n", + " for gen in gens:\n", + " try:\n", + " index = f.gens.index(gen)\n", + " except ValueError:\n", + " raise GeneratorsError(\n", + " \"%s doesn't have %s as generator\" % (f, gen))\n", + " else:\n", + " indices.add(index)\n", + "\n", + " for monom in f.monoms():\n", + " for i, elt in enumerate(monom):\n", + " if i not in indices and elt:\n", + " return False\n", + "\n", + " return True\n", + "\n", + " def to_ring(f):\n", + " \"\"\"\n", + " Make the ground domain a ring.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly, QQ\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**2 + 1, domain=QQ).to_ring()\n", + " Poly(x**2 + 1, x, domain='ZZ')\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'to_ring'):\n", + " result = f.rep.to_ring()\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'to_ring')\n", + "\n", + " return f.per(result)\n", + "\n", + " def to_field(f):\n", + " \"\"\"\n", + " Make the ground domain a field.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly, ZZ\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**2 + 1, x, domain=ZZ).to_field()\n", + " Poly(x**2 + 1, x, domain='QQ')\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'to_field'):\n", + " result = f.rep.to_field()\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'to_field')\n", + "\n", + " return f.per(result)\n", + "\n", + " def to_exact(f):\n", + " \"\"\"\n", + " Make the ground domain exact.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly, RR\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**2 + 1.0, x, domain=RR).to_exact()\n", + " Poly(x**2 + 1, x, domain='QQ')\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'to_exact'):\n", + " result = f.rep.to_exact()\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'to_exact')\n", + "\n", + " return f.per(result)\n", + "\n", + " def retract(f, field=None):\n", + " \"\"\"\n", + " Recalculate the ground domain of a polynomial.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> f = Poly(x**2 + 1, x, domain='QQ[y]')\n", + " >>> f\n", + " Poly(x**2 + 1, x, domain='QQ[y]')\n", + "\n", + " >>> f.retract()\n", + " Poly(x**2 + 1, x, domain='ZZ')\n", + " >>> f.retract(field=True)\n", + " Poly(x**2 + 1, x, domain='QQ')\n", + "\n", + " \"\"\"\n", + " dom, rep = construct_domain(f.as_dict(zero=True),\n", + " field=field, composite=f.domain.is_Composite or None)\n", + " return f.from_dict(rep, f.gens, domain=dom)\n", + "\n", + " def slice(f, x, m, n=None):\n", + " \"\"\"Take a continuous subsequence of terms of ``f``. \"\"\"\n", + " if n is None:\n", + " j, m, n = 0, x, m\n", + " else:\n", + " j = f._gen_to_level(x)\n", + "\n", + " m, n = int(m), int(n)\n", + "\n", + " if hasattr(f.rep, 'slice'):\n", + " result = f.rep.slice(m, n, j)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'slice')\n", + "\n", + " return f.per(result)\n", + "\n", + " def coeffs(f, order=None):\n", + " \"\"\"\n", + " Returns all non-zero coefficients from ``f`` in lex order.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**3 + 2*x + 3, x).coeffs()\n", + " [1, 2, 3]\n", + "\n", + " See Also\n", + " ========\n", + " all_coeffs\n", + " coeff_monomial\n", + " nth\n", + "\n", + " \"\"\"\n", + " return [f.rep.dom.to_sympy(c) for c in f.rep.coeffs(order=order)]\n", + "\n", + " def monoms(f, order=None):\n", + " \"\"\"\n", + " Returns all non-zero monomials from ``f`` in lex order.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y\n", + "\n", + " >>> Poly(x**2 + 2*x*y**2 + x*y + 3*y, x, y).monoms()\n", + " [(2, 0), (1, 2), (1, 1), (0, 1)]\n", + "\n", + " See Also\n", + " ========\n", + " all_monoms\n", + "\n", + " \"\"\"\n", + " return f.rep.monoms(order=order)\n", + "\n", + " def terms(f, order=None):\n", + " \"\"\"\n", + " Returns all non-zero terms from ``f`` in lex order.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y\n", + "\n", + " >>> Poly(x**2 + 2*x*y**2 + x*y + 3*y, x, y).terms()\n", + " [((2, 0), 1), ((1, 2), 2), ((1, 1), 1), ((0, 1), 3)]\n", + "\n", + " See Also\n", + " ========\n", + " all_terms\n", + "\n", + " \"\"\"\n", + " return [(m, f.rep.dom.to_sympy(c)) for m, c in f.rep.terms(order=order)]\n", + "\n", + " def all_coeffs(f):\n", + " \"\"\"\n", + " Returns all coefficients from a univariate polynomial ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**3 + 2*x - 1, x).all_coeffs()\n", + " [1, 0, 2, -1]\n", + "\n", + " \"\"\"\n", + " return [f.rep.dom.to_sympy(c) for c in f.rep.all_coeffs()]\n", + "\n", + " def all_monoms(f):\n", + " \"\"\"\n", + " Returns all monomials from a univariate polynomial ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**3 + 2*x - 1, x).all_monoms()\n", + " [(3,), (2,), (1,), (0,)]\n", + "\n", + " See Also\n", + " ========\n", + " all_terms\n", + "\n", + " \"\"\"\n", + " return f.rep.all_monoms()\n", + "\n", + " def all_terms(f):\n", + " \"\"\"\n", + " Returns all terms from a univariate polynomial ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**3 + 2*x - 1, x).all_terms()\n", + " [((3,), 1), ((2,), 0), ((1,), 2), ((0,), -1)]\n", + "\n", + " \"\"\"\n", + " return [(m, f.rep.dom.to_sympy(c)) for m, c in f.rep.all_terms()]\n", + "\n", + " def termwise(f, func, *gens, **args):\n", + " \"\"\"\n", + " Apply a function to all terms of ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> def func(k, coeff):\n", + " ... k = k[0]\n", + " ... return coeff//10**(2-k)\n", + "\n", + " >>> Poly(x**2 + 20*x + 400).termwise(func)\n", + " Poly(x**2 + 2*x + 4, x, domain='ZZ')\n", + "\n", + " \"\"\"\n", + " terms = {}\n", + "\n", + " for monom, coeff in f.terms():\n", + " result = func(monom, coeff)\n", + "\n", + " if isinstance(result, tuple):\n", + " monom, coeff = result\n", + " else:\n", + " coeff = result\n", + "\n", + " if coeff:\n", + " if monom not in terms:\n", + " terms[monom] = coeff\n", + " else:\n", + " raise PolynomialError(\n", + " \"%s monomial was generated twice\" % monom)\n", + "\n", + " return f.from_dict(terms, *(gens or f.gens), **args)\n", + "\n", + " def length(f):\n", + " \"\"\"\n", + " Returns the number of non-zero terms in ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**2 + 2*x - 1).length()\n", + " 3\n", + "\n", + " \"\"\"\n", + " return len(f.as_dict())\n", + "\n", + " def as_dict(f, native=False, zero=False):\n", + " \"\"\"\n", + " Switch to a ``dict`` representation.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y\n", + "\n", + " >>> Poly(x**2 + 2*x*y**2 - y, x, y).as_dict()\n", + " {(0, 1): -1, (1, 2): 2, (2, 0): 1}\n", + "\n", + " \"\"\"\n", + " if native:\n", + " return f.rep.to_dict(zero=zero)\n", + " else:\n", + " return f.rep.to_sympy_dict(zero=zero)\n", + "\n", + " def as_list(f, native=False):\n", + " \"\"\"Switch to a ``list`` representation. \"\"\"\n", + " if native:\n", + " return f.rep.to_list()\n", + " else:\n", + " return f.rep.to_sympy_list()\n", + "\n", + " def as_expr(f, *gens):\n", + " \"\"\"\n", + " Convert a Poly instance to an Expr instance.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y\n", + "\n", + " >>> f = Poly(x**2 + 2*x*y**2 - y, x, y)\n", + "\n", + " >>> f.as_expr()\n", + " x**2 + 2*x*y**2 - y\n", + " >>> f.as_expr({x: 5})\n", + " 10*y**2 - y + 25\n", + " >>> f.as_expr(5, 6)\n", + " 379\n", + "\n", + " \"\"\"\n", + " if not gens:\n", + " gens = f.gens\n", + " elif len(gens) == 1 and isinstance(gens[0], dict):\n", + " mapping = gens[0]\n", + " gens = list(f.gens)\n", + "\n", + " for gen, value in mapping.items():\n", + " try:\n", + " index = gens.index(gen)\n", + " except ValueError:\n", + " raise GeneratorsError(\n", + " \"%s doesn't have %s as generator\" % (f, gen))\n", + " else:\n", + " gens[index] = value\n", + "\n", + " return basic_from_dict(f.rep.to_sympy_dict(), *gens)\n", + "\n", + " def lift(f):\n", + " \"\"\"\n", + " Convert algebraic coefficients to rationals.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly, I\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**2 + I*x + 1, x, extension=I).lift()\n", + " Poly(x**4 + 3*x**2 + 1, x, domain='QQ')\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'lift'):\n", + " result = f.rep.lift()\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'lift')\n", + "\n", + " return f.per(result)\n", + "\n", + " def deflate(f):\n", + " \"\"\"\n", + " Reduce degree of ``f`` by mapping ``x_i**m`` to ``y_i``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y\n", + "\n", + " >>> Poly(x**6*y**2 + x**3 + 1, x, y).deflate()\n", + " ((3, 2), Poly(x**2*y + x + 1, x, y, domain='ZZ'))\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'deflate'):\n", + " J, result = f.rep.deflate()\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'deflate')\n", + "\n", + " return J, f.per(result)\n", + "\n", + " def inject(f, front=False):\n", + " \"\"\"\n", + " Inject ground domain generators into ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y\n", + "\n", + " >>> f = Poly(x**2*y + x*y**3 + x*y + 1, x)\n", + "\n", + " >>> f.inject()\n", + " Poly(x**2*y + x*y**3 + x*y + 1, x, y, domain='ZZ')\n", + " >>> f.inject(front=True)\n", + " Poly(y**3*x + y*x**2 + y*x + 1, y, x, domain='ZZ')\n", + "\n", + " \"\"\"\n", + " dom = f.rep.dom\n", + "\n", + " if dom.is_Numerical:\n", + " return f\n", + " elif not dom.is_Poly:\n", + " raise DomainError(\"can't inject generators over %s\" % dom)\n", + "\n", + " if hasattr(f.rep, 'inject'):\n", + " result = f.rep.inject(front=front)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'inject')\n", + "\n", + " if front:\n", + " gens = dom.symbols + f.gens\n", + " else:\n", + " gens = f.gens + dom.symbols\n", + "\n", + " return f.new(result, *gens)\n", + "\n", + " def eject(f, *gens):\n", + " \"\"\"\n", + " Eject selected generators into the ground domain.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y\n", + "\n", + " >>> f = Poly(x**2*y + x*y**3 + x*y + 1, x, y)\n", + "\n", + " >>> f.eject(x)\n", + " Poly(x*y**3 + (x**2 + x)*y + 1, y, domain='ZZ[x]')\n", + " >>> f.eject(y)\n", + " Poly(y*x**2 + (y**3 + y)*x + 1, x, domain='ZZ[y]')\n", + "\n", + " \"\"\"\n", + " dom = f.rep.dom\n", + "\n", + " if not dom.is_Numerical:\n", + " raise DomainError(\"can't eject generators over %s\" % dom)\n", + "\n", + " k = len(gens)\n", + "\n", + " if f.gens[:k] == gens:\n", + " _gens, front = f.gens[k:], True\n", + " elif f.gens[-k:] == gens:\n", + " _gens, front = f.gens[:-k], False\n", + " else:\n", + " raise NotImplementedError(\n", + " \"can only eject front or back generators\")\n", + "\n", + " dom = dom.inject(*gens)\n", + "\n", + " if hasattr(f.rep, 'eject'):\n", + " result = f.rep.eject(dom, front=front)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'eject')\n", + "\n", + " return f.new(result, *_gens)\n", + "\n", + " def terms_gcd(f):\n", + " \"\"\"\n", + " Remove GCD of terms from the polynomial ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y\n", + "\n", + " >>> Poly(x**6*y**2 + x**3*y, x, y).terms_gcd()\n", + " ((3, 1), Poly(x**3*y + 1, x, y, domain='ZZ'))\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'terms_gcd'):\n", + " J, result = f.rep.terms_gcd()\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'terms_gcd')\n", + "\n", + " return J, f.per(result)\n", + "\n", + " def add_ground(f, coeff):\n", + " \"\"\"\n", + " Add an element of the ground domain to ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x + 1).add_ground(2)\n", + " Poly(x + 3, x, domain='ZZ')\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'add_ground'):\n", + " result = f.rep.add_ground(coeff)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'add_ground')\n", + "\n", + " return f.per(result)\n", + "\n", + " def sub_ground(f, coeff):\n", + " \"\"\"\n", + " Subtract an element of the ground domain from ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x + 1).sub_ground(2)\n", + " Poly(x - 1, x, domain='ZZ')\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'sub_ground'):\n", + " result = f.rep.sub_ground(coeff)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'sub_ground')\n", + "\n", + " return f.per(result)\n", + "\n", + " def mul_ground(f, coeff):\n", + " \"\"\"\n", + " Multiply ``f`` by a an element of the ground domain.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x + 1).mul_ground(2)\n", + " Poly(2*x + 2, x, domain='ZZ')\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'mul_ground'):\n", + " result = f.rep.mul_ground(coeff)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'mul_ground')\n", + "\n", + " return f.per(result)\n", + "\n", + " def quo_ground(f, coeff):\n", + " \"\"\"\n", + " Quotient of ``f`` by a an element of the ground domain.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(2*x + 4).quo_ground(2)\n", + " Poly(x + 2, x, domain='ZZ')\n", + "\n", + " >>> Poly(2*x + 3).quo_ground(2)\n", + " Poly(x + 1, x, domain='ZZ')\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'quo_ground'):\n", + " result = f.rep.quo_ground(coeff)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'quo_ground')\n", + "\n", + " return f.per(result)\n", + "\n", + " def exquo_ground(f, coeff):\n", + " \"\"\"\n", + " Exact quotient of ``f`` by a an element of the ground domain.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(2*x + 4).exquo_ground(2)\n", + " Poly(x + 2, x, domain='ZZ')\n", + "\n", + " >>> Poly(2*x + 3).exquo_ground(2)\n", + " Traceback (most recent call last):\n", + " ...\n", + " ExactQuotientFailed: 2 does not divide 3 in ZZ\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'exquo_ground'):\n", + " result = f.rep.exquo_ground(coeff)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'exquo_ground')\n", + "\n", + " return f.per(result)\n", + "\n", + " def abs(f):\n", + " \"\"\"\n", + " Make all coefficients in ``f`` positive.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**2 - 1, x).abs()\n", + " Poly(x**2 + 1, x, domain='ZZ')\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'abs'):\n", + " result = f.rep.abs()\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'abs')\n", + "\n", + " return f.per(result)\n", + "\n", + " def neg(f):\n", + " \"\"\"\n", + " Negate all coefficients in ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**2 - 1, x).neg()\n", + " Poly(-x**2 + 1, x, domain='ZZ')\n", + "\n", + " >>> -Poly(x**2 - 1, x)\n", + " Poly(-x**2 + 1, x, domain='ZZ')\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'neg'):\n", + " result = f.rep.neg()\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'neg')\n", + "\n", + " return f.per(result)\n", + "\n", + " def add(f, g):\n", + " \"\"\"\n", + " Add two polynomials ``f`` and ``g``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**2 + 1, x).add(Poly(x - 2, x))\n", + " Poly(x**2 + x - 1, x, domain='ZZ')\n", + "\n", + " >>> Poly(x**2 + 1, x) + Poly(x - 2, x)\n", + " Poly(x**2 + x - 1, x, domain='ZZ')\n", + "\n", + " \"\"\"\n", + " g = sympify(g)\n", + "\n", + " if not g.is_Poly:\n", + " return f.add_ground(g)\n", + "\n", + " _, per, F, G = f._unify(g)\n", + "\n", + " if hasattr(f.rep, 'add'):\n", + " result = F.add(G)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'add')\n", + "\n", + " return per(result)\n", + "\n", + " def sub(f, g):\n", + " \"\"\"\n", + " Subtract two polynomials ``f`` and ``g``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**2 + 1, x).sub(Poly(x - 2, x))\n", + " Poly(x**2 - x + 3, x, domain='ZZ')\n", + "\n", + " >>> Poly(x**2 + 1, x) - Poly(x - 2, x)\n", + " Poly(x**2 - x + 3, x, domain='ZZ')\n", + "\n", + " \"\"\"\n", + " g = sympify(g)\n", + "\n", + " if not g.is_Poly:\n", + " return f.sub_ground(g)\n", + "\n", + " _, per, F, G = f._unify(g)\n", + "\n", + " if hasattr(f.rep, 'sub'):\n", + " result = F.sub(G)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'sub')\n", + "\n", + " return per(result)\n", + "\n", + " def mul(f, g):\n", + " \"\"\"\n", + " Multiply two polynomials ``f`` and ``g``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**2 + 1, x).mul(Poly(x - 2, x))\n", + " Poly(x**3 - 2*x**2 + x - 2, x, domain='ZZ')\n", + "\n", + " >>> Poly(x**2 + 1, x)*Poly(x - 2, x)\n", + " Poly(x**3 - 2*x**2 + x - 2, x, domain='ZZ')\n", + "\n", + " \"\"\"\n", + " g = sympify(g)\n", + "\n", + " if not g.is_Poly:\n", + " return f.mul_ground(g)\n", + "\n", + " _, per, F, G = f._unify(g)\n", + "\n", + " if hasattr(f.rep, 'mul'):\n", + " result = F.mul(G)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'mul')\n", + "\n", + " return per(result)\n", + "\n", + " def sqr(f):\n", + " \"\"\"\n", + " Square a polynomial ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x - 2, x).sqr()\n", + " Poly(x**2 - 4*x + 4, x, domain='ZZ')\n", + "\n", + " >>> Poly(x - 2, x)**2\n", + " Poly(x**2 - 4*x + 4, x, domain='ZZ')\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'sqr'):\n", + " result = f.rep.sqr()\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'sqr')\n", + "\n", + " return f.per(result)\n", + "\n", + " def pow(f, n):\n", + " \"\"\"\n", + " Raise ``f`` to a non-negative power ``n``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x - 2, x).pow(3)\n", + " Poly(x**3 - 6*x**2 + 12*x - 8, x, domain='ZZ')\n", + "\n", + " >>> Poly(x - 2, x)**3\n", + " Poly(x**3 - 6*x**2 + 12*x - 8, x, domain='ZZ')\n", + "\n", + " \"\"\"\n", + " n = int(n)\n", + "\n", + " if hasattr(f.rep, 'pow'):\n", + " result = f.rep.pow(n)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'pow')\n", + "\n", + " return f.per(result)\n", + "\n", + " def pdiv(f, g):\n", + " \"\"\"\n", + " Polynomial pseudo-division of ``f`` by ``g``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**2 + 1, x).pdiv(Poly(2*x - 4, x))\n", + " (Poly(2*x + 4, x, domain='ZZ'), Poly(20, x, domain='ZZ'))\n", + "\n", + " \"\"\"\n", + " _, per, F, G = f._unify(g)\n", + "\n", + " if hasattr(f.rep, 'pdiv'):\n", + " q, r = F.pdiv(G)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'pdiv')\n", + "\n", + " return per(q), per(r)\n", + "\n", + " def prem(f, g):\n", + " \"\"\"\n", + " Polynomial pseudo-remainder of ``f`` by ``g``.\n", + "\n", + " Caveat: The function prem(f, g, x) can be safely used to compute\n", + " in Z[x] _only_ subresultant polynomial remainder sequences (prs's).\n", + "\n", + " To safely compute Euclidean and Sturmian prs's in Z[x]\n", + " employ anyone of the corresponding functions found in\n", + " the module sympy.polys.subresultants_qq_zz. The functions\n", + " in the module with suffix _pg compute prs's in Z[x] employing\n", + " rem(f, g, x), whereas the functions with suffix _amv\n", + " compute prs's in Z[x] employing rem_z(f, g, x).\n", + "\n", + " The function rem_z(f, g, x) differs from prem(f, g, x) in that\n", + " to compute the remainder polynomials in Z[x] it premultiplies\n", + " the divident times the absolute value of the leading coefficient\n", + " of the divisor raised to the power degree(f, x) - degree(g, x) + 1.\n", + "\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**2 + 1, x).prem(Poly(2*x - 4, x))\n", + " Poly(20, x, domain='ZZ')\n", + "\n", + " \"\"\"\n", + " _, per, F, G = f._unify(g)\n", + "\n", + " if hasattr(f.rep, 'prem'):\n", + " result = F.prem(G)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'prem')\n", + "\n", + " return per(result)\n", + "\n", + " def pquo(f, g):\n", + " \"\"\"\n", + " Polynomial pseudo-quotient of ``f`` by ``g``.\n", + "\n", + " See the Caveat note in the function prem(f, g).\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**2 + 1, x).pquo(Poly(2*x - 4, x))\n", + " Poly(2*x + 4, x, domain='ZZ')\n", + "\n", + " >>> Poly(x**2 - 1, x).pquo(Poly(2*x - 2, x))\n", + " Poly(2*x + 2, x, domain='ZZ')\n", + "\n", + " \"\"\"\n", + " _, per, F, G = f._unify(g)\n", + "\n", + " if hasattr(f.rep, 'pquo'):\n", + " result = F.pquo(G)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'pquo')\n", + "\n", + " return per(result)\n", + "\n", + " def pexquo(f, g):\n", + " \"\"\"\n", + " Polynomial exact pseudo-quotient of ``f`` by ``g``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**2 - 1, x).pexquo(Poly(2*x - 2, x))\n", + " Poly(2*x + 2, x, domain='ZZ')\n", + "\n", + " >>> Poly(x**2 + 1, x).pexquo(Poly(2*x - 4, x))\n", + " Traceback (most recent call last):\n", + " ...\n", + " ExactQuotientFailed: 2*x - 4 does not divide x**2 + 1\n", + "\n", + " \"\"\"\n", + " _, per, F, G = f._unify(g)\n", + "\n", + " if hasattr(f.rep, 'pexquo'):\n", + " try:\n", + " result = F.pexquo(G)\n", + " except ExactQuotientFailed as exc:\n", + " raise exc.new(f.as_expr(), g.as_expr())\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'pexquo')\n", + "\n", + " return per(result)\n", + "\n", + " def div(f, g, auto=True):\n", + " \"\"\"\n", + " Polynomial division with remainder of ``f`` by ``g``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**2 + 1, x).div(Poly(2*x - 4, x))\n", + " (Poly(1/2*x + 1, x, domain='QQ'), Poly(5, x, domain='QQ'))\n", + "\n", + " >>> Poly(x**2 + 1, x).div(Poly(2*x - 4, x), auto=False)\n", + " (Poly(0, x, domain='ZZ'), Poly(x**2 + 1, x, domain='ZZ'))\n", + "\n", + " \"\"\"\n", + " dom, per, F, G = f._unify(g)\n", + " retract = False\n", + "\n", + " if auto and dom.is_Ring and not dom.is_Field:\n", + " F, G = F.to_field(), G.to_field()\n", + " retract = True\n", + "\n", + " if hasattr(f.rep, 'div'):\n", + " q, r = F.div(G)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'div')\n", + "\n", + " if retract:\n", + " try:\n", + " Q, R = q.to_ring(), r.to_ring()\n", + " except CoercionFailed:\n", + " pass\n", + " else:\n", + " q, r = Q, R\n", + "\n", + " return per(q), per(r)\n", + "\n", + " def rem(f, g, auto=True):\n", + " \"\"\"\n", + " Computes the polynomial remainder of ``f`` by ``g``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**2 + 1, x).rem(Poly(2*x - 4, x))\n", + " Poly(5, x, domain='ZZ')\n", + "\n", + " >>> Poly(x**2 + 1, x).rem(Poly(2*x - 4, x), auto=False)\n", + " Poly(x**2 + 1, x, domain='ZZ')\n", + "\n", + " \"\"\"\n", + " dom, per, F, G = f._unify(g)\n", + " retract = False\n", + "\n", + " if auto and dom.is_Ring and not dom.is_Field:\n", + " F, G = F.to_field(), G.to_field()\n", + " retract = True\n", + "\n", + " if hasattr(f.rep, 'rem'):\n", + " r = F.rem(G)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'rem')\n", + "\n", + " if retract:\n", + " try:\n", + " r = r.to_ring()\n", + " except CoercionFailed:\n", + " pass\n", + "\n", + " return per(r)\n", + "\n", + " def quo(f, g, auto=True):\n", + " \"\"\"\n", + " Computes polynomial quotient of ``f`` by ``g``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**2 + 1, x).quo(Poly(2*x - 4, x))\n", + " Poly(1/2*x + 1, x, domain='QQ')\n", + "\n", + " >>> Poly(x**2 - 1, x).quo(Poly(x - 1, x))\n", + " Poly(x + 1, x, domain='ZZ')\n", + "\n", + " \"\"\"\n", + " dom, per, F, G = f._unify(g)\n", + " retract = False\n", + "\n", + " if auto and dom.is_Ring and not dom.is_Field:\n", + " F, G = F.to_field(), G.to_field()\n", + " retract = True\n", + "\n", + " if hasattr(f.rep, 'quo'):\n", + " q = F.quo(G)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'quo')\n", + "\n", + " if retract:\n", + " try:\n", + " q = q.to_ring()\n", + " except CoercionFailed:\n", + " pass\n", + "\n", + " return per(q)\n", + "\n", + " def exquo(f, g, auto=True):\n", + " \"\"\"\n", + " Computes polynomial exact quotient of ``f`` by ``g``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**2 - 1, x).exquo(Poly(x - 1, x))\n", + " Poly(x + 1, x, domain='ZZ')\n", + "\n", + " >>> Poly(x**2 + 1, x).exquo(Poly(2*x - 4, x))\n", + " Traceback (most recent call last):\n", + " ...\n", + " ExactQuotientFailed: 2*x - 4 does not divide x**2 + 1\n", + "\n", + " \"\"\"\n", + " dom, per, F, G = f._unify(g)\n", + " retract = False\n", + "\n", + " if auto and dom.is_Ring and not dom.is_Field:\n", + " F, G = F.to_field(), G.to_field()\n", + " retract = True\n", + "\n", + " if hasattr(f.rep, 'exquo'):\n", + " try:\n", + " q = F.exquo(G)\n", + " except ExactQuotientFailed as exc:\n", + " raise exc.new(f.as_expr(), g.as_expr())\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'exquo')\n", + "\n", + " if retract:\n", + " try:\n", + " q = q.to_ring()\n", + " except CoercionFailed:\n", + " pass\n", + "\n", + " return per(q)\n", + "\n", + " def _gen_to_level(f, gen):\n", + " \"\"\"Returns level associated with the given generator. \"\"\"\n", + " if isinstance(gen, int):\n", + " length = len(f.gens)\n", + "\n", + " if -length <= gen < length:\n", + " if gen < 0:\n", + " return length + gen\n", + " else:\n", + " return gen\n", + " else:\n", + " raise PolynomialError(\"-%s <= gen < %s expected, got %s\" %\n", + " (length, length, gen))\n", + " else:\n", + " try:\n", + " return f.gens.index(sympify(gen))\n", + " except ValueError:\n", + " raise PolynomialError(\n", + " \"a valid generator expected, got %s\" % gen)\n", + "\n", + " def degree(f, gen=0):\n", + " \"\"\"\n", + " Returns degree of ``f`` in ``x_j``.\n", + "\n", + " The degree of 0 is negative infinity.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y\n", + "\n", + " >>> Poly(x**2 + y*x + 1, x, y).degree()\n", + " 2\n", + " >>> Poly(x**2 + y*x + y, x, y).degree(y)\n", + " 1\n", + " >>> Poly(0, x).degree()\n", + " -oo\n", + "\n", + " \"\"\"\n", + " j = f._gen_to_level(gen)\n", + "\n", + " if hasattr(f.rep, 'degree'):\n", + " return f.rep.degree(j)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'degree')\n", + "\n", + " def degree_list(f):\n", + " \"\"\"\n", + " Returns a list of degrees of ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y\n", + "\n", + " >>> Poly(x**2 + y*x + 1, x, y).degree_list()\n", + " (2, 1)\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'degree_list'):\n", + " return f.rep.degree_list()\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'degree_list')\n", + "\n", + " def total_degree(f):\n", + " \"\"\"\n", + " Returns the total degree of ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y\n", + "\n", + " >>> Poly(x**2 + y*x + 1, x, y).total_degree()\n", + " 2\n", + " >>> Poly(x + y**5, x, y).total_degree()\n", + " 5\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'total_degree'):\n", + " return f.rep.total_degree()\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'total_degree')\n", + "\n", + " def homogenize(f, s):\n", + " \"\"\"\n", + " Returns the homogeneous polynomial of ``f``.\n", + "\n", + " A homogeneous polynomial is a polynomial whose all monomials with\n", + " non-zero coefficients have the same total degree. If you only\n", + " want to check if a polynomial is homogeneous, then use\n", + " :func:`Poly.is_homogeneous`. If you want not only to check if a\n", + " polynomial is homogeneous but also compute its homogeneous order,\n", + " then use :func:`Poly.homogeneous_order`.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y, z\n", + "\n", + " >>> f = Poly(x**5 + 2*x**2*y**2 + 9*x*y**3)\n", + " >>> f.homogenize(z)\n", + " Poly(x**5 + 2*x**2*y**2*z + 9*x*y**3*z, x, y, z, domain='ZZ')\n", + "\n", + " \"\"\"\n", + " if not isinstance(s, Symbol):\n", + " raise TypeError(\"``Symbol`` expected, got %s\" % type(s))\n", + " if s in f.gens:\n", + " i = f.gens.index(s)\n", + " gens = f.gens\n", + " else:\n", + " i = len(f.gens)\n", + " gens = f.gens + (s,)\n", + " if hasattr(f.rep, 'homogenize'):\n", + " return f.per(f.rep.homogenize(i), gens=gens)\n", + " raise OperationNotSupported(f, 'homogeneous_order')\n", + "\n", + " def homogeneous_order(f):\n", + " \"\"\"\n", + " Returns the homogeneous order of ``f``.\n", + "\n", + " A homogeneous polynomial is a polynomial whose all monomials with\n", + " non-zero coefficients have the same total degree. This degree is\n", + " the homogeneous order of ``f``. If you only want to check if a\n", + " polynomial is homogeneous, then use :func:`Poly.is_homogeneous`.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y\n", + "\n", + " >>> f = Poly(x**5 + 2*x**3*y**2 + 9*x*y**4)\n", + " >>> f.homogeneous_order()\n", + " 5\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'homogeneous_order'):\n", + " return f.rep.homogeneous_order()\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'homogeneous_order')\n", + "\n", + " def LC(f, order=None):\n", + " \"\"\"\n", + " Returns the leading coefficient of ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(4*x**3 + 2*x**2 + 3*x, x).LC()\n", + " 4\n", + "\n", + " \"\"\"\n", + " if order is not None:\n", + " return f.coeffs(order)[0]\n", + "\n", + " if hasattr(f.rep, 'LC'):\n", + " result = f.rep.LC()\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'LC')\n", + "\n", + " return f.rep.dom.to_sympy(result)\n", + "\n", + " def TC(f):\n", + " \"\"\"\n", + " Returns the trailing coefficient of ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**3 + 2*x**2 + 3*x, x).TC()\n", + " 0\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'TC'):\n", + " result = f.rep.TC()\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'TC')\n", + "\n", + " return f.rep.dom.to_sympy(result)\n", + "\n", + " def EC(f, order=None):\n", + " \"\"\"\n", + " Returns the last non-zero coefficient of ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**3 + 2*x**2 + 3*x, x).EC()\n", + " 3\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'coeffs'):\n", + " return f.coeffs(order)[-1]\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'EC')\n", + "\n", + " def coeff_monomial(f, monom):\n", + " \"\"\"\n", + " Returns the coefficient of ``monom`` in ``f`` if there, else None.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly, exp\n", + " >>> from sympy.abc import x, y\n", + "\n", + " >>> p = Poly(24*x*y*exp(8) + 23*x, x, y)\n", + "\n", + " >>> p.coeff_monomial(x)\n", + " 23\n", + " >>> p.coeff_monomial(y)\n", + " 0\n", + " >>> p.coeff_monomial(x*y)\n", + " 24*exp(8)\n", + "\n", + " Note that ``Expr.coeff()`` behaves differently, collecting terms\n", + " if possible; the Poly must be converted to an Expr to use that\n", + " method, however:\n", + "\n", + " >>> p.as_expr().coeff(x)\n", + " 24*y*exp(8) + 23\n", + " >>> p.as_expr().coeff(y)\n", + " 24*x*exp(8)\n", + " >>> p.as_expr().coeff(x*y)\n", + " 24*exp(8)\n", + "\n", + " See Also\n", + " ========\n", + " nth: more efficient query using exponents of the monomial's generators\n", + "\n", + " \"\"\"\n", + " return f.nth(*Monomial(monom, f.gens).exponents)\n", + "\n", + " def nth(f, *N):\n", + " \"\"\"\n", + " Returns the ``n``-th coefficient of ``f`` where ``N`` are the\n", + " exponents of the generators in the term of interest.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly, sqrt\n", + " >>> from sympy.abc import x, y\n", + "\n", + " >>> Poly(x**3 + 2*x**2 + 3*x, x).nth(2)\n", + " 2\n", + " >>> Poly(x**3 + 2*x*y**2 + y**2, x, y).nth(1, 2)\n", + " 2\n", + " >>> Poly(4*sqrt(x)*y)\n", + " Poly(4*y*(sqrt(x)), y, sqrt(x), domain='ZZ')\n", + " >>> _.nth(1, 1)\n", + " 4\n", + "\n", + " See Also\n", + " ========\n", + " coeff_monomial\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'nth'):\n", + " if len(N) != len(f.gens):\n", + " raise ValueError('exponent of each generator must be specified')\n", + " result = f.rep.nth(*list(map(int, N)))\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'nth')\n", + "\n", + " return f.rep.dom.to_sympy(result)\n", + "\n", + " def coeff(f, x, n=1, right=False):\n", + " # the semantics of coeff_monomial and Expr.coeff are different;\n", + " # if someone is working with a Poly, they should be aware of the\n", + " # differences and chose the method best suited for the query.\n", + " # Alternatively, a pure-polys method could be written here but\n", + " # at this time the ``right`` keyword would be ignored because Poly\n", + " # doesn't work with non-commutatives.\n", + " raise NotImplementedError(\n", + " 'Either convert to Expr with `as_expr` method '\n", + " 'to use Expr\\'s coeff method or else use the '\n", + " '`coeff_monomial` method of Polys.')\n", + "\n", + " def LM(f, order=None):\n", + " \"\"\"\n", + " Returns the leading monomial of ``f``.\n", + "\n", + " The Leading monomial signifies the monomial having\n", + " the highest power of the principal generator in the\n", + " expression f.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y\n", + "\n", + " >>> Poly(4*x**2 + 2*x*y**2 + x*y + 3*y, x, y).LM()\n", + " x**2*y**0\n", + "\n", + " \"\"\"\n", + " return Monomial(f.monoms(order)[0], f.gens)\n", + "\n", + " def EM(f, order=None):\n", + " \"\"\"\n", + " Returns the last non-zero monomial of ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y\n", + "\n", + " >>> Poly(4*x**2 + 2*x*y**2 + x*y + 3*y, x, y).EM()\n", + " x**0*y**1\n", + "\n", + " \"\"\"\n", + " return Monomial(f.monoms(order)[-1], f.gens)\n", + "\n", + " def LT(f, order=None):\n", + " \"\"\"\n", + " Returns the leading term of ``f``.\n", + "\n", + " The Leading term signifies the term having\n", + " the highest power of the principal generator in the\n", + " expression f along with its coefficient.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y\n", + "\n", + " >>> Poly(4*x**2 + 2*x*y**2 + x*y + 3*y, x, y).LT()\n", + " (x**2*y**0, 4)\n", + "\n", + " \"\"\"\n", + " monom, coeff = f.terms(order)[0]\n", + " return Monomial(monom, f.gens), coeff\n", + "\n", + " def ET(f, order=None):\n", + " \"\"\"\n", + " Returns the last non-zero term of ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y\n", + "\n", + " >>> Poly(4*x**2 + 2*x*y**2 + x*y + 3*y, x, y).ET()\n", + " (x**0*y**1, 3)\n", + "\n", + " \"\"\"\n", + " monom, coeff = f.terms(order)[-1]\n", + " return Monomial(monom, f.gens), coeff\n", + "\n", + " def max_norm(f):\n", + " \"\"\"\n", + " Returns maximum norm of ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(-x**2 + 2*x - 3, x).max_norm()\n", + " 3\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'max_norm'):\n", + " result = f.rep.max_norm()\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'max_norm')\n", + "\n", + " return f.rep.dom.to_sympy(result)\n", + "\n", + " def l1_norm(f):\n", + " \"\"\"\n", + " Returns l1 norm of ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(-x**2 + 2*x - 3, x).l1_norm()\n", + " 6\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'l1_norm'):\n", + " result = f.rep.l1_norm()\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'l1_norm')\n", + "\n", + " return f.rep.dom.to_sympy(result)\n", + "\n", + " def clear_denoms(self, convert=False):\n", + " \"\"\"\n", + " Clear denominators, but keep the ground domain.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly, S, QQ\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> f = Poly(x/2 + S(1)/3, x, domain=QQ)\n", + "\n", + " >>> f.clear_denoms()\n", + " (6, Poly(3*x + 2, x, domain='QQ'))\n", + " >>> f.clear_denoms(convert=True)\n", + " (6, Poly(3*x + 2, x, domain='ZZ'))\n", + "\n", + " \"\"\"\n", + " f = self\n", + "\n", + " if not f.rep.dom.is_Field:\n", + " return S.One, f\n", + "\n", + " dom = f.get_domain()\n", + " if dom.has_assoc_Ring:\n", + " dom = f.rep.dom.get_ring()\n", + "\n", + " if hasattr(f.rep, 'clear_denoms'):\n", + " coeff, result = f.rep.clear_denoms()\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'clear_denoms')\n", + "\n", + " coeff, f = dom.to_sympy(coeff), f.per(result)\n", + "\n", + " if not convert or not dom.has_assoc_Ring:\n", + " return coeff, f\n", + " else:\n", + " return coeff, f.to_ring()\n", + "\n", + " def rat_clear_denoms(self, g):\n", + " \"\"\"\n", + " Clear denominators in a rational function ``f/g``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y\n", + "\n", + " >>> f = Poly(x**2/y + 1, x)\n", + " >>> g = Poly(x**3 + y, x)\n", + "\n", + " >>> p, q = f.rat_clear_denoms(g)\n", + "\n", + " >>> p\n", + " Poly(x**2 + y, x, domain='ZZ[y]')\n", + " >>> q\n", + " Poly(y*x**3 + y**2, x, domain='ZZ[y]')\n", + "\n", + " \"\"\"\n", + " f = self\n", + "\n", + " dom, per, f, g = f._unify(g)\n", + "\n", + " f = per(f)\n", + " g = per(g)\n", + "\n", + " if not (dom.is_Field and dom.has_assoc_Ring):\n", + " return f, g\n", + "\n", + " a, f = f.clear_denoms(convert=True)\n", + " b, g = g.clear_denoms(convert=True)\n", + "\n", + " f = f.mul_ground(b)\n", + " g = g.mul_ground(a)\n", + "\n", + " return f, g\n", + "\n", + " def integrate(self, *specs, **args):\n", + " \"\"\"\n", + " Computes indefinite integral of ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y\n", + "\n", + " >>> Poly(x**2 + 2*x + 1, x).integrate()\n", + " Poly(1/3*x**3 + x**2 + x, x, domain='QQ')\n", + "\n", + " >>> Poly(x*y**2 + x, x, y).integrate((0, 1), (1, 0))\n", + " Poly(1/2*x**2*y**2 + 1/2*x**2, x, y, domain='QQ')\n", + "\n", + " \"\"\"\n", + " f = self\n", + "\n", + " if args.get('auto', True) and f.rep.dom.is_Ring:\n", + " f = f.to_field()\n", + "\n", + " if hasattr(f.rep, 'integrate'):\n", + " if not specs:\n", + " return f.per(f.rep.integrate(m=1))\n", + "\n", + " rep = f.rep\n", + "\n", + " for spec in specs:\n", + " if type(spec) is tuple:\n", + " gen, m = spec\n", + " else:\n", + " gen, m = spec, 1\n", + "\n", + " rep = rep.integrate(int(m), f._gen_to_level(gen))\n", + "\n", + " return f.per(rep)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'integrate')\n", + "\n", + " def diff(f, *specs, **kwargs):\n", + " \"\"\"\n", + " Computes partial derivative of ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y\n", + "\n", + " >>> Poly(x**2 + 2*x + 1, x).diff()\n", + " Poly(2*x + 2, x, domain='ZZ')\n", + "\n", + " >>> Poly(x*y**2 + x, x, y).diff((0, 0), (1, 1))\n", + " Poly(2*x*y, x, y, domain='ZZ')\n", + "\n", + " \"\"\"\n", + " if not kwargs.get('evaluate', True):\n", + " return Derivative(f, *specs, **kwargs)\n", + "\n", + " if hasattr(f.rep, 'diff'):\n", + " if not specs:\n", + " return f.per(f.rep.diff(m=1))\n", + "\n", + " rep = f.rep\n", + "\n", + " for spec in specs:\n", + " if type(spec) is tuple:\n", + " gen, m = spec\n", + " else:\n", + " gen, m = spec, 1\n", + "\n", + " rep = rep.diff(int(m), f._gen_to_level(gen))\n", + "\n", + " return f.per(rep)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'diff')\n", + "\n", + " _eval_derivative = diff\n", + "\n", + " def eval(self, x, a=None, auto=True):\n", + " \"\"\"\n", + " Evaluate ``f`` at ``a`` in the given variable.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y, z\n", + "\n", + " >>> Poly(x**2 + 2*x + 3, x).eval(2)\n", + " 11\n", + "\n", + " >>> Poly(2*x*y + 3*x + y + 2, x, y).eval(x, 2)\n", + " Poly(5*y + 8, y, domain='ZZ')\n", + "\n", + " >>> f = Poly(2*x*y + 3*x + y + 2*z, x, y, z)\n", + "\n", + " >>> f.eval({x: 2})\n", + " Poly(5*y + 2*z + 6, y, z, domain='ZZ')\n", + " >>> f.eval({x: 2, y: 5})\n", + " Poly(2*z + 31, z, domain='ZZ')\n", + " >>> f.eval({x: 2, y: 5, z: 7})\n", + " 45\n", + "\n", + " >>> f.eval((2, 5))\n", + " Poly(2*z + 31, z, domain='ZZ')\n", + " >>> f(2, 5)\n", + " Poly(2*z + 31, z, domain='ZZ')\n", + "\n", + " \"\"\"\n", + " f = self\n", + "\n", + " if a is None:\n", + " if isinstance(x, dict):\n", + " mapping = x\n", + "\n", + " for gen, value in mapping.items():\n", + " f = f.eval(gen, value)\n", + "\n", + " return f\n", + " elif isinstance(x, (tuple, list)):\n", + " values = x\n", + "\n", + " if len(values) > len(f.gens):\n", + " raise ValueError(\"too many values provided\")\n", + "\n", + " for gen, value in zip(f.gens, values):\n", + " f = f.eval(gen, value)\n", + "\n", + " return f\n", + " else:\n", + " j, a = 0, x\n", + " else:\n", + " j = f._gen_to_level(x)\n", + "\n", + " if not hasattr(f.rep, 'eval'): # pragma: no cover\n", + " raise OperationNotSupported(f, 'eval')\n", + "\n", + " try:\n", + " result = f.rep.eval(a, j)\n", + " except CoercionFailed:\n", + " if not auto:\n", + " raise DomainError(\"can't evaluate at %s in %s\" % (a, f.rep.dom))\n", + " else:\n", + " a_domain, [a] = construct_domain([a])\n", + " new_domain = f.get_domain().unify_with_symbols(a_domain, f.gens)\n", + "\n", + " f = f.set_domain(new_domain)\n", + " a = new_domain.convert(a, a_domain)\n", + "\n", + " result = f.rep.eval(a, j)\n", + "\n", + " return f.per(result, remove=j)\n", + "\n", + " def __call__(f, *values):\n", + " \"\"\"\n", + " Evaluate ``f`` at the give values.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y, z\n", + "\n", + " >>> f = Poly(2*x*y + 3*x + y + 2*z, x, y, z)\n", + "\n", + " >>> f(2)\n", + " Poly(5*y + 2*z + 6, y, z, domain='ZZ')\n", + " >>> f(2, 5)\n", + " Poly(2*z + 31, z, domain='ZZ')\n", + " >>> f(2, 5, 7)\n", + " 45\n", + "\n", + " \"\"\"\n", + " return f.eval(values)\n", + "\n", + " def half_gcdex(f, g, auto=True):\n", + " \"\"\"\n", + " Half extended Euclidean algorithm of ``f`` and ``g``.\n", + "\n", + " Returns ``(s, h)`` such that ``h = gcd(f, g)`` and ``s*f = h (mod g)``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> f = x**4 - 2*x**3 - 6*x**2 + 12*x + 15\n", + " >>> g = x**3 + x**2 - 4*x - 4\n", + "\n", + " >>> Poly(f).half_gcdex(Poly(g))\n", + " (Poly(-1/5*x + 3/5, x, domain='QQ'), Poly(x + 1, x, domain='QQ'))\n", + "\n", + " \"\"\"\n", + " dom, per, F, G = f._unify(g)\n", + "\n", + " if auto and dom.is_Ring:\n", + " F, G = F.to_field(), G.to_field()\n", + "\n", + " if hasattr(f.rep, 'half_gcdex'):\n", + " s, h = F.half_gcdex(G)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'half_gcdex')\n", + "\n", + " return per(s), per(h)\n", + "\n", + " def gcdex(f, g, auto=True):\n", + " \"\"\"\n", + " Extended Euclidean algorithm of ``f`` and ``g``.\n", + "\n", + " Returns ``(s, t, h)`` such that ``h = gcd(f, g)`` and ``s*f + t*g = h``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> f = x**4 - 2*x**3 - 6*x**2 + 12*x + 15\n", + " >>> g = x**3 + x**2 - 4*x - 4\n", + "\n", + " >>> Poly(f).gcdex(Poly(g))\n", + " (Poly(-1/5*x + 3/5, x, domain='QQ'),\n", + " Poly(1/5*x**2 - 6/5*x + 2, x, domain='QQ'),\n", + " Poly(x + 1, x, domain='QQ'))\n", + "\n", + " \"\"\"\n", + " dom, per, F, G = f._unify(g)\n", + "\n", + " if auto and dom.is_Ring:\n", + " F, G = F.to_field(), G.to_field()\n", + "\n", + " if hasattr(f.rep, 'gcdex'):\n", + " s, t, h = F.gcdex(G)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'gcdex')\n", + "\n", + " return per(s), per(t), per(h)\n", + "\n", + " def invert(f, g, auto=True):\n", + " \"\"\"\n", + " Invert ``f`` modulo ``g`` when possible.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**2 - 1, x).invert(Poly(2*x - 1, x))\n", + " Poly(-4/3, x, domain='QQ')\n", + "\n", + " >>> Poly(x**2 - 1, x).invert(Poly(x - 1, x))\n", + " Traceback (most recent call last):\n", + " ...\n", + " NotInvertible: zero divisor\n", + "\n", + " \"\"\"\n", + " dom, per, F, G = f._unify(g)\n", + "\n", + " if auto and dom.is_Ring:\n", + " F, G = F.to_field(), G.to_field()\n", + "\n", + " if hasattr(f.rep, 'invert'):\n", + " result = F.invert(G)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'invert')\n", + "\n", + " return per(result)\n", + "\n", + " def revert(f, n):\n", + " \"\"\"\n", + " Compute ``f**(-1)`` mod ``x**n``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(1, x).revert(2)\n", + " Poly(1, x, domain='ZZ')\n", + "\n", + " >>> Poly(1 + x, x).revert(1)\n", + " Poly(1, x, domain='ZZ')\n", + "\n", + " >>> Poly(x**2 - 1, x).revert(1)\n", + " Traceback (most recent call last):\n", + " ...\n", + " NotReversible: only unity is reversible in a ring\n", + "\n", + " >>> Poly(1/x, x).revert(1)\n", + " Traceback (most recent call last):\n", + " ...\n", + " PolynomialError: 1/x contains an element of the generators set\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'revert'):\n", + " result = f.rep.revert(int(n))\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'revert')\n", + "\n", + " return f.per(result)\n", + "\n", + " def subresultants(f, g):\n", + " \"\"\"\n", + " Computes the subresultant PRS of ``f`` and ``g``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**2 + 1, x).subresultants(Poly(x**2 - 1, x))\n", + " [Poly(x**2 + 1, x, domain='ZZ'),\n", + " Poly(x**2 - 1, x, domain='ZZ'),\n", + " Poly(-2, x, domain='ZZ')]\n", + "\n", + " \"\"\"\n", + " _, per, F, G = f._unify(g)\n", + "\n", + " if hasattr(f.rep, 'subresultants'):\n", + " result = F.subresultants(G)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'subresultants')\n", + "\n", + " return list(map(per, result))\n", + "\n", + " def resultant(f, g, includePRS=False):\n", + " \"\"\"\n", + " Computes the resultant of ``f`` and ``g`` via PRS.\n", + "\n", + " If includePRS=True, it includes the subresultant PRS in the result.\n", + " Because the PRS is used to calculate the resultant, this is more\n", + " efficient than calling :func:`subresultants` separately.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> f = Poly(x**2 + 1, x)\n", + "\n", + " >>> f.resultant(Poly(x**2 - 1, x))\n", + " 4\n", + " >>> f.resultant(Poly(x**2 - 1, x), includePRS=True)\n", + " (4, [Poly(x**2 + 1, x, domain='ZZ'), Poly(x**2 - 1, x, domain='ZZ'),\n", + " Poly(-2, x, domain='ZZ')])\n", + "\n", + " \"\"\"\n", + " _, per, F, G = f._unify(g)\n", + "\n", + " if hasattr(f.rep, 'resultant'):\n", + " if includePRS:\n", + " result, R = F.resultant(G, includePRS=includePRS)\n", + " else:\n", + " result = F.resultant(G)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'resultant')\n", + "\n", + " if includePRS:\n", + " return (per(result, remove=0), list(map(per, R)))\n", + " return per(result, remove=0)\n", + "\n", + " def discriminant(f):\n", + " \"\"\"\n", + " Computes the discriminant of ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**2 + 2*x + 3, x).discriminant()\n", + " -8\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'discriminant'):\n", + " result = f.rep.discriminant()\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'discriminant')\n", + "\n", + " return f.per(result, remove=0)\n", + "\n", + " def dispersionset(f, g=None):\n", + " r\"\"\"Compute the *dispersion set* of two polynomials.\n", + "\n", + " For two polynomials `f(x)` and `g(x)` with `\\deg f > 0`\n", + " and `\\deg g > 0` the dispersion set `\\operatorname{J}(f, g)` is defined as:\n", + "\n", + " .. math::\n", + " \\operatorname{J}(f, g)\n", + " & := \\{a \\in \\mathbb{N}_0 | \\gcd(f(x), g(x+a)) \\neq 1\\} \\\\\n", + " & = \\{a \\in \\mathbb{N}_0 | \\deg \\gcd(f(x), g(x+a)) \\geq 1\\}\n", + "\n", + " For a single polynomial one defines `\\operatorname{J}(f) := \\operatorname{J}(f, f)`.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import poly\n", + " >>> from sympy.polys.dispersion import dispersion, dispersionset\n", + " >>> from sympy.abc import x\n", + "\n", + " Dispersion set and dispersion of a simple polynomial:\n", + "\n", + " >>> fp = poly((x - 3)*(x + 3), x)\n", + " >>> sorted(dispersionset(fp))\n", + " [0, 6]\n", + " >>> dispersion(fp)\n", + " 6\n", + "\n", + " Note that the definition of the dispersion is not symmetric:\n", + "\n", + " >>> fp = poly(x**4 - 3*x**2 + 1, x)\n", + " >>> gp = fp.shift(-3)\n", + " >>> sorted(dispersionset(fp, gp))\n", + " [2, 3, 4]\n", + " >>> dispersion(fp, gp)\n", + " 4\n", + " >>> sorted(dispersionset(gp, fp))\n", + " []\n", + " >>> dispersion(gp, fp)\n", + " -oo\n", + "\n", + " Computing the dispersion also works over field extensions:\n", + "\n", + " >>> from sympy import sqrt\n", + " >>> fp = poly(x**2 + sqrt(5)*x - 1, x, domain='QQ')\n", + " >>> gp = poly(x**2 + (2 + sqrt(5))*x + sqrt(5), x, domain='QQ')\n", + " >>> sorted(dispersionset(fp, gp))\n", + " [2]\n", + " >>> sorted(dispersionset(gp, fp))\n", + " [1, 4]\n", + "\n", + " We can even perform the computations for polynomials\n", + " having symbolic coefficients:\n", + "\n", + " >>> from sympy.abc import a\n", + " >>> fp = poly(4*x**4 + (4*a + 8)*x**3 + (a**2 + 6*a + 4)*x**2 + (a**2 + 2*a)*x, x)\n", + " >>> sorted(dispersionset(fp))\n", + " [0, 1]\n", + "\n", + " See Also\n", + " ========\n", + "\n", + " dispersion\n", + "\n", + " References\n", + " ==========\n", + "\n", + " 1. [ManWright94]_\n", + " 2. [Koepf98]_\n", + " 3. [Abramov71]_\n", + " 4. [Man93]_\n", + " \"\"\"\n", + " from sympy.polys.dispersion import dispersionset\n", + " return dispersionset(f, g)\n", + "\n", + " def dispersion(f, g=None):\n", + " r\"\"\"Compute the *dispersion* of polynomials.\n", + "\n", + " For two polynomials `f(x)` and `g(x)` with `\\deg f > 0`\n", + " and `\\deg g > 0` the dispersion `\\operatorname{dis}(f, g)` is defined as:\n", + "\n", + " .. math::\n", + " \\operatorname{dis}(f, g)\n", + " & := \\max\\{ J(f,g) \\cup \\{0\\} \\} \\\\\n", + " & = \\max\\{ \\{a \\in \\mathbb{N} | \\gcd(f(x), g(x+a)) \\neq 1\\} \\cup \\{0\\} \\}\n", + "\n", + " and for a single polynomial `\\operatorname{dis}(f) := \\operatorname{dis}(f, f)`.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import poly\n", + " >>> from sympy.polys.dispersion import dispersion, dispersionset\n", + " >>> from sympy.abc import x\n", + "\n", + " Dispersion set and dispersion of a simple polynomial:\n", + "\n", + " >>> fp = poly((x - 3)*(x + 3), x)\n", + " >>> sorted(dispersionset(fp))\n", + " [0, 6]\n", + " >>> dispersion(fp)\n", + " 6\n", + "\n", + " Note that the definition of the dispersion is not symmetric:\n", + "\n", + " >>> fp = poly(x**4 - 3*x**2 + 1, x)\n", + " >>> gp = fp.shift(-3)\n", + " >>> sorted(dispersionset(fp, gp))\n", + " [2, 3, 4]\n", + " >>> dispersion(fp, gp)\n", + " 4\n", + " >>> sorted(dispersionset(gp, fp))\n", + " []\n", + " >>> dispersion(gp, fp)\n", + " -oo\n", + "\n", + " Computing the dispersion also works over field extensions:\n", + "\n", + " >>> from sympy import sqrt\n", + " >>> fp = poly(x**2 + sqrt(5)*x - 1, x, domain='QQ')\n", + " >>> gp = poly(x**2 + (2 + sqrt(5))*x + sqrt(5), x, domain='QQ')\n", + " >>> sorted(dispersionset(fp, gp))\n", + " [2]\n", + " >>> sorted(dispersionset(gp, fp))\n", + " [1, 4]\n", + "\n", + " We can even perform the computations for polynomials\n", + " having symbolic coefficients:\n", + "\n", + " >>> from sympy.abc import a\n", + " >>> fp = poly(4*x**4 + (4*a + 8)*x**3 + (a**2 + 6*a + 4)*x**2 + (a**2 + 2*a)*x, x)\n", + " >>> sorted(dispersionset(fp))\n", + " [0, 1]\n", + "\n", + " See Also\n", + " ========\n", + "\n", + " dispersionset\n", + "\n", + " References\n", + " ==========\n", + "\n", + " 1. [ManWright94]_\n", + " 2. [Koepf98]_\n", + " 3. [Abramov71]_\n", + " 4. [Man93]_\n", + " \"\"\"\n", + " from sympy.polys.dispersion import dispersion\n", + " return dispersion(f, g)\n", + "\n", + " def cofactors(f, g):\n", + " \"\"\"\n", + " Returns the GCD of ``f`` and ``g`` and their cofactors.\n", + "\n", + " Returns polynomials ``(h, cff, cfg)`` such that ``h = gcd(f, g)``, and\n", + " ``cff = quo(f, h)`` and ``cfg = quo(g, h)`` are, so called, cofactors\n", + " of ``f`` and ``g``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**2 - 1, x).cofactors(Poly(x**2 - 3*x + 2, x))\n", + " (Poly(x - 1, x, domain='ZZ'),\n", + " Poly(x + 1, x, domain='ZZ'),\n", + " Poly(x - 2, x, domain='ZZ'))\n", + "\n", + " \"\"\"\n", + " _, per, F, G = f._unify(g)\n", + "\n", + " if hasattr(f.rep, 'cofactors'):\n", + " h, cff, cfg = F.cofactors(G)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'cofactors')\n", + "\n", + " return per(h), per(cff), per(cfg)\n", + "\n", + " def gcd(f, g):\n", + " \"\"\"\n", + " Returns the polynomial GCD of ``f`` and ``g``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**2 - 1, x).gcd(Poly(x**2 - 3*x + 2, x))\n", + " Poly(x - 1, x, domain='ZZ')\n", + "\n", + " \"\"\"\n", + " _, per, F, G = f._unify(g)\n", + "\n", + " if hasattr(f.rep, 'gcd'):\n", + " result = F.gcd(G)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'gcd')\n", + "\n", + " return per(result)\n", + "\n", + " def lcm(f, g):\n", + " \"\"\"\n", + " Returns polynomial LCM of ``f`` and ``g``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**2 - 1, x).lcm(Poly(x**2 - 3*x + 2, x))\n", + " Poly(x**3 - 2*x**2 - x + 2, x, domain='ZZ')\n", + "\n", + " \"\"\"\n", + " _, per, F, G = f._unify(g)\n", + "\n", + " if hasattr(f.rep, 'lcm'):\n", + " result = F.lcm(G)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'lcm')\n", + "\n", + " return per(result)\n", + "\n", + " def trunc(f, p):\n", + " \"\"\"\n", + " Reduce ``f`` modulo a constant ``p``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(2*x**3 + 3*x**2 + 5*x + 7, x).trunc(3)\n", + " Poly(-x**3 - x + 1, x, domain='ZZ')\n", + "\n", + " \"\"\"\n", + " p = f.rep.dom.convert(p)\n", + "\n", + " if hasattr(f.rep, 'trunc'):\n", + " result = f.rep.trunc(p)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'trunc')\n", + "\n", + " return f.per(result)\n", + "\n", + " def monic(self, auto=True):\n", + " \"\"\"\n", + " Divides all coefficients by ``LC(f)``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly, ZZ\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(3*x**2 + 6*x + 9, x, domain=ZZ).monic()\n", + " Poly(x**2 + 2*x + 3, x, domain='QQ')\n", + "\n", + " >>> Poly(3*x**2 + 4*x + 2, x, domain=ZZ).monic()\n", + " Poly(x**2 + 4/3*x + 2/3, x, domain='QQ')\n", + "\n", + " \"\"\"\n", + " f = self\n", + "\n", + " if auto and f.rep.dom.is_Ring:\n", + " f = f.to_field()\n", + "\n", + " if hasattr(f.rep, 'monic'):\n", + " result = f.rep.monic()\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'monic')\n", + "\n", + " return f.per(result)\n", + "\n", + " def content(f):\n", + " \"\"\"\n", + " Returns the GCD of polynomial coefficients.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(6*x**2 + 8*x + 12, x).content()\n", + " 2\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'content'):\n", + " result = f.rep.content()\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'content')\n", + "\n", + " return f.rep.dom.to_sympy(result)\n", + "\n", + " def primitive(f):\n", + " \"\"\"\n", + " Returns the content and a primitive form of ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(2*x**2 + 8*x + 12, x).primitive()\n", + " (2, Poly(x**2 + 4*x + 6, x, domain='ZZ'))\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'primitive'):\n", + " cont, result = f.rep.primitive()\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'primitive')\n", + "\n", + " return f.rep.dom.to_sympy(cont), f.per(result)\n", + "\n", + " def compose(f, g):\n", + " \"\"\"\n", + " Computes the functional composition of ``f`` and ``g``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**2 + x, x).compose(Poly(x - 1, x))\n", + " Poly(x**2 - x, x, domain='ZZ')\n", + "\n", + " \"\"\"\n", + " _, per, F, G = f._unify(g)\n", + "\n", + " if hasattr(f.rep, 'compose'):\n", + " result = F.compose(G)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'compose')\n", + "\n", + " return per(result)\n", + "\n", + " def decompose(f):\n", + " \"\"\"\n", + " Computes a functional decomposition of ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**4 + 2*x**3 - x - 1, x, domain='ZZ').decompose()\n", + " [Poly(x**2 - x - 1, x, domain='ZZ'), Poly(x**2 + x, x, domain='ZZ')]\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'decompose'):\n", + " result = f.rep.decompose()\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'decompose')\n", + "\n", + " return list(map(f.per, result))\n", + "\n", + " def shift(f, a):\n", + " \"\"\"\n", + " Efficiently compute Taylor shift ``f(x + a)``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**2 - 2*x + 1, x).shift(2)\n", + " Poly(x**2 + 2*x + 1, x, domain='ZZ')\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'shift'):\n", + " result = f.rep.shift(a)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'shift')\n", + "\n", + " return f.per(result)\n", + "\n", + " def transform(f, p, q):\n", + " \"\"\"\n", + " Efficiently evaluate the functional transformation ``q**n * f(p/q)``.\n", + "\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**2 - 2*x + 1, x).transform(Poly(x + 1, x), Poly(x - 1, x))\n", + " Poly(4, x, domain='ZZ')\n", + "\n", + " \"\"\"\n", + " P, Q = p.unify(q)\n", + " F, P = f.unify(P)\n", + " F, Q = F.unify(Q)\n", + "\n", + " if hasattr(F.rep, 'transform'):\n", + " result = F.rep.transform(P.rep, Q.rep)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(F, 'transform')\n", + "\n", + " return F.per(result)\n", + "\n", + " def sturm(self, auto=True):\n", + " \"\"\"\n", + " Computes the Sturm sequence of ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**3 - 2*x**2 + x - 3, x).sturm()\n", + " [Poly(x**3 - 2*x**2 + x - 3, x, domain='QQ'),\n", + " Poly(3*x**2 - 4*x + 1, x, domain='QQ'),\n", + " Poly(2/9*x + 25/9, x, domain='QQ'),\n", + " Poly(-2079/4, x, domain='QQ')]\n", + "\n", + " \"\"\"\n", + " f = self\n", + "\n", + " if auto and f.rep.dom.is_Ring:\n", + " f = f.to_field()\n", + "\n", + " if hasattr(f.rep, 'sturm'):\n", + " result = f.rep.sturm()\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'sturm')\n", + "\n", + " return list(map(f.per, result))\n", + "\n", + " def gff_list(f):\n", + " \"\"\"\n", + " Computes greatest factorial factorization of ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> f = x**5 + 2*x**4 - x**3 - 2*x**2\n", + "\n", + " >>> Poly(f).gff_list()\n", + " [(Poly(x, x, domain='ZZ'), 1), (Poly(x + 2, x, domain='ZZ'), 4)]\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'gff_list'):\n", + " result = f.rep.gff_list()\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'gff_list')\n", + "\n", + " return [(f.per(g), k) for g, k in result]\n", + "\n", + " def norm(f):\n", + " \"\"\"\n", + " Computes the product, ``Norm(f)``, of the conjugates of\n", + " a polynomial ``f`` defined over a number field ``K``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly, sqrt\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> a, b = sqrt(2), sqrt(3)\n", + "\n", + " A polynomial over a quadratic extension.\n", + " Two conjugates x - a and x + a.\n", + "\n", + " >>> f = Poly(x - a, x, extension=a)\n", + " >>> f.norm()\n", + " Poly(x**2 - 2, x, domain='QQ')\n", + "\n", + " A polynomial over a quartic extension.\n", + " Four conjugates x - a, x - a, x + a and x + a.\n", + "\n", + " >>> f = Poly(x - a, x, extension=(a, b))\n", + " >>> f.norm()\n", + " Poly(x**4 - 4*x**2 + 4, x, domain='QQ')\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'norm'):\n", + " r = f.rep.norm()\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'norm')\n", + "\n", + " return f.per(r)\n", + "\n", + " def sqf_norm(f):\n", + " \"\"\"\n", + " Computes square-free norm of ``f``.\n", + "\n", + " Returns ``s``, ``f``, ``r``, such that ``g(x) = f(x-sa)`` and\n", + " ``r(x) = Norm(g(x))`` is a square-free polynomial over ``K``,\n", + " where ``a`` is the algebraic extension of the ground domain.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly, sqrt\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> s, f, r = Poly(x**2 + 1, x, extension=[sqrt(3)]).sqf_norm()\n", + "\n", + " >>> s\n", + " 1\n", + " >>> f\n", + " Poly(x**2 - 2*sqrt(3)*x + 4, x, domain='QQ')\n", + " >>> r\n", + " Poly(x**4 - 4*x**2 + 16, x, domain='QQ')\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'sqf_norm'):\n", + " s, g, r = f.rep.sqf_norm()\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'sqf_norm')\n", + "\n", + " return s, f.per(g), f.per(r)\n", + "\n", + " def sqf_part(f):\n", + " \"\"\"\n", + " Computes square-free part of ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**3 - 3*x - 2, x).sqf_part()\n", + " Poly(x**2 - x - 2, x, domain='ZZ')\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'sqf_part'):\n", + " result = f.rep.sqf_part()\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'sqf_part')\n", + "\n", + " return f.per(result)\n", + "\n", + " def sqf_list(f, all=False):\n", + " \"\"\"\n", + " Returns a list of square-free factors of ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> f = 2*x**5 + 16*x**4 + 50*x**3 + 76*x**2 + 56*x + 16\n", + "\n", + " >>> Poly(f).sqf_list()\n", + " (2, [(Poly(x + 1, x, domain='ZZ'), 2),\n", + " (Poly(x + 2, x, domain='ZZ'), 3)])\n", + "\n", + " >>> Poly(f).sqf_list(all=True)\n", + " (2, [(Poly(1, x, domain='ZZ'), 1),\n", + " (Poly(x + 1, x, domain='ZZ'), 2),\n", + " (Poly(x + 2, x, domain='ZZ'), 3)])\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'sqf_list'):\n", + " coeff, factors = f.rep.sqf_list(all)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'sqf_list')\n", + "\n", + " return f.rep.dom.to_sympy(coeff), [(f.per(g), k) for g, k in factors]\n", + "\n", + " def sqf_list_include(f, all=False):\n", + " \"\"\"\n", + " Returns a list of square-free factors of ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly, expand\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> f = expand(2*(x + 1)**3*x**4)\n", + " >>> f\n", + " 2*x**7 + 6*x**6 + 6*x**5 + 2*x**4\n", + "\n", + " >>> Poly(f).sqf_list_include()\n", + " [(Poly(2, x, domain='ZZ'), 1),\n", + " (Poly(x + 1, x, domain='ZZ'), 3),\n", + " (Poly(x, x, domain='ZZ'), 4)]\n", + "\n", + " >>> Poly(f).sqf_list_include(all=True)\n", + " [(Poly(2, x, domain='ZZ'), 1),\n", + " (Poly(1, x, domain='ZZ'), 2),\n", + " (Poly(x + 1, x, domain='ZZ'), 3),\n", + " (Poly(x, x, domain='ZZ'), 4)]\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'sqf_list_include'):\n", + " factors = f.rep.sqf_list_include(all)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'sqf_list_include')\n", + "\n", + " return [(f.per(g), k) for g, k in factors]\n", + "\n", + " def factor_list(f):\n", + " \"\"\"\n", + " Returns a list of irreducible factors of ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y\n", + "\n", + " >>> f = 2*x**5 + 2*x**4*y + 4*x**3 + 4*x**2*y + 2*x + 2*y\n", + "\n", + " >>> Poly(f).factor_list()\n", + " (2, [(Poly(x + y, x, y, domain='ZZ'), 1),\n", + " (Poly(x**2 + 1, x, y, domain='ZZ'), 2)])\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'factor_list'):\n", + " try:\n", + " coeff, factors = f.rep.factor_list()\n", + " except DomainError:\n", + " return S.One, [(f, 1)]\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'factor_list')\n", + "\n", + " return f.rep.dom.to_sympy(coeff), [(f.per(g), k) for g, k in factors]\n", + "\n", + " def factor_list_include(f):\n", + " \"\"\"\n", + " Returns a list of irreducible factors of ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y\n", + "\n", + " >>> f = 2*x**5 + 2*x**4*y + 4*x**3 + 4*x**2*y + 2*x + 2*y\n", + "\n", + " >>> Poly(f).factor_list_include()\n", + " [(Poly(2*x + 2*y, x, y, domain='ZZ'), 1),\n", + " (Poly(x**2 + 1, x, y, domain='ZZ'), 2)]\n", + "\n", + " \"\"\"\n", + " if hasattr(f.rep, 'factor_list_include'):\n", + " try:\n", + " factors = f.rep.factor_list_include()\n", + " except DomainError:\n", + " return [(f, 1)]\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'factor_list_include')\n", + "\n", + " return [(f.per(g), k) for g, k in factors]\n", + "\n", + " def intervals(f, all=False, eps=None, inf=None, sup=None, fast=False, sqf=False):\n", + " \"\"\"\n", + " Compute isolating intervals for roots of ``f``.\n", + "\n", + " For real roots the Vincent-Akritas-Strzebonski (VAS) continued fractions method is used.\n", + "\n", + " References\n", + " ==========\n", + " .. [#] Alkiviadis G. Akritas and Adam W. Strzebonski: A Comparative Study of Two Real Root\n", + " Isolation Methods . Nonlinear Analysis: Modelling and Control, Vol. 10, No. 4, 297-304, 2005.\n", + " .. [#] Alkiviadis G. Akritas, Adam W. Strzebonski and Panagiotis S. Vigklas: Improving the\n", + " Performance of the Continued Fractions Method Using new Bounds of Positive Roots. Nonlinear\n", + " Analysis: Modelling and Control, Vol. 13, No. 3, 265-279, 2008.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**2 - 3, x).intervals()\n", + " [((-2, -1), 1), ((1, 2), 1)]\n", + " >>> Poly(x**2 - 3, x).intervals(eps=1e-2)\n", + " [((-26/15, -19/11), 1), ((19/11, 26/15), 1)]\n", + "\n", + " \"\"\"\n", + " if eps is not None:\n", + " eps = QQ.convert(eps)\n", + "\n", + " if eps <= 0:\n", + " raise ValueError(\"'eps' must be a positive rational\")\n", + "\n", + " if inf is not None:\n", + " inf = QQ.convert(inf)\n", + " if sup is not None:\n", + " sup = QQ.convert(sup)\n", + "\n", + " if hasattr(f.rep, 'intervals'):\n", + " result = f.rep.intervals(\n", + " all=all, eps=eps, inf=inf, sup=sup, fast=fast, sqf=sqf)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'intervals')\n", + "\n", + " if sqf:\n", + " def _real(interval):\n", + " s, t = interval\n", + " return (QQ.to_sympy(s), QQ.to_sympy(t))\n", + "\n", + " if not all:\n", + " return list(map(_real, result))\n", + "\n", + " def _complex(rectangle):\n", + " (u, v), (s, t) = rectangle\n", + " return (QQ.to_sympy(u) + I*QQ.to_sympy(v),\n", + " QQ.to_sympy(s) + I*QQ.to_sympy(t))\n", + "\n", + " real_part, complex_part = result\n", + "\n", + " return list(map(_real, real_part)), list(map(_complex, complex_part))\n", + " else:\n", + " def _real(interval):\n", + " (s, t), k = interval\n", + " return ((QQ.to_sympy(s), QQ.to_sympy(t)), k)\n", + "\n", + " if not all:\n", + " return list(map(_real, result))\n", + "\n", + " def _complex(rectangle):\n", + " ((u, v), (s, t)), k = rectangle\n", + " return ((QQ.to_sympy(u) + I*QQ.to_sympy(v),\n", + " QQ.to_sympy(s) + I*QQ.to_sympy(t)), k)\n", + "\n", + " real_part, complex_part = result\n", + "\n", + " return list(map(_real, real_part)), list(map(_complex, complex_part))\n", + "\n", + " def refine_root(f, s, t, eps=None, steps=None, fast=False, check_sqf=False):\n", + " \"\"\"\n", + " Refine an isolating interval of a root to the given precision.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**2 - 3, x).refine_root(1, 2, eps=1e-2)\n", + " (19/11, 26/15)\n", + "\n", + " \"\"\"\n", + " if check_sqf and not f.is_sqf:\n", + " raise PolynomialError(\"only square-free polynomials supported\")\n", + "\n", + " s, t = QQ.convert(s), QQ.convert(t)\n", + "\n", + " if eps is not None:\n", + " eps = QQ.convert(eps)\n", + "\n", + " if eps <= 0:\n", + " raise ValueError(\"'eps' must be a positive rational\")\n", + "\n", + " if steps is not None:\n", + " steps = int(steps)\n", + " elif eps is None:\n", + " steps = 1\n", + "\n", + " if hasattr(f.rep, 'refine_root'):\n", + " S, T = f.rep.refine_root(s, t, eps=eps, steps=steps, fast=fast)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'refine_root')\n", + "\n", + " return QQ.to_sympy(S), QQ.to_sympy(T)\n", + "\n", + " def count_roots(f, inf=None, sup=None):\n", + " \"\"\"\n", + " Return the number of roots of ``f`` in ``[inf, sup]`` interval.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly, I\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**4 - 4, x).count_roots(-3, 3)\n", + " 2\n", + " >>> Poly(x**4 - 4, x).count_roots(0, 1 + 3*I)\n", + " 1\n", + "\n", + " \"\"\"\n", + " inf_real, sup_real = True, True\n", + "\n", + " if inf is not None:\n", + " inf = sympify(inf)\n", + "\n", + " if inf is S.NegativeInfinity:\n", + " inf = None\n", + " else:\n", + " re, im = inf.as_real_imag()\n", + "\n", + " if not im:\n", + " inf = QQ.convert(inf)\n", + " else:\n", + " inf, inf_real = list(map(QQ.convert, (re, im))), False\n", + "\n", + " if sup is not None:\n", + " sup = sympify(sup)\n", + "\n", + " if sup is S.Infinity:\n", + " sup = None\n", + " else:\n", + " re, im = sup.as_real_imag()\n", + "\n", + " if not im:\n", + " sup = QQ.convert(sup)\n", + " else:\n", + " sup, sup_real = list(map(QQ.convert, (re, im))), False\n", + "\n", + " if inf_real and sup_real:\n", + " if hasattr(f.rep, 'count_real_roots'):\n", + " count = f.rep.count_real_roots(inf=inf, sup=sup)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'count_real_roots')\n", + " else:\n", + " if inf_real and inf is not None:\n", + " inf = (inf, QQ.zero)\n", + "\n", + " if sup_real and sup is not None:\n", + " sup = (sup, QQ.zero)\n", + "\n", + " if hasattr(f.rep, 'count_complex_roots'):\n", + " count = f.rep.count_complex_roots(inf=inf, sup=sup)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'count_complex_roots')\n", + "\n", + " return Integer(count)\n", + "\n", + " def root(f, index, radicals=True):\n", + " \"\"\"\n", + " Get an indexed root of a polynomial.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> f = Poly(2*x**3 - 7*x**2 + 4*x + 4)\n", + "\n", + " >>> f.root(0)\n", + " -1/2\n", + " >>> f.root(1)\n", + " 2\n", + " >>> f.root(2)\n", + " 2\n", + " >>> f.root(3)\n", + " Traceback (most recent call last):\n", + " ...\n", + " IndexError: root index out of [-3, 2] range, got 3\n", + "\n", + " >>> Poly(x**5 + x + 1).root(0)\n", + " CRootOf(x**3 - x**2 + 1, 0)\n", + "\n", + " \"\"\"\n", + " return sympy.polys.rootoftools.rootof(f, index, radicals=radicals)\n", + "\n", + " def real_roots(f, multiple=True, radicals=True):\n", + " \"\"\"\n", + " Return a list of real roots with multiplicities.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(2*x**3 - 7*x**2 + 4*x + 4).real_roots()\n", + " [-1/2, 2, 2]\n", + " >>> Poly(x**3 + x + 1).real_roots()\n", + " [CRootOf(x**3 + x + 1, 0)]\n", + "\n", + " \"\"\"\n", + " reals = sympy.polys.rootoftools.CRootOf.real_roots(f, radicals=radicals)\n", + "\n", + " if multiple:\n", + " return reals\n", + " else:\n", + " return group(reals, multiple=False)\n", + "\n", + " def all_roots(f, multiple=True, radicals=True):\n", + " \"\"\"\n", + " Return a list of real and complex roots with multiplicities.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(2*x**3 - 7*x**2 + 4*x + 4).all_roots()\n", + " [-1/2, 2, 2]\n", + " >>> Poly(x**3 + x + 1).all_roots()\n", + " [CRootOf(x**3 + x + 1, 0),\n", + " CRootOf(x**3 + x + 1, 1),\n", + " CRootOf(x**3 + x + 1, 2)]\n", + "\n", + " \"\"\"\n", + " roots = sympy.polys.rootoftools.CRootOf.all_roots(f, radicals=radicals)\n", + "\n", + " if multiple:\n", + " return roots\n", + " else:\n", + " return group(roots, multiple=False)\n", + "\n", + " def nroots(f, n=15, maxsteps=50, cleanup=True):\n", + " \"\"\"\n", + " Compute numerical approximations of roots of ``f``.\n", + "\n", + " Parameters\n", + " ==========\n", + "\n", + " n ... the number of digits to calculate\n", + " maxsteps ... the maximum number of iterations to do\n", + "\n", + " If the accuracy `n` cannot be reached in `maxsteps`, it will raise an\n", + " exception. You need to rerun with higher maxsteps.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**2 - 3).nroots(n=15)\n", + " [-1.73205080756888, 1.73205080756888]\n", + " >>> Poly(x**2 - 3).nroots(n=30)\n", + " [-1.73205080756887729352744634151, 1.73205080756887729352744634151]\n", + "\n", + " \"\"\"\n", + " from sympy.functions.elementary.complexes import sign\n", + " if f.is_multivariate:\n", + " raise MultivariatePolynomialError(\n", + " \"can't compute numerical roots of %s\" % f)\n", + "\n", + " if f.degree() <= 0:\n", + " return []\n", + "\n", + " # For integer and rational coefficients, convert them to integers only\n", + " # (for accuracy). Otherwise just try to convert the coefficients to\n", + " # mpmath.mpc and raise an exception if the conversion fails.\n", + " if f.rep.dom is ZZ:\n", + " coeffs = [int(coeff) for coeff in f.all_coeffs()]\n", + " elif f.rep.dom is QQ:\n", + " denoms = [coeff.q for coeff in f.all_coeffs()]\n", + " from sympy.core.numbers import ilcm\n", + " fac = ilcm(*denoms)\n", + " coeffs = [int(coeff*fac) for coeff in f.all_coeffs()]\n", + " else:\n", + " coeffs = [coeff.evalf(n=n).as_real_imag()\n", + " for coeff in f.all_coeffs()]\n", + " try:\n", + " coeffs = [mpmath.mpc(*coeff) for coeff in coeffs]\n", + " except TypeError:\n", + " raise DomainError(\"Numerical domain expected, got %s\" % \\\n", + " f.rep.dom)\n", + "\n", + " dps = mpmath.mp.dps\n", + " mpmath.mp.dps = n\n", + "\n", + " try:\n", + " # We need to add extra precision to guard against losing accuracy.\n", + " # 10 times the degree of the polynomial seems to work well.\n", + " roots = mpmath.polyroots(coeffs, maxsteps=maxsteps,\n", + " cleanup=cleanup, error=False, extraprec=f.degree()*10)\n", + "\n", + " # Mpmath puts real roots first, then complex ones (as does all_roots)\n", + " # so we make sure this convention holds here, too.\n", + " roots = list(map(sympify,\n", + " sorted(roots, key=lambda r: (1 if r.imag else 0, r.real, abs(r.imag), sign(r.imag)))))\n", + " except NoConvergence:\n", + " raise NoConvergence(\n", + " 'convergence to root failed; try n < %s or maxsteps > %s' % (\n", + " n, maxsteps))\n", + " finally:\n", + " mpmath.mp.dps = dps\n", + "\n", + " return roots\n", + "\n", + " def ground_roots(f):\n", + " \"\"\"\n", + " Compute roots of ``f`` by factorization in the ground domain.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**6 - 4*x**4 + 4*x**3 - x**2).ground_roots()\n", + " {0: 2, 1: 2}\n", + "\n", + " \"\"\"\n", + " if f.is_multivariate:\n", + " raise MultivariatePolynomialError(\n", + " \"can't compute ground roots of %s\" % f)\n", + "\n", + " roots = {}\n", + "\n", + " for factor, k in f.factor_list()[1]:\n", + " if factor.is_linear:\n", + " a, b = factor.all_coeffs()\n", + " roots[-b/a] = k\n", + "\n", + " return roots\n", + "\n", + " def nth_power_roots_poly(f, n):\n", + " \"\"\"\n", + " Construct a polynomial with n-th powers of roots of ``f``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> f = Poly(x**4 - x**2 + 1)\n", + "\n", + " >>> f.nth_power_roots_poly(2)\n", + " Poly(x**4 - 2*x**3 + 3*x**2 - 2*x + 1, x, domain='ZZ')\n", + " >>> f.nth_power_roots_poly(3)\n", + " Poly(x**4 + 2*x**2 + 1, x, domain='ZZ')\n", + " >>> f.nth_power_roots_poly(4)\n", + " Poly(x**4 + 2*x**3 + 3*x**2 + 2*x + 1, x, domain='ZZ')\n", + " >>> f.nth_power_roots_poly(12)\n", + " Poly(x**4 - 4*x**3 + 6*x**2 - 4*x + 1, x, domain='ZZ')\n", + "\n", + " \"\"\"\n", + " if f.is_multivariate:\n", + " raise MultivariatePolynomialError(\n", + " \"must be a univariate polynomial\")\n", + "\n", + " N = sympify(n)\n", + "\n", + " if N.is_Integer and N >= 1:\n", + " n = int(N)\n", + " else:\n", + " raise ValueError(\"'n' must an integer and n >= 1, got %s\" % n)\n", + "\n", + " x = f.gen\n", + " t = Dummy('t')\n", + "\n", + " r = f.resultant(f.__class__.from_expr(x**n - t, x, t))\n", + "\n", + " return r.replace(t, x)\n", + "\n", + " def cancel(f, g, include=False):\n", + " \"\"\"\n", + " Cancel common factors in a rational function ``f/g``.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(2*x**2 - 2, x).cancel(Poly(x**2 - 2*x + 1, x))\n", + " (1, Poly(2*x + 2, x, domain='ZZ'), Poly(x - 1, x, domain='ZZ'))\n", + "\n", + " >>> Poly(2*x**2 - 2, x).cancel(Poly(x**2 - 2*x + 1, x), include=True)\n", + " (Poly(2*x + 2, x, domain='ZZ'), Poly(x - 1, x, domain='ZZ'))\n", + "\n", + " \"\"\"\n", + " dom, per, F, G = f._unify(g)\n", + "\n", + " if hasattr(F, 'cancel'):\n", + " result = F.cancel(G, include=include)\n", + " else: # pragma: no cover\n", + " raise OperationNotSupported(f, 'cancel')\n", + "\n", + " if not include:\n", + " if dom.has_assoc_Ring:\n", + " dom = dom.get_ring()\n", + "\n", + " cp, cq, p, q = result\n", + "\n", + " cp = dom.to_sympy(cp)\n", + " cq = dom.to_sympy(cq)\n", + "\n", + " return cp/cq, per(p), per(q)\n", + " else:\n", + " return tuple(map(per, result))\n", + "\n", + " @property\n", + " def is_zero(f):\n", + " \"\"\"\n", + " Returns ``True`` if ``f`` is a zero polynomial.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(0, x).is_zero\n", + " True\n", + " >>> Poly(1, x).is_zero\n", + " False\n", + "\n", + " \"\"\"\n", + " return f.rep.is_zero\n", + "\n", + " @property\n", + " def is_one(f):\n", + " \"\"\"\n", + " Returns ``True`` if ``f`` is a unit polynomial.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(0, x).is_one\n", + " False\n", + " >>> Poly(1, x).is_one\n", + " True\n", + "\n", + " \"\"\"\n", + " return f.rep.is_one\n", + "\n", + " @property\n", + " def is_sqf(f):\n", + " \"\"\"\n", + " Returns ``True`` if ``f`` is a square-free polynomial.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**2 - 2*x + 1, x).is_sqf\n", + " False\n", + " >>> Poly(x**2 - 1, x).is_sqf\n", + " True\n", + "\n", + " \"\"\"\n", + " return f.rep.is_sqf\n", + "\n", + " @property\n", + " def is_monic(f):\n", + " \"\"\"\n", + " Returns ``True`` if the leading coefficient of ``f`` is one.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x + 2, x).is_monic\n", + " True\n", + " >>> Poly(2*x + 2, x).is_monic\n", + " False\n", + "\n", + " \"\"\"\n", + " return f.rep.is_monic\n", + "\n", + " @property\n", + " def is_primitive(f):\n", + " \"\"\"\n", + " Returns ``True`` if GCD of the coefficients of ``f`` is one.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(2*x**2 + 6*x + 12, x).is_primitive\n", + " False\n", + " >>> Poly(x**2 + 3*x + 6, x).is_primitive\n", + " True\n", + "\n", + " \"\"\"\n", + " return f.rep.is_primitive\n", + "\n", + " @property\n", + " def is_ground(f):\n", + " \"\"\"\n", + " Returns ``True`` if ``f`` is an element of the ground domain.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y\n", + "\n", + " >>> Poly(x, x).is_ground\n", + " False\n", + " >>> Poly(2, x).is_ground\n", + " True\n", + " >>> Poly(y, x).is_ground\n", + " True\n", + "\n", + " \"\"\"\n", + " return f.rep.is_ground\n", + "\n", + " @property\n", + " def is_linear(f):\n", + " \"\"\"\n", + " Returns ``True`` if ``f`` is linear in all its variables.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y\n", + "\n", + " >>> Poly(x + y + 2, x, y).is_linear\n", + " True\n", + " >>> Poly(x*y + 2, x, y).is_linear\n", + " False\n", + "\n", + " \"\"\"\n", + " return f.rep.is_linear\n", + "\n", + " @property\n", + " def is_quadratic(f):\n", + " \"\"\"\n", + " Returns ``True`` if ``f`` is quadratic in all its variables.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y\n", + "\n", + " >>> Poly(x*y + 2, x, y).is_quadratic\n", + " True\n", + " >>> Poly(x*y**2 + 2, x, y).is_quadratic\n", + " False\n", + "\n", + " \"\"\"\n", + " return f.rep.is_quadratic\n", + "\n", + " @property\n", + " def is_monomial(f):\n", + " \"\"\"\n", + " Returns ``True`` if ``f`` is zero or has only one term.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(3*x**2, x).is_monomial\n", + " True\n", + " >>> Poly(3*x**2 + 1, x).is_monomial\n", + " False\n", + "\n", + " \"\"\"\n", + " return f.rep.is_monomial\n", + "\n", + " @property\n", + " def is_homogeneous(f):\n", + " \"\"\"\n", + " Returns ``True`` if ``f`` is a homogeneous polynomial.\n", + "\n", + " A homogeneous polynomial is a polynomial whose all monomials with\n", + " non-zero coefficients have the same total degree. If you want not\n", + " only to check if a polynomial is homogeneous but also compute its\n", + " homogeneous order, then use :func:`Poly.homogeneous_order`.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y\n", + "\n", + " >>> Poly(x**2 + x*y, x, y).is_homogeneous\n", + " True\n", + " >>> Poly(x**3 + x*y, x, y).is_homogeneous\n", + " False\n", + "\n", + " \"\"\"\n", + " return f.rep.is_homogeneous\n", + "\n", + " @property\n", + " def is_irreducible(f):\n", + " \"\"\"\n", + " Returns ``True`` if ``f`` has no factors over its domain.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> Poly(x**2 + x + 1, x, modulus=2).is_irreducible\n", + " True\n", + " >>> Poly(x**2 + 1, x, modulus=2).is_irreducible\n", + " False\n", + "\n", + " \"\"\"\n", + " return f.rep.is_irreducible\n", + "\n", + " @property\n", + " def is_univariate(f):\n", + " \"\"\"\n", + " Returns ``True`` if ``f`` is a univariate polynomial.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y\n", + "\n", + " >>> Poly(x**2 + x + 1, x).is_univariate\n", + " True\n", + " >>> Poly(x*y**2 + x*y + 1, x, y).is_univariate\n", + " False\n", + " >>> Poly(x*y**2 + x*y + 1, x).is_univariate\n", + " True\n", + " >>> Poly(x**2 + x + 1, x, y).is_univariate\n", + " False\n", + "\n", + " \"\"\"\n", + " return len(f.gens) == 1\n", + "\n", + " @property\n", + " def is_multivariate(f):\n", + " \"\"\"\n", + " Returns ``True`` if ``f`` is a multivariate polynomial.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x, y\n", + "\n", + " >>> Poly(x**2 + x + 1, x).is_multivariate\n", + " False\n", + " >>> Poly(x*y**2 + x*y + 1, x, y).is_multivariate\n", + " True\n", + " >>> Poly(x*y**2 + x*y + 1, x).is_multivariate\n", + " False\n", + " >>> Poly(x**2 + x + 1, x, y).is_multivariate\n", + " True\n", + "\n", + " \"\"\"\n", + " return len(f.gens) != 1\n", + "\n", + " @property\n", + " def is_cyclotomic(f):\n", + " \"\"\"\n", + " Returns ``True`` if ``f`` is a cyclotomic polnomial.\n", + "\n", + " Examples\n", + " ========\n", + "\n", + " >>> from sympy import Poly\n", + " >>> from sympy.abc import x\n", + "\n", + " >>> f = x**16 + x**14 - x**10 + x**8 - x**6 + x**2 + 1\n", + "\n", + " >>> Poly(f).is_cyclotomic\n", + " False\n", + "\n", + " >>> g = x**16 + x**14 - x**10 - x**8 - x**6 + x**2 + 1\n", + "\n", + " >>> Poly(g).is_cyclotomic\n", + " True\n", + "\n", + " \"\"\"\n", + " return f.rep.is_cyclotomic\n", + "\n", + " def __abs__(f):\n", + " return f.abs()\n", + "\n", + " def __neg__(f):\n", + " return f.neg()\n", + "\n", + " @_sympifyit('g', NotImplemented)\n", + " def __add__(f, g):\n", + " if not g.is_Poly:\n", + " try:\n", + " g = f.__class__(g, *f.gens)\n", + " except PolynomialError:\n", + " return f.as_expr() + g\n", + "\n", + " return f.add(g)\n", + "\n", + " @_sympifyit('g', NotImplemented)\n", + " def __radd__(f, g):\n", + " if not g.is_Poly:\n", + " try:\n", + " g = f.__class__(g, *f.gens)\n", + " except PolynomialError:\n", + " return g + f.as_expr()\n", + "\n", + " return g.add(f)\n", + "\n", + " @_sympifyit('g', NotImplemented)\n", + " def __sub__(f, g):\n", + " if not g.is_Poly:\n", + " try:\n", + " g = f.__class__(g, *f.gens)\n", + " except PolynomialError:\n", + " return f.as_expr() - g\n", + "\n", + " return f.sub(g)\n", + "\n", + " @_sympifyit('g', NotImplemented)\n", + " def __rsub__(f, g):\n", + " if not g.is_Poly:\n", + " try:\n", + " g = f.__class__(g, *f.gens)\n", + " except PolynomialError:\n", + " return g - f.as_expr()\n", + "\n", + " return g.sub(f)\n", + "\n", + " @_sympifyit('g', NotImplemented)\n", + " def __mul__(f, g):\n", + " if not g.is_Poly:\n", + " try:\n", + " g = f.__class__(g, *f.gens)\n", + " except PolynomialError:\n", + " return f.as_expr()*g\n", + "\n", + " return f.mul(g)\n", + "\n", + " @_sympifyit('g', NotImplemented)\n", + " def __rmul__(f, g):\n", + " if not g.is_Poly:\n", + " try:\n", + " g = f.__class__(g, *f.gens)\n", + " except PolynomialError:\n", + " return g*f.as_expr()\n", + "\n", + " return g.mul(f)\n", + "\n", + " @_sympifyit('n', NotImplemented)\n", + " def __pow__(f, n):\n", + " if n.is_Integer and n >= 0:\n", + " return f.pow(n)\n", + " else:\n", + " return f.as_expr()**n\n", + "\n", + " @_sympifyit('g', NotImplemented)\n", + " def __divmod__(f, g):\n", + " if not g.is_Poly:\n", + " g = f.__class__(g, *f.gens)\n", + "\n", + " return f.div(g)\n", + "\n", + " @_sympifyit('g', NotImplemented)\n", + " def __rdivmod__(f, g):\n", + " if not g.is_Poly:\n", + " g = f.__class__(g, *f.gens)\n", + "\n", + " return g.div(f)\n", + "\n", + " @_sympifyit('g', NotImplemented)\n", + " def __mod__(f, g):\n", + " if not g.is_Poly:\n", + " g = f.__class__(g, *f.gens)\n", + "\n", + " return f.rem(g)\n", + "\n", + " @_sympifyit('g', NotImplemented)\n", + " def __rmod__(f, g):\n", + " if not g.is_Poly:\n", + " g = f.__class__(g, *f.gens)\n", + "\n", + " return g.rem(f)\n", + "\n", + " @_sympifyit('g', NotImplemented)\n", + " def __floordiv__(f, g):\n", + " if not g.is_Poly:\n", + " g = f.__class__(g, *f.gens)\n", + "\n", + " return f.quo(g)\n", + "\n", + " @_sympifyit('g', NotImplemented)\n", + " def __rfloordiv__(f, g):\n", + " if not g.is_Poly:\n", + " g = f.__class__(g, *f.gens)\n", + "\n", + " return g.quo(f)\n", + "\n", + " @_sympifyit('g', NotImplemented)\n", + " def __div__(f, g):\n", + " return f.as_expr()/g.as_expr()\n", + "\n", + " @_sympifyit('g', NotImplemented)\n", + " def __rdiv__(f, g):\n", + " return g.as_expr()/f.as_expr()\n", + "\n", + " __truediv__ = __div__\n", + " __rtruediv__ = __rdiv__\n", + "\n", + " @_sympifyit('other', NotImplemented)\n", + " def __eq__(self, other):\n", + " f, g = self, other\n", + "\n", + " if not g.is_Poly:\n", + " try:\n", + " g = f.__class__(g, f.gens, domain=f.get_domain())\n", + " except (PolynomialError, DomainError, CoercionFailed):\n", + " return False\n", + "\n", + " if f.gens != g.gens:\n", + " return False\n", + "\n", + " if f.rep.dom != g.rep.dom:\n", + " try:\n", + " dom = f.rep.dom.unify(g.rep.dom, f.gens)\n", + " except UnificationFailed:\n", + " return False\n", + "\n", + " f = f.set_domain(dom)\n", + " g = g.set_domain(dom)\n", + "\n", + " return f.rep == g.rep\n", + "\n", + " @_sympifyit('g', NotImplemented)\n", + " def __ne__(f, g):\n", + " return not f == g\n", + "\n", + " def __nonzero__(f):\n", + " return not f.is_zero\n", + "\n", + " __bool__ = __nonzero__\n", + "\n", + " def eq(f, g, strict=False):\n", + " if not strict:\n", + " return f == g\n", + " else:\n", + " return f._strict_eq(sympify(g))\n", + "\n", + " def ne(f, g, strict=False):\n", + " return not f.eq(g, strict=strict)\n", + "\n", + " def _strict_eq(f, g):\n", + " return isinstance(g, f.__class__) and f.gens == g.gens and f.rep.eq(g.rep, strict=True)\n", + "\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/home/grzegorz/Pobrane/SageMath/local/lib/python3.7/site-packages/sympy/core/decorators.py:38: SymPyDeprecationWarning: \n", + "\n", + "source has been deprecated since SymPy 1.3. Use ?? in IPython/Jupyter\n", + "or inspect.getsource instead. See\n", + "https://github.com/sympy/sympy/issues/14905 for more info.\n", + "\n", + " _warn_deprecation(wrapped, 3)\n" + ] + } + ], + "source": [ + "source(Poly)" + ] + }, + { + "cell_type": "code", + "execution_count": 126, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\operatorname{Poly}{\\left( x + \\sqrt{x}, \\sqrt{x}, domain=\\mathbb{Z} \\right)}$" + ], + "text/plain": [ + "Poly((sqrt(x))**2 + (sqrt(x)), sqrt(x), domain='ZZ')" + ] + }, + "execution_count": 126, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Poly({1:1,2:1},gens=S('sqrt(x)'))" + ] + }, + { + "cell_type": "code", + "execution_count": 115, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle - x + \\sqrt{x^{2}}$" + ], + "text/plain": [ + "-x + sqrt(x**2)" + ] + }, + "execution_count": 115, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x=symbols('x', positive=True)\n", + "S('sqrt(x^2)-x')" + ] + }, + { + "cell_type": "code", + "execution_count": 130, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "\"Poly((sqrt(x))**4 + (sqrt(x))**2 + (sqrt(x)), sqrt(x), domain='ZZ')\"" + ] + }, + "execution_count": 130, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "str(Poly({1:1,2:1,4:1},gens=S('sqrt(x)')))" + ] + }, + { + "cell_type": "code", + "execution_count": 131, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "\"Poly(x**2 + x + (sqrt(x)), x, sqrt(x), domain='ZZ')\"" + ] + }, + "execution_count": 131, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "str(Poly('x^2+x+sqrt(x)'))" + ] + }, + { + "cell_type": "code", + "execution_count": 164, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "Substitute $a\\to a+b$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $b\\to b+c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Optimization terminated successfully.\n", + " Current function value: 1.000000\n", + " Iterations: 137\n", + " Function evaluations: 249\n" + ] + }, + { + "data": { + "text/plain": [ + "(2.5326984818340415e-10, 7.129450063690368, 1.7908873553542452e-10)" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "1.4142142855953455" + ] + }, + "execution_count": 164, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def findvalues(formula,values=None,variables=None):\n", + " num,den=fractioncancel(formula)\n", + " if variables==None:\n", + " variables=sorted(num.free_symbols,key=str)\n", + " num=num.subs(zip(variables,list(map(lambda x:x**2,fs))))\n", + " num=Poly(num)\n", + " newformula=S((num.abs()+num)/(num.abs()-num))\n", + " f=lambdify(variables,newformula)\n", + " f2=lambda x:f(*x)\n", + " if values==None:\n", + " values=[1.0]*len(variables)\n", + " tup=tuple(fmin(f2,values))\n", + " return tuple([x*x for x in tup])\n", + "formula=cyclize(Sm('((a-b)/c)^2-8**(1/2)*(a-b)/c'))\n", + "formula=(makesubs(formula,'[b,oo],[c,oo]'))\n", + "values=findvalues(formula)\n", + "display(values)\n", + "nsimplify(values,tolerance=0.1,rational=True)\n", + "values[0]/values[2]" + ] + }, + { + "cell_type": "code", + "execution_count": 156, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "Substitute $a\\to a+b$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $b\\to b+c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ok\n", + "100 loops, best of 5: 9.06 ms per loop\n" + ] + }, + { + "ename": "TypeError", + "evalue": "int() argument must be a string, a bytes-like object or a number, not 'dict'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 16\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'ok'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 17\u001b[0m \u001b[0mget_ipython\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmagic\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'timeit evaluate((random(),random(),random()))'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 18\u001b[0;31m \u001b[0mget_ipython\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmagic\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'timeit evaluate2((random(),random(),random()))'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 19\u001b[0m \u001b[0mPoly\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'x^2+sqrt(x)'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0meval\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/home/grzegorz/Pobrane/SageMath/local/lib/python3.7/site-packages/IPython/core/interactiveshell.py\u001b[0m in \u001b[0;36mmagic\u001b[0;34m(self, arg_s)\u001b[0m\n\u001b[1;32m 2158\u001b[0m \u001b[0mmagic_name\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0m_\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmagic_arg_s\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0marg_s\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpartition\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m' '\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2159\u001b[0m \u001b[0mmagic_name\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmagic_name\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlstrip\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mprefilter\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mESC_MAGIC\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2160\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrun_line_magic\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmagic_name\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmagic_arg_s\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2161\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2162\u001b[0m \u001b[0;31m#-------------------------------------------------------------------------\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/home/grzegorz/Pobrane/SageMath/local/lib/python3.7/site-packages/IPython/core/interactiveshell.py\u001b[0m in \u001b[0;36mrun_line_magic\u001b[0;34m(self, magic_name, line)\u001b[0m\n\u001b[1;32m 2079\u001b[0m \u001b[0mkwargs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'local_ns'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0msys\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_getframe\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mstack_depth\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mf_locals\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2080\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbuiltin_trap\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2081\u001b[0;31m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2082\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2083\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m\u001b[0m in \u001b[0;36mtimeit\u001b[0;34m(self, line, cell)\u001b[0m\n", + "\u001b[0;32m/home/grzegorz/Pobrane/SageMath/local/lib/python3.7/site-packages/IPython/core/magic.py\u001b[0m in \u001b[0;36m\u001b[0;34m(f, *a, **k)\u001b[0m\n\u001b[1;32m 186\u001b[0m \u001b[0;31m# but it's overkill for just that one bit of state.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 187\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mmagic_deco\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marg\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 188\u001b[0;31m \u001b[0mcall\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mlambda\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 189\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 190\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mcallable\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marg\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/home/grzegorz/Pobrane/SageMath/local/lib/python3.7/site-packages/IPython/core/magics/execution.py\u001b[0m in \u001b[0;36mtimeit\u001b[0;34m(self, line, cell)\u001b[0m\n\u001b[1;32m 1055\u001b[0m \u001b[0mnumber\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1056\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0m_\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m10\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1057\u001b[0;31m \u001b[0mtime_number\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtimer\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtimeit\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnumber\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1058\u001b[0m \u001b[0mworst_tuning\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmax\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mworst_tuning\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtime_number\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0mnumber\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1059\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mtime_number\u001b[0m \u001b[0;34m>=\u001b[0m \u001b[0;36m0.2\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/home/grzegorz/Pobrane/SageMath/local/lib/python3.7/site-packages/IPython/core/magics/execution.py\u001b[0m in \u001b[0;36mtimeit\u001b[0;34m(self, number)\u001b[0m\n\u001b[1;32m 137\u001b[0m \u001b[0mgc\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdisable\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 138\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 139\u001b[0;31m \u001b[0mtiming\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minner\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mit\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtimer\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 140\u001b[0m \u001b[0;32mfinally\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 141\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mgcold\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m\u001b[0m in \u001b[0;36minner\u001b[0;34m(_it, _timer)\u001b[0m\n", + "\u001b[0;32m\u001b[0m in \u001b[0;36mevaluate2\u001b[0;34m(x)\u001b[0m\n\u001b[1;32m 12\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mnewformula\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mevalf\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msubs\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mzip\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfs\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 13\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mevaluate2\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 14\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mnum1\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mevalf\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mzip\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfs\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0mnum2\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mevalf\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mzip\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfs\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 15\u001b[0m \u001b[0;31m#display(num2.eval(dict(zip(fs,(1,1,1)))))\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 16\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'ok'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/home/grzegorz/Pobrane/SageMath/local/lib/python3.7/site-packages/sympy/core/evalf.py\u001b[0m in \u001b[0;36mevalf\u001b[0;34m(self, n, subs, maxn, chop, strict, quad, verbose)\u001b[0m\n\u001b[1;32m 1432\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mevalf_table\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1433\u001b[0m \u001b[0m_create_evalf_table\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1434\u001b[0;31m \u001b[0mprec\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdps_to_prec\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mn\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1435\u001b[0m options = {'maxprec': max(prec, int(maxn*LG10)), 'chop': chop,\n\u001b[1;32m 1436\u001b[0m 'strict': strict, 'verbose': verbose}\n", + "\u001b[0;32m/home/grzegorz/Pobrane/SageMath/local/lib/python3.7/site-packages/mpmath/libmp/libmpf.py\u001b[0m in \u001b[0;36mdps_to_prec\u001b[0;34m(n)\u001b[0m\n\u001b[1;32m 65\u001b[0m \"\"\"Return the number of bits required to represent n decimals\n\u001b[1;32m 66\u001b[0m accurately.\"\"\"\n\u001b[0;32m---> 67\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mmax\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mround\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mn\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0;36m3.3219280948873626\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 68\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 69\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mrepr_dps\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mn\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mTypeError\u001b[0m: int() argument must be a string, a bytes-like object or a number, not 'dict'" + ] + } + ], + "source": [ + "from random import random\n", + "formula=cyclize(Sm('((a-b)/c)^2-8**(1/2)*(a-b)/c'))\n", + "formula=(makesubs(formula,'[b,oo],[c,oo]'))\n", + "num,den=fractioncancel(formula)\n", + "fs=sorted(num.free_symbols,key=str)\n", + "num=num.subs(zip(fs,list(map(lambda x:x**2,fs))))\n", + "num=Poly(num,domain='RR')\n", + "num1=(num.abs()+num)\n", + "num2=(num.abs()-num)\n", + "newformula=S(num1/num2)\n", + "def evaluate(x):\n", + " return newformula.evalf(subs=dict(zip(fs,(1,1,1))))\n", + "def evaluate2(x):\n", + " return num1.evalf(dict(zip(fs,x)))/num2.eval(dict(zip(fs,x)))\n", + "#display(num2.eval(dict(zip(fs,(1,1,1)))))\n", + "print('ok')\n", + "%timeit evaluate((random(),random(),random()))\n", + "%timeit evaluate2((random(),random(),random()))\n", + "Poly('x^2+sqrt(x)').eval\n" + ] + }, + { + "cell_type": "code", + "execution_count": 162, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "100000 loops, best of 5: 6.56 µs per loop\n", + "100000 loops, best of 5: 6.39 µs per loop\n" + ] + } + ], + "source": [ + "evaluate4=lambdify(fs,newformula)\n", + "evaluate5=lambda x:evaluate4(*x)\n", + "%timeit evaluate4(*(random(),random(),random()))\n", + "%timeit evaluate5((random(),random(),random()))" + ] + }, + { + "cell_type": "code", + "execution_count": 172, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "first attempt: Poly(x**2 + x + (sqrt(x)), x, sqrt(x), domain='ZZ')\n", + "second attempt: Poly(x**2 + x + (sqrt(x)), x, sqrt(x), domain='ZZ')\n", + "third attempt: Poly((sqrt(x))**4 + (sqrt(x))**2 + (sqrt(x)), sqrt(x), domain='ZZ')\n" + ] + } + ], + "source": [ + "from sympy import *\n", + "print('first attempt:',Poly('x^2+x+sqrt(x)'))\n", + "x=Symbol('x', positive=True)\n", + "print('second attempt:',Poly(x**2+x+sqrt(x)))\n", + "print('third attempt:',str(Poly({1:1,2:1,4:1},gens=S('sqrt(x)'))))" + ] + }, + { + "cell_type": "code", + "execution_count": 176, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\sqrt{x} + x$" + ], + "text/plain": [ + "sqrt(x) + x" + ] + }, + "execution_count": 176, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(Poly({1:1,2:1,4:1},gens=S('sqrt(x)'))-Poly('x^2')).as_expr()" + ] + }, + { + "cell_type": "code", + "execution_count": 178, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(x*(1 - x), [])" + ] + }, + "execution_count": 178, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from sympy.solvers.solvers import unrad\n", + "unrad('sqrt(x)+x')" + ] + }, + { + "cell_type": "code", + "execution_count": 206, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 206, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "formula=('x^(2/3)+x^(3/4)+sqrt(x+y)')\n", + "type((Poly(formula).gens[1]).args[0])==Symbol" + ] + }, + { + "cell_type": "code", + "execution_count": 223, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(x, 1/2)" + ] + }, + "execution_count": 223, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "S('sqrt(x)').args" + ] + }, + { + "cell_type": "code", + "execution_count": 222, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\operatorname{Poly}{\\left( x^{2} + y^{2} + \\sqrt{x + y} + \\sqrt{x} + \\sqrt[3]{x_{12}}, x, y, \\sqrt{x + y}, \\sqrt{x}, \\sqrt[3]{x_{12}}, domain=\\mathbb{Z} \\right)}$" + ], + "text/plain": [ + "Poly(x**2 + y**2 + (sqrt(x + y)) + (sqrt(x)) + (x12**(1/3)), x, y, sqrt(x + y), sqrt(x), x12**(1/3), domain='ZZ')" + ] + }, + "execution_count": 222, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def _powr(formula):\n", + "\tif formula.func==Pow:\n", + "\t\treturn formula.args\n", + "\telse:\n", + "\t\treturn [formula,S('1')]\n", + "pol=Poly('x**2+y**2+sqrt(x+y)+x**(1/2)+x**(1/3)')\n", + "genes=pol.gens\n", + "newgens={}\n", + "for gen in genes:\n", + " gen=_powr(gen):\n", + " if gen[0] in newgens:\n", + " newgens[gen[0]]=\n", + " else:\n", + " newgens[gen[0]]=gen[1]" + ] + }, + { + "cell_type": "code", + "execution_count": 227, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "sympy.core.add.Add" + ] + }, + "execution_count": 227, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "S('x+y*6').func==" + ] + }, + { + "cell_type": "code", + "execution_count": 229, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 229, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "6 in {3:4,5:6}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "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.7.3" + } + }, "nbformat": 4, "nbformat_minor": 2 } diff --git a/__pycache__/shiroindev.cpython-36.pyc b/__pycache__/shiroindev.cpython-36.pyc new file mode 100644 index 0000000..4c76e45 Binary files /dev/null and b/__pycache__/shiroindev.cpython-36.pyc differ diff --git a/__pycache__/shiroindev.cpython-37.pyc b/__pycache__/shiroindev.cpython-37.pyc index e8efac0..547e22c 100644 Binary files a/__pycache__/shiroindev.cpython-37.pyc and b/__pycache__/shiroindev.cpython-37.pyc differ diff --git a/examples.ipynb b/examples.ipynb index ecc0aa6..7755427 100644 --- a/examples.ipynb +++ b/examples.ipynb @@ -4,7 +4,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "In this notebook there are presented examples of usage of shiroin, a python library for proving inequalities of multivariate polynomials." + "In this notebook there are presented examples of usage of shiroin, a python library for proving inequalities of multivariate polynomials.\n", + "\n", + "At the beginning we need to load the packages." ] }, { @@ -13,17 +15,20 @@ "metadata": {}, "outputs": [], "source": [ + "from sympy import *\n", "from shiroindev import *\n", - "sVars.seed=1\n", "from IPython.display import Latex\n", - "sVars.print=lambda x:display(Latex(x))" + "sVars.seed=1\n", + "sVars.display=lambda x:display(Latex(x))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "The first line obviously loads this package. The second one sets a seed for proving functions. If you don't write it, you can get a slightly different proof each time you run a function. The next two lines provide a nicer display of proofs, i.e. formulas will be shown instead of LaTeX code of these formulas. Note that this works on Jupyter, but not on the git page.\n", + "`sVars.seed=1` sets a seed for proving functions. If you don't write it, you can get a slightly different proof each time you run a function. This line is here only for the sake of reproducibility. \n", + "\n", + "The next line provides a nicer display of proofs, i.e. formulas will be shown instead of LaTeX code of these formulas. Note that this works on Jupyter, but not on the git page.\n", "\n", "Now let's make some proofs. We will use problems from https://www.imomath.com/index.php?options=593&lmm=0." ] @@ -139,7 +144,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Function prove prints several things. The first two gives us a formula after expanding it. To proceed, a **numerator** has to be a **polynomial with integer coefficients**. The next one is status, which is the return status of the first use of ```scipy.optimize.linprog```. Possible outputs and explanations are\n", + "Function prove prints several things. The first two gives us a formula after expanding it. The next one is status, which is the return status of the first use of ```scipy.optimize.linprog```. Possible outputs and explanations are\n", "\n", "* 0 - found a proof with real coefficients,\n", "* 1 - need more time, \n", @@ -376,7 +381,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "This time `prove` didn't found the proof. But it doesn't mean that the inequality is not true! `prove` uses a list of values for which the formula should be small. There is no strict rule here, but the smaller that value is, the higher are chances to find a proof. List of values should correspond to the list of variables in alphabetical order. So let's try $a=2$ and $b=c=d=1$." + "This time `prove` didn't found the proof. But it doesn't mean that the inequality is not true! `prove` uses a list of $n$ positive values, where $n$ is a number of variables in the formula. List of values should correspond to the list of variables in alphabetical order. Here are a few tips how to choose the right values.\n", + "\n", + "1. Consider a function $pos(values)$ which is the sum of the positive addends in the formula after substitution of values to variables. Analogically, let $neg(values)$ be the sum of the negative addends. We should choose such values for which $quotient=pos(values)/|neg(values)|$ is small. \n", + "2. The symmetry group of the formula splits set of variables into orbits. Using the same values for variables in one orbit is recommended. In particular, if the symmetry group of the formula is transitive (for example, when the formula is cyclic), then all values (probably) should be the same.\n", + "3. If the formula is homogeneous, then $values=(a_1,a_2,...,a_n)$ provide a proof iff $values=(ka_1,ka_2,...,ka_n)$ provides a proof for any $k\\in Q_+$ (as long as you don't run into overflow error).\n", + "\n", + "In the formula above $b,c,d$ are in one orbit and the formula is homogenous, so let's try $a=2$ and $b=c=d=1$." ] }, { @@ -672,6 +683,257 @@ "source": [ "Now we can see that if $a^2+b^2+c^2+d^2-a(b+c+d)=0$, then $7a'^2+2b^2+2c^2+2d^2=0$ and eventually $a=b=c=d=0$. Note that inequality is proved only for positive numbers (which, by continuity, can be expanded to nonnegative numbers). But using similar argumentation to the one in previous problem, if $(a,b,c,d)=(x,y,z,t)$ is the solution of $a^2+b^2+c^2+d^2-a(b+c+d)=0$, then $(a,b,c,d)=(|x|,|y|,|z|,|t|)$ is a solution, too. Since the only nonnegative solution is $(0,0,0,0)$, it means that it is the only solution.\n", "\n", + "We can also use the `findvalues` function to find values for the proof more automatically. It looks for (local) minimum of the $quotient$ value defined above." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Optimization terminated successfully.\n", + " Current function value: 1.154701\n", + " Iterations: 68\n", + " Function evaluations: 127\n" + ] + }, + { + "data": { + "text/plain": [ + "(1.4339109663193974,\n", + " 0.8278441585048405,\n", + " 0.8279027492686561,\n", + " 0.8278930696996669)" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "formula=S('a^2+b^2+c^2+d^2-a*(b+c+d)')\n", + "numvalues=findvalues(formula)\n", + "numvalues" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "If the $quotient$ value were less than 1, that would mean that the formula is negative for given values. If $quotient$ were equal to 1, then we have to choose exactly these values (or other values for which the $quotient$ is equal to 1. But here $quotient$ is greater than 1, so we can take a point near it and (probably) still have a proof. The values given to the `prove` function must not be floating point numbers, so we can rationalize them." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\left( \\frac{10}{7}, \\ \\frac{5}{6}, \\ \\frac{5}{6}, \\ \\frac{5}{6}\\right)$" + ], + "text/plain": [ + "(10/7, 5/6, 5/6, 5/6)" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "values=nsimplify(numvalues,tolerance=0.1,rational=True)\n", + "values" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "Substitute $a\\to 10a/7$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $b\\to 5b/6$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $c\\to 5c/6$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $d\\to 5d/6$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "numerator: $3600a^2-2100ab-2100ac-2100ad+1225b^2+1225c^2+1225d^2$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $1764$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "From weighted AM-GM inequality:" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$2100ab \\le 1050a^2+1050b^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$2100ac \\le 1050a^2+1050c^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$2100ad \\le 1050a^2+1050d^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le 450a^2+175b^2+175c^2+175d^2 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "prove(formula,values)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "If you set the tolerance bigger, then the values will have smaller numerators and denominators, so coefficients in the proof will be smaller, too. But if the tolerance is too big, then proof will not be found.\n", + "\n", "Let's skip the problem 3 and look solve the problem 4 instead.\n", "\n", "#### Problem 4\n", @@ -681,7 +943,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -774,7 +1036,7 @@ "2" ] }, - "execution_count": 7, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -789,13 +1051,13 @@ "source": [ "`prove` assumes that formula is well-defined if all variables are positive, so it doesn't have to analyze the denominator (except of choosing the right sign). In this case it is not true, since if $x=1$, then $1-x^2=0$. Also denominator is equal to $(x^2-1)(y^2-1)(xy-1)$ which is negative for $x,y\\in (0,1)$. So we need to make some substitution after which new variables can have all positive values, not just these inside (0,1) interval.\n", "\n", - "We will use a function `makesubs` to generate these substitutions. It has three basic parameters: `formula`, `intervals` and `values`. `intervals` are current limitations of variables, `values` are values of variables for which `formula` is small. `values` should be inside corresponding `intervals`. This argument is optional but it's better to use it.\n", + "We will use a function `makesubs` to generate these substitutions. It has three basic parameters: `formula`, `intervals` and `values`. `intervals` are current limitations of variables, `values` are values of variables for which $quotient$ of `formula` is small. `values` should be inside corresponding `intervals`. This argument is optional but it's better to use it.\n", "Let's go back to our problem. If $x=y$, then $\\frac{1}{1-x^2}+\\frac{1}{1-y^2}\\ge \\frac{2}{1-xy}$, so it's the minimum value of the formula. So let `values=(1/2,1/2)` (**warning: do not use decimal point**, for example '0.5,0.5')." ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -948,7 +1210,7 @@ "0" ] }, - "execution_count": 8, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } @@ -979,7 +1241,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -1132,7 +1394,7 @@ "0" ] }, - "execution_count": 9, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -1156,7 +1418,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -1273,7 +1535,7 @@ "0" ] }, - "execution_count": 10, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -1295,7 +1557,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 14, "metadata": {}, "outputs": [ { @@ -1364,7 +1626,7 @@ "2" ] }, - "execution_count": 11, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -1382,7 +1644,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 15, "metadata": {}, "outputs": [ { @@ -1463,7 +1725,7 @@ "0" ] }, - "execution_count": 12, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -1474,7 +1736,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 16, "metadata": { "scrolled": true }, @@ -1557,7 +1819,7 @@ "0" ] }, - "execution_count": 13, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } @@ -1580,7 +1842,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 17, "metadata": {}, "outputs": [ { @@ -1592,7 +1854,7 @@ "a/(b + c) + b/(c + d) + c/(a + d) + d/(a + b) - 2" ] }, - "execution_count": 14, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } @@ -1604,7 +1866,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 18, "metadata": {}, "outputs": [ { @@ -1673,7 +1935,7 @@ "2" ] }, - "execution_count": 15, + "execution_count": 18, "metadata": {}, "output_type": "execute_result" } @@ -1691,7 +1953,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 19, "metadata": {}, "outputs": [ { @@ -1796,7 +2058,7 @@ "0" ] }, - "execution_count": 16, + "execution_count": 19, "metadata": {}, "output_type": "execute_result" } @@ -1807,7 +2069,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 20, "metadata": {}, "outputs": [ { @@ -1924,7 +2186,7 @@ "0" ] }, - "execution_count": 17, + "execution_count": 20, "metadata": {}, "output_type": "execute_result" } @@ -1942,7 +2204,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 21, "metadata": {}, "outputs": [ { @@ -2083,7 +2345,7 @@ "0" ] }, - "execution_count": 18, + "execution_count": 21, "metadata": {}, "output_type": "execute_result" } @@ -2101,7 +2363,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 22, "metadata": {}, "outputs": [ { @@ -2273,6 +2535,16 @@ }, "metadata": {}, "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "Counter({0: 2})" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ @@ -2281,7 +2553,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 23, "metadata": {}, "outputs": [ { @@ -3119,6 +3391,16 @@ }, "metadata": {}, "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "Counter({0: 8})" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ @@ -3140,7 +3422,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 24, "metadata": {}, "outputs": [ { @@ -3250,12 +3532,574 @@ }, "metadata": {}, "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ "provef('(-f(1,2,3)-f(2,3,1)-f(3,1,2)+f(4,3,-1)+f(3,-1,4)+f(-1,4,3))*21')" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Let's try to solve problem 6 from the finals of LXIII Polish Mathematical Olympiad. It was one of the hardest inequality in the history of this contest, solved only by 3 finalists.\n", + "\n", + "#### Problem\n", + "Prove the inequality\n", + "$$\\left(\\frac{a - b}{c}\\right)^2 + \\left(\\frac{b - c}{a}\\right)^2 + \\left(\\frac{c - a}{b}\\right)^2\\ge 2 \\sqrt{2} \\left(\\frac{a - b}{c} + \\frac{b - c}{a}+ \\frac{c-a}{b}\\right)$$\n", + "for any positive numbers $a,b,c$.\n", + "\n", + "The first observation is that the formula is cyclic, so without loss of generality we may assume that $a\\ge b,c$. We can go a step further and divide it into two cases: $a\\ge b\\ge c$ and $a\\ge c\\ge b$." + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [], + "source": [ + "sVars.display=lambda x:None #turn off printing of proofs\n", + "formula=cyclize('((a-b)/c)^2-2*sqrt(2)*(a-b)/c')" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "formula1=makesubs(formula,'[b,oo],[c,oo]',variables='a,b') #a>=b>=c\n", + "prove(formula1) " + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "formula2=makesubs(formula,'[c,oo],[b,oo]',variables='a,c') #a>=c>=b\n", + "prove(formula2) " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "So the case $a\\ge c\\ge b$ is done, but $a\\ge b\\ge c$ is not. But maybe we can adjust values." + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Optimization terminated successfully.\n", + " Current function value: 1.000000\n", + " Iterations: 137\n", + " Function evaluations: 249\n" + ] + }, + { + "data": { + "text/plain": [ + "(2.5326984818340415e-10, 7.129450063690368, 1.7908873553542452e-10)" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "values=findvalues(formula1)\n", + "values" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "First and third value is approximately equal to 0, so we can try to replace 0 with 1." + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "prove(formula1,values='1,7,1')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The key observation is that the `formula1` is homogenous, so we can scale values." + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(1.4142142855953455, 39809595184.05965, 1)" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "newvalues=(values[0]/values[2],values[1]/values[2],1)\n", + "newvalues" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2.000002045581953" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "newvalues[0]**2" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now the second value is very big. Technically we could use it, but it would run into overflow error, so we will use 1 instead of it. First value is very close to $\\sqrt{2}$, so this value will be our next try." + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "prove(formula1,values='sqrt(2),1,1')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "So after getting the code all together we have got the following proof." + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "Case $a\\ge c\\ge b$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $a\\to a+c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $c\\to b+c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "numerator: $2a^4b^2+2a^4bc+a^4c^2+4a^3b^3+2\\sqrt{2}a^3b^2c+10a^3b^2c+2\\sqrt{2}a^3bc^2+6a^3bc^2+2a^3c^3+2a^2b^4+2\\sqrt{2}a^2b^3c+10a^2b^3c+6\\sqrt{2}a^2b^2c^2+12a^2b^2c^2+4a^2bc^3+4\\sqrt{2}a^2bc^3+a^2c^4+2ab^4c+2\\sqrt{2}ab^3c^2+6ab^3c^2+4ab^2c^3+4\\sqrt{2}ab^2c^3+2\\sqrt{2}abc^4+2b^4c^2+4b^3c^3+2b^2c^4$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $a^2b^4+2a^2b^3c+a^2b^2c^2+2ab^5+6ab^4c+6ab^3c^2+2ab^2c^3+b^6+4b^5c+6b^4c^2+4b^3c^3+b^2c^4$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le 2a^4b^2+2a^4bc+a^4c^2+4a^3b^3+2\\sqrt{2}a^3b^2c+10a^3b^2c+2\\sqrt{2}a^3bc^2+6a^3bc^2+2a^3c^3+2a^2b^4+2\\sqrt{2}a^2b^3c+10a^2b^3c+6\\sqrt{2}a^2b^2c^2+12a^2b^2c^2+4\\sqrt{2}a^2bc^3+4a^2bc^3+a^2c^4+2ab^4c+2\\sqrt{2}ab^3c^2+6ab^3c^2+4\\sqrt{2}ab^2c^3+4ab^2c^3+2\\sqrt{2}abc^4+2b^4c^2+4b^3c^3+2b^2c^4 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Case $a\\ge b\\ge c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $a\\to a+b$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $b\\to b+c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $a\\to \\sqrt{2}a$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "numerator: $4a^4b^2+8a^4bc+8a^4c^2+4\\sqrt{2}a^3b^3-8a^3b^2c+12\\sqrt{2}a^3b^2c-8a^3bc^2+20\\sqrt{2}a^3bc^2+8\\sqrt{2}a^3c^3+2a^2b^4-8\\sqrt{2}a^2b^3c+8a^2b^3c-12\\sqrt{2}a^2b^2c^2+24a^2b^2c^2-4\\sqrt{2}a^2bc^3+20a^2bc^3+4a^2c^4-4ab^4c-8ab^3c^2+4\\sqrt{2}ab^3c^2-4ab^2c^3+6\\sqrt{2}ab^2c^3+2\\sqrt{2}abc^4+2b^4c^2+4b^3c^3+2b^2c^4$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $2a^2b^2c^2+4a^2bc^3+2a^2c^4+2\\sqrt{2}ab^3c^2+6\\sqrt{2}ab^2c^3+6\\sqrt{2}abc^4+2\\sqrt{2}ac^5+b^4c^2+4b^3c^3+6b^2c^4+4bc^5+c^6$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "From weighted AM-GM inequality:" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$8a^3b^2c \\le 4a^4b^2+4a^2b^2c^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$8\\sqrt{2}a^2b^3c \\le 4\\sqrt{2}a^3b^3+4\\sqrt{2}ab^3c^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$12\\sqrt{2}a^2b^2c^2 \\le 6\\sqrt{2}a^3b^2c+6\\sqrt{2}ab^2c^3$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$4\\sqrt{2}a^2bc^3 \\le 2\\sqrt{2}a^3bc^2+2\\sqrt{2}abc^4$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$4ab^4c \\le 2a^2b^4+2b^4c^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$8ab^3c^2 \\le 4a^2b^3c+4b^3c^3$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$8a^3bc^2 \\le 4a^4bc+4a^2bc^3$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$4ab^2c^3 \\le 2a^2b^2c^2+2b^2c^4$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le 4a^4bc+8a^4c^2+6\\sqrt{2}a^3b^2c+18\\sqrt{2}a^3bc^2+8\\sqrt{2}a^3c^3+4a^2b^3c+18a^2b^2c^2+16a^2bc^3+4a^2c^4 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sVars.display=lambda x:display(Latex(x)) #turn on printing proofs \n", + "formula=cyclize('((a-b)/c)^2-2*sqrt(2)*(a-b)/c')\n", + "display(Latex('Case $a\\ge c\\ge b$'))\n", + "formula1=makesubs(formula,'[c,oo],[b,oo]',variables='a,c,b')\n", + "prove(formula1)\n", + "display(Latex('Case $a\\ge b\\ge c$'))\n", + "formula2=makesubs(formula,'[b,oo],[c,oo]')\n", + "prove(formula2,values='2**(1/2),1,1')" + ] + }, { "cell_type": "code", "execution_count": null, @@ -3266,9 +4110,9 @@ ], "metadata": { "kernelspec": { - "display_name": "SageMath 9.0", - "language": "sage", - "name": "sagemath" + "display_name": "Python 3", + "language": "python", + "name": "python3" }, "language_info": { "codemirror_mode": { diff --git a/sandbox.ipynb b/sandbox.ipynb index dca4f4c..8596d7a 100644 --- a/sandbox.ipynb +++ b/sandbox.ipynb @@ -21,10 +21,11 @@ "outputs": [], "source": [ "from shiroindev import *\n", + "from sympy import *\n", "from itertools import permutations, combinations\n", "sVars.seed=1\n", "from IPython.display import Latex\n", - "sVars.print=lambda x:display(Latex(x))" + "sVars.display=lambda x:display(Latex(x))" ] }, { @@ -158,25 +159,7 @@ }, { "cell_type": "code", - "execution_count": 63, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "a**2 - a*(b + c + d) + b**2 + c**2 + d**2\n", - "[-a*(1 - 1/(a*b**2*c)) + 2*b - 2/(a**2*b**3*c**2), -a*(1 - 1/(a*b*c**2)) + 2*c - 2/(a**2*b**2*c**3), 2*a - b - c - 2/(a**3*b**2*c**2)]\n" - ] - } - ], - "source": [ - "point(Sm('(a^2+b^2+c^2+d^2)-a*(b+c+d)'))" - ] - }, - { - "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -281,7 +264,7 @@ "0" ] }, - "execution_count": 5, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -292,7 +275,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -307,30 +290,7 @@ }, { "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "data": { - "text/latex": [ - "$\\displaystyle \\infty$" - ], - "text/plain": [ - "oo" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "oo" - ] - }, - { - "cell_type": "code", - "execution_count": 8, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -345,13 +305,13 @@ " b=ls[j]\n", " if expand(formula-formula.subs({a:b, b:a}, simultaneous=True))==S(0):\n", " formula=makesubs(formula,[[b,S('oo')]],variables=[a,b])\n", - " sVars.print('$$'+latex(formula)+'$$')\n", + " sVars.display('$$'+latex(formula)+'$$')\n", " symprove(formula,n-1)" ] }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -385,16 +345,232 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "def provesym(formula,n):\n", + " formula=S(formula)\n", + " if n==0:\n", + " return\n", + " fs=list(formula.free_symbols)\n", + " print \n", + " for i in range(2,len(fs)+1):\n", + " for fs2 in combinations(fs,i):\n", + " for fsp in permutations(fs2[1:]):\n", + " if expand(formula-formula.subs(zip((fs2[0],)+fsp,fsp+(fs2[0],)), simultaneous=True))==S(0):\n", + " newformula=makesubs(formula,[[fs2[0],oo]]*(len(fsp)),variables=fsp)\n", + " sVars.display(str(n)+' $$'+latex(newformula)+'$$')\n", + " provesym(newformula,n-1)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "(y, x)\n" - ] + "data": { + "text/latex": [ + "Substitute $y\\to x+y$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" }, + { + "data": { + "text/latex": [ + "4 $$x^{2} z^{t} - x x^{t} y + x y z^{t} + x y \\left(x + y\\right)^{t} - 2 x z z^{t} + x^{t} y z + y^{2} \\left(x + y\\right)^{t} - y z z^{t} - y z \\left(x + y\\right)^{t} + z^{2} z^{t}$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $z\\to x+z$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "4 $$x^{2} y^{t} - x x^{t} z - 2 x y y^{t} + x y^{t} z + x z \\left(x + z\\right)^{t} + x^{t} y z + y^{2} y^{t} - y y^{t} z - y z \\left(x + z\\right)^{t} + z^{2} \\left(x + z\\right)^{t}$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $z\\to y+z$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "4 $$x^{2} x^{t} - 2 x x^{t} y - x x^{t} z + x y^{t} z - x z \\left(y + z\\right)^{t} + x^{t} y^{2} + x^{t} y z - y y^{t} z + y z \\left(y + z\\right)^{t} + z^{2} \\left(y + z\\right)^{t}$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $y\\to x+y$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $z\\to x+z$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "4 $$x^{t} y z + y^{2} \\left(x + y\\right)^{t} - y z \\left(x + y\\right)^{t} - y z \\left(x + z\\right)^{t} + z^{2} \\left(x + z\\right)^{t}$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $z\\to y+z$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "3 $$x^{t} y^{2} + x^{t} y z - y z \\left(x + y\\right)^{t} + y z \\left(x + y + z\\right)^{t} + z^{2} \\left(x + y + z\\right)^{t}$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $z\\to x+z$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $y\\to x+y$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "4 $$x^{t} y z + y^{2} \\left(x + y\\right)^{t} - y z \\left(x + y\\right)^{t} - y z \\left(x + z\\right)^{t} + z^{2} \\left(x + z\\right)^{t}$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $z\\to y+z$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "3 $$x^{t} y^{2} + x^{t} y z - y z \\left(x + y\\right)^{t} + y z \\left(x + y + z\\right)^{t} + z^{2} \\left(x + y + z\\right)^{t}$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "provesym(Sm('x^t(x-y)(x-z) + y^t (y-z)(y-x) + z^t (z-x)(z-y)'),4)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ { "data": { "text/latex": [ @@ -410,31 +586,19 @@ { "data": { "text/latex": [ - "$$x^{2} \\left(x + y\\right)^{t} - x y y^{t} + x y z^{t} + x y \\left(x + y\\right)^{t} + x y^{t} z - x z z^{t} - x z \\left(x + y\\right)^{t} + y^{2} z^{t} - 2 y z z^{t} + z^{2} z^{t}$$" + "$\\displaystyle x^{2} \\left(x + y\\right)^{t} - x y y^{t} + x y z^{t} + x y \\left(x + y\\right)^{t} + x y^{t} z - x z z^{t} - x z \\left(x + y\\right)^{t} + y^{2} z^{t} - 2 y z z^{t} + z^{2} z^{t}$" ], "text/plain": [ - "" + "x**2*(x + y)**t - x*y*y**t + x*y*z**t + x*y*(x + y)**t + x*y**t*z - x*z*z**t - x*z*(x + y)**t + y**2*z**t - 2*y*z*z**t + z**2*z**t" ] }, + "execution_count": 10, "metadata": {}, - "output_type": "display_data" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "(y, x)\n", - "(y, t)\n", - "(x, t)\n", - "(y, x, t)\n", - "(y, t)\n", - "(x, t)\n", - "(y, x, t)\n" - ] + "output_type": "execute_result" } ], "source": [ - "provesym(Sm('x^t(x-y)(x-z) + y^t (y-z)(y-x) + z^t (z-x)(z-y)'),4)" + "makesubs(Sm('x^t(x-y)(x-z) + y^t (y-z)(y-x) + z^t (z-x)(z-y)'),'[y,oo]',variables='x')" ] }, { @@ -469,7 +633,7 @@ } ], "source": [ - "makesubs(Sm('x^t(x-y)(x-z) + y^t (y-z)(y-x) + z^t (z-x)(z-y)'),'[y,oo]',variables='x')" + "makesubs(Sm('x^t*(x-y)(x-z) + y^t*(y-z)(y-x) + z^t*(z-x)(z-y)'),'[y,oo]',variables='x')" ] }, { @@ -480,7 +644,7 @@ { "data": { "text/latex": [ - "Substitute $x\\to x+y$" + "Substitute $y\\to x+y$" ], "text/plain": [ "" @@ -492,51 +656,7 @@ { "data": { "text/latex": [ - "$\\displaystyle x^{2} \\left(x + y\\right)^{t} - x y y^{t} + x y z^{t} + x y \\left(x + y\\right)^{t} + x y^{t} z - x z z^{t} - x z \\left(x + y\\right)^{t} + y^{2} z^{t} - 2 y z z^{t} + z^{2} z^{t}$" - ], - "text/plain": [ - "x**2*(x + y)**t - x*y*y**t + x*y*z**t + x*y*(x + y)**t + x*y**t*z - x*z*z**t - x*z*(x + y)**t + y**2*z**t - 2*y*z*z**t + z**2*z**t" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "makesubs(Sm('x^t*(x-y)(x-z) + y^t*(y-z)(y-x) + z^t*(z-x)(z-y)'),'[y,oo]',variables='x')" - ] - }, - { - "cell_type": "code", - "execution_count": 56, - "metadata": {}, - "outputs": [], - "source": [ - "def provesym(formula,n):\n", - " formula=S(formula)\n", - " if n==0:\n", - " return\n", - " fs=list(formula.free_symbols)\n", - " print \n", - " for i in range(2,len(fs)+1):\n", - " for fs2 in combinations(fs,i):\n", - " for fsp in permutations(fs2[1:]):\n", - " if expand(formula-formula.subs(zip((fs2[0],)+fsp,fsp+(fs2[0],)), simultaneous=True))==S(0):\n", - " newformula=makesubs(formula,[[fs2[0],oo]]*(len(fsp)),variables=fsp)\n", - " sVars.print(str(n)+' $$'+latex(newformula)+'$$')\n", - " provesym(newformula,n-1)" - ] - }, - { - "cell_type": "code", - "execution_count": 57, - "metadata": {}, - "outputs": [ - { - "data": { - "text/latex": [ - "Substitute $y\\to y+z$" + "4 $$x^{2} z^{t} - x x^{t} y + x y z^{t} + x y \\left(x + y\\right)^{t} - 2 x z z^{t} + x^{t} y z + y^{2} \\left(x + y\\right)^{t} - y z z^{t} - y z \\left(x + y\\right)^{t} + z^{2} z^{t}$$" ], "text/plain": [ "" @@ -548,7 +668,7 @@ { "data": { "text/latex": [ - "4 $$x^{2} x^{t} - x x^{t} y - 2 x x^{t} z + x y z^{t} - x y \\left(y + z\\right)^{t} + x^{t} y z + x^{t} z^{2} + y^{2} \\left(y + z\\right)^{t} - y z z^{t} + y z \\left(y + z\\right)^{t}$$" + "Substitute $z\\to x+z$" ], "text/plain": [ "" @@ -560,7 +680,7 @@ { "data": { "text/latex": [ - "Substitute $x\\to x+z$" + "4 $$x^{2} y^{t} - x x^{t} z - 2 x y y^{t} + x y^{t} z + x z \\left(x + z\\right)^{t} + x^{t} y z + y^{2} y^{t} - y y^{t} z - y z \\left(x + z\\right)^{t} + z^{2} \\left(x + z\\right)^{t}$$" ], "text/plain": [ "" @@ -572,7 +692,7 @@ { "data": { "text/latex": [ - "4 $$x^{2} \\left(x + z\\right)^{t} - x y y^{t} + x y z^{t} - x y \\left(x + z\\right)^{t} + x y^{t} z - x z z^{t} + x z \\left(x + z\\right)^{t} + y^{2} y^{t} - 2 y y^{t} z + y^{t} z^{2}$$" + "Substitute $z\\to y+z$" ], "text/plain": [ "" @@ -584,7 +704,7 @@ { "data": { "text/latex": [ - "Substitute $x\\to x+y$" + "4 $$x^{2} x^{t} - 2 x x^{t} y - x x^{t} z + x y^{t} z - x z \\left(y + z\\right)^{t} + x^{t} y^{2} + x^{t} y z - y y^{t} z + y z \\left(y + z\\right)^{t} + z^{2} \\left(y + z\\right)^{t}$$" ], "text/plain": [ "" @@ -596,7 +716,7 @@ { "data": { "text/latex": [ - "4 $$x^{2} \\left(x + y\\right)^{t} - x y y^{t} + x y z^{t} + x y \\left(x + y\\right)^{t} + x y^{t} z - x z z^{t} - x z \\left(x + y\\right)^{t} + y^{2} z^{t} - 2 y z z^{t} + z^{2} z^{t}$$" + "Substitute $y\\to x+y$" ], "text/plain": [ "" @@ -608,7 +728,7 @@ { "data": { "text/latex": [ - "Substitute $y\\to y+z$" + "Substitute $z\\to x+z$" ], "text/plain": [ "" @@ -620,7 +740,7 @@ { "data": { "text/latex": [ - "Substitute $x\\to x+z$" + "4 $$x^{t} y z + y^{2} \\left(x + y\\right)^{t} - y z \\left(x + y\\right)^{t} - y z \\left(x + z\\right)^{t} + z^{2} \\left(x + z\\right)^{t}$$" ], "text/plain": [ "" @@ -632,7 +752,7 @@ { "data": { "text/latex": [ - "4 $$x^{2} \\left(x + z\\right)^{t} + x y z^{t} - x y \\left(x + z\\right)^{t} - x y \\left(y + z\\right)^{t} + y^{2} \\left(y + z\\right)^{t}$$" + "Substitute $z\\to y+z$" ], "text/plain": [ "" @@ -644,7 +764,7 @@ { "data": { "text/latex": [ - "Substitute $x\\to x+y$" + "3 $$x^{t} y^{2} + x^{t} y z - y z \\left(x + y\\right)^{t} + y z \\left(x + y + z\\right)^{t} + z^{2} \\left(x + y + z\\right)^{t}$$" ], "text/plain": [ "" @@ -656,7 +776,7 @@ { "data": { "text/latex": [ - "3 $$x^{2} \\left(x + y + z\\right)^{t} + x y z^{t} - x y \\left(y + z\\right)^{t} + x y \\left(x + y + z\\right)^{t} + y^{2} z^{t}$$" + "Substitute $z\\to x+z$" ], "text/plain": [ "" @@ -668,7 +788,7 @@ { "data": { "text/latex": [ - "Substitute $x\\to x+z$" + "Substitute $y\\to x+y$" ], "text/plain": [ "" @@ -680,7 +800,7 @@ { "data": { "text/latex": [ - "Substitute $y\\to y+z$" + "4 $$x^{t} y z + y^{2} \\left(x + y\\right)^{t} - y z \\left(x + y\\right)^{t} - y z \\left(x + z\\right)^{t} + z^{2} \\left(x + z\\right)^{t}$$" ], "text/plain": [ "" @@ -692,7 +812,7 @@ { "data": { "text/latex": [ - "4 $$x^{2} \\left(x + z\\right)^{t} + x y z^{t} - x y \\left(x + z\\right)^{t} - x y \\left(y + z\\right)^{t} + y^{2} \\left(y + z\\right)^{t}$$" + "Substitute $z\\to y+z$" ], "text/plain": [ "" @@ -704,19 +824,7 @@ { "data": { "text/latex": [ - "Substitute $x\\to x+y$" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/latex": [ - "3 $$x^{2} \\left(x + y + z\\right)^{t} + x y z^{t} - x y \\left(y + z\\right)^{t} + x y \\left(x + y + z\\right)^{t} + y^{2} z^{t}$$" + "3 $$x^{t} y^{2} + x^{t} y z - y z \\left(x + y\\right)^{t} + y z \\left(x + y + z\\right)^{t} + z^{2} \\left(x + y + z\\right)^{t}$$" ], "text/plain": [ "" @@ -732,16 +840,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle x^{t} \\left(x - y\\right) \\left(x - z\\right) + y^{t} \\left(- x + y\\right) \\left(y - z\\right) + z^{t} \\left(- x + z\\right) \\left(- y + z\\right)$" + ], + "text/plain": [ + "x**t*(x - y)*(x - z) + y**t*(-x + y)*(y - z) + z**t*(-x + z)*(-y + z)" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "Sm('x^t(x-y)(x-z) + y^t (y-z)(y-x) + z^t (z-x)(z-y)')" ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 14, "metadata": {}, "outputs": [ { @@ -753,7 +875,7 @@ "3*x + y + 2*z" ] }, - "execution_count": 16, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -784,7 +906,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 16, "metadata": {}, "outputs": [ { @@ -796,7 +918,7 @@ "-t*x*y**2 + t*x*z**2 - x**2*(x + y)**t + x**2*(x + z)**t + x*y*y**t - x*y*(x + y)**t - x*y*(x + z)**t - x*z*z**t + x*z*(x + y)**t + x*z*(x + z)**t + y**2*y**t - y**2*z**t - 2*y*y**t*z + 2*y*z*z**t + y**t*z**2 - z**2*z**t" ] }, - "execution_count": 37, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } @@ -808,28 +930,9 @@ }, { "cell_type": "code", - "execution_count": 71, + "execution_count": 17, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "a**2 - a*(b + c + 1/(a*b*c)) + b**2 + c**2 + 1/(a**2*b**2*c**2)\n", - "[-a*(1 - 1/(a*b**2*c)) + 2*b - 2/(a**2*b**3*c**2), -a*(1 - 1/(a*b*c**2)) + 2*c - 2/(a**2*b**2*c**3), 2*a - b - c - 2/(a**3*b**2*c**2)]\n" - ] - }, - { - "data": { - "text/plain": [ - "[]" - ] - }, - "execution_count": 71, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "def point(formula):\n", " fs=list(formula.free_symbols)\n", @@ -839,18 +942,18 @@ " fr=formula.subs(fs[0],1/il)\n", " print(fr)\n", " return(extrema(fr))\n", - "point(Sm('(a^2+b^2+c^2+d^2)-a*(b+c+d)'))" + "#point(Sm('(a^2+b^2+c^2+d^2)-a*(b+c+d)'))" ] }, { "cell_type": "code", - "execution_count": 69, + "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/latex": [ - "Substitute $a\\to 343a/216$" + "Substitute $a\\to 11a/8$" ], "text/plain": [ "" @@ -862,7 +965,7 @@ { "data": { "text/latex": [ - "Substitute $b\\to 6b/7$" + "Substitute $b\\to 4b/5$" ], "text/plain": [ "" @@ -874,7 +977,7 @@ { "data": { "text/latex": [ - "Substitute $c\\to 6c/7$" + "Substitute $c\\to 4c/5$" ], "text/plain": [ "" @@ -886,7 +989,7 @@ { "data": { "text/latex": [ - "Substitute $d\\to 6d/7$" + "Substitute $d\\to 4d/5$" ], "text/plain": [ "" @@ -898,7 +1001,7 @@ { "data": { "text/latex": [ - "numerator: $5764801a^2-3111696ab-3111696ac-3111696ad+1679616b^2+1679616c^2+1679616d^2$" + "numerator: $3025a^2-1760ab-1760ac-1760ad+1024b^2+1024c^2+1024d^2$" ], "text/plain": [ "" @@ -910,7 +1013,7 @@ { "data": { "text/latex": [ - "denominator: $2286144$" + "denominator: $1600$" ], "text/plain": [ "" @@ -946,7 +1049,7 @@ { "data": { "text/latex": [ - "$$3111696ab \\le 1555848a^2+1555848b^2$$" + "$$1760ab \\le 880a^2+880b^2$$" ], "text/plain": [ "" @@ -958,7 +1061,7 @@ { "data": { "text/latex": [ - "$$3111696ac \\le 1555848a^2+1555848c^2$$" + "$$1760ac \\le 880a^2+880c^2$$" ], "text/plain": [ "" @@ -970,7 +1073,7 @@ { "data": { "text/latex": [ - "$$3111696ad \\le 1555848a^2+1555848d^2$$" + "$$1760ad \\le 880a^2+880d^2$$" ], "text/plain": [ "" @@ -982,7 +1085,7 @@ { "data": { "text/latex": [ - "$$ 0 \\le 1097257a^2+123768b^2+123768c^2+123768d^2 $$" + "$$ 0 \\le 385a^2+144b^2+144c^2+144d^2 $$" ], "text/plain": [ "" @@ -1009,27 +1112,27 @@ "0" ] }, - "execution_count": 69, + "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "prove(Sm('(a^2+b^2+c^2+d^2)-a*(b+c+d)'),'343/216,6/7,6/7,6/7')" + "prove(Sm('(a^2+b^2+c^2+d^2)-a*(b+c+d)'),'11/8,4/5,4/5,4/5')" ] }, { "cell_type": "code", - "execution_count": 68, + "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "23/375" + "0.06133333333333324" ] }, - "execution_count": 68, + "execution_count": 19, "metadata": {}, "output_type": "execute_result" } @@ -1038,6 +1141,2252 @@ "216/125-5/3" ] }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle - \\frac{2 \\sqrt{2} \\left(a - b\\right)}{c} + \\frac{\\left(a - b\\right)^{2}}{c^{2}} - \\frac{2 \\sqrt{2} \\left(- a + c\\right)}{b} + \\frac{\\left(- a + c\\right)^{2}}{b^{2}} - \\frac{2 \\sqrt{2} \\left(b - c\\right)}{a} + \\frac{\\left(b - c\\right)^{2}}{a^{2}}$" + ], + "text/plain": [ + "-2*sqrt(2)*(a - b)/c + (a - b)**2/c**2 - 2*sqrt(2)*(-a + c)/b + (-a + c)**2/b**2 - 2*sqrt(2)*(b - c)/a + (b - c)**2/a**2" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $a\\to a+b$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $b\\to b+c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Optimization terminated successfully.\n", + " Current function value: 0.000000\n", + " Iterations: 51\n", + " Function evaluations: 97\n", + "[1.17092486 1.170961 1.17093843]\n" + ] + }, + { + "data": { + "text/latex": [ + "$\\displaystyle \\frac{a^{4} b^{2} + 2 a^{4} b c + 2 a^{4} c^{2} + 2 a^{3} b^{3} - 2 \\sqrt{2} a^{3} b^{2} c + 6 a^{3} b^{2} c - 2 \\sqrt{2} a^{3} b c^{2} + 10 a^{3} b c^{2} + 4 a^{3} c^{3} + a^{2} b^{4} - 4 \\sqrt{2} a^{2} b^{3} c + 4 a^{2} b^{3} c - 6 \\sqrt{2} a^{2} b^{2} c^{2} + 12 a^{2} b^{2} c^{2} - 2 \\sqrt{2} a^{2} b c^{3} + 10 a^{2} b c^{3} + 2 a^{2} c^{4} - 2 \\sqrt{2} a b^{4} c - 4 \\sqrt{2} a b^{3} c^{2} + 4 a b^{3} c^{2} - 2 \\sqrt{2} a b^{2} c^{3} + 6 a b^{2} c^{3} + 2 a b c^{4} + 2 b^{4} c^{2} + 4 b^{3} c^{3} + 2 b^{2} c^{4}}{c^{2} \\left(a^{2} b^{2} + 2 a^{2} b c + a^{2} c^{2} + 2 a b^{3} + 6 a b^{2} c + 6 a b c^{2} + 2 a c^{3} + b^{4} + 4 b^{3} c + 6 b^{2} c^{2} + 4 b c^{3} + c^{4}\\right)}$" + ], + "text/plain": [ + "(a**4*b**2 + 2*a**4*b*c + 2*a**4*c**2 + 2*a**3*b**3 - 2*sqrt(2)*a**3*b**2*c + 6*a**3*b**2*c - 2*sqrt(2)*a**3*b*c**2 + 10*a**3*b*c**2 + 4*a**3*c**3 + a**2*b**4 - 4*sqrt(2)*a**2*b**3*c + 4*a**2*b**3*c - 6*sqrt(2)*a**2*b**2*c**2 + 12*a**2*b**2*c**2 - 2*sqrt(2)*a**2*b*c**3 + 10*a**2*b*c**3 + 2*a**2*c**4 - 2*sqrt(2)*a*b**4*c - 4*sqrt(2)*a*b**3*c**2 + 4*a*b**3*c**2 - 2*sqrt(2)*a*b**2*c**3 + 6*a*b**2*c**3 + 2*a*b*c**4 + 2*b**4*c**2 + 4*b**3*c**3 + 2*b**2*c**4)/(c**2*(a**2*b**2 + 2*a**2*b*c + a**2*c**2 + 2*a*b**3 + 6*a*b**2*c + 6*a*b*c**2 + 2*a*c**3 + b**4 + 4*b**3*c + 6*b**2*c**2 + 4*b*c**3 + c**4))" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "formula=cyclize(Sm('((a-b)/c)^2-8**(1/2)*(a-b)/c'))\n", + "display(formula)\n", + "from scipy.optimize import fmin\n", + "import numpy as np\n", + "def f(x):\n", + " num,den=fraction(cancel(formula))\n", + " fs=sorted(newformula.free_symbols,key=str)\n", + " return num.subs(zip(fs,x))\n", + "newformula=(makesubs(formula,'[b,oo],[c,oo]'))\n", + "print(fmin(f,np.array([2,1,1])))\n", + "display(simplify(newformula))\n", + "#prove(newformula)\n", + "#prove(makesubs(formula,'[b,oo],[a,oo]',variables='c,b,a'))" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Warning: Maximum number of function evaluations has been exceeded.\n" + ] + }, + { + "data": { + "text/plain": [ + "array([-1.62831265e+41, -1.93382892e+41])" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def g(x):\n", + " return x[0]+x[1]\n", + "fmin(g,[0,0])" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\frac{a^{2} + b^{2} + c^{2} + d^{2}}{a \\left(b + c + d\\right)}$" + ], + "text/plain": [ + "(a**2 + b**2 + c**2 + d**2)/(a*(b + c + d))" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Optimization terminated successfully.\n", + " Current function value: 1.154701\n", + " Iterations: 80\n", + " Function evaluations: 144\n" + ] + }, + { + "data": { + "text/latex": [ + "$\\displaystyle \\left( \\frac{11}{8}, \\ \\frac{4}{5}, \\ \\frac{4}{5}, \\ \\frac{4}{5}\\right)$" + ], + "text/plain": [ + "(11/8, 4/5, 4/5, 4/5)" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "formula=Sm('(a^2+b^2+c^2+d^2)/(a*(b+c+d))')\n", + "display(formula)\n", + "def f(x):\n", + " fs=sorted(formula.free_symbols,key=str)\n", + " return formula.subs(zip(fs,x))\n", + "nsimplify(tuple(fmin(f,(1,1,1,1))),tolerance=0.1,rational=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\frac{55}{32}$" + ], + "text/plain": [ + "55/32" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "_[0]/_[1]" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "Substitute $a\\to a+b$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $b\\to b+c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "ename": "NameError", + "evalue": "name 'fs' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mformula\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmakesubs\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mformula\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m'[b,oo],[c,oo]'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mnum\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mden\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mfraction\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcancel\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mformula\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0mnum\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mnum\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msubs\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mzip\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfs\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mlist\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmap\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;32mlambda\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mfs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 5\u001b[0m \u001b[0mdisplay\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnum\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0mnumm\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mNameError\u001b[0m: name 'fs' is not defined" + ] + } + ], + "source": [ + "formula=cyclize(Sm('((a-b)/c)^2-8**(1/2)*(a-b)/c'))\n", + "formula=(makesubs(formula,'[b,oo],[c,oo]'))\n", + "num,den=fraction(cancel(formula))\n", + "num=num.subs(zip(fs,list(map(lambda x:x**2,fs))))\n", + "display(num)\n", + "numm=0\n", + "nump=0\n", + "for addend in num.as_ordered_terms():\n", + " coef,facts=addend.as_coeff_mul()\n", + " if coef<0:\n", + " numm-=addend\n", + " else:\n", + " nump+=addend\n", + "num=nump/numm\n", + "fs=sorted(num.free_symbols,key=str)\n", + "numm,nump=Poly(numm),Poly(nump)\n", + "def f(x):\n", + " return nump.eval(dict(zip(fs,x)))/numm.eval(dict(zip(fs,x))) \n", + "print(dict(zip(fs,(2,2,2))))\n", + "display(f((2,2,2)))\n", + "print('x')\n", + "tup=tuple(fmin(f,(2,2,2)))\n", + "display(tuple([x*x for x in tup]))\n", + "nsimplify(tuple([x*x for x in tup]),tolerance=0.1,rational=True)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "nsimplify((2.1002573656763053, 10.340431462974655, 1.7661001788212371),tolerance=0.3,rational=True)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "(2.1002573656763053/1.7661001788212371)**2" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "Case $a\\ge c\\ge b$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $a\\to a+c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $c\\to b+c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "numerator: $2a^4b^2+2a^4bc+a^4c^2+4a^3b^3+2\\sqrt{2}a^3b^2c+10a^3b^2c+2\\sqrt{2}a^3bc^2+6a^3bc^2+2a^3c^3+2a^2b^4+2\\sqrt{2}a^2b^3c+10a^2b^3c+6\\sqrt{2}a^2b^2c^2+12a^2b^2c^2+4a^2bc^3+4\\sqrt{2}a^2bc^3+a^2c^4+2ab^4c+2\\sqrt{2}ab^3c^2+6ab^3c^2+4ab^2c^3+4\\sqrt{2}ab^2c^3+2\\sqrt{2}abc^4+2b^4c^2+4b^3c^3+2b^2c^4$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $a^2b^4+2a^2b^3c+a^2b^2c^2+2ab^5+6ab^4c+6ab^3c^2+2ab^2c^3+b^6+4b^5c+6b^4c^2+4b^3c^3+b^2c^4$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le 2a^4b^2+2a^4bc+a^4c^2+4a^3b^3+2\\sqrt{2}a^3b^2c+10a^3b^2c+2\\sqrt{2}a^3bc^2+6a^3bc^2+2a^3c^3+2a^2b^4+2\\sqrt{2}a^2b^3c+10a^2b^3c+6\\sqrt{2}a^2b^2c^2+12a^2b^2c^2+4\\sqrt{2}a^2bc^3+4a^2bc^3+a^2c^4+2ab^4c+2\\sqrt{2}ab^3c^2+6ab^3c^2+4\\sqrt{2}ab^2c^3+4ab^2c^3+2\\sqrt{2}abc^4+2b^4c^2+4b^3c^3+2b^2c^4 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Case $a\\ge b\\ge c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $a\\to a+b$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $b\\to b+c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $a\\to \\sqrt{2}a$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "numerator: $16a^4b^2+32a^4bc+32a^4c^2+16\\sqrt{2}a^3b^3-32a^3b^2c+48\\sqrt{2}a^3b^2c-32a^3bc^2+80\\sqrt{2}a^3bc^2+32\\sqrt{2}a^3c^3+8a^2b^4-32\\sqrt{2}a^2b^3c+32a^2b^3c-48\\sqrt{2}a^2b^2c^2+96a^2b^2c^2-16\\sqrt{2}a^2bc^3+80a^2bc^3+16a^2c^4-16ab^4c-32ab^3c^2+16\\sqrt{2}ab^3c^2-16ab^2c^3+24\\sqrt{2}ab^2c^3+8\\sqrt{2}abc^4+8b^4c^2+16b^3c^3+8b^2c^4$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $2a^2b^2c^2+4a^2bc^3+2a^2c^4+2\\sqrt{2}ab^3c^2+6\\sqrt{2}ab^2c^3+6\\sqrt{2}abc^4+2\\sqrt{2}ac^5+b^4c^2+4b^3c^3+6b^2c^4+4bc^5+c^6$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "From weighted AM-GM inequality:" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$32a^3b^2c \\le 16a^4b^2+16a^2b^2c^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$32\\sqrt{2}a^2b^3c \\le 16\\sqrt{2}a^3b^3+16\\sqrt{2}ab^3c^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$48\\sqrt{2}a^2b^2c^2 \\le 24\\sqrt{2}a^3b^2c+24\\sqrt{2}ab^2c^3$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$16\\sqrt{2}a^2bc^3 \\le 8\\sqrt{2}a^3bc^2+8\\sqrt{2}abc^4$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$16ab^4c \\le 8a^2b^4+8b^4c^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$32ab^3c^2 \\le 16a^2b^3c+16b^3c^3$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$32a^3bc^2 \\le 16a^4bc+16a^2bc^3$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$16ab^2c^3 \\le 8a^2b^2c^2+8b^2c^4$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le 16a^4bc+32a^4c^2+24\\sqrt{2}a^3b^2c+72\\sqrt{2}a^3bc^2+32\\sqrt{2}a^3c^3+16a^2b^3c+72a^2b^2c^2+64a^2bc^3+16a^2c^4 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\displaystyle - \\frac{2 \\sqrt{2} \\left(a - b\\right)}{c} + \\frac{\\left(a - b\\right)^{2}}{c^{2}} - \\frac{2 \\sqrt{2} \\left(- a + c\\right)}{b} + \\frac{\\left(- a + c\\right)^{2}}{b^{2}} - \\frac{2 \\sqrt{2} \\left(b - c\\right)}{a} + \\frac{\\left(b - c\\right)^{2}}{a^{2}}$" + ], + "text/plain": [ + "-2*sqrt(2)*(a - b)/c + (a - b)**2/c**2 - 2*sqrt(2)*(-a + c)/b + (-a + c)**2/b**2 - 2*sqrt(2)*(b - c)/a + (b - c)**2/a**2" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "formula=cyclize(Sm('((a-b)/c)^2-8**(1/2)*(a-b)/c'))\n", + "display(Latex('Case $a\\ge c\\ge b$'))\n", + "formula1=makesubs(formula,'[c,oo],[b,oo]',variables='a,c,b')\n", + "prove(formula1)\n", + "display(Latex('Case $a\\ge b\\ge c$'))\n", + "formula2=makesubs(formula,'[b,oo],[c,oo]')\n", + "prove(formula2*4,values='2**(1/2),1,1')\n", + "formula" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "formula=cyclize(Sm('((a-b)/c)^2-8**(1/2)*(a-b)/c'))\n", + "formula=(makesubs(formula,'[b,oo],[c,oo]'))\n", + "formula,_=fraction(cancel(formula))\n", + "formula=formula.subs('a','2**(1/2)*a')\n", + "sVars.display(r'Substitute $a\\to\\sqrt{2}a$')\n", + "prove(formula)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "S('2**(1/2)*x*y').as_coeff_mul()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "S('sqrt(2)*x*y').as_coeff_mul()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "Poly('sqrt(2)*x*y+8').monoms()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "Poly('sqrt(2)*x*y+58').coeffs()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "Poly('sqrt(2)*x*y+sqrt(3)+sqrt(2)*sqrt(3)').gens" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def _formula2list(formula):\n", + " neg=pos=0\n", + " for addend in formula.as_ordered_terms():\n", + " coef,facts=addend.as_coeff_mul()\n", + " if coef<0:\n", + " neg-=addend\n", + " else:\n", + " pos+=addend\n", + " neg=Poly(neg,gens=Poly(formula).gens)\n", + " pos=Poly(pos,gens=Poly(formula).gens)\n", + " return neg.coeffs(),neg.monoms(),pos.coeffs(),pos.monoms(),Poly(formula).gens\n", + "_formula2list(S('x^2+7*y'))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "prove(S('sqrt(2)*x^2-sqrt(8)*x*y+sqrt(2)*y^2'))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "[Poly('1+2**(1/3)+4**(1/3)+x').monoms(),Poly('1+2**(1/3)+4**(1/3)+x').coeffs()]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "x=Symbol('x', positive=True)\n", + "Poly(x+sqrt(x))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "prove?" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "Poly('x^2-1').abs()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "Poly(Poly('x')/Poly('x+y'))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "Poly('sqrt(2)+x+sqrt(x)+x**(1/4)+x**(1/3)+x**(2/3)',extension=1)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "Poly('x+sqrt(6)',S('x'),S('sqrt(2)'),S('sqrt(3)')).coeffs()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "Poly('x+sqrt(x)',S('sqrt(x)')).coeffs()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "source(Poly)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "Poly({1:1,2:1},gens=S('sqrt(x)'))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "x=symbols('x', positive=True)\n", + "S('sqrt(x^2)-x')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "str(Poly({1:1,2:1,4:1},gens=S('sqrt(x)')))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "str(Poly('x^2+x+sqrt(x)'))" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "Substitute $a\\to a+b$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $b\\to b+c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Optimization terminated successfully.\n", + " Current function value: 1.000000\n", + " Iterations: 137\n", + " Function evaluations: 249\n" + ] + }, + { + "data": { + "text/plain": [ + "(2.5326984818340415e-10, 7.129450063690368, 1.7908873553542452e-10)" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "1.4142142855953455" + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def findvalues(formula,values=None,variables=None):\n", + " formula=S(formula)\n", + " num,den=fractioncancel(formula)\n", + " if variables==None:\n", + " variables=sorted(num.free_symbols,key=str)\n", + " num=num.subs(zip(variables,list(map(lambda x:x**2,variables))))\n", + " num=Poly(num)\n", + " newformula=S((num.abs()+num)/(num.abs()-num))\n", + " f=lambdify(variables,newformula)\n", + " f2=lambda x:f(*x)\n", + " if values==None:\n", + " values=[1.0]*len(variables)\n", + " tup=tuple(fmin(f2,values))\n", + " return tuple([x*x for x in tup])\n", + "formula=cyclize(Sm('((a-b)/c)^2-8**(1/2)*(a-b)/c'))\n", + "formula=(makesubs(formula,'[b,oo],[c,oo]'))\n", + "values=findvalues(formula)\n", + "display(values)\n", + "nsimplify(values,tolerance=0.1,rational=True)\n", + "values[0]/values[2]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from random import random\n", + "formula=cyclize(Sm('((a-b)/c)^2-8**(1/2)*(a-b)/c'))\n", + "formula=(makesubs(formula,'[b,oo],[c,oo]'))\n", + "num,den=fractioncancel(formula)\n", + "fs=sorted(num.free_symbols,key=str)\n", + "num=num.subs(zip(fs,list(map(lambda x:x**2,fs))))\n", + "num=Poly(num,domain='RR')\n", + "num1=(num.abs()+num)\n", + "num2=(num.abs()-num)\n", + "newformula=S(num1/num2)\n", + "def evaluate(x):\n", + " return newformula.evalf(subs=dict(zip(fs,(1,1,1))))\n", + "def evaluate2(x):\n", + " return num1.evalf(dict(zip(fs,x)))/num2.eval(dict(zip(fs,x)))\n", + "#display(num2.eval(dict(zip(fs,(1,1,1)))))\n", + "print('ok')\n", + "%timeit evaluate((random(),random(),random()))\n", + "%timeit evaluate2((random(),random(),random()))\n", + "Poly('x^2+sqrt(x)').eval\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "evaluate4=lambdify(fs,newformula)\n", + "evaluate5=lambda x:evaluate4(*x)\n", + "%timeit evaluate4(*(random(),random(),random()))\n", + "%timeit evaluate5((random(),random(),random()))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from sympy import *\n", + "print('first attempt:',Poly('x^2+x+sqrt(x)'))\n", + "x=Symbol('x', positive=True)\n", + "print('second attempt:',Poly(x**2+x+sqrt(x)))\n", + "print('third attempt:',str(Poly({1:1,2:1,4:1},gens=S('sqrt(x)'))))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "(Poly({1:1,2:1,4:1},gens=S('sqrt(x)'))-Poly('x^2')).as_expr()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from sympy.solvers.solvers import unrad\n", + "unrad('sqrt(x)+x')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "formula=('x^(2/3)+x^(3/4)+sqrt(x+y)')\n", + "type((Poly(formula).gens[1]).args[0])==Symbol" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "S('sqrt(x)').args" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def _powr(formula):\n", + "\tif formula.func==Pow:\n", + "\t\treturn formula.args\n", + "\telse:\n", + "\t\treturn [formula,S('1')]\n", + "pol=Poly('x**2+y**2+sqrt(x+y)+x**(1/2)+x**(1/3)')\n", + "newgens={}\n", + "for gen in pol.gens:\n", + " base,pw=_powr(gen)\n", + " num,den=fraction(pw)\n", + " if (gen[0],num) in newgens:\n", + " newgens[gen[0]]=\n", + " else:\n", + " newgens[gen[0]]=gen[1]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "isinstance(S('1'),Rational)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "6 in {3:4,5:6}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from math import *\n", + "from sympy import *\n", + "gcd(S('a/b'),S('c/d'))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "Poly('x^(2*pi)')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "gcd(S('1/8'),S('1/4'))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "S('sqrt(2)*3*x').as_coeff_mul()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def _powr(formula):\n", + "\tif formula.func==Pow:\n", + "\t\treturn formula.args\n", + "\telse:\n", + "\t\treturn [formula,S('1')]\n", + "def reducegens(formula):\n", + "\tpol=Poly(formula)\n", + "\tnewgens={}\n", + "\tind={}\n", + "\tfor gen in pol.gens:\n", + "\t\tbase,pw=_powr(gen)\n", + "\t\tcoef,_=pw.as_coeff_mul()\n", + "\t\tml=pw/coef\n", + "\t\tif base**ml in newgens:\n", + "\t\t\tnewgens[base**ml]=gcd(newgens[base**ml],coef)\n", + "\t\telse:\n", + "\t\t\tnewgens[base**ml]=coef\n", + "\t\t\tind[base**ml]=S('tmp'+str(len(ind)))\n", + "\tfor gen in pol.gens:\n", + "\t\tbase,pw=_powr(gen)\n", + "\t\tcoef,_=pw.as_coeff_mul()\n", + "\t\tml=pw/coef\n", + "\t\tpol=pol.replace(gen,ind[base**ml]**(coef/newgens[base**ml]))\n", + "\tnewpol=Poly(pol.as_expr())\n", + "\tfor gen in newgens:\n", + "\t\tnewpol=newpol.replace(ind[gen],gen**newgens[gen])\n", + "\treturn newpol\n", + "print(reducegens(S('x^2+x+sqrt(x)')))\n", + "print(reducegens(S('x**2+y**2+x**(1/2)+x**(1/3)')))\n", + "print(reducegens(S('sqrt(x)+sqrt(z)+sqrt(x*z)')))\n", + "print(reducegens(S('sqrt(x)+sqrt(z)+sqrt(x)*sqrt(z)')))\n", + "print(reducegens(S('sqrt(x+y)+sqrt(z+t)+sqrt((x+y)*(z+t))')))\n", + "print(reducegens(S('sqrt(2)+sqrt(3)+sqrt(6)')))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "S('-2').as_coeff_mul()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "x=Symbol('x', positive=True)\n", + "y=Symbol('y', positive=True)\n", + "Poly(sqrt(x)+sqrt(y)+sqrt(x*y))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "sqrt(x*y)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "simplify(S('sqrt(x*y)-sqrt(x)*sqrt(y)'))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "x=symbols('x',positive=True)\n", + "ask(Q.positive(x))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "Poly('x^2+x')+Poly('-x+7')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print(reducegens(S('sqrt(8)')))\n", + "sqrt(-1*-1)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "Poly('sqrt(2*x)+sqrt(3*x)+sqrt(6*x)')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "Poly('sqrt(2*pi)+sqrt(3*pi)')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "solve(S('sqrt(6*x)')-S('sqrt(2*y)'))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "Poly('sqrt(6)+sqrt(10)+sqrt(14)+sqrt(15)+sqrt(21)+sqrt(35)+sqrt()')" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "Substitute $a\\to a+c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "numerator: $a^2+2ab+b^2$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $1$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le a^2+2ab+b^2 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $c\\to a+c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "numerator: $b^2-2bc+c^2$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $1$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "From weighted AM-GM inequality:" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$2bc \\le b^2+c^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le 0 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from shiroindev import *\n", + "formula=S('(a+b-c)^2')\n", + "prove(makesubs(formula,'[c,oo]'))\n", + "prove(makesubs(formula,'[a,oo]',variables='c'))" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "Substitute $c\\to a+b+c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $d\\to a+b+d$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "numerator: $c^2+d^2$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $1$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le c^2+d^2 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $c\\to a+b+(-a-b)/(c+1)$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $d\\to a+b+d$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "numerator: $a^2+2ab+b^2+c^2d^2+2cd^2+d^2$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $c^2+2c+1$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le a^2+2ab+b^2+c^2d^2+2cd^2+d^2 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $c\\to a+b+(-a-b)/(c+1)$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $d\\to a+b+(-a-b)/(d+1)$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "numerator: $a^2c^2+2a^2c+a^2d^2+2a^2d+2a^2+2abc^2+4abc+2abd^2+4abd+4ab+b^2c^2+2b^2c+b^2d^2+2b^2d+2b^2$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $c^2d^2+2c^2d+c^2+2cd^2+4cd+2c+d^2+2d+1$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le a^2c^2+2a^2c+a^2d^2+2a^2d+2a^2+2abc^2+4abc+2abd^2+4abd+4ab+b^2c^2+2b^2c+b^2d^2+2b^2d+2b^2 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "formula=S('(a+b-d)^2+(a+b-c)^2')\n", + "prove(makesubs(formula,'[a+b,oo],[a+b,oo]',variables='c,d'))\n", + "prove(makesubs(formula,'[0,a+b],[a+b,oo]',variables='c,d'))\n", + "prove(makesubs(formula,'[0,a+b],[0,a+b]',variables='c,d'))" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Optimization terminated successfully.\n", + " Current function value: 1.000000\n", + " Iterations: 65\n", + " Function evaluations: 124\n" + ] + }, + { + "data": { + "text/plain": [ + "(0.8742272651582828,\n", + " 0.45912361618095604,\n", + " 1.3333325089656345,\n", + " 1.3333771594633597)" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "findvalues(formula)" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\frac{\\left(a - b\\right)^{2}}{c^{2}} + \\frac{\\left(- a + c\\right)^{2}}{b^{2}} + \\frac{\\left(b - c\\right)^{2}}{a^{2}}$" + ], + "text/plain": [ + "(a - b)**2/c**2 + (-a + c)**2/b**2 + (b - c)**2/a**2" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\displaystyle 2 \\sqrt{2} \\left(\\frac{a - b}{c} + \\frac{- a + c}{b} + \\frac{b - c}{a}\\right)$" + ], + "text/plain": [ + "2*sqrt(2)*((a - b)/c + (-a + c)/b + (b - c)/a)" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "display(cyclize('((a-b)/c)^2'))\n", + "display(S('sqrt(8)')*cyclize('(a-b)/c'))" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "Case $a\\ge c\\ge b$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $a\\to a+c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $c\\to b+c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "numerator: $2a^4b^2+2a^4bc+a^4c^2+4a^3b^3+2\\sqrt{2}a^3b^2c+10a^3b^2c+2\\sqrt{2}a^3bc^2+6a^3bc^2+2a^3c^3+2a^2b^4+2\\sqrt{2}a^2b^3c+10a^2b^3c+6\\sqrt{2}a^2b^2c^2+12a^2b^2c^2+4a^2bc^3+4\\sqrt{2}a^2bc^3+a^2c^4+2ab^4c+2\\sqrt{2}ab^3c^2+6ab^3c^2+4ab^2c^3+4\\sqrt{2}ab^2c^3+2\\sqrt{2}abc^4+2b^4c^2+4b^3c^3+2b^2c^4$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $a^2b^4+2a^2b^3c+a^2b^2c^2+2ab^5+6ab^4c+6ab^3c^2+2ab^2c^3+b^6+4b^5c+6b^4c^2+4b^3c^3+b^2c^4$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le 2a^4b^2+2a^4bc+a^4c^2+4a^3b^3+2\\sqrt{2}a^3b^2c+10a^3b^2c+2\\sqrt{2}a^3bc^2+6a^3bc^2+2a^3c^3+2a^2b^4+2\\sqrt{2}a^2b^3c+10a^2b^3c+6\\sqrt{2}a^2b^2c^2+12a^2b^2c^2+4\\sqrt{2}a^2bc^3+4a^2bc^3+a^2c^4+2ab^4c+2\\sqrt{2}ab^3c^2+6ab^3c^2+4\\sqrt{2}ab^2c^3+4ab^2c^3+2\\sqrt{2}abc^4+2b^4c^2+4b^3c^3+2b^2c^4 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Case $a\\ge b\\ge c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $a\\to a+b$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $b\\to b+c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $a\\to \\sqrt{2}a$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "numerator: $16a^4b^2+32a^4bc+32a^4c^2+16\\sqrt{2}a^3b^3-32a^3b^2c+48\\sqrt{2}a^3b^2c-32a^3bc^2+80\\sqrt{2}a^3bc^2+32\\sqrt{2}a^3c^3+8a^2b^4-32\\sqrt{2}a^2b^3c+32a^2b^3c-48\\sqrt{2}a^2b^2c^2+96a^2b^2c^2-16\\sqrt{2}a^2bc^3+80a^2bc^3+16a^2c^4-16ab^4c-32ab^3c^2+16\\sqrt{2}ab^3c^2-16ab^2c^3+24\\sqrt{2}ab^2c^3+8\\sqrt{2}abc^4+8b^4c^2+16b^3c^3+8b^2c^4$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "denominator: $2a^2b^2c^2+4a^2bc^3+2a^2c^4+2\\sqrt{2}ab^3c^2+6\\sqrt{2}ab^2c^3+6\\sqrt{2}abc^4+2\\sqrt{2}ac^5+b^4c^2+4b^3c^3+6b^2c^4+4bc^5+c^6$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "status: 0" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "From weighted AM-GM inequality:" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$32a^3b^2c \\le 16a^4b^2+16a^2b^2c^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$32\\sqrt{2}a^2b^3c \\le 16\\sqrt{2}a^3b^3+16\\sqrt{2}ab^3c^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$48\\sqrt{2}a^2b^2c^2 \\le 24\\sqrt{2}a^3b^2c+24\\sqrt{2}ab^2c^3$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$16\\sqrt{2}a^2bc^3 \\le 8\\sqrt{2}a^3bc^2+8\\sqrt{2}abc^4$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$16ab^4c \\le 8a^2b^4+8b^4c^2$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$32ab^3c^2 \\le 16a^2b^3c+16b^3c^3$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$32a^3bc^2 \\le 16a^4bc+16a^2bc^3$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$16ab^2c^3 \\le 8a^2b^2c^2+8b^2c^4$$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$$ 0 \\le 16a^4bc+32a^4c^2+24\\sqrt{2}a^3b^2c+72\\sqrt{2}a^3bc^2+32\\sqrt{2}a^3c^3+16a^2b^3c+72a^2b^2c^2+64a^2bc^3+16a^2c^4 $$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "The sum of all inequalities gives us a proof of the inequality." + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\displaystyle - \\frac{2 \\sqrt{2} \\left(a - b\\right)}{c} + \\frac{\\left(a - b\\right)^{2}}{c^{2}} - \\frac{2 \\sqrt{2} \\left(- a + c\\right)}{b} + \\frac{\\left(- a + c\\right)^{2}}{b^{2}} - \\frac{2 \\sqrt{2} \\left(b - c\\right)}{a} + \\frac{\\left(b - c\\right)^{2}}{a^{2}}$" + ], + "text/plain": [ + "-2*sqrt(2)*(a - b)/c + (a - b)**2/c**2 - 2*sqrt(2)*(-a + c)/b + (-a + c)**2/b**2 - 2*sqrt(2)*(b - c)/a + (b - c)**2/a**2" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "formula=cyclize('((a-b)/c)^2-8**(1/2)*(a-b)/c')\n", + "display(Latex('Case $a\\ge c\\ge b$'))\n", + "formula1=makesubs(formula,'[c,oo],[b,oo]',variables='a,c,b')\n", + "prove(formula1)\n", + "display(Latex('Case $a\\ge b\\ge c$'))\n", + "formula2=makesubs(formula,'[b,oo],[c,oo]')\n", + "prove(formula2*4,values='2**(1/2),1,1')" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "Substitute $a\\to a+c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $b\\to b+c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "formula=cyclize('((a-b)/c)^2-8**(1/2)*(a-b)/c')\n", + "formula2=makesubs(formula,'[c,oo],[c,oo]')" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Optimization terminated successfully.\n", + " Current function value: 1.000000\n", + " Iterations: 271\n", + " Function evaluations: 485\n" + ] + }, + { + "data": { + "text/plain": [ + "(12.42960536989153, 12.429310393555546, 0.00020878153950706037)" + ] + }, + "execution_count": 49, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "findvalues(formula2,values=[5,2,7])" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x,y=symbols('x,y')\n", + "ask(Q.positive(x**2+1),Q.real(x))" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'Sm' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mformula\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mSm\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'(a^2+b^2+c^2)^2- 3(a^3b+b^3c+c^3a)'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mformula1\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mmakesubs\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mformula\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m'[b,oo],[c,oo]'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mvariables\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'a,b'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mformula2\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mmakesubs\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mformula\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m'[c,oo],[b,oo]'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mvariables\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'a,c'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mprove\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mformula2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfindvalues\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mformula1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mNameError\u001b[0m: name 'Sm' is not defined" + ] + } + ], + "source": [ + "formula=Sm('(a^2+b^2+c^2)^2- 3(a^3b+b^3c+c^3a)')\n", + "formula1=makesubs(formula,'[b,oo],[c,oo]',variables='a,b')\n", + "formula2=makesubs(formula,'[c,oo],[b,oo]',variables='a,c')\n", + "prove(formula2)\n", + "print(findvalues(formula1))\n", + "#prove(formula1,values='4*b*(1-b)-1,4*c*(1-c)-1,1')" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "Substitute $b\\to b+c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "Substitute $c\\to a+c$" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/latex": [ + "$\\displaystyle - a b - a c + b c$" + ], + "text/plain": [ + "-a*b - a*c + b*c" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "makesubs(Sm('a^2-2ab+bc-c^2+ca'),'[c,oo],[a,oo]',variables='b,c')" + ] + }, { "cell_type": "code", "execution_count": null, @@ -1048,9 +3397,9 @@ ], "metadata": { "kernelspec": { - "display_name": "SageMath 9.0", - "language": "sage", - "name": "sagemath" + "display_name": "Python 3", + "language": "python", + "name": "python3" }, "language_info": { "codemirror_mode": { diff --git a/shiroindev.py b/shiroindev.py index 873b512..106ed66 100644 --- a/shiroindev.py +++ b/shiroindev.py @@ -1,13 +1,13 @@ from __future__ import (absolute_import, division, - print_function, unicode_literals) + print_function, unicode_literals) import warnings,operator -warnings.filterwarnings("ignore") +warnings.filterwarnings("ignore") #Seed is needed to select the weights in linprog function. #None means that the seed is random. -class Empty: +class Vars: pass -sVars=Empty() -sVars.print=print +sVars=Vars() +sVars.display=print sVars.seed=None sVars.translation={} translationList=['numerator:','denominator:','status:', @@ -24,9 +24,10 @@ translationList=['numerator:','denominator:','status:', #Initialize english-english dictionary. for phrase in translationList: sVars.translation[phrase]=phrase -from scipy.optimize import linprog +from scipy.optimize import linprog,fmin import random -from sympy import S,cancel,fraction,Pow,expand,solve,latex,oo +from sympy import S,cancel,fraction,Pow,expand,solve,latex,oo,Poly,lambdify +from collections import Counter import re def _remzero(coef,fun): #coef, fun represents an expression. @@ -72,6 +73,28 @@ def ssolve(formula,variables): return result def sstr(formula): return str(formula).replace('**','^').replace('*','').replace(' ','') +def reducegens(formula): + pol=Poly(formula) + newgens={} + ind={} + for gen in pol.gens: + base,pw=_powr(gen) + coef,_=pw.as_coeff_mul() + ml=pw/coef + if base**ml in newgens: + newgens[base**ml]=gcd(newgens[base**ml],coef) + else: + newgens[base**ml]=coef + ind[base**ml]=S('tmp'+str(len(ind))) + for gen in pol.gens: + base,pw=_powr(gen) + coef,_=pw.as_coeff_mul() + ml=pw/coef + pol=pol.replace(gen,ind[base**ml]**(coef/newgens[base**ml])) + newpol=Poly(pol.as_expr()) + for gen in newgens: + newpol=newpol.replace(ind[gen],gen**newgens[gen]) + return newpol def Sm(formula): #Adds multiplication signs and sympifies a formula. #For example, Sm('(2x+y)(7+5xz)') -> S('(2*x+y)*(7+5*x*z)') @@ -88,14 +111,14 @@ def _input2fraction(formula,variables,values): subst=[] for x,y in zip(variables,values): if y!=1: - sVars.print(sVars.translation['Substitute']+' $'+str(x)+'\\to '+slatex(S(y)*S(x))+'$') + sVars.display(sVars.translation['Substitute']+' $'+str(x)+'\\to '+slatex(S(y)*S(x))+'$') subst+=[(x,x*y)] formula=formula.subs(subst) numerator,denominator=fractioncancel(formula) - sVars.print(sVars.translation['numerator:']+' $'+slatex(numerator)+'$') - sVars.print(sVars.translation['denominator:']+' $'+slatex(denominator)+'$') + sVars.display(sVars.translation['numerator:']+' $'+slatex(numerator)+'$') + sVars.display(sVars.translation['denominator:']+' $'+slatex(denominator)+'$') return (numerator,denominator) -def _formula2list(formula,variables): +def _formula2list(formula): #Splits a polynomial to a difference of two polynomials with positive #coefficients and extracts coefficients and powers of both polynomials. #'variables' is used to set order of powers @@ -103,30 +126,13 @@ def _formula2list(formula,variables): #the program tries to prove that #0<=5x^2-4xy+8y^3 #4xy<=5x^2+8y^3 -#lcoef=[4] -#lfun=[[1,1]] -#rcoef=[5,8] -#rfun=[[2,0],[0,3]] - lfun=[] - lcoef=[] - rfun=[] - rcoef=[] - varorder=dict(zip(variables,range(len(variables)))) - for addend in formula.as_ordered_terms(): - coef,facts=addend.as_coeff_mul() - powers=[0]*len(variables) - for var in variables: - powers[varorder[var]]=0 - for fact in facts: - var,pw=_powr(fact) - powers[varorder[var]]=int(pw) - if(coef<0): - lcoef+=[-coef] - lfun+=[powers] - else: - rcoef+=[coef] - rfun+=[powers] - return(lcoef,lfun,rcoef,rfun) +#returns [4],[(1,1)], [5,8],[(2,0),(0,3)], (x,y) + formula=reducegens(formula) + neg=(formula.abs()-formula)/2 + pos=(formula.abs()+formula)/2 + neg=Poly(neg,gens=formula.gens) + pos=Poly(pos,gens=formula.gens) + return neg.coeffs(),neg.monoms(),pos.coeffs(),pos.monoms(),Poly(formula).gens def _list2proof(lcoef,lfun,rcoef,rfun,variables,itermax,linprogiter,_writ2=_writ2,theorem="From weighted AM-GM inequality:"): #Now the formula is splitted on two polynomials with positive coefficients. #we will call them LHS and RHS and our inequality to prove would @@ -157,13 +163,15 @@ def _list2proof(lcoef,lfun,rcoef,rfun,variables,itermax,linprogiter,_writ2=_writ #If LHS is empty, then break. localseed=sVars.seed bufer=[] + lcoef,lfun=_remzero(lcoef,lfun) + rcoef,rfun=_remzero(rcoef,rfun) itern=0 if len(lcoef)==0: #if LHS is empty - sVars.print(sVars.translation['status:']+' 0') + sVars.display(sVars.translation['status:']+' 0') status=0 elif len(rcoef)==0: #if RHS is empty, but LHS is not - sVars.print(sVars.translation['status:']+' 2') + sVars.display(sVars.translation['status:']+' 2') status=2 itermax=0 foundreal=0 @@ -200,9 +208,9 @@ def _list2proof(lcoef,lfun,rcoef,rfun,variables,itermax,linprogiter,_writ2=_writ res=linprog(vecc,A_eq=A,b_eq=b,A_ub=A_ub,b_ub=b_ub,options={'maxiter':linprogiter}) status=res.status if itern==1: - sVars.print(sVars.translation['status:']+' '+str(status)) + sVars.display(sVars.translation['status:']+' '+str(status)) if status==0: - sVars.print(sVars.translation[theorem]) + sVars.display(sVars.translation[theorem]) if status==2: #if real solution of current inequality doesn't exist if foundreal==0: #if this is the first inequality, then break break @@ -214,7 +222,7 @@ def _list2proof(lcoef,lfun,rcoef,rfun,variables,itermax,linprogiter,_writ2=_writ continue if status==0:#if found a solution with real coefficients for ineq in bufer: - sVars.print(ineq) + sVars.display(ineq) foundreal=1 bufer=[] oldlfun,oldrfun=lfun,rfun @@ -246,25 +254,25 @@ def _list2proof(lcoef,lfun,rcoef,rfun,variables,itermax,linprogiter,_writ2=_writ lcoef,lfun=_remzero(lcoef,lfun) rcoef,rfun=_remzero(rcoef,rfun) for ineq in bufer: - sVars.print(ineq) + sVars.display(ineq) lhs='+'.join([_writ2(c,f,variables) for c,f in zip(lcoef,lfun)]) if lhs=='': lhs='0' elif status==0: - sVars.print(sVars.translation[ + sVars.display(sVars.translation[ "Program couldn't find a solution with integer coefficients. Try "+ "to multiple the formula by some integer and run this function again."]) elif(status==2): - sVars.print(sVars.translation["Program couldn't find any proof."]) + sVars.display(sVars.translation["Program couldn't find any proof."]) #return res.status elif status==1: - sVars.print(sVars.translation["Try to set higher linprogiter parameter."]) + sVars.display(sVars.translation["Try to set higher linprogiter parameter."]) rhs='+'.join([_writ2(c,f,variables) for c,f in zip(rcoef,rfun)]) if rhs=='': rhs='0' - sVars.print('$$ '+slatex(lhs)+' \\le '+slatex(rhs)+' $$') + sVars.display('$$ '+slatex(lhs)+' \\le '+slatex(rhs)+' $$') if lhs=='0': - sVars.print(sVars.translation['The sum of all inequalities gives us a proof of the inequality.']) + sVars.display(sVars.translation['The sum of all inequalities gives us a proof of the inequality.']) return status def _isiterable(obj): try: @@ -290,13 +298,13 @@ def prove(formula,values=None,variables=None,niter=200,linprogiter=10000): if values: values=_smakeiterable(values) else: values=[1]*len(variables) num,den=_input2fraction(formula,variables,values) - st=_list2proof(*(_formula2list(num,variables)+(variables,niter,linprogiter))) + st=_list2proof(*(_formula2list(num)+(niter,linprogiter))) if st==2 and issymetric(num): fs=sorted([str(x) for x in num.free_symbols]) - sVars.print(sVars.translation["It looks like the formula is symmetric. "+ + sVars.display(sVars.translation["It looks like the formula is symmetric. "+ "You can assume without loss of generality that "]+ ' >= '.join([str(x) for x in fs])+'. '+sVars.translation['Try']) - sVars.print('prove(makesubs(S("'+str(num)+'"),'+ + sVars.display('prove(makesubs(S("'+str(num)+'"),'+ str([(str(x),'oo') for x in variables[1:]])+')') return st def powerprove(formula,values=None,variables=None,niter=200,linprogiter=10000): @@ -309,10 +317,11 @@ def powerprove(formula,values=None,variables=None,niter=200,linprogiter=10000): else: values=[1]*len(variables) num,den=_input2fraction(formula,variables,values) subst2=[] + statusses=[] for j in range(len(variables)): subst2+=[(variables[j],1+variables[j])] for i in range(1<R instead of a polynomial. provef checks if a formula @@ -403,7 +413,7 @@ def provef(formula,niter=200,linprogiter=10000): #provides a proof of nonnegativity. formula=S(formula) num,den=_input2fraction(formula,[],[]) - _list2proof(*(_formula2listf(num)+(None,niter,linprogiter,_writ,'From Jensen inequality:'))) + return _list2proof(*(_formula2listf(num)+(niter,linprogiter,_writ,'From Jensen inequality:'))) def issymetric(formula): #checks if formula is symmetric #and has at least two variables if len(formula.free_symbols)<2: @@ -447,3 +457,19 @@ def symmetrize(formula,oper=operator.add,variables=None,init=None): for i in range(1,len(variables)): formula=cyclize(formula,oper,variables[:i+1]) return formula +def findvalues(formula,values=None,variables=None): + formula=S(formula) + num,den=fractioncancel(formula) + if variables==None: + variables=sorted(num.free_symbols,key=str) + num=num.subs(zip(variables,list(map(lambda x:x**2,variables)))) + num=Poly(num) + newformula=S((num.abs()+num)/(num.abs()-num)) + f=lambdify(variables,newformula) + f2=lambda x:f(*x) + if values==None: + values=[1.0]*len(variables) + else: + values=S(values) + tup=tuple(fmin(f2,values)) + return tuple([x*x for x in tup]) diff --git a/shiroindev.pyc b/shiroindev.pyc new file mode 100644 index 0000000..5ab3c39 Binary files /dev/null and b/shiroindev.pyc differ