Skip to content

%lagoon sub-rays jet don't work right #999

@yapishu

Description

@yapishu

the %sub-rays jet from the lagoon lib subtracts out of order, ie (sub a b) evaluates as (sub b a). Here's the relevant PR in numerics by @sigilante : urbit/numerics#20

the c jet calls saxpy(N, -1, x_bytes, 1, y_bytes, 1). axpy semantics are Y := alpha*X + Y, so with alpha=-1 you get Y = y - x, then it returns y_bytes. but the hoon contract (sub:la a b) is supposed to give a - b, and the jet loaded a as x_data and b as y_data, so it returns b - a. this wasn't picked up by tests because the only test case was subtracting two ones

urbit -F zod
> |new-desk %lagoon
> |mount %lagoon
git clone https://github.com/urbit/numerics
mkdir -p zod/lagoon
cp -Lr numerics/lagoon/desk/* zod/lagoon/
echo '[%zuse 409]' > zod/lagoon/sys.kelvin

edit zod/lagoon/lib/lagoon.hoon, find ++ sub (~line 903), add a copy right after it called sub2 with no jet hint:

++  sub   :: original, jetted
  ~/  %sub-rays
  |=  [a=ray b=ray]
  ^-  ray
  (bin-op a b (fun-scalar meta.a %sub))
++  sub2  :: identical body, no jet
  |=  [a=ray b=ray]
  ^-  ray
  (bin-op a b (fun-scalar meta.a %sub))

drop this in zod/lagoon/gen/test-sub.hoon:

/-  ls=lagoon
/+  *lagoon
:-  %say
|=  *
:-  %noun
=/  la  (lake %n)
=/  meta=meta:ls  [~[1] 5 %i754 ~]
=/  a-ray  (fill:la meta .5)
=/  b-ray  (fill:la meta .2)
=/  diff  (sub:la a-ray b-ray)
=/  v  `@rs`(get-item:la diff ~[0])
~&  >  ['(sub:la 5.0 2.0)' v]
~&  >  ['Jetted' ~]
~&  >  ?:(=(v .3) 'PASS — a - b' ?:(=(v .-3) 'FAIL — b - a' 'FAIL — other'))
~&  >  ['Unjetted' ~]
=/  diff2  (sub2:la a-ray b-ray)
=/  v  `@rs`(get-item:la diff2 ~[0])
~&  >  ['(sub2:la 5.0 2.0)' v]
~&  >  ?:(=(v .3) 'PASS — a - b' ?:(=(v .-3) 'FAIL — b - a' 'FAIL — other'))
~
> |commit %lagoon
> +lagoon!test-sub

Output:

>   ['(sub:la 5.0 2.0)' .-3]
>   ['Jetted' ~]
>   'FAIL — b - a'
>   ['Unjetted' ~]
>   ['(sub2:la 5.0 2.0)' .3]
>   'PASS — a - b'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions