| 1 | initial version |
I re-ran your code, replacing ϕ withphi. After :
f = function('f')(x,y,z) == phi_t.expand();
we have :
sage: f
f(x, y, z) == k*q/(a^2 + x^2 + y^2 + 2*a*z + z^2) + k*q/(a^2 + x^2 + y^2 - 2*a*z + z^2) - 2*k*q/(x^2 + y^2 + z^2)
meaning that f is a Python variable whose value is an equality. Probably not what you wanted.
I am guessing that your intent was :
sage: reset("f")
sage: f(x,y,z) = phi_t.expand(); f
(x, y, z) |--> k*q/(a^2 + x^2 + y^2 + 2*a*z + z^2) + k*q/(a^2 + x^2 + y^2 - 2*a*z + z^2) - 2*k*q/(x^2 + y^2 + z^2)
f is now (a Python variable whose value is) a symbolic function (a. k. a. a callable symbolic expression).
sage: f(x, y, z).subs(z^2+x^2+y^2+w0==r^2+w0)
k*q/(a^2 + r^2 + 2*a*z) + k*q/(a^2 + r^2 - 2*a*z) - 2*k*q/(x^2 + y^2 + z^2)
which seems to be closer to what you seem to want.
But writing yourself your conversion functions may be unnecessary : you may be interested by this tutorial, then by this one, using this (large) Sage module.
HTH,
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.