From 1a9a60563a2c0fe11feb1088d989a692fc84cf82 Mon Sep 17 00:00:00 2001 From: utensil Date: Fri, 10 May 2024 18:28:56 +0800 Subject: [PATCH] Fix #511 --- examples/ipython/issue-511.ipynb | 145 ++++++++++++++++++++++++++++++- galgebra/mv.py | 3 + 2 files changed, 146 insertions(+), 2 deletions(-) diff --git a/examples/ipython/issue-511.ipynb b/examples/ipython/issue-511.ipynb index 5d0ef59f..5902a167 100644 --- a/examples/ipython/issue-511.ipynb +++ b/examples/ipython/issue-511.ipynb @@ -9,7 +9,7 @@ { "data": { "text/plain": [ - "(1, e_0)" + "(e_0, e_0)" ] }, "execution_count": 1, @@ -28,9 +28,150 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "ea2d702a-dd04-4f5c-8794-1efefc8e7ee9", "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\frac{1}{8} \\mathbf{e}_{0}$" + ], + "text/plain": [ + "e_0/8" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(2*ex)**-3" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "09faf76e-f43c-4023-be91-3f2460de0456", + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\frac{1}{65536}$" + ], + "text/plain": [ + "1/65536" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(2*ex)**-16" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "91e20a05-ba7d-48cd-8916-d7460fb99e87", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(2*e_0/29 + 3*e_1/29 + 4*e_2/29, 2*e_0/841 + 3*e_1/841 + 4*e_2/841)" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "((2*ex + 3*ey + 4*ez).inv(), (2*ex + 3*ey + 4*ez)**-3)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "bdf6ce81-ab58-4e3b-aa72-6cd320e6062d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\frac{1}{841}$" + ], + "text/plain": [ + "1/841" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(2*ex + 3*ey + 4*ez).inv() * (2*ex + 3*ey + 4*ez)**-3" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "2a557448-ac80-4b1c-87a0-0d25d731953c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle 1$" + ], + "text/plain": [ + "1" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "((2*ex + 3*ey + 4*ez)**3) * (2*ex + 3*ey + 4*ez)**-3" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "fd88f171-7f74-4112-9123-e986d8d92d76", + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle 1$" + ], + "text/plain": [ + "1" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(2*ex + 3*ey + 4*ez)**-3 * ((2*ex + 3*ey + 4*ez)**3)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "47ca185d-a790-4ba9-9c45-265572e6675d", + "metadata": {}, "outputs": [], "source": [] } diff --git a/galgebra/mv.py b/galgebra/mv.py index 32c2dd2d..7a652123 100644 --- a/galgebra/mv.py +++ b/galgebra/mv.py @@ -815,6 +815,9 @@ def __ror__(self, A): # dot (|) product def __pow__(self, n): # Integer power operator if not isinstance(n, int): raise ValueError('!!!!Multivector power can only be to integer power!!!!') + + if n < 0: + return (self**(-n)).inv() result = S.One for x in range(n):