Help save net neutrality! Learn more.

#1501 noun / verb confusion for real/imag part


I think (%o4) should be (conjugate(z)+z)/2:

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

(%o4) realpart(z)

For the sub to happen, we need to nounify:

(%i5) subst(lambda([s], (s + conjugate(s))/2), nounify(realpart), realpart(z));
(%o5) (conjugate(z)+z)/2

For other functions (say cos), the nounify isn't needed:

(%i7) subst(lambda([s], 42), 'cos, cos(x));
(%o7) 42

So, I think the nounify(realpart) shouldn't be needed in (%i5).


  • Dieter Kaiser

    Dieter Kaiser - 2009-01-10

    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:


    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


    With the original code and the changed code we get:

    '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.


    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

  • Dieter Kaiser

    Dieter Kaiser - 2009-11-28
    • status: open --> pending
  • Dieter Kaiser

    Dieter Kaiser - 2009-11-28

    The substitution does not work as expected, because internally in Maxima the function realpart lives in two different forms: a noun form with the symbol %realpart and a verb form with the symbol $realpart.

    Because of this, we do not get the expected answer for the example of the bug report. The symbol 'realpart is passed with its noun form to the function subst. The verb function realpart(z) is evaluated (not simplified) to the internal noun form ((%realpart) $z). The substitution does not work, because subst distinguish the two forms:

    (%i1) declare(z,complex)$

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

    As written in the bug report a nounify helps. Again realpart(z) is evaluated to an internal noun form. Now we do not pass the verb form, but the symbol %realpart to subst:

    (%i3) subst(lambda([s], (s + conjugate(s))/2), nounify(realpart), realpart(z));
    (%o3) (conjugate(z)+z)/2

    We get the same result, when we prevent the evaluation of realpart(z) by quoting the function. Now only the verb form is present:

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

    This behavior is different from simplifing functions like sin, cos, ... These functions only have one internal representation, that is a noun form.

    The "noun/verb confusion" is the expected behavior and is due to the implementation of functions like realpart. Perhaps, we can improve the documentation on this topic.

    I had no look at the code of subst. Perhaps, it is possible to do an implementation which ignores the noun/verb scheme for symbols.

    We could change the implementation of the function realpart and friends or we might modify the function subst. I think both ways are feature requests. Therefore, I would like to close this bug report.

    Dieter Kaiser

  • SourceForge Robot

    • status: pending --> closed
  • SourceForge Robot

    This Tracker item was closed automatically by the system. It was
    previously set to a Pending status, and the original submitter
    did not respond within 14 days (the time period specified by
    the administrator of this Tracker).


Log in to post a comment.