MathGroup Archive 2005

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

Search the Archive

Re: Making a new definition of Equal work with lists as well

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63400] Re: Making a new definition of Equal work with lists as well
  • From: Bill Rowe <readnewsciv at earthlink.net>
  • Date: Thu, 29 Dec 2005 02:57:31 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

On 12/28/05 at 3:55 AM, dan.bernstein at gmail.com wrote:

>I'm afraid I didn't give a sufficiently general example in my
>question. What I would like to do is to be able to get True/False
>results for expressions as general as

>{CL[2,3], 5, {CL[4,5], CL[2,2]}, x} == {CL[2,3], 8, {CL[6,7],
>CL[9,9]}, y}

>that is, lists containing both CLs and other elements, and nested
>lists etc.

>Making Equal listable wouldn't work because I would then get also a
>list (of booleans) as a result.

>I think defining Equal for CL[a_, b_] could have "just worked" if
>Equal for lists was internally defined to AND the Equal of all
>matching pairs, something like

>Equal[j_ListQ, k_ListQ]:=If[Length[j]!=Length[k], False,
>And@@Table[Equal[j[[i]], k[[i]]], {i, 1, Length[j]}]

I would do the above as:

Equal[a_List,b_List]:=
  If[Length@a != Length@b, False, And@@MapThread[Equal, {a,b}]]

or

Equal[a_List,b_List]:=
  If[Length@a != Length@b, False, And@@(Equal@@@Transpose@{a,b})]


>And I guess I could re-define it this way, but I wonder what the
>built-in definition is, and what I stand to lose by overriding it
>like that.

To me, this is really the key issue. For myself, I am quite reluctant to override any built-in function especially one used as often as Equal. The potential for unintended side effects is always there. So, without a very, very compelling reason for overriding built-in functions, my preference would be to create a new function that cannot possibly impact usage of a built-in function.
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: PaddedForm-like behavior for GridBox[]
  • Next by Date: Re: Re: Taking either a sequence or a list
  • Previous by thread: Re: Re: Making a new definition of Equal work with lists as well
  • Next by thread: preparing multiple choice questions