MathGroup Archive 1997

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

Search the Archive

possible bug in Cases/pattern matching??

  • To: mathgroup at smc.vnet.net
  • Subject: [mg6859] possible bug in Cases/pattern matching??
  • From: Elaine Kant <kant at kathmandu.scicomp.com>
  • Date: Thu, 24 Apr 1997 02:44:37 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

I am getting some very strange behavior when using Cases and
replacement rules on a moderately long, but not horribly long
expression.  When I use the expression bound to "tester" (below) in a
variety of ways (also shown below), Mathematica just goes off into
hyperspace and cannot even be properly interrupted, only aborted.  

I can make the expression just a little bit simpler and the correct
answer is quickly returned, so I don't think it is a matter of
insufficient memory or anything like that.  I have the same problem
under both mma2 and mma3 under solaris and linux, and under at least
mma2 on a PC.  Does this return the right answer for anyone?  Anyone
have any idea what is happening??  Would appreciate direct answers to
kant at scicomp.com for speed as well as to the mailing list if desired.

  Much thanks.  
 - Elaine Kant

(*************************************************************)

(* Give the expression tester, defined below, *)

    Cases[tester[[2]], xx_ + num_Real, Infinity]

(* returns {}, correctly and virtually instantly (as does tester[[1]] etc),
BUT
*)

    Cases[tester, xx_ + num_Real, Infinity]

(* goes off into hyperspace.
In addition, the following works fine:    *)

    Scan[Print[# /. (xx_ + num_Real :> xx+mcDouble[num])]&, tester[[2]]];
    Print[done];

(* But this also seems to hang: *)

     tester[[2]] /. (xx_ + num_Real :> xx+mcDouble[num]) 

(* here's the expression used *)

tester = set[part[r1, i21, j1, k1], part[r1, i21, j1, k1] + 
    part[U, -1 + i21, -1 + j1, -1 + k1]*part[SA1, 1, 0, 0, 0] + 
    part[U, -1 + i21, -1 + j1, k1]*part[SA1, 1, 0, 0, 1] + 
    part[U, -1 + i21, -1 + j1, 1 + k1]*part[SA1, 1, 0, 0, 2] + 
    part[U, -1 + i21, j1, -1 + k1]*part[SA1, 1, 0, 1, 0] + 
    part[U, -1 + i21, j1, k1]*part[SA1, 1, 0, 1, 1] + 
    part[U, -1 + i21, j1, 1 + k1]*part[SA1, 1, 0, 1, 2] + 
    part[U, -1 + i21, 1 + j1, -1 + k1]*part[SA1, 1, 0, 2, 0] + 
    part[U, -1 + i21, 1 + j1, k1]*part[SA1, 1, 0, 2, 1] + 
    part[U, -1 + i21, 1 + j1, 1 + k1]*part[SA1, 1, 0, 2, 2] + 
    part[U, i21, -1 + j1, -1 + k1]*part[SA1, 1, 1, 0, 0] + 
    part[U, i21, -1 + j1, k1]*part[SA1, 1, 1, 0, 1] + 
    part[U, i21, -1 + j1, 1 + k1]*part[SA1, 1, 1, 0, 2] + 
    part[U, i21, j1, -1 + k1]*part[SA1, 1, 1, 1, 0] + 
    part[U, i21, j1, k1]*part[SA1, 1, 1, 1, 1] + 
    part[U, i21, j1, 1 + k1]*part[SA1, 1, 1, 1, 2] + 
    part[U, i21, 1 + j1, -1 + k1]*part[SA1, 1, 1, 2, 0] + 
    part[U, i21, 1 + j1, k1]*part[SA1, 1, 1, 2, 1] + 
    part[U, i21, 1 + j1, 1 + k1]*part[SA1, 1, 1, 2, 2] + 
    part[U, 1 + i21, -1 + j1, -1 + k1]*part[SA1, 1, 2, 0, 0] + 
    part[U, 1 + i21, -1 + j1, k1]*part[SA1, 1, 2, 0, 1] + 
    part[U, 1 + i21, -1 + j1, 1 + k1]*part[SA1, 1, 2, 0, 2] + 
    part[U, 1 + i21, j1, -1 + k1]*part[SA1, 1, 2, 1, 0] + 
    part[U, 1 + i21, j1, k1]*part[SA1, 1, 2, 1, 1] + 
    part[U, 1 + i21, j1, 1 + k1]*part[SA1, 1, 2, 1, 2] + 
    part[U, 1 + i21, 1 + j1, -1 + k1]*part[SA1, 1, 2, 2, 0] + 
    part[U, 1 + i21, 1 + j1, k1]*part[SA1, 1, 2, 2, 1] + 
    part[U, 1 + i21, 1 + j1, 1 + k1]*part[SA1, 1, 2, 2, 2]];

Print[Cases[tester[[2]], xx_ + num_Real, Infinity]];
Scan[Print[# /. (xx_ + num_Real :> xx+mcDouble[num])]&, tester[[2]]];
Print[done];

(* trouble ahead *)
Cases[tester, xx_ + num_Real, Infinity]

(* tester[[2]] /. (xx_ + num_Real :> xx+mcDouble[num])  *)

====================================

Elaine Kant
SciComp Inc.
5806 Mesa Drive, Suite 250
Austin, TX 78731

email:	kant at scicomp.com
voice:  512-451-1430
fax:    512-451-1622
www:	http://www.sig.net/~scicomp/




  • Prev by Date: Re: Assume() similar to Maple?
  • Next by Date: Re: Strange Compile Results
  • Previous by thread: 3 dimensional grid
  • Next by thread: Re: possible bug in Cases/pattern matching??