Re: A riddle: Functions that return unevaluated when they cannot

• To: mathgroup at smc.vnet.net
• Subject: [mg82465] Re: A riddle: Functions that return unevaluated when they cannot
• From: Szabolcs Horvát <szhorvat at gmail.com>
• Date: Sat, 20 Oct 2007 22:16:31 -0400 (EDT)
• References: <ff9sin\$5vc\$1@smc.vnet.net> <ffckoe\$sop\$1@smc.vnet.net>

```Jens-Peer Kuska wrote:
> Hi,
>
> you don't have to do anything
>
> fact[0] = 1;
> fact[n_ /; n > 0] := n*fact[n - 1]
>
> will return fact[-4] because *no* rule matches.
>

Of course.  But the fact function was just an illustrative example.  The
question was:  what should one do when

1. The problem is solvable for certain inputs only
2. To decide whether the problem is solvable for some
input is just as difficult as solving the problem.

For the factorial function, deciding whether the problem is solvable is
simple: just check whether the input is >= 0 or not.  For Integrate[],
it is much more difficult.

For such functions, I would cache whether the problem was solvable or
not, and use a Condition[] with this cached value to prevent further
evaluation.

But this is not what Mathematica does.  The result of an unsolvable (by
Mathematica) integral is the unevaluated Integrate[] itself.  If this
result is not evaluated any further, then why is the same Integrate[...]
expression evaluated again (as shown by timing values) when I type it
again as input?

I hope this clears up why I tried to ask in my last post.

--
Szabolcs

```

• Prev by Date: Re: Is there anyway to save Graphics Output from command line?
• Next by Date: Re: Example of Dynamic Appearance of Locator in LocatorPane?
• Previous by thread: Re: A riddle: Functions that return unevaluated when they cannot
• Next by thread: Re: A riddle: Functions that return unevaluated when they cannot