diff --git a/examples/ipython/issue-513.ipynb b/examples/ipython/issue-513.ipynb new file mode 100644 index 00000000..5e42d46c --- /dev/null +++ b/examples/ipython/issue-513.ipynb @@ -0,0 +1,196 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "26c91d51-9f62-4c3e-9d02-2ca3a0977913", + "metadata": {}, + "outputs": [], + "source": [ + "from galgebra.ga import Ga\n", + "import sympy as S\n", + "\n", + "x,y,z = coords = S.symbols('x y z', real=True)\n", + "ga = Ga('e', g=[1,1,1], coords=coords, wedge=False)\n", + "ex,ey,ez = ga.mv()" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "5d541f6c-f9f8-4adb-a4b5-5ab27a9293dc", + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\mathbf{e}_{x} \\frac{\\partial}{\\partial x} + \\mathbf{e}_{y} \\frac{\\partial}{\\partial y} + \\mathbf{e}_{z} \\frac{\\partial}{\\partial z}$" + ], + "text/plain": [ + "e_x*D{x} + e_y*D{y} + e_z*D{z}" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ga.grad" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "d07a0e79-b467-4cef-9ea6-3b49e925bf0e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle 1$" + ], + "text/plain": [ + "1" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ga.grad * (x*ex)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "417d322c-30f5-4353-9f32-cc39cb7b2d8e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\mathbf{e}_{x}$" + ], + "text/plain": [ + "e_x" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(x*ex).diff(x)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "7d66fe00-5011-4946-ad4f-9ae6f38c315d", + "metadata": {}, + "outputs": [], + "source": [ + "x,y,z = coords = S.symbols('x y z', real=True)\n", + "ga = Ga('e', g=[1,1,1], coords=coords, wedge=False)\n", + "ex,ey,ez = ga.mv()" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "7bac45e6-985f-497d-b13e-b40f9150dfd5", + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\mathbf{e}_{x} \\frac{\\partial}{\\partial x} + \\mathbf{e}_{y} \\frac{\\partial}{\\partial y} + \\mathbf{e}_{z} \\frac{\\partial}{\\partial z}$" + ], + "text/plain": [ + "e_x*D{x} + e_y*D{y} + e_z*D{z}" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ga.grad" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "2f8161af-c147-4fcf-adfa-53613b24210f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle 1$" + ], + "text/plain": [ + "1" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ga.grad * (x*ex)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "231177c9-3422-4e33-9ace-d914502ba060", + "metadata": {}, + "outputs": [ + { + "data": { + "text/latex": [ + "$\\displaystyle \\mathbf{e}_{x}$" + ], + "text/plain": [ + "e_x" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(x*ex).pdiff(x) # notice this is pdiff() not diff() this tim" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.9.18" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/galgebra/ga.py b/galgebra/ga.py index c88a0d35..68956561 100644 --- a/galgebra/ga.py +++ b/galgebra/ga.py @@ -2049,7 +2049,10 @@ def pDiff(self, A: _mv.Mv, coord: Union[List, Symbol]) -> _mv.Mv: # Simple partial differentiation, once with respect to a single # variable, but including case of non-constant basis vectors - dA = self.mv(expand(diff(A.obj, coord))) + if isinstance(A, mv.Mv): + A = A.obj + + dA = self.mv(expand(diff(A, coord))) if self.connect_flg and self.dslot == -1 and not A.is_scalar(): # Basis blades are function of coordinates B = self.remove_scalar_part(A)