Re: Classifying by Inequalities???

• To: mathgroup at smc.vnet.net
• Subject: [mg29219] Re: [mg29212] Classifying by Inequalities???
• From: Daniel Lichtblau <danl at wolfram.com>
• Date: Tue, 5 Jun 2001 04:21:50 -0400 (EDT)
• References: <200106040930.FAA15721@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Moranresearch at aol.com wrote:
>
> 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
> Thanks. John

Here is one approach. First we make a function that can generate each
type of pair of interest.

In[35]:= pair[] := Module[{ii=Random[], rr=Random[]},
Which [ii <.1, {0,2*rr-1},
ii<.2, {2*rr-1,0},
ii<.3, 2*{rr,rr}-1,
True, 2*{rr,Random[]}-1]

Now make a bunch of pairs.

In[37]:= InputForm[l1 = Table[pair[], {50}]]

Out[37]//InputForm=
{{-0.7277720328476165, -0.7277720328476165}, {0.3650932569449612, 0},
{0.3828321773557133, -0.020274616446146254},
{-0.3940875158130537, 0.997067967530467}, {0.6213444854391139,
0.09675465779260661}, {0.6600609675409608, -0.7314420021404626},
{0.6730425898894106, 0.03683216049718552}, {0.9847914349300675, 0},
{0.5421321367722511, -0.2841344899487116},
{0.5916667018905335, 0.25533189681510304},
{0.6589619623709377, -0.7911654754651798}, {-0.7777235695190945, 0},
{-0.7882334429956468, -0.6909830807230597},
{0.9562948203913848, 0.22151633148255012}, {-0.6676260528177457,
0.20161235884951756}, {0.6121237912387938, -0.9745531204517499},
{0.6845790725502223, -0.9300083455334571},
{0.6338220167426081, -0.9070876293403111},
{0.9588091163906343, 0.9748600543716706}, {-0.46094675560980947,
0.7365326859097288}, {0.6723112891205154, -0.7699636748867497},
{-0.03448424420370577, -0.5492050423620347},
{-0.19677320631431716, 0.7639033969467766},
{0.9689565821384771, -0.22222008586256725},
{0.2177421434946034, 0.2177421434946034}, {0.46819854464047106,
-0.08673954371528148}, {0.08430517002049442, 0.5093894282498368},
{0.24075192671004575, -0.4547480743696961},
{-0.9834101742746311, 0.5684406375895303}, {-0.3627439985278291, 0},
{0.11764567995156505, -0.2658647728602175},
{0.28717067298229804, -0.7846755360932607},
{0.05624929364905529, -0.25991180004502856},
{-0.13378628267062875, 0.5880507490085842},
{0.8727525475772215, 0.7819085473088767}, {0, -0.11157265824279505},
{0.23665662167857282, -0.6941954215813606},
{0.06355998327764567, -0.07855897883848062},
{0.8207634461027611, 0.9459143033260806}, {0, 0.8345193691599806},
{0.7305898394193413, 0.7305898394193413}, {-0.22172992448907458,
0.7935045731654915}, {-0.4440865683089399, 0.1902193265023413},
{-0.13974502857001625, -0.2259951156178166},
{0.07824948773803353, -0.7717456494371921},
{-0.19424657267504564, -0.7935880282938024},
{-0.384092758457909, 0.13720485037848573}, {0.21878006395908178, 0},
{0.30268548121850514, 0.30268548121850514},
{0.4881902245397405, 0.00647429849992287}}

Now we make pairs of the form {inequality,name}.

In[38]:= ineqs = {{A<0&&B<0,k}, {A<0&&B==0,l},
{A<0&&A==B,m}, {A<0&&B>0,n},
{A>0&&B>0,p}, {A==0&&B>0,q},
{A>0&&A==B,q}};

I use Outer[Cases[...]&, l1, ineqs, 1] in order to test every inequality
against every pair.

In[39]:= Map[Flatten,
Outer[Cases[{#1}, ({A_,B_}/;Evaluate[#2[[1]]])->#2[[2]]]&, l1, ineqs,
1]]

Out[39]= {{k, m}, {}, {}, {n}, {p}, {}, {p}, {}, {}, {p}, {}, {l}, {k},
{p},
{n}, {}, {}, {}, {p}, {n}, {}, {k}, {n}, {}, {p, q}, {}, {p}, {}, {n},
{l}, {}, {}, {}, {n}, {p}, {}, {}, {}, {p}, {q}, {p, q}, {n}, {n}, {k},
{}, {k}, {n}, {}, {p, q}, {p}}

Note that one might try to be more efficient (at the expense of trickier
coding) insofar as many inequalities are mutually exclusive. Hence once
one is found that fits a given pair, it could be used to rule out
several others.

Daniel Lichtblau
Wolfram Research

```

• Prev by Date: Bug in matrix operation using MatrixExp?
• Next by Date: Re: Re: Compound Expressions
• Previous by thread: Re: Classifying by Inequalities???
• Next by thread: Re: Classifying by Inequalities???