Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

hyper operator

Name: Anonymous 2009-01-11 22:52

http://en.wikipedia.org/wiki/Hyper_operator
integralElem :: (Integral b) => [a] -> b -> a
hyper' :: (Integral a) => a -> (a -> a -> a)
hyper :: (Integral a) => a -> a -> a -> a

integralElem a b = a !! fromIntegral b

hyper' 0 = (+) . flip (^) 0
hyper' 1 = (+)
hyper' 2 = (*)
hyper' 3 = (^)
hyper' 4 = integralElem . (hyper4list)
    where hyper4list a = 1 : (zipWith (^) [a,a..] (hyper4list a))
hyper' n = integralElem . (hyperlist n)
    where hyperlist n a = 1 : (zipWith (hyper' (n-1)) [a,a..] (hyperlist n a))

hyper a n b = (hyper' n) a b


improvements to the above are welcome.

Name: Anonymous 2012-05-19 20:46

my Int sub hyper(Int $a, Int $n, Int $b)
{ return $b + 1        if !$n;
  return 4             if [==] $a, $b, 2;
  return $a + $b       if $n == 0;
  return $a            if $b == 1;
  return $a * $b       if $n == 2;
  return 1             if !$b;
  return 0             if !$a;
  return 1             if $a == 1;
  return $a ** $b      if $n == 3;
  return [**] $a xx $b if $n == 4;
  return reduce sub ($x, $y) { hyper($y, $n - 1, $x) }, $a xx $b; }

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List