kevinlawler / kona

Open-source implementation of the K programming language
ISC License
1.36k stars 138 forks source link

Problems with all 3 forms of Each Pair #595

Closed tavmem closed 4 years ago

tavmem commented 4 years ago

in k2.8

  (,':) . (1 2;3 4 5)
(1 2
 4 3
 5 4)

  {x,':y} . (1 2;3 4 5)
(1 2
 4 3
 5 4)

  1 2 ,': 3 4 5
(1 2
 4 3
 5 4)

in kona

  (,':) . (1 2;3 4 5)
,3 4 5 1 2

  {x,':y} . (1 2;3 4 5)
(1 2 3
 4 3
 5 4)

  1 2 ,': 3 4 5
(1 2 3
 4 3
 5 4)
tavmem commented 4 years ago

In the k2.0 reference manual

Each Pair applies its argument function f  to successive pairs of consecutive items in the list argument y. 
If y is a list of count at least two, then f':x  is a list withcount (#x)-1  
and the ith item of the result is  f[x[i+1];x[i]]. 
For example:
  -': 1 4 9 14 25 36
3 5 5 11 11

This works in kona:

    -': 1 4 9 14 25 36
3 5 5 11 11
tavmem commented 4 years ago

Also in the k2.0 reference manual:

The dyadic case x f':y  is defined in terms of the monadic as (,x),f':y.

Clearly, it's the dyadic case that is broken, since in kona and in k2.8:

  ,': 3 4 5
(4 3
 5 4)
tavmem commented 4 years ago

2 of the 3 cases have been fixed. Now, in kona:

  1 2 ,': 3 4 5
(1 2
 4 3
 5 4)

  (,':) . (1 2;3 4 5)
,3 4 5 1 2

  {x,':y} . (1 2;3 4 5)
(1 2
 4 3
 5 4)
tavmem commented 4 years ago

After making all Each Pair tests consistent with k2.8 results, 3 tests fail:

Failed. These are not equal:
10 1 , ."10 -': 2 3"
********************************
10 1
--------------------------------
8 1

Failed. These are not equal:
10 , ."10 -': 2"
********************************
10
--------------------------------
8

Failed. These are not equal:
10 , ."10 +': 2"
********************************
10
--------------------------------
12
tavmem commented 4 years ago

After the last changes, we get another inconsistency in kona:

  10 -': 2 3
8 1
  10 -'': 2 3
10 1
tavmem commented 4 years ago

The 2 fails that are left:

Failed. These are not equal:
(1 2;4 3;5 4) , ."(,':) . (1 2;3 4 5)"
********************************
(1 2
 4 3
 5 4)
--------------------------------
,3 4 5 1 2

Failed. These are not equal:
10 1 , ."10 -': 2 3"
********************************
10 1
--------------------------------
8 1
tavmem commented 4 years ago

Lsst one to fix:

Failed. These are not equal:
(1 2;4 3;5 4) , ."(,':) . (1 2;3 4 5)"
********************************
(1 2
 4 3
 5 4)
--------------------------------
,3 4 5 1 2