Sorry to keep ploughing this furrow, but
  %/@:,/.  does work ok  where %//. doesn't...

  4{.open(%/@:,/.@:,:)close NB. as required

100.978 0.994022 1.00616 1.00542

  4{.open(%~/@:,/.@:,:)close NB. reciprocals

100.978 1.00601 0.993881 0.994607

Why is " , " necessary?

M

Mike Day wrote:
I'm puzzled! - and embarrassed (again).  I should have
checked for consistency, although I don't understand
the aberrant behaviour.

Our correspondent "J Language" should avoid my solution
pro tem.

Following Devon, with apologies for extra line throws

  open=. 100+?1e2$0 [ close=. 100+?1e2$0

  4{. open(</.@:,:) close NB. check 1st few pairs

+-------+---------------+---------------+--------------+
|100.978|100.368 100.971|100.663 100.047|100.874 100.33|
+-------+---------------+---------------+--------------+

  4 {. open((%//.@:,:)) close NB. check ratios...

100.978 1.00601 0.993881 0.994607

NB. .... these are reciprocals of the required ratios!!!

  %/100.368 100.971  NB. it's ok on an explicit pair...

0.994028

  %~/100.368 100.971 NB. evidently %~/ is done here ...

1.00601

  4 {. open((%~//.@:,:))close NB. check inverse ratios...

100.978 1.00601 0.993881 0.994607

NB. ... these are just the same!!!

Why doesn't " ~ " work here?  Is this a bug or one of
those features I keep missing?

Mike
Devon McCormick wrote:
Out of curiousity, is there any particular reason you want a tacit version?

To my eye, still not comfortable with tacit, Raul's initial solution looks
simplest
and most straightforward.

ocrsum0=: 4 : '+/(}.x) % }:y' NB. Sum open[n+1]%close[n] -
explicit (Raul's original)
  ocrsum1=: [:+/[EMAIL PROTECTED](]}:)                  NB. Sum 
open[n+1]%close[n] -
tacit
ocrsum2=: (+/@[EMAIL PROTECTED]:@(%//.@:,:)) NB. Sum open[n+1]%close[n] - tacit using
"oblique"
  100 101 103 104 103 102 (ocrsum0-:ocrsum2) 101 100 104 104 105 103
1
  100 101 103 104 103 102 (ocrsum0-:ocrsum1) 101 100 104 104 105 103
1

Mike Day's solution using "oblique", which is the coolest, works the same
for the
example numbers but otherwise has some unexplained differences:

  open=. 100+?1e2$0 [ close=. 100+?1e2$0
  open (ocrsum0-:ocrsum1) close
1
  open (ocrsum0-:ocrsum2) close
0
  open (ocrsum0,ocrsum2) close
99.05473 98.947048

I also liked Mike's initial approach of combining "open" and "close" into a
single array
as this is more "J-like": it reduces the number of items to keep in synch.

[nb snipped the rest Mike .............]
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to