[Date Index]
[Thread Index]
[Author Index]
Re: Piecewise vs. /; ?
*To*: mathgroup at smc.vnet.net
*Subject*: [mg104024] Re: Piecewise vs. /; ?
*From*: Daniel Lichtblau <danl at wolfram.com>
*Date*: Fri, 16 Oct 2009 07:18:17 -0400 (EDT)
*References*: <hashpc$qu8$1@smc.vnet.net> <hav19a$4gr$1@smc.vnet.net> <200910151119.HAA09248@smc.vnet.net>
Dan Dubin wrote:
> Folks --
>
> I would respectfully disagree with the idea that /; is more general
> than Piecewise. The example given, a function that returns a
> different value in the morning than the evening, is simply a
> time-dependent function that could be constructed using Piecewise, as
> in
>
> f[x_,h_] = Piecewise[{{x, h < 12}, {-x, h >= 12}}];
>
> and called via
>
> f[x,DateList[[4]]]
>
>
> In fact, it seems to me that any difference in the way that
> Mathematica interprets Piecewise and conditionals should be removed
> from later editions of Mathematica, since as far as I can see the
> difference between them is merely a Mathematica-specific matter of
> the mechanics of how the expressions are evaluated with little (or
> no?) utility, that causes considerable confusion among new users. I
> don't see any benefit in this distinction, but feel free to convince
> me otherwise!
> [...]
The documentation makes quite clear that Condition is a construct meant
for, and understood by, pattern matching functions. In this capacity it
may be used for programmatic constructs, e.g. DownValues that only
evaluate under certain conditions. Piecewise would be a terrible
emulator of this functionality.
By way of contrast, functions like NIntegrate understand mathematical
constructs such as Piecewise. As some examples earlier in the thread
indicated, evaluation of "functions" defined in terms of Condition might
leave one with an unintended integrand.
Let me comment on some specifics of your note.
"[A]s far as I can see the difference between them is merely
a Mathematica-specific matter of the mechanics of how the
expressions are evaluated..."
The life blood of Mathematica semantics is in the mechanics of
evaluation. While this might well be deemed Mathematica-specific, it
determines whether and how the language functions.
"with little (or no?) utility,..."
The differences in supported functionality, several presented in this
thread, argue otherwise. But I concede this is a matter of opinion.
"that causes considerable confusion among new users."
I think some amount of confusion is not new, but rather of the following
form. One defines a function using multiple DownValues with Conditional,
then tries to use it in Reduce or Integrate, and this has an unwanted
outcome. Question might be: "Why does Piecewise work and not my
definition?" A few versions ago, prior to introduction of Piecewise to
Mathematica*, the question was simply "Why does this not work?" Point
being this: Piecewise has extended the range of Mathematica, to do
things that Condition was never designed to do, and for which evaluation
semantics do not (and never did) support use of Condition.
Bottom line: The intended and supported usage of each tend to be quite
different, though there may be some amount of overlap at least in terms
of attempted usage. Suffice it to say, neither functionality will be
getting supplanted by the other.
Daniel Lichtblau
Wolfram Research
*Around 2003 we had a design meeting where the R&D Director said "I plan
to introduce some new functionality to Mathematica, piecewise". Naively,
I said "Okay. What's the functionality." True story.
Prev by Date:
**Re: Packaged Dynamic Problem**
Next by Date:
**Re: Plotting question w/ customized X "buckets"**
Previous by thread:
**Re: Piecewise vs. /; ?**
Next by thread:
**Re: Piecewise vs. /; ?**
| |