MathGroup Archive 2005

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

Search the Archive

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


On 12/26/05 at 4:59 AM, dan.bernstein at gmail.com (Dan  Bernstein)
wrote:

>I have defined Equal[a_CL,b_CL] := a[[1]]-a[[2]] == b[[1]]-b[[2]]
>and then 

>CL[2,3] == CL[4,5]
>CL[2,3] == CL[2,4]

>evaluate to True and False respectively, as expected. However,
>{CL[2,3]} == {CL[4,5]} just stays in that form.

>What should I do to make list equality use my "CL equality"?

There are two ways I can think of to accomplish this. First, you can use SetAttributes to give Equal the Listable attribute, i.e.,

SetAttributes[Equal, Listable]

then {CL[2,3]} == {CL[4,5]} will evaluate to {True}. But, making Equal Listable may have some undesired side effects on other usages of Equal I haven't considered. Modifying commonly used built-in functions in this manner is risky.

An alternative would be to add another definition for equal, i.e.,

Equal[{a_CL},{b_CL}]:= Equal[a,b]

Doing things this way prevents side effects since this definition only operates on lists with one element with head CL
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: Making a new definition of Equal work with lists as well
  • Next by Date: Re: Re: Questions regarding MatrixExp, and its usage
  • Previous by thread: Re: Making a new definition of Equal work with lists as well
  • Next by thread: Re: Making a new definition of Equal work with lists as well