Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*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 2005

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

Search the Archive

Re: Warning from Piecewise

  • To: mathgroup at smc.vnet.net
  • Subject: [mg61549] Re: Warning from Piecewise
  • From: albert <awnl at arcor.de>
  • Date: Sat, 22 Oct 2005 00:35:41 -0400 (EDT)
  • References: <dja298$fhh$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi Chris,

> When I try to set a delayed expression like this:
> 
> Comm[Piecewise[A:{{_, _}..}], Piecewise[B:{{_, _}..}]] :=
>    Comm[Testy[A], Testy2[B]]
> 
> I get a warning from Piecewise that says:
> 
> Piecewise::pairs: The first argument A : {{_, _} ..} of Piecewise is not
> a list of pairs.
> 
> I thought that the HoldAll attribute on SetDelayed should prevent
> evaluation of the LHS argument, so where is this warning coming from?

It does, but of course the code within SetDelayed can evaluate whatever part
of it's arguments it likes. For some reason this is done if the first
argument is not just a symbol. Check this:

i = 1
f[i] := 5
DownValues[f]

To avoid the errormessage and get the result you want you could wrap
HoldPattern around your arguments:

Comm[HoldPattern[Piecewise[A : {{_, _} ..}]], 
    HoldPattern[Piecewise[B : {{_, _} ..}]]] := Comm[Testy[A], Testy2[B]]

just checked and found that you will need a different pattern because
Piecwise automatically adds a second argument if called with only one
argument:

In[2]:= Piecewise[{{0 < x < 1, x}, {1 < x, 1}}]//InputForm

Out[2]//InputForm= Piecewise[{{0 < x < 1, x}, {1 < x, 1}}, 0]

So this pattern should do what you want:

Comm[HoldPattern[Piecewise[A : {{_, _} ..}, 0]], 
    HoldPattern[Piecewise[B : {{_, _} ..}, 0]]] := Comm[Testy[A], Testy2[B]]

but of course you should handle the last argument correctly if the
Comm-function shall handle arbitrary Piecewise-functions...

hth

albert



  • Prev by Date: tracking precision through ndsolve, findfit, regress, etc
  • Next by Date: Re: Circle equation problem
  • Previous by thread: Re: Warning from Piecewise
  • Next by thread: Re: Warning from Piecewise