Am Dienstag, den 20.04.2010, 07:44 -0500 schrieb Barton Willis:
> I'm experimenting with converting spherical harmonic to a simplifying function,
> but I think the code has a noun/verb problem. Consider
>
> (%i58) integrate(integrate(spherical_harmonic(n1,m1,th,ph) *
> conjugate(spherical_harmonic(n2,m2,th,ph)) * sin(th),th,0,%pi),ph,0,2*%pi);
>
> (%o58) (-1)^m2*'integrate('integrate(spherical_harmonic(n1,m1,th,ph)
> *spherical_harmonic(n2,-m2,th,ph)
> *sin(th),th,0,%pi),ph,0,2*%pi)
>
> (%i59) subst([n1=3,m1=1,n2=5,m2=1],%);
>
> (%o59) sqrt(3)*sqrt(7)
> *('integrate(%e^(%i*ph)*'integrate(
> ''spherical_harmonic(5,1,th,-ph)
> *(-5*(1-cos(th))/2+5*(1-cos(th))^2/4+1)
> *sin(th)^2,th,0,%pi),ph,0,2*%pi))
> /(2*sqrt(%pi))
>
> Now we have a form (($spherical_harmonic) ...) that refuses to simplify:
>
> (%i60) ?print(%);
>
> ((MTIMES SIMP) ((RAT SIMP) 1 2) ((MEXPT SIMP) 3 ((RAT SIMP) 1 2)) ((MEXPT SIMP) 7 ((RAT SIMP) 1 2)) ((MEXPT SIMP) $%PI ((RAT SIMP) -1 2)) ((%INTEGRATE SIMP) ((MTIMES SIMP) ((MEXPT SIMP) $%E ((MTIMES SIMP) $%I $PH)) ((%INTEGRATE SIMP) ((MTIMES SIMP) (($SPHERICAL_HARMONIC SIMP) 5 1 $TH ((MTIMES SIMP) -1 $PH)) ((MPLUS SIMP) 1 ((MTIMES SIMP) ((RAT SIMP) 5 4) ((MEXPT SIMP) ((MPLUS SIMP) 1 ((MTIMES SIMP) -1 ((%COS SIMP) $TH))) 2)) ((MTIMES SIMP) ((RAT SIMP) -5 2) ((MPLUS SIMP) 1 ((MTIMES SIMP) -1 ((%COS SIMP) $TH))))) ((MEXPT SIMP) ((%SIN SIMP) $TH) 2)) $TH 0 $%PI)) $PH 0 ((MTIMES SIMP) 2 $%PI)))
>
> I don't know what all of the following do, but:
>
> (%i61) :lisp(get '%spherical_harmonic 'operators);
> SIMP-SPHERICAL-HARMONIC
>
> (%i61) :lisp(get '%spherical_harmonic 'noun);
> $SPHERICAL_HARMONIC
>
> (%i61) :lisp(get '%spherical_harmonic 'verb);
> NIL
>
> (%i61) :lisp(get '$spherical_harmonic 'noun);
> NIL
>
> (%i61) :lisp(get '$spherical_harmonic 'verb);
> %SPHERICAL_HARMONIC
>
> (%i61) :lisp(get '%spherical_harmonic 'alias);
> NIL
>
> (%i61) :lisp(get '$spherical_harmonic 'alias);
> %SPHERICAL_HARMONIC
>
> (%i61) :lisp(get '$spherical_harmonic 'reversealias);
> NIL
>
> (%i61) :lisp(get '%spherical_harmonic 'reversealias);
> $SPHERICAL_HARMONIC
Hello Barton,
the most simple and complete implementation of a simplifying function
which works like the trig functions and a lot of other function too (but
not all) is like the sqrt function:
;;; Implementation of the Square root function
(defprop $sqrt %sqrt verb)
(defprop $sqrt %sqrt alias)
(defprop %sqrt $sqrt noun)
(defprop %sqrt $sqrt reversealias)
(defprop %sqrt simp-sqrt operators)
(defun $sqrt (z)
(simplify (list '(%sqrt) z)))
(defmfun simp-sqrt (x y z)
(declare (ignore y))
(oneargcheck x)
(simplifya (list '(mexpt) (cadr x) '((rat simp) 1 2)) z))
You have to set the properties verb, alias, noun, rerversealias.
Furthermore, a verb function $sqrt and a simplifying function is needed,
which has to be put on the property list. The property list of the noun
and verb must look like (I have cut out some information which is not
needed for the most simple implementation):
(%i1) :lisp (symbol-plist '$sqrt)
(ALIAS %SQRT VERB %SQRT)
(%i1) :lisp (symbol-plist '%sqrt)
(OPERATORS SIMP-SQRT REVERSEALIAS $SQRT NOUN $SQRT)
The properties you have shown for the function spherical_harmonic seems
to me all correct. Perhaps, it is better to show the complete list with
the Lips command symbol-plist.
With a correct setting of the properties, Maxima should not introduce
the symbol $spherical_harmonic. Do you have some code which uses the
symbol $spherical_harmonic and not %spherical_harmonic?
Dieter Kaiser