The reason for the different behavior is that the functions realpart() and imagpart() have not the property ALIAS like the functions sin() or cos().

The parser returns for the input 'realpart the symbol $realpart. For fully implemented simplifying functions the parser returns e.g. for the input cos the symbol %cos because of the property ALIAS.

Unfortunately, the Lisp function risplit-noun introduces the symbols %realpart and %imagpart and realpart(z) simplifies to the expression ((%realpart) z).

The function subst() does not work because of the different symbols. The call nounify(realpart) changes the verb form $realpart to the noun form %realpart and now it works again.

This behavior can be changed when we do not use the symbol %realpart but change the function risplit-noun like:

(defun risplit-noun (l)

(cons (list '($realpart) l) (list '($imagpart) l)))

A noun which is declared to be complex now gives the expression:

(($REALPART SIMP) $Z)

The original code does a simplify, but I think this is not possible for the whole expression (we loop endlessly) and not necessary for the argument l. We get the correct expression from the simplifier.

We have to change the symbols %realpart and %imagpart at about 5 places in the whole code. The testsuite has no problems with this changes.

With this change the example will work as expected:

(%i25) subst(lambda([s], (s + conjugate(s))/2), 'realpart, realpart(z));

(%o25) (conjugate(z)+z)/2

Remark:

With the original code and the changed code we get:

'realpart(x+%i*y);

'realpart(x+%i*y) /* intern ((%realpart) .... ) */

In this case the parser returns the symbol %realpart. Because realpart() is not a simplifying function Maxima can not further simplify this expression e.g.

rectform('realpart(1));

realpart(1)

So what do you think? Should we change %realpart to $realpart in risplit-noun. Perhaps later we can introduce a simplifying function realpart().

Dieter Kaiser