[ prog / sol / mona ]

prog


e and the Stern-Brocot tree

36 2021-02-26 04:19

The evaluation context updated with storage:

def work_fixedgroup (target, group, *, debug = True, matrixclass = None):
   log    = print
   M      = Matrix if matrixclass is None else matrixclass
   slots  = 2
   mstack = Stack.alloc (slots, M)
   ctx    = {
      "matrixclass": M,
      "stack":       mstack,
      "storage":     {},
   }

   if debug:
      log (" group {}".format (group.show ()))
      log ("target {:.15f}".format (target))

   group.eval (ctx, 1)
   M.mul (M.S, mstack [1], mstack [0])
   a, b = M.pair (mstack [0])

   if debug:
      log ("result {:.15f}".format (a / b))
      log ("{:d}".format (a))
      log ("{:d}".format (b))
      log ("stack {:d}".format (len (mstack)))


def work_speclimit (spec, limit, *, debug = True, matrixclass = None, compiler = None):
   C      = Compiler if compiler is None else compiler
   target = spec.targetfloat ()
   ret    = C.fixedlimit (spec, limit)
   group  = ret ["group"]

   work_fixedgroup (target, group, debug = debug, matrixclass = matrixclass)
54


VIP:

do not edit these