[ prog / sol / mona ]

prog


e and the Stern-Brocot tree

33 2021-02-25 11:07

Spec for the e stream:

class StamploopSpec (Spec):
   @ classmethod
   def kind (cls):
      return "stamploop"

   def __init__ (self, stamp):
      self.stamp = stamp

   def stamplength (self, index):
      pass

   def tailgroup (self, index):
      pass


def work_loadstore_repeat ():
   return ListGroup ([
      StoreGroup ("a", ListGroup ([
         LoadGroup ("a", FixedGroup ("LR")),
         LoadGroup ("l4", FixedGroup ("LLLL"))])),
      StoreGroup ("b", ListGroup ([
         LoadGroup ("b", FixedGroup ("RLRR")),
         LoadGroup ("r4", FixedGroup ("RRRR"))]))])


class EStamp (StamploopSpec):
   def __init__ (self):
      StamploopSpec.__init__ (self,
         work_loadstore_repeat ())

   def stamplength (self, index):
      return 14 + 8 * index

   def tailgroup (self, index):
      return ListGroup ([
         FixedGroup ("LR"),
         ExpoGroup (FixedGroup ("L"), 4 + 4 * index),
         FixedGroup ("RL"),
         ExpoGroup (FixedGroup ("R"), 6 + 4 * index)])


class Specs:
   class E (ListGroup):
      @ classmethod
      def targetfloat (cls):
         return math.e

      def __init__ (self):
         ListGroup.__init__ (self, [
            FixedGroup ("RRLRR"), EStamp ()])
54


VIP:

do not edit these