Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

DownValues and Cases

  • To: mathgroup at smc.vnet.net
  • Subject: [mg70759] DownValues and Cases
  • From: Bruce Colletti <vze269bv at verizon.net>
  • Date: Thu, 26 Oct 2006 02:39:08 -0400 (EDT)

Re Mathematica 5.2 under WinXP.

The results of the first two Cases statements leads me to anticipate {{1,3.5}, {2,5}, {_,0}} as the output of the third.  

The output of the fourth Cases statement confirms this expectation.

Unfortunately, the output of the third statement is the empty list.  

Why so?  I've reviewed a related mid-July MathGroup thread, but don't see the answer (if it's there at all). 

Thankx.

Bruce

--------------------------

f at 1=3.5;
f@2=5;
f[_]:=0;
h=DownValues@f

Out[4]={HoldPattern[f[1]] :> 3.5, HoldPattern[f[2]] :> 5, HoldPattern[f[_]] :> 0}

Cases[h,HoldPattern[f[x_]] -> x,Infinity]
Out[5]={1,2,_}

Cases[h,(_ :> y_) -> y,Infinity]
Out[6]={3.5,5,0}

Cases[h,(HoldPattern[f[x_]] :> y_) -> {x,y},Infinity]
Out[7]={}

Cases[{a :> 4,b :> 5, c :> 6},(x_ :> y_) -> {x,y}]
Out[8]={{a,4},{b,5},{c,6}}


  • Prev by Date: Re: what's the command to load a specific "page" in the help browser?
  • Next by Date: Solving a PDE with fixed endpoints
  • Previous by thread: Re: kernel error: invalid machine instruction
  • Next by thread: Re: DownValues and Cases