Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: The uses of Condition (/;)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg82970] Re: The uses of Condition (/;)
  • From: magma <maderri2 at gmail.com>
  • Date: Mon, 5 Nov 2007 05:03:36 -0500 (EST)
  • References: <fgka9u$q02$1@smc.vnet.net>

On Nov 4, 12:26 pm, Thomas E Burton <tbur... at brahea.com> wrote:
> Assuming that you mean (as in your examples for testing)
>
> A. pattern /; condition := definition
>
> I think A & B do yield the same results.
>
> Despite the fact that Condition has a higher Precedence than
> SetDelayed and RuleDelayed, Condition seems to apply itself the
> entire assignment or rule, not just the definition.  Perhaps the
> documentation emphasizes both A and B to bring out this somewhat
> unexpected behavior.
>


No, Condition does not apply itself to the entire assignment or rule.
the 2 definitions

j[x_] := Sqrt[x] /; x > 0
jj[x_] := (Sqrt[x] /; x > 0)

are equivalent. Condition (/; ) attaches itself to the nearest
expression on its left, in accordance to the precedence levels.
Indeed Condition is an exotic little beast.
Let's observe it in its natural habitat...
Evaluate the following:

On[]
j[1]
j[-1]
Off[]

As you see, Condition does not appear anywhere. Instead we see
RuleCondition and $Conditionhold, two"Top Secret" internal symbols.
Let's now observe Condition outside its natural habitat...
Evaluate the following:

On[]
x=3
Sqrt[x] /; x > 0
Off[]

Here we finally see Condition in action, but...it does not really do
very much. For some reason x gets replaced in the first argument, but
not in the second. Please note that Condition has HoldAll attribute.
Not yet satisfied we try...

On[]
Sqrt[x] /; 3 > 0
Sqrt[x] /; True
Sqrt[x] /; False
Off[]

As we see, when we use Condition by itself, It reappears in the trace,
but there is no (simple?) way to make it evaluate to something
meaningful, even of the test is clearly passed or rejected.
It seems that Condition can only be used in the well-known ways, never
by itself
So my question is: what does Condition evaluates to, if test is True.
And if test is False?
Apparently there is no easy answer



  • Prev by Date: Re: Jagged Spine (MultinormalDistribution)
  • Next by Date: Re: Size of graphic
  • Previous by thread: Re: The uses of Condition (/;)
  • Next by thread: Re: Problem with supplying custom tick marks