MathGroup Archive 2001

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

Search the Archive

Re: Classifying by Inequalities???

  • To: mathgroup at smc.vnet.net
  • Subject: [mg29223] Re: [mg29212] Classifying by Inequalities???
  • From: BobHanlon at aol.com
  • Date: Tue, 5 Jun 2001 04:21:52 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

In a message dated 2001/6/4 5:52:09 AM, Moranresearch at aol.com writes:

>I have a series of integers l1={{a1,b1},{a2,b2},...{ai,bi}}
>I want to label each pair in the series according to the inequality rules
>
>defined below
>such that I get a series of labels l2={n,k,p....}
>
>k   =  A<0  B<0 
>l   =  A<0  B=0 
>m   =  A<0  B<0 A=B
>n   =  A<0  B>0 
>p   =  A>0  B>0 
>q   =  A=0  B>0 
>r   =  A>0  B>0 A=B
>

You cannot test with your rules in the order given. For example, any pair 
meeting the condition for m, that is, A<0 && B<0 && A==B (which is 
more simply A<0 && A==B) would always first meet the condition for k.  
Likewise, the condition for r would always be met first by the condition 
for p.

Generate random data restricted to meet one of your conditions (that is, 
there are pairs which do not meet any of your conditions such as 
{0, 0}, {0, -1}, {1, 0}, {1, -1})

l1 = Select[
      Table[{Random[Integer, {-2, 2}], 
          Random[Integer, {-2, 2}]}, {50}], #[[1]]<
              0&&#[[2]]==#[[1]]||
          #[[1]]<0&&#[[2]]<
              0||
          #[[1]]<0&&#[[2]]\[Equal]0||
          #[[1]]<
              0&&#[[2]]>0||
          #[[1]]==0&&#[[2]]>0||
          #[[1]]>
              0&&#[[2]]==#[[1]]||
          #[[1]]>0&&#[[2]]>0&];

You can use a Which statement

ans = (Which[
          #[[1]]<0 && #[[2]]==#[[1]],m,
          #[[1]]<0 && #[[2]]<0,k,
          #[[1]]<0 && #[[2]]==0,l,
          #[[1]]<0 && #[[2]]>0,n,
          #[[1]]==0 && #[[2]]>0,q,
          #[[1]]>0 && #[[2]]==#[[1]],r,
          #[[1]]>0 && #[[2]]>0,p]&/@l1)

{n, n, k, n, n, k, l, k, n, q, n, p, r, 
  k, l, n, m, n, r, n, n, r, k, n, m, 
  n, n, k, l, n, q, m, r, p, l}

or you can nest several If statements

ans = (If[#[[1]]<0, 
          If[#[[2]]==#[[1]],m, 
            If[#[[2]]<0,k, 
              If[#[[2]]==0,l,n]]],
          If[#[[1]]==0&&#[[2]]>0,q,
            If[#[[1]]>0,
              If[#[[2]]==#[[1]],r,
                If[#[[2]]>0,p]]]]]&/@l1)

True


Bob Hanlon
Chantilly, VA  USA


  • Prev by Date: Re: Re: Compound Expressions
  • Next by Date: I am looking for references
  • Previous by thread: Re: Classifying by Inequalities???
  • Next by thread: Re: Classifying by Inequalities???