MathGroup Archive 2007

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

Search the Archive

Re: The uses of Condition (/;)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg82974] Re: The uses of Condition (/;)
  • From: Szabolcs Horvát <szhorvat at gmail.com>
  • Date: Mon, 5 Nov 2007 05:05:40 -0500 (EST)
  • References: <fghcbl$k9n$1@smc.vnet.net> <fgk9sk$pmk$1@smc.vnet.net>

magma wrote:
> Usage C is described in the Mathematica 6 documentation under Condition - More
> information (and nowhere else I think) 

Thanks for the reply!

Yes, that's what I meant by hidden: it's hidden under "More 
information".  I thought that using /; with Module is completely 
different from the other two uses, therefore it would deserve an 
explanation at a more prominent place in the documentation.

But Ingolf Dahl's and your examples showed that this is not the 
case---in fact, B and C are sub-cases of the same kind of usage.  My 
confusion came from not realizing that /; has a higher precedence than ;.

Szabolcs

> in the form
> 
> lhs:=Module[{vars},rhs/;test]
> 
> They say that "this usage allows local variables to be shared between
> test and rhs "
> On the same Documentation page , under Scope, there is a concrete
> example of usage C.
> 
> f[x_] := Module[{u}, u^2 /; ((u = x - 1) > 0)]
> 
> here it is seen that the pattern (u) is a local variable.
> In your examples you were using x, a global variable, so no difference
> was apparent.
> In C, condition is evaluated before definition, for example (please
> make sure you have Remove[f] before typing this:
> 
> f[x_] := Module[{u}, (Print [u]; u^2) /; ((u = x - 1) > 0)]
> f[3]
> 2
> 4
> u only acquires a value after cond is evaluated and then def (Print
> [u]; u^2) will be evaluated.
> A and B are very similar, but A is considered a bit faster, because
> evaluation stops immediately if the cond is not safisfied


  • Prev by Date: Re: Re: Manipulating a complex modulus expression
  • Next by Date: How to Print without linebreaks?
  • Previous by thread: Re: The uses of Condition (/;)
  • Next by thread: Re: The uses of Condition (/;)