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

MathGroup Archive 2007

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

Search the Archive

infinite loop depending on previous function call

  • To: mathgroup at smc.vnet.net
  • Subject: [mg75785] infinite loop depending on previous function call
  • From: Hannes Kessler <HannesKessler at hushmail.com>
  • Date: Thu, 10 May 2007 05:21:30 -0400 (EDT)

Hello,

here are 2 string replacement functions:

(*1*) k[s_String] := StringReplace[s, {"ab" :> "bb", "a" ~~
EndOfString :> "b"}]
(*2*) h[s_String] := FixedPoint[k, s];

Examples:

(*e1*) k["aaa"] --> "aab"
(*e2*) h["aaa"] --> "bbb"

Next, I have some function definitions built on h:

(*3*) g[s_String, 0] := 0;
(*4*) g[s_String, y_] := g[h@s, y];

(*5*) f[s_String, 0] := True;
(*6*) f[s_String, x_] := NumericQ@g[s, x];

NumericQ can be replaced by any other function of a number which
returns True or False.
And finally, I want to define a generalized inequality ("s0" is a
string parameter):

(*7*) Unprotect[Greater];
(*8*) Greater[x_ /; f["s0",x], y_ /; f["s0", y]] := Greater[g["s0",
x], g["s0", y]];
(*9*) Protect[Greater];

Running (*1*) - (*9) in a fresh kernel including the function call
(*e2*) does not cause problems if the function call occurs before the
inequality definition (*8*). On the other hand, running (*e2*) the
first time only after (*8*) results in an infinite loop without any
messages.

Can anybody explain this behavior and devise a solution?

Thanks in advance.

Best regards,
Hannes Kessler



  • Prev by Date: Re: Mathematica v6: Slower in the following fields
  • Next by Date: Re: Simplify by Recurrence Relations
  • Previous by thread: Re: Simplify by Recurrence Relations 2
  • Next by thread: Re: infinite loop depending on previous function call