Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This was a bit hard to read, requiring some note taking and some factorizating to check the correspondence between variable names and primes.

> You can get the product of two registers(x*y) by keeping an intermediate result and state register. Keeping the resulting product, by naming the first register for the result, prevents the accumulator grow too much in size:

    :: r acc x y
    :: iter acc > x iter
    :: iter >
    :: x y > r acc y 
    :: y > iter
    :: x > 

    AC 8575 x^2 y^2
    .. r^6
This one is harder to figure out. The first line reserves primes 2,3,5,7 for variables r, acc, x, y. The unreserved iter should then be assigned prime 11. The accumulator AC starts at value 8575 = 5^2 * 7^3, so the y^2 has a typo and should be y^3. Which matches the desired end result of 2*3 = 6. But how exactly does it get there?

Btw, the corresponding FRACTRAN program would be

    5*11  1   2*3*7  11  1
    ----  --  -----  --  -
    3*11  11   5*7    7  5


Reduction steps from the example: https://git.sr.ht/~rabbits/fractran/tree/main/item/examples

  :: 55/33 acc.3 iter.11 > x.5 iter.11 
  :: 1/11 iter.11 > 
  :: 42/35 x.5 y.7 > r.2 acc.3 y.7 
  :: 11/7 y.7 > iter.11 
  :: 1/5 x.5 > 

  AC x x y y y 
  02 42/35 r acc x y y y 
  02 42/35 r r acc acc y y y 
  03 11/7 r r acc acc y y iter 
  00 55/33 r r acc x y y iter 
  00 55/33 r r x x y y iter 
  01 1/11 r r x x y y 
  02 42/35 r r r acc x y y 
  02 42/35 r r r r acc acc y y 
  03 11/7 r r r r acc acc y iter 
  00 55/33 r r r r acc x y iter 
  00 55/33 r r r r x x y iter 
  01 1/11 r r r r x x y 
  02 42/35 r r r r r acc x y 
  02 42/35 r r r r r r acc acc y 
  03 11/7 r r r r r r acc acc iter 
  00 55/33 r r r r r r acc x iter 
  00 55/33 r r r r r r x x iter 
  01 1/11 r r r r r r x x 
  04 1/5 r r r r r r x 
  04 1/5 r r r r r r 

  r r r r r r


Even looking at this, I find it still very hard to see how it's computing x*y for arbitrary values of x and y...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: