       if s.first() % 2 == 1
         recur -> step(mul(p, r), r, sub(s, ONE))
       else
-        recur -> step(p, mul(r, r), div(s, TWO))
+        recur -> step(p, Sequence.stored(mul(r, r)), div(s, TWO))
     else
       p
   resolve step(ONE, r, s)

    [lo, carry] = if tmp < BASE then [tmp, 0] else [tmp - BASE, 1]
    [lo, a1 * b1 + m1 + carry]

streamTimesDigit = (s, d, c = 0) ->
  if c or s
    s_ = s or ZERO
    [lo, hi] = digitTimesDigit(d, s_.first())
    new Stream(lo + c, -> streamTimesDigit(s_.rest(), d, hi))

mul = (a, b) ->
  step = (r, a, b) ->
    if a
      t = add(r, streamTimesDigit(b, a.first())) or ZERO
      new Stream(t.first(), -> step(t.rest(), a.rest(), b))
    else
      r
  step null, a, b

div = (r, s) ->
  f = Math.floor BASE / (s.last() + 1)
  [r_, s_] = (streamTimesDigit(x, f) for x in [r, s])
  log "div(#{dump r}, #{dump s}): premultiplying by #{f}, divisor ~> #{dump s_}"
  [m, d] = [s_.size(), s_.last() + 1]


sqrt = (s) ->
  n = s.size()
  if n == 1
    Sequence.conj Math.floor Math.sqrt s.first()
  else
    step = (r) ->
      rn = Sequence.stored div(add(r, div(s, r)), TWO)
      if cmp(r, rn) then recur -> step(rn) else rn
    resolve step s.take n >> 1

