How to write a function which may return noun form of itself in Maxima language
Subject: How to write a function which may return noun form of itself in Maxima language
From: Richard Fateman
Date: Sat, 06 Aug 2011 10:01:49 -0700
I don't like using nouns for anything. You really have two concepts
involved here.
One is the request to do a computation.
The other is a data structure which represents a suspension or an
inability to do a computation.
If these are represented differently, things become much simpler.
define
computef(x):= if numberp(x) then x^2 else f(x).
s1: computef(3)
s2: computef(n+3)
work as expected.
now try
s2, f=computef, n=5
which works as expected also.
(I'm also not a fan of "ev" which is being using implicitly, here.
However, this is an appropriate use of ev!)
RJF
On 8/5/2011 11:31 PM, ???? wrote:
> Dear maxima users,
>
> Is there a suggested way to write a function in Maxima language which
> may return its noun form if it cannot process the arguments?
>
> Let me explain the issue with the following example:
> The (%i27) defines a function which returns its noun form if the
> argument is
> not a number.
> (%i27) f(x):=if numberp(x) then x^2 else 'f(x)$
>
> (%i28) f(n+3);
> (%o28) 'f(n+3)
> So far it seems working as defined.
>
> (%i29) %,n:5;
> (%o29) 'f(8)
>
> (%i30) %,nouns;
> (%o30) 64
> With additional informations, I can continue to compute using nouns flag.
> All this seems good. However:
>
> (%i31) f(n+3);
> (%o31) 'f(n+3)
>
> (%i32) %,nouns;
>
> This rather simpler example at (%i32), it never returns. It looks like
> the
> infinite recursive loop happens.
>
> I noticed that if everything is written in Lisp, then the above
> infinite loop
> can be avoided. integrate() and sum() functions does not cause such
> loop when evaluated with nouns.
>
> So my question is, is there any suggested way to write a function that
> may return noun form of itself, without causing infinite loop when
> evaluated
> with the noun flag set?
>
> Thanks and best regards,
> Yasuaki Honda, Chiba, Japan
>
> Imaxima and Imath maintainer
>
>
>
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima