Re: Piecewise vs. /; ?

*To*: mathgroup at smc.vnet.net*Subject*: [mg104038] Re: Piecewise vs. /; ?*From*: Leonid Shifrin <lshifr at gmail.com>*Date*: Fri, 16 Oct 2009 07:21:01 -0400 (EDT)*References*: <hashpc$qu8$1@smc.vnet.net> <hav19a$4gr$1@smc.vnet.net>

Hi Dan, The way I understand the difference between /; and Piecewise is the following (I am in the camp of David and Szabolcs): Condition is a programming construct, not necessarily used only in a mathematical setting. For internals of Mathematica (such as pattern-matcher and evaluator), Condition is more fundamental - if you wish, it is a component of the pattern-matcher. It is a part of the programming language, which can be used for lots of other purposes outside its applications to pure mathematical problems. Pattern-matching is very powerful, but in its pure form completely syntax-based. Condition (along with PatternTest) allows pattern-matcher to call evaluator on parts of the expression where the fact of the match can not be determined by pure syntax (head, structure checks), and this greatly expands the class of useful patterns that can be constructed. I think that anyone interested in software development aspects of Mathematica programming language (for example, to exploit new/interesting programming techniques) will probably be hard pressed to see how many of the things possible due to existence of Condition would find simple substitutes should you remove it from the language. This is amplified by the fact that a lot of existing Mathematica functionality has been developed in Mathematica language itself. It seems to me that Piecewise was introduced for exactly the purpose of better integration of piecewise functions with the other mathematical functionality. Since it is less general than Condition (in the above sense), and furthermore completely separated from the evaluation process (pattern-matching), it must be easier to formulate rules or identities involving Piecewise and be sure that they will always hold in (and only in) situations when they should (this is my guess). As far as Mathematica novices are concerned, I think that a clean separation of programming and mathematical layers of Mathematica language is one of the most inportant things to be achieved by an introductory presentation of Mathematica, to save them (novices) from the confusion you mentioned. This is only my opinion anyway. Regards, Leonid On Thu, Oct 15, 2009 at 3:19 PM, Dan Dubin <ddubin at ucsd.edu> 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! > > > >Szabolcs Horv=E1t wrote: > >> In short, /; is a programming construct that affects evaluation. > >> Piecewise[] is used to represent a mathematical concept: piecewise > >> functions. > >> > >> If you want to do mathematical operations like integration, then use > >> Piecewise[]. Condition[] (/;) is a lot more general than Piecewise[], > >> for example one could write a "function" that returns a different value > >> in the evening than in the morning, which is obviously not a function > in > >> the mathematical sense, and thus can't be integrated. > > > >Got it! Thanks to you and David for responding. > > > >-- > >Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ > > San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis > > God is love, but get it in writing. > > -- Gypsy Rose Lee > > > -- > > >

**Re: Mathematica 7.01 and Mac OS 10.6**

**Re: Mathematica 7.01 and Mac OS 10.6**

**Re: Piecewise vs. /; ?**

**Re: Piecewise vs. /; ?**