What we could try first is a simple shift

   tr2=: &+
   eqt2=: 2 : '(m eq)&:(n tr2)'

But the radius would skew as we increase n

   0 (0.001 eqt2 10) 0+0.01
1
   0 (0.001 eqt2 10) 0+0.011
0
   
   3 (0.001 eqt2 10) 3+0.013
1
   3 (0.001 eqt2 10) 3+0.014
0
   
   _3 (0.001 eqt2 10) _3+0.007
1
   _3 (0.001 eqt2 10) _3+0.008
0

   0 (0.001 eqt2 100) 0+0.1
1
   0 (0.001 eqt2 100) 0+0.11
0

   3 (0.001 eqt2 100) 3+0.1
1
   3 (0.001 eqt2 100) 3+0.2
0

   _3 (0.001 eqt2 100) _3+0.09
1
   _3 (0.001 eqt2 100) _3+0.1
0

Alternatively, we can adjust t by n:

   eqt3=: 2 : '((m%n) eq)&:(n tr2)'
   0 (0.001 eqt3 100) 0+0.001
1
   0 (0.001 eqt3 100) 0+0.0010001
0

And it works on opposite sides of 0.
   0 (+ (0.001 eqt3 100) -) 0.0005
1
   0 (+ (0.001 eqt3 100) -) 0.0006
0

Now, what's the meaning of n?

   3 (0.001 eqt3 100) 3+0.00103
1
   3 (0.001 eqt3 100) 3+0.001031
0

   _3 (0.001 eqt3 100) _3+0.001-0.000029991
1
   _3 (0.001 eqt3 100) _3+0.001-0.00002999
0
   0.001-0.00002999
0.00097001
   0.001-0.000029991
0.000970009

   0.00103-0.00097001
5.999e_5
   6*0.001%100
6e_5

Range of identity radius (r1-r0)
    is range of domain (d1-d0) times t%n.
n is 
    t*(d1-d0)%(r1-r0)

   0.001*6%6e_5
100


--- Oleg Kobchenko <[EMAIL PROTECTED]> wrote:

> The comparator show below won't work with values on 
> the opposite sides of 0. So the question is still open.
> 
> 
> --- Oleg Kobchenko <[EMAIL PROTECTED]> wrote:
> 
> > So you are confirming what I discovered to myself.
> > I expected tolerance to be uniform in space,
> > or at least not singular at zero.
> > (Thinking of it as a _identity radius_, 
> > being within which two points are equal).
> > As it turns out, the identity radius is proportional 
> > to the (max) magnitude of the points. It is the same 
> > as tolerance t in the vicinity of 1:
> > 
> >    1=1+2^_44
> > 1
> >    1=1+2^_43
> > 0
> > 
> > And identity radius grows with the magnitude
> > 
> >    (2^32)=(2^32)+2^_44+32
> > 1
> >    (2^32)=(2^32)+2^_44+33
> > 0
> >    (2^32),2^_44+32          NB. point and radius
> > 4.29497e9 0.000244141
> > 
> > In zero the radius converges to 0, thus no tolerance.
> > 
> >    (2^_1024)=(2^_1024)+2^_44-1024
> > 1
> >    (2^_1024)=(2^_1024)+2^_44-1023
> > 0
> >    (2^_1024) , 2^_44-1024   NB. point and radius
> > 5.56268e_309 3.16202e_322
> > 
> > In other words, as we move closer to 0, the
> > radius shrinks and never reaches to include 0
> > (unless t >: 1).
> > 
> > Such tolerance model becomes an issue if the domain 
> > is in the region that includes 0, for examples -3..3.
> > Typical application, is when we do calculations
> > with errors, of course, and we still want to identify
> > the same points.
> > 
> > To make it work, we can transform the domain to
> > for example, [-6..-3) U [3,6]:
> > 
> >    (1:[EMAIL PROTECTED](*@|) * 3 + |) 1 _1 0 1j_1 3j_3 3
> > 4 _4 3 3.12132j_3.12132 5.12132j_5.12132 6
> > 
> > So how would such nicer comparator look like?
> > 
> >    eq=: 1 : '|@- <:!.0 m * >.&|'
> >    tr=: 1 : '1:[EMAIL PROTECTED](*@|) * m + |'
> >    eqt=: 2 : '(m eq)&:(n tr)'
> > 
> >    0 (0.001 eqt 1) 0+0.001
> > 1
> >    0 (0.001 eqt 1) 0+0.002
> > 0
> >    0 (0.001 eqt 3) 0+0.001*3
> > 1
> >    0 (0.001 eqt 3) 0+0.002*3
> > 0
> > 
> > 
> > --- Roger Hui <[EMAIL PROTECTED]> wrote:
> > 
> > > It is a direct consequence of the definition of tolerant
> > > equality that comparisons with 0 are not tolerant:
> > > 
> > > x=!.t y if (|x-y)<:t*x>.&|y   definition of tolerant =
> > > 0=!.t y if (|0-y)<:t*0>.&|y   substitute 0 for x
> > > 0=!.t y if (|y)<:t*|y         algebra
> > > 
> > > So if t<1 (which t is required to be), y must be 0.
> > > 
> > > See also the essay in the J Wiki:
> > > http://www.jsoftware.com/jwiki/Essays/Tolerant_Comparison
> > > which among other things demonstrates that t>:1 gives
> > > nonsense results.
> > > 
> > > 
> > > 
> > > ----- Original Message ----- 
> > > From: "Oleg Kobchenko" <[EMAIL PROTECTED]>
> > > To: "Programming forum" <[email protected]>
> > > Sent: Sunday, May 28, 2006 10:08 PM
> > > Subject: [Jprogramming] Equal tolerance fit conjunction -- again
> > > 
> > > I need to compare floats (complex) with more lenient
> > > tolerance, that is numbers a bit farther apart would
> > > return equal. 
> > > 
> > > In particular, I need to compare with 0, so that
> > > for 0e_11 it returns 1 and for 0e_9 it returns 0.
> > > 
> > > >From the dictionary,
> > >   http://www.jsoftware.com/books/help/dictionary/d000.htm
> > > "comparison is made with a tolerance t , normally 2 to 
> > > the power _44". But
> > > 
> > >    0 = 2^_44
> > > 0
> > >    0 = 2^_60
> > > 0
> > >    0 = 2^_20
> > > 0
> > > 
> > > So how does this example relate to the rule above?
> > > 
> > > It continues, "but also controlled by the fit conjunction !. , 
> > > as in x=!.0 y . Formally, x=y is 1 if the magnitude of x-y does 
> > > not exceed t times the larger of the magnitudes of x and y ."
> > > 
> > > With zero and positive x we have
> > > 
> > >    (|x-0) <: t*x
> > >    x <: t*x
> > >    1 <: t
> > > 
> > > This doesn't make sense. Can I compare tolerantly
> > > with zero at all?
> > 
> > 
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam?  Yahoo! Mail has the best spam protection around 
> > http://mail.yahoo.com 
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> > 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to