Index: dyn_modules/openmath/applicationbsp
===================================================================
--- dyn_modules/openmath/applicationbsp	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/applicationbsp	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,2 @@
+
+<OMA><OMS name="plus" cdbase="http://www.openmath.org/cd" cd="arith1"></OMS><OMV name="x"></OMV><OMV name="y"></OMV></OMA>
Index: dyn_modules/openmath/arith1.bpl
===================================================================
--- dyn_modules/openmath/arith1.bpl	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/arith1.bpl	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,2 @@
+(dp1
+.
Index: dyn_modules/openmath/attrbsp
===================================================================
--- dyn_modules/openmath/attrbsp	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/attrbsp	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,9 @@
+<OMOBJ>
+  <OMATTR>
+    <OMATP>
+      <OMSTR>sgjkgjsdk</OMSTR>
+      <OMI>234924</OMI>
+    </OMATP>
+    <OMV name="x"/>
+  </OMATTR>
+</OMOBJ>
Index: dyn_modules/openmath/bindingbsp
===================================================================
--- dyn_modules/openmath/bindingbsp	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/bindingbsp	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,14 @@
+<OMA>
+	<OMBIND>
+		<OMS name="lambda" cd="fns1" cdbase="http://www.openmath.org/cd"></OMS>
+		<OMV name="x"/>
+		<OMV name="y"/>
+		<OMA>
+			<OMS name="plus" cdbase="http://www.openmath.org/cd" cd="arith1"></OMS>
+			<OMV name="x"></OMV>
+			<OMI>1</OMI>
+		</OMA>
+	</OMBIND>
+	<OMI>3</OMI>
+	<OMI>5</OMI>
+</OMA>
Index: dyn_modules/openmath/bytearraybsp
===================================================================
--- dyn_modules/openmath/bytearraybsp	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/bytearraybsp	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,1 @@
+<OMB>AA33==</OMB>
Index: dyn_modules/openmath/cas/__init__.py
===================================================================
--- dyn_modules/openmath/cas/__init__.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/cas/__init__.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,2 @@
+__all__=["singular"]
+
Index: dyn_modules/openmath/cas/kuchenessen.py
===================================================================
--- dyn_modules/openmath/cas/kuchenessen.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/cas/kuchenessen.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,343 @@
+# -*- coding: utf-8 -*-
+#Copyright Michael Brickenstein
+#you are free to use this script under the terms of the Gnu LGPL
+from sets import Set
+import sets
+class kuchen:
+    __greater_equal_zero_set=Set()
+    __not_greater_equal_zero_set=Set()
+    __z=0
+    def __init__(self,gebiete):
+        if type(gebiete)==type(list()):
+            self.gebiete=gebiete[:]
+        else:
+            self.gebiete=[]
+            for (r,n) in gebiete:
+                self.gebiete.extend([r]*n)
+
+    def simplify(self):
+        def quad_simple(x):
+            (l,r)=x
+            if (l %2==1) and(r %2==1):
+                return (1,1)
+            if l==r:
+                return (1,1)
+            else:
+                return x
+        
+
+        gebiete=[quad_simple(a) for a in self.gebiete]
+        g2=gebiete[:]
+        for i in range(len(g2)):
+            if g2[i]==None:
+                continue
+            (r,l)=g2[i]
+            if (l,r) in g2[i+1:]:
+                g2[i+1+ g2[i+1:].index((l,r))]=None
+                g2[i]=None
+        while None in g2:
+            g2.remove(None)
+        return kuchen(g2)
+    def __char(self):
+        d={}
+        for i in self.gebiete:
+            try:
+                d[i]=d[i]+1
+            except KeyError:
+                d[i]=1
+        s=Set()
+        for k in d.keys():
+            s.add((k,d[k]))
+        return s
+
+    def take_column(self, rect_n, column):
+        """works only for column in the first half"""
+        (l,r)=self.gebiete[rect_n]
+        if column==0:
+            if(r==1):
+                g=[]
+            else:
+                g=[(l,r-1)]
+        else:
+            g=[(l,column),(l,r-1-column)]
+        return kuchen(self.gebiete[:rect_n]+g+self.gebiete[rect_n+1:])
+    
+    def take_row(self, rect_n, row):
+        """works only for row in the first half"""
+        (l,r)=self.gebiete[rect_n]
+        if row==0:
+            if(l==1):
+                g=[]
+            else:
+                g=[(l-1,r)]
+        else:
+            g=[(row,r),(l-1-row,r)]
+        return kuchen(self.gebiete[:rect_n]+g+self.gebiete[rect_n+1:])
+    
+    def right_options(self):
+        s=Set()
+        for i in range(len(self.gebiete)):
+            (l,r)=self.gebiete[i]
+            if r %2==0:
+                m=r/2
+            else:
+                m=r/2+1
+            for j in range(m):
+                s.add(self.take_column(i,j).__char())
+        l=list(s)
+        return [kuchen(k) for k in l]
+    def right_options_for_geq0(self):
+        """Not al and not necessarily the best right options,
+        but if there is a right option <= 0, then the return
+        Set will also contain such an option"""
+        s=Set()
+        if len(self.gebiete)>0:
+            class strategy_failed(Exception):
+                pass
+            try:
+                fuzzy=0
+                for (l,r) in self.gebiete:
+                    if (r%2==0) and (l!=r): 
+                        raise strategy_failed
+                    if (l%2==1) or (l==r):
+                        fuzzy=fuzzy+1
+                if fuzzy%2==1:
+                    for i in range(len(self.gebiete)):
+                        (l,r)=self.gebiete[i]
+                        if (l%2==1) and (r%2==1):
+                            if r==1:
+                                j=0
+                            else:
+                                j=1
+                            return [self.take_column(i,j)]
+                        else:
+                            if (l==r):
+                                #even case
+                                return [self.take_column(i,j)]
+                            
+                else:
+                    for i in range(len(self.gebiete)):
+                        if (l%2==0) and (r%2==1):
+                            if r==1:
+                                j=0
+                            else:
+                                j=1
+                            return [self.take_column(i,j)]
+                #shouldn't fail here in simplified games
+                raise strategy_failed
+            except strategy_failed:
+                pass
+        #fuzzy should be one or zero in simplified games
+        for i in range(len(self.gebiete)):
+            (l,r)=self.gebiete[i]
+            if r %2==0:
+                m=r/2
+            else:
+                m=r/2+1
+            for j in range(m):
+                if(l%2==1) and (r%2==1):
+                    if (r>1) and (j!=1):
+                        continue
+                s.add(self.take_column(i,j).__char())
+        l=list(s)
+        return [kuchen(k) for k in l]
+
+        
+        
+        
+    def right_options_move(self):
+        """Not al and not necessarily the best right options,
+        but if there is a right option <= 0, then the return
+        Set will also contain such an option"""
+        d={}
+        if len(self.gebiete)>0:
+            class strategy_failed(Exception):
+                pass
+            try:
+                fuzzy=0
+                for (l,r) in self.gebiete:
+                    if (r%2==0) and (l!=r): 
+                        raise strategy_failed
+                    if (l%2==1) or (l==r):
+                        fuzzy=fuzzy+1
+                if fuzzy%2==1:
+                    for i in range(len(self.gebiete)):
+                        (l,r)=self.gebiete[i]
+                        if (l%2==1) and (r%2==1):
+                            if r==1:
+                                j=0
+                            else:
+                                j=1
+                            return [(self.take_column(i,j),(i,j))]
+                        else:
+                            if (l==r):
+                                #even case
+                                return [(self.take_column(i,j),(i,j))]
+                else:
+                    for i in range(len(self.gebiete)):
+                        if (l%2==0) and (r%2==1):
+                            if r==1:
+                                j=0
+                            else:
+                                j=1
+                            return [(self.take_column(i,j),(i,j))]
+                #shouldn't fail here in simplified games
+                raise strategy_failed
+            except strategy_failed:
+                pass
+
+        for i in range(len(self.gebiete)):
+            (l,r)=self.gebiete[i]
+            if r %2==0:
+                m=r/2
+            else:
+                m=r/2+1
+            for j in range(m):
+                if(l%2==1) and (r%2==1):
+                    if (r>1) and (j!=1):
+                        continue
+                d[sets.ImmutableSet(self.take_column(i,j).__char())]=(i,j)
+       
+        return [(kuchen(k),d[k]) for k in d.keys()]
+
+    
+    def left_options(self):
+        s=Set()
+        for i in range(len(self.gebiete)):
+            (l,r)=self.gebiete[i]
+            if l %2==0:
+                m=l/2
+            else:
+                m=l/2+1
+            for j in range(m):
+                s.add(self.take_row(i,j).__char())
+        l=list(s)
+        return [kuchen(k) for k in l]
+   
+    def greater_equal_zero(self):
+        k=self.simplify()
+        if k.__char() in kuchen.__greater_equal_zero_set:
+            return True
+        if k.__char() in kuchen.__not_greater_equal_zero_set:
+            return False
+       
+        erg=k.__do_greater_equal_zero()
+        if erg:
+            kuchen.__greater_equal_zero_set.add(k.__char())
+        else:
+            kuchen.__not_greater_equal_zero_set.add(k.__char())
+        return erg
+    
+    def __do_greater_equal_zero(self):
+        class myError(Exception):
+            pass
+        if len(self.gebiete)==1:
+            (l,r)=self.gebiete[0]
+            if (l%2==r%2) or (l==r):
+                return False
+        try:
+            for i in range(len(self.gebiete)):
+                (l,r)=self.gebiete[i]
+                if (l % 2 == 0) or (r % 2 == 1):
+                    raise myError
+            return True
+        except myError:
+            pass
+        
+        complex_positiv_index=-1;
+        complexity=0
+        for i in range(len(self.gebiete)):
+            (l,r)=self.gebiete[i]
+            if (l%2==1) and (r%2==0) and l*r>complexity:
+                complexity=l*r
+                complex_positiv_index=i
+        if complex_positiv_index>=0:
+            rest=self.gebiete[:complex_positiv_index] \
+                  + self.gebiete[complex_positiv_index+1:]
+            if kuchen(rest).greater_equal_zero():
+                return True
+        #small rects have often bigger values
+        not_complex_positiv_index=-1
+        complexity=1000000000 #big number
+        for i in range(len(self.gebiete)):
+            (l,r)=self.gebiete[i]
+            if (l%2==1) and (r%2==0) and l*r<complexity:
+                complexity=l*r
+                not_complex_positiv_index=i
+        if not_complex_positiv_index>=0:
+            rest=self.gebiete[:not_complex_positiv_index] \
+                  + self.gebiete[not_complex_positiv_index+1:]
+            #try to pick some other from rest
+            j=0
+            can=[self.gebiete[not_complex_positiv_index]]
+            while (len(rest)>1) and (j<len(rest)):
+                if j==not_complex_positiv_index:
+                    j=j+1
+                    continue
+
+                if (rest[j][0]%2==1) and (rest[j][1]%2==0):
+                    j=j+1
+                    continue
+                to_test=can[:]
+                to_test.append(rest[j])
+                if kuchen(to_test).greater_equal_zero():
+                    can=to_test
+                    rest.remove(rest[j])
+                    continue
+                j=j+1
+            if kuchen(rest).greater_equal_zero():
+                return True
+        if len(self.gebiete)>0:
+            try:
+                for i in range(len(self.gebiete)):
+                    (l,r)=self.gebiete[i]
+                    if (l % 2==1) or (r % 2 ==0):
+                        raise myError
+                return False
+            except myError:
+                  complex_negativ_index=-1;
+                  complexity=0
+                  for i in range(len(self.gebiete)):
+                      (l,r)=self.gebiete[i]
+                      if (l%2==0) and (r%2==1) and l*r>complexity:
+                          complexity=l*r
+                          complex_negativ_index=i
+                  if complex_negativ_index>=0:
+                      if kuchen(self.gebiete[:complex_negativ_index] \
+                                                   + self.gebiete[complex_negativ_index+1:]).smaller_equal_zero():
+                          return False
+        o=self.right_options_for_geq0()
+        for i in range(len(o)):
+            if o[i].smaller_equal_zero():
+                return False
+        return True
+    
+    def smaller_equal_zero(self):
+        k=self.negative()
+        return k.greater_equal_zero()
+    def negative(self):
+        return kuchen([(m[1],m[0]) for m in self.gebiete])
+
+
+try:
+	from objects import *
+	import CD.gametheory
+	def decode_kuchen_OM(kOM):
+		assert isinstance(kOM,OMApply)
+		sizes=[a.getValue() for a in kOM.args]
+		regions=[(sizes[i],sizes[i+1]) for i in xrange(0, len(sizes),2)]
+		return kuchen(regions)
+	def left_wins_func(context, kuchen):
+		kuchen=decode_kuchen_OM(kuchen)
+		erg=kuchen.greater_equal_zero()
+		if erg:
+			return OMint(1)
+		else:
+			return OMint(0)
+	def install_kuchenessen_plugin():
+		CD.gametheory.implementation.implement("left_wins", left_wins_func)
+except:
+	print "no openmath library available"
+
+
+	
Index: dyn_modules/openmath/cas/singular.py
===================================================================
--- dyn_modules/openmath/cas/singular.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/cas/singular.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,191 @@
+from Singular import *
+from interpreter import *
+from objects import *
+from util import create_ring
+import cd.polyd, cd.primdec, cd.list1
+from cd.polyd import DMPsym, SDMPsym, termsym, lpsym,dpsym,poly_ring_dsym, DMPLsym, implementation, groebnerdsym
+from cd.fieldname1 import Qsym as Rationals
+singular=SingularGlobalsProxy()
+import cd.primdec
+class SingularException(Exception):
+  pass
+
+def poly2OM(p):
+  terms=[term2OM(t) for t in p]
+  return OMA(SDMPsym,terms)
+
+def poly_in_ring2OM(p):
+  pe=poly2OM(p)
+  r=ring2OM(p.ring())
+  return OMA(DMPsym,[r,pe])
+  
+def gb2OM(gb):
+  i=ideal2OM(gb)
+  o=ordering2OM(gb.ring())
+  return OMA(groebnerdsym,[o,i])
+orderingTable={
+  "lp": lpsym,
+  "dp": dpsym
+}
+OrderingTableBack={}
+for k in orderingTable:
+  OrderingTableBack[orderingTable[k]]=k
+
+def ordering2OM(r):
+  rl=singular.ringlist(r)
+  return orderingTable[rl[2][0][0]]
+
+def encode_field(r):
+  char=singular.char(r)
+  if char==0 and singular.npars(r)==0:
+    return Rationals
+  else:
+    raise SingularException("unknown field to encode")
+
+def ideal2OM(i):
+  r=ring2OM(i.ring())
+  return OMA(DMPLsym,[r]+[poly2OM(p) for p in i])
+def ring2OM(r):
+    nv=singular.nvars(r)
+    f=encode_field(r)
+    return OMA(poly_ring_dsym,[f,nv])   
+
+def OM2ring(ring_desc, ordering="dp"):
+  assert isinstance(ring_desc, OMA)
+  if (ring_desc.args[0]==Rationals):
+    i=ring_desc.args[1]
+    return create_ring(char=0, nvars=i, ordering=ordering)
+ 
+  raise SingularException("ring not supported")
+def OM2poly(poly_desc):
+  """assumes the right ring is set"""
+  assert isinstance(poly_desc, OMA)
+  terms=[OM2term(t) for t in poly_desc.args]
+  res=Polynomial(Number(0))
+  for t in terms:
+    res=res+t
+    #res+=t
+  return res
+def OM2term(term_desc):
+  assert isinstance(term_desc, OMA)
+  assert len(term_desc.args)==singular.nvars(Ring())+1
+  assert isinstance(term_desc.args[0], int)
+  
+  coef=Number(term_desc.args[0])
+  exp=IntVector()
+  for e in term_desc.args[1:]:
+    assert isinstance(e,int)
+    exp.append(e)
+  #print coef, polynomial(exp)
+  return coef*Polynomial(exp)
+
+def OM2ideal_raw(dmpl):
+  """assumes that the right ring is set"""
+  i=Ideal()
+  assert len(dmpl.args)>=1
+  ps=[OM2poly(d) for d in dmpl.args[1:]]
+  for p in ps:
+    i.append(p)
+  return i
+def OM2ideal(dmpl,o):
+  assert len(dmpl.args)>=1
+  return OM2ring(dmpl.args[0], ordering=OrderingTableBack[o])
+
+leadcoef=singular.leadcoef
+leadexp=singular.leadexp
+def term2OM(t):
+  """FIXME: ugly because it uses slow interpreter interface and setting of rings for this should be automatically"""
+  #t.ring().set()
+  #exponents=leadexp(t)
+  #c=leadcoef(t)
+  exponents=t.leadExp()
+  c=t.leadCoef()
+  exponents=[i for i in exponents]
+  return OMA(termsym,[int(str(c))]+exponents)
+def groebnerfunc(ordering, dmpl):
+
+  r=OM2ring(dmpl.args[0], OrderingTableBack[ordering])
+  r.set()
+  i=OM2ideal_raw(dmpl)
+  res=singular.groebner(i)
+  #FIXME: singular.groebner does not work may because of bad ring changes
+  #FIXME: increase reference to ring in ideal, polynomial class
+  return gb2OM(res)
+implementation.groebner=groebnerfunc
+
+def dmplQ(a):
+    if isinstance(a,OMA) and a.func==DMPLsym:
+        return True
+    else:
+        return False
+
+
+def input_convert(f):
+    def my2OM(a):
+        """FIXME: very dirty"""
+        global save_ring
+
+
+        if (dmplQ(a)):
+            dmpl=a
+            r=OM2ring(dmpl.args[0])
+            r.set()
+            i=OM2ideal_raw(dmpl)
+            save_ring=r
+            return i
+        
+        return a
+            
+    def wrapper(*args):
+        return f(*[my2OM(a) for a in args])
+    
+    
+    wrapper.__name__=f.__name__
+    return wrapper
+    
+def output_convert(f):
+    def my2om(a):
+        """FIXME: very dirty"""
+        global save_ring
+
+        if isinstance(a,Ideal):
+            return ideal2OM(a)
+        if (isinstance(a,list)):
+            return cd.list1.list2OM([my2om(a2) for a2 in a])
+        
+        return a
+            
+    def wrapper(*args):
+        return my2om(f(*args))
+    
+    
+    wrapper.__name__=f.__name__
+    return wrapper
+    
+def min_ass_func(dmpl):
+    r=OM2ring(dmpl.args[0])
+    r.set()
+    i=OM2ideal_raw(dmpl)
+    l=singular.minAssGTZ(i)
+    return cd.list1.OM2list([ideal2OM(i) for i in l])
+@input_convert
+def min_ass_func2(i):
+
+    l=singular.minAssGTZ(i)
+    return cd.list1.list2OM([ideal2OM(i) for i in l])
+    
+
+def singular_default_converter(f):
+    return output_convert(input_convert(f))
+cd.primdec.implementation.converter=singular_default_converter
+#cd.primdec.implementation.minAss=min_ass_func2
+cd.primdec.implementation.minAss=singular.minAssGTZ#input_convert(output_convert(singular.minAssGTZ))
+
+cd.primdec.implementation.minAssGTZ=singular.minAssGTZ
+#input_convert(output_convert(singular.minAssGTZ))
+
+cd.primdec.implementation.primdecGTZ=singular.primdecGTZ#input_convert(output_convert(singular.primdecGTZ))
+cd.primdec.implementation.radical=singular.radical
+
+optimize(poly2OM)
+optimize(term2OM)
Index: dyn_modules/openmath/cd/__init__.py
===================================================================
--- dyn_modules/openmath/cd/__init__.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/cd/__init__.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,1 @@
+__all__=["polyd","arith1", "primdec", "list"]
Index: dyn_modules/openmath/cd/arith1.py
===================================================================
--- dyn_modules/openmath/cd/arith1.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/cd/arith1.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,12 @@
+"Implementation of arith1 content dictionary"
+from objects import OMS,OMCD, OMCDImplementation
+from operator import add, sub, mul, div, neg, abs
+content = OMCD("arith1")
+implementation = OMCDImplementation(content)
+#implementation.divide=div no integer division allowed
+implementation.plus=add
+implementation.times=mul
+
+implementation.power=pow
+implementation.unary_minus=neg
+implementation.abs=abs
Index: dyn_modules/openmath/cd/fieldname1.py
===================================================================
--- dyn_modules/openmath/cd/fieldname1.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/cd/fieldname1.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,11 @@
+#from binding import *
+#from context import *
+from objects import *
+#from cd import *
+#from omexceptions import *
+
+content=OMCD("fieldname1")
+implementation=OMCDImplementation(content)
+
+Qsym=OMS("Q",content)
+implementation.support("Q")
Index: dyn_modules/openmath/cd/gametheory.py
===================================================================
--- dyn_modules/openmath/cd/gametheory.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/cd/gametheory.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,19 @@
+from binding import *
+from context import *
+from objects import *
+from cd import *
+from omexceptions import *
+
+content=OMCD("gametheory","http://www.singular.uni-kl.de/openmath/cd")
+implementation=OMCDImplementation(content)
+
+eatcake_sym=OMSymbol("eatcake", content)
+left_wins_sym=OMSymbol("left_wins",content)
+
+def cake_to_OM(region_list):
+	args=[]
+	for (l,r) in region_list:
+		args.append(OMint(l))
+		args.append(OMint(r))
+	return OMApply(eatcake_sym,args)
+
Index: dyn_modules/openmath/cd/list1.py
===================================================================
--- dyn_modules/openmath/cd/list1.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/cd/list1.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,7 @@
+from objects import *
+from copy import copy
+content=OMCD("list1")
+implementation=OMCDImplementation(content)
+implementation.support("list")
+def list2OM(l):
+    return OMA(implementation.list,copy(l))
Index: dyn_modules/openmath/cd/polyd.py
===================================================================
--- dyn_modules/openmath/cd/polyd.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/cd/polyd.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,38 @@
+#from binding import *
+#from context import *
+from objects import *
+#from cd import *
+from omexceptions import *
+
+content=OMCD("polyd")
+implementation=OMCDImplementation(content)
+
+groebner=OMS("groebner",content)
+#implementation.support("groebner")
+implementation.support("DMP")
+implementation.support("DMPL")
+implementation.support("SDMP")
+implementation.support("term")
+implementation.support("graded_reverse_lexicographic")
+implementation.support("lexicographic")
+implementation.support("poly_ring_d")
+implementation.support("groebnerd")
+DMPsym=OMS("DMP",content)
+DMPLsym=OMS("DMPL",content)
+SDMPsym=OMS("SDMP",content)
+termsym=OMS("term", content)
+dpsym=OMS("graded_reverse_lexicographic", content)
+lpsym=OMS("lexicographic", content)
+groebnersym=OMS("groebner", content)
+groebnerdsym=OMS("groebnerd", content)
+poly_ring_dsym=OMS("poly_ring_d",content)
+#def groebnerfunc(context, *args):
+#    #print "plusfunc", args
+#    args=[context.toGeneric(o) for o in args]
+#    if len(args)==0:
+#        return content.package(0)
+#    else:
+#        erg=args[0]
+#        for i in xrange(1,len(args)):
+#            erg=erg+args[i]
+#    return erg
Index: dyn_modules/openmath/cd/primdec.py
===================================================================
--- dyn_modules/openmath/cd/primdec.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/cd/primdec.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,6 @@
+
+from objects import *
+
+
+content=OMCD("primdec", "http://www.singular.uni-kl.de/openmath")
+implementation=OMCDImplementation(content)
Index: dyn_modules/openmath/context.py
===================================================================
--- dyn_modules/openmath/context.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/context.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,166 @@
+from exceptions import *
+from copy import copy
+#from cd import *
+from omexceptions import *
+from objects import *
+from re import compile
+import StringIO
+from xml.sax.saxutils import XMLGenerator
+raiseException=True
+class Context(object):
+    #TODO: Referenzen durch scope richtig behandeln
+    def __init__(self):
+        self.scope=Scope()
+        self.scope.push({})
+        self.implementations={}
+        self.XMLEncoder=SimpleXMLEncoder()
+        self.errorHandler=SimpleErrorHandler()
+    def addCDImplementation(self, implementation):
+        self.implementations[implementation.cd]=implementation
+    def lookupImplementation(self, oms):
+        #print self.implementations
+        try:
+            
+            return getattr(self.implementations[oms.cd],oms.name)
+        except ValueError:
+            raise NotImplementedError
+    def __getitem__(self,itemname):
+        return self.scope[itemname]
+    def __setitem__(self,itemname, item):
+        self.scope[itemname]=item
+    def push(self, dict):
+        """push a lexical context in form of a dictionary"""
+        self.scope.push(dict)
+    def pop(self, dict):
+        """pop a lexical context"""
+        return self.scope.pop(dict)
+    def scopeFromCurrentScope(self):
+        """returns a new Scope object, sharing the dictionaries,
+           which will represent the current scope"""
+        return self.scope.derriveScope()
+    def toGeneric(self, o):
+        return o.getValue()
+
+    def evaluateSymbol(self, oms):
+        try:
+            impl=self.lookupImplementation(oms)
+            #if len(oms.attributes)>0:
+            #    impl=copy(impl)
+            #    impl.attributes=copy(oms.attributes)
+            return impl
+        except NotImplementedError:
+            #TODO log this, report it
+            return oms
+    def evaluateVariable(self, omv):
+        try:
+            return self[omv.name]
+        except OutOfScopeError:
+            return omv
+    def evaluateApplication(self, app):
+        efunc = self.evaluate(app.func)
+        eargs = [self.evaluate(a) for a in app.args]
+        if callable(efunc):
+            if raiseException:
+                return self.apply(efunc,eargs)
+            else:
+                try:
+                    return self.apply(efunc, eargs)
+                except EvaluationFailedError, NotImplementedError:
+                    return OMA(efunc, eargs)
+                #return self
+        else:
+            #print efunc
+            return OMA(efunc, eargs)
+    def evaluate(self,omobject):
+        
+        if isinstance(omobject,OMV):
+           
+            return self.evaluateVariable(omobject)
+        if isinstance(omobject,OMS):
+            return self.evaluateSymbol(omobject)
+        if isinstance(omobject,OMA):
+            return self.evaluateApplication(omobject)
+        if isinstance(omobject,OMBIND):
+            return omobject.evaluate(self)
+        return omobject
+    def evaluateInScope(self,omobject, scope):
+        bak=self.scope
+        self.scope=scope
+        erg=self.evaluate(omobject)
+        self.scope=bak
+        #print "my erg is", erg
+        return erg
+    def package(self, val):
+        return val
+        if isinstance(val, int):
+            return OMint(val)
+        if isinstance(val, float):
+            return OMfloat(val)
+            
+            raise NotImplementedError
+    def apply(self,func,args):
+        try:
+            return func(self,*args)
+        except:
+            from traceback import print_exc
+            print_exc()
+            raise EvaluationFailedError
+    def XMLEncodeBody(self,body):
+        return self.XMLEncoder.encode(body)
+    def XMLEncodeObject(self, obj):
+        #TODO: Make Attribution List attributes
+        #TODO: Make all objects __hash__ and __eq__
+        out=StringIO.StringIO()
+        G=XMLGenerator(out)
+        obj.XMLSAXEncode(self,G)
+        return out.getvalue()
+        if (len(obj.attributes)==0):
+            return "".join(obj.XMLPreEncode(self))
+        else:
+            toencode=copy(obj)
+            toencode.attributes={}
+            #FIXME: look on order
+            attribution=OMAttribution(*([OMAttributePair(k,obj.attributes[k])\
+                for k in obj.attributes])+[toencode])
+            return attribution.XMLEncode(self)
+class SimpleErrorHandler(object):
+    def __init__(self):
+        super(SimpleErrorHandler,self).__init__()
+    def handle_unexpected_symbol(self, symbol):
+        pass
+    def handle_unsupported_cd(self, symbol):
+        pass
+    def handle_unexpected_symbol(self, symbol):
+        pass 
+class SimpleXMLEncoder(object):
+    def __init__(self):
+      self.re_inner=compile("&")
+      self.re_outer=compile("<")
+    def encode(self, string):
+        #return sub("<","&lt;",sub("&","&amp;",string))
+      return self.re_outer.sub("&lt", self.re_inner.sub("&amp", string)) 
+class Scope(object):
+    def __init__(self):
+        self.dicts=[]
+    def push(self, dict):
+        self.dicts.append(dict)
+    def pop(self):
+        return self.dicts.pop()
+    def __getitem__(self,itemname):
+        i=len(self.dicts)-1
+        while i>=0:
+            try:
+                return self.dicts[i][itemname]
+            except KeyError:
+                pass
+            i=i-1
+        raise OutOfScopeError
+    def  __setitem__(self, itemname, item):
+        try:
+            self.dicts[len(self.dicts)-1][itemname]=item
+        except IndexError:
+            print "scope has no layers"
+    def derriveScope(self):
+        erg=Scope()
+        erg.dicts=copy(self.dicts)
+        return erg
Index: dyn_modules/openmath/cyc5.out
===================================================================
--- dyn_modules/openmath/cyc5.out	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/cyc5.out	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,2 @@
+OMA(OMS(groebnerd, polyd)[OMS(lexicographic, polyd), OMA(OMS(DMPL, polyd)[OMA(OMS(poly_ring_d, polyd)[OMS(Q, fieldname1), 5], OMA(OMS(SDMP, polyd)[OMA(OMS(term, polyd)[1, 0, 0, 0, 0, 15], OMA(OMS(term, polyd)[122, 0, 0, 0, 0, 10], OMA(OMS(term, polyd)[-122, 0, 0, 0, 0, 5], OMA(OMS(term, polyd)[-1, 0, 0, 0, 0, 0]], OMA(OMS(SDMP, polyd)[OMA(OMS(term, polyd)[55, 0, 0, 0, 2, 5], OMA(OMS(term, polyd)[-55, 0, 0, 0, 2, 0], OMA(OMS(term, polyd)[-2, 0, 0, 0, 1, 11], OMA(OMS(term, polyd)[-231, 0, 0, 0, 1, 6], OMA(OMS(term, polyd)[233, 0, 0, 0, 1, 1], OMA(OMS(term, polyd)[-8, 0, 0, 0, 0, 12], OMA(OMS(term, polyd)[-979, 0, 0, 0, 0, 7], OMA(OMS(term, polyd)[987, 0, 0, 0, 0, 2]], OMA(OMS(SDMP, polyd)[OMA(OMS(term, polyd)[6, 0, 0, 0, 7, 0], OMA(OMS(term, polyd)[57, 0, 0, 0, 6, 6], OMA(OMS(term, polyd)[-39, 0, 0, 0, 6, 1], OMA(OMS(term, polyd)[25, 0, 0, 0, 5, 7], OMA(OMS(term, polyd)[-19, 0, 0, 0, 5, 2], OMA(OMS(term, polyd)[-5, 0, 0, 0, 4, 8], OMA(OMS(term, polyd)[5, 0, 0, 0, 4, 3], OMA(OMS(term, polyd)[-8, 0, 0, 0, 3, 9], OMA(OMS(term, polyd)[8, 0, 0, 0, 3, 4], OMA(OMS(term, polyd)[-2, 0, 0, 0, 2, 10], OMA(OMS(term, polyd)[14, 0, 0, 0, 2, 5], OMA(OMS(term, polyd)[-18, 0, 0, 0, 2, 0], OMA(OMS(term, polyd)[-18, 0, 0, 0, 1, 6], OMA(OMS(term, polyd)[-6, 0, 0, 0, 0, 7]], OMA(OMS(SDMP, polyd)[OMA(OMS(term, polyd)[10564400, 0, 0, 1, 0, 5], OMA(OMS(term, polyd)[-10564400, 0, 0, 1, 0, 0], OMA(OMS(term, polyd)[1323490, 0, 0, 0, 9, 2], OMA(OMS(term, polyd)[-30221992, 0, 0, 0, 8, 3], OMA(OMS(term, polyd)[-153374547, 0, 0, 0, 7, 4], OMA(OMS(term, polyd)[-189699120, 0, 0, 0, 6, 5], OMA(OMS(term, polyd)[-855295, 0, 0, 0, 6, 0], OMA(OMS(term, polyd)[37459263, 0, 0, 0, 5, 6], OMA(OMS(term, polyd)[-89579914, 0, 0, 0, 5, 1], OMA(OMS(term, polyd)[187440435, 0, 0, 0, 4, 7], OMA(OMS(term, polyd)[-188763925, 0, 0, 0, 4, 2], OMA(OMS(term, polyd)[91961138, 0, 0, 0, 3, 8], OMA(OMS(term, polyd)[-61739146, 0, 0, 0, 3, 3], OMA(OMS(term, polyd)[12510703, 0, 0, 0, 2, 9], OMA(OMS(term, polyd)[140863844, 0, 0, 0, 2, 4], OMA(OMS(term, polyd)[190777365, 0, 0, 0, 1, 5], OMA(OMS(term, polyd)[-222950, 0, 0, 0, 1, 0], OMA(OMS(term, polyd)[51897701, 0, 0, 0, 0, 6], OMA(OMS(term, polyd)[222950, 0, 0, 0, 0, 1]], OMA(OMS(SDMP, polyd)[OMA(OMS(term, polyd)[10564400, 0, 0, 1, 1, 0], OMA(OMS(term, polyd)[-10564400, 0, 0, 1, 0, 6], OMA(OMS(term, polyd)[-1323490, 0, 0, 0, 10, 2], OMA(OMS(term, polyd)[30221992, 0, 0, 0, 9, 3], OMA(OMS(term, polyd)[153374547, 0, 0, 0, 8, 4], OMA(OMS(term, polyd)[189276544, 0, 0, 0, 7, 5], OMA(OMS(term, polyd)[855295, 0, 0, 0, 7, 0], OMA(OMS(term, polyd)[-21823951, 0, 0, 0, 6, 6], OMA(OMS(term, polyd)[89579914, 0, 0, 0, 6, 1], OMA(OMS(term, polyd)[-141379651, 0, 0, 0, 5, 7], OMA(OMS(term, polyd)[188763925, 0, 0, 0, 5, 2], OMA(OMS(term, polyd)[-95553034, 0, 0, 0, 4, 8], OMA(OMS(term, polyd)[65331042, 0, 0, 0, 4, 3], OMA(OMS(term, polyd)[-46528071, 0, 0, 0, 3, 9], OMA(OMS(term, polyd)[-117410876, 0, 0, 0, 3, 4], OMA(OMS(term, polyd)[-12043416, 0, 0, 0, 2, 10], OMA(OMS(term, polyd)[-167746973, 0, 0, 0, 2, 5], OMA(OMS(term, polyd)[222950, 0, 0, 0, 2, 0], OMA(OMS(term, polyd)[-67533013, 0, 0, 0, 1, 6], OMA(OMS(term, polyd)[-222950, 0, 0, 0, 1, 1], OMA(OMS(term, polyd)[-46060784, 0, 0, 0, 0, 7]], OMA(OMS(SDMP, polyd)[OMA(OMS(term, polyd)[31693200, 0, 0, 3, 0, 0], OMA(OMS(term, polyd)[-3970470, 0, 0, 2, 9, 2], OMA(OMS(term, polyd)[90665976, 0, 0, 2, 8, 3], OMA(OMS(term, polyd)[460123641, 0, 0, 2, 7, 4], OMA(OMS(term, polyd)[600790560, 0, 0, 2, 6, 5], OMA(OMS(term, polyd)[2565885, 0, 0, 2, 6, 0], OMA(OMS(term, polyd)[-857167989, 0, 0, 2, 5, 6], OMA(OMS(term, polyd)[268739742, 0, 0, 2, 5, 1], OMA(OMS(term, polyd)[140211295, 0, 0, 2, 4, 7], OMA(OMS(term, polyd)[566291775, 0, 0, 2, 4, 2], OMA(OMS(term, polyd)[41048586, 0, 0, 2, 3, 8], OMA(OMS(term, polyd)[153524238, 0, 0, 2, 3, 3], OMA(OMS(term, polyd)[-343899709, 0, 0, 2, 2, 9], OMA(OMS(term, polyd)[-221867932, 0, 0, 2, 2, 4], OMA(OMS(term, polyd)[15846600, 0, 0, 2, 1, 10], OMA(OMS(term, polyd)[-868135295, 0, 0, 2, 1, 5], OMA(OMS(term, polyd)[668850, 0, 0, 2, 1, 0], OMA(OMS(term, polyd)[18619497, 0, 0, 2, 0, 6], OMA(OMS(term, polyd)[-668850, 0, 0, 2, 0, 1], OMA(OMS(term, polyd)[-31693200, 0, 0, 1, 6, 6], OMA(OMS(term, polyd)[-459551400, 0, 0, 1, 5, 7], OMA(OMS(term, polyd)[73950800, 0, 0, 1, 4, 8], OMA(OMS(term, polyd)[195441400, 0, 0, 1, 3, 9], OMA(OMS(term, polyd)[52822000, 0, 0, 1, 3, 4], OMA(OMS(term, polyd)[-63386400, 0, 0, 1, 2, 10], OMA(OMS(term, polyd)[633864000, 0, 0, 1, 2, 5], OMA(OMS(term, polyd)[-639146200, 0, 0, 1, 1, 6], OMA(OMS(term, polyd)[174312600, 0, 0, 1, 0, 7], OMA(OMS(term, polyd)[-31693200, 0, 0, 0, 3, 5]], OMA(OMS(SDMP, polyd)[OMA(OMS(term, polyd)[22, 0, 1, 0, 0, 5], OMA(OMS(term, polyd)[-22, 0, 1, 0, 0, 0], OMA(OMS(term, polyd)[9, 0, 0, 4, 2, 0], OMA(OMS(term, polyd)[-9, 0, 0, 4, 0, 2], OMA(OMS(term, polyd)[-1, 0, 0, 3, 3, 0], OMA(OMS(term, polyd)[-5, 0, 0, 3, 2, 1], OMA(OMS(term, polyd)[-20, 0, 0, 3, 1, 2], OMA(OMS(term, polyd)[-10, 0, 0, 3, 0, 3], OMA(OMS(term, polyd)[3, 0, 0, 2, 3, 1], OMA(OMS(term, polyd)[9, 0, 0, 2, 2, 2], OMA(OMS(term, polyd)[-102, 0, 0, 2, 1, 3], OMA(OMS(term, polyd)[18, 0, 0, 2, 0, 4], OMA(OMS(term, polyd)[-2, 0, 0, 1, 4, 1], OMA(OMS(term, polyd)[71, 0, 0, 1, 3, 2], OMA(OMS(term, polyd)[-20, 0, 0, 1, 2, 3], OMA(OMS(term, polyd)[-18, 0, 0, 1, 1, 4], OMA(OMS(term, polyd)[41, 0, 0, 1, 0, 5], OMA(OMS(term, polyd)[3, 0, 0, 0, 4, 2], OMA(OMS(term, polyd)[32, 0, 0, 0, 3, 3], OMA(OMS(term, polyd)[-24, 0, 0, 0, 2, 4], OMA(OMS(term, polyd)[3, 0, 0, 0, 1, 5], OMA(OMS(term, polyd)[22, 0, 0, 0, 0, 6]], OMA(OMS(SDMP, polyd)[OMA(OMS(term, polyd)[110, 0, 1, 0, 1, 0], OMA(OMS(term, polyd)[-110, 0, 1, 0, 0, 6], OMA(OMS(term, polyd)[-45, 0, 0, 4, 3, 0], OMA(OMS(term, polyd)[8, 0, 0, 4, 2, 1], OMA(OMS(term, polyd)[67, 0, 0, 4, 1, 2], OMA(OMS(term, polyd)[-30, 0, 0, 4, 0, 3], OMA(OMS(term, polyd)[5, 0, 0, 3, 4, 0], OMA(OMS(term, polyd)[29, 0, 0, 3, 3, 1], OMA(OMS(term, polyd)[87, 0, 0, 3, 2, 2], OMA(OMS(term, polyd)[119, 0, 0, 3, 1, 3], OMA(OMS(term, polyd)[-136, 0, 0, 3, 0, 4], OMA(OMS(term, polyd)[-15, 0, 0, 2, 4, 1], OMA(OMS(term, polyd)[31, 0, 0, 2, 3, 2], OMA(OMS(term, polyd)[507, 0, 0, 2, 2, 3], OMA(OMS(term, polyd)[-78, 0, 0, 2, 1, 4], OMA(OMS(term, polyd)[-237, 0, 0, 2, 0, 5], OMA(OMS(term, polyd)[10, 0, 0, 1, 5, 1], OMA(OMS(term, polyd)[-347, 0, 0, 1, 4, 2], OMA(OMS(term, polyd)[190, 0, 0, 1, 3, 3], OMA(OMS(term, polyd)[203, 0, 0, 1, 2, 4], OMA(OMS(term, polyd)[-23, 0, 0, 1, 1, 5], OMA(OMS(term, polyd)[-241, 0, 0, 1, 0, 6], OMA(OMS(term, polyd)[-15, 0, 0, 0, 5, 2], OMA(OMS(term, polyd)[-172, 0, 0, 0, 4, 3], OMA(OMS(term, polyd)[91, 0, 0, 0, 3, 4], OMA(OMS(term, polyd)[81, 0, 0, 0, 2, 5], OMA(OMS(term, polyd)[21, 0, 0, 0, 1, 6], OMA(OMS(term, polyd)[-110, 0, 0, 0, 0, 7]], OMA(OMS(SDMP, polyd)[OMA(OMS(term, polyd)[22, 0, 1, 1, 0, 0], OMA(OMS(term, polyd)[-22, 0, 1, 0, 3, 3], OMA(OMS(term, polyd)[-66, 0, 1, 0, 2, 4], OMA(OMS(term, polyd)[88, 0, 1, 0, 1, 5], OMA(OMS(term, polyd)[-22, 0, 1, 0, 0, 6], OMA(OMS(term, polyd)[-9, 0, 0, 5, 2, 0], OMA(OMS(term, polyd)[9, 0, 0, 5, 0, 2], OMA(OMS(term, polyd)[1, 0, 0, 4, 3, 0], OMA(OMS(term, polyd)[5, 0, 0, 4, 2, 1], OMA(OMS(term, polyd)[20, 0, 0, 4, 1, 2], OMA(OMS(term, polyd)[10, 0, 0, 4, 0, 3], OMA(OMS(term, polyd)[-3, 0, 0, 3, 3, 1], OMA(OMS(term, polyd)[-31, 0, 0, 3, 2, 2], OMA(OMS(term, polyd)[124, 0, 0, 3, 1, 3], OMA(OMS(term, polyd)[-18, 0, 0, 3, 0, 4], OMA(OMS(term, polyd)[2, 0, 0, 2, 4, 1], OMA(OMS(term, polyd)[-49, 0, 0, 2, 3, 2], OMA(OMS(term, polyd)[-46, 0, 0, 2, 2, 3], OMA(OMS(term, polyd)[84, 0, 0, 2, 1, 4], OMA(OMS(term, polyd)[-41, 0, 0, 2, 0, 5], OMA(OMS(term, polyd)[-3, 0, 0, 1, 4, 2], OMA(OMS(term, polyd)[-32, 0, 0, 1, 3, 3], OMA(OMS(term, polyd)[-42, 0, 0, 1, 2, 4], OMA(OMS(term, polyd)[129, 0, 0, 1, 1, 5], OMA(OMS(term, polyd)[-44, 0, 0, 1, 0, 6], OMA(OMS(term, polyd)[-22, 0, 0, 0, 4, 3], OMA(OMS(term, polyd)[-88, 0, 0, 0, 3, 4], OMA(OMS(term, polyd)[-22, 0, 0, 0, 2, 5], OMA(OMS(term, polyd)[88, 0, 0, 0, 1, 6], OMA(OMS(term, polyd)[-22, 0, 0, 0, 0, 7]], OMA(OMS(SDMP, polyd)[OMA(OMS(term, polyd)[1, 0, 2, 0, 0, 0], OMA(OMS(term, polyd)[1, 0, 1, 0, 1, 0], OMA(OMS(term, polyd)[2, 0, 1, 0, 0, 1], OMA(OMS(term, polyd)[-1, 0, 0, 1, 1, 0], OMA(OMS(term, polyd)[1, 0, 0, 1, 0, 1], OMA(OMS(term, polyd)[1, 0, 0, 0, 0, 2]], OMA(OMS(SDMP, polyd)[OMA(OMS(term, polyd)[1, 1, 0, 0, 0, 0], OMA(OMS(term, polyd)[1, 0, 1, 0, 0, 0], OMA(OMS(term, polyd)[1, 0, 0, 1, 0, 0], OMA(OMS(term, polyd)[1, 0, 0, 0, 1, 0], OMA(OMS(term, polyd)[1, 0, 0, 0, 0, 1]]]]
+
Index: dyn_modules/openmath/kuchenessen_demo.py
===================================================================
--- dyn_modules/openmath/kuchenessen_demo.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/kuchenessen_demo.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,41 @@
+﻿# -*- coding: utf-8 -*-
+#imports and basic objects
+import sys
+sys.path.insert(0,"/Users/michael/sing3/modules/openmathserver")
+import CD.gametheory as gametheory
+from objects import OMApply
+from context import Context
+from os import pipe
+from subprocess import Popen,PIPE
+from omxmlreader import *
+context=Context()
+
+#our cake
+rectangle_list=[(4,3),(3,3),(1,1),(2,4),(4,2)]
+print "Eingabeliste", rectangle_list
+#create Openmath representation
+cake=gametheory.cake_to_OM(rectangle_list)
+task=OMApply(gametheory.left_wins_sym,[cake])
+task=context.XMLEncodeObject(task)
+
+
+
+
+#open a pipe
+p=Popen(["python", "/Users/michael/sing3/modules/openmathserver/openmathhashunger.py"],
+    stdout=PIPE,stdin=PIPE)
+p.stdin.write(task)
+p.stdin.close()
+
+#parse it
+root=readStream(p.stdout)
+builder=OMFromXMLBuilder()
+doc=builder.build(root)
+
+#output
+erg=doc.getValue()
+if erg:
+    print "Spieler 1 gewinnt"
+else:
+    print "Spieler 1 gewinnt nicht"
+p.stdout.close()
Index: dyn_modules/openmath/lxmldecoder.py
===================================================================
--- dyn_modules/openmath/lxmldecoder.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/lxmldecoder.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,79 @@
+import lxml.etree as et
+from objects import *
+
+class OMFromXMLBuilder:
+    def buildFromNode(self, node):
+        erg=None
+        if (node.tag=="OMI"):
+            erg=int(node.text)
+        if (node.tag=="OMSTR"):
+            #print "data", node.text
+            erg=node.text
+        if (node.tag=="OMB"):
+            erg=OMByteArray(base64.decodestring(node.text))
+        if (node.tag=="OMV"):
+            name=node.get("name") #node.attributes["name"]
+            #print dir(name)
+            erg= OMV(name)
+        if (node.tag=="OMS"):
+            if "cdbase" in node.attrib:
+                #FIXME: obtain from ancestors
+                cdbase=node.get("cdbase")
+            else: 
+                cdbase=None
+            cdname=node.get("cd")
+            name=node.get("name")
+            #print repr(node)
+            #print node.attributes
+            #print "cdbase", cdbase
+            if cdbase==None:
+                cd=OMCD(cdname)
+            else:
+                cd=OMCD(cdname,cdbase)
+            erg=OMS(name,cd)
+        if (node.tag=="OMA"):
+            children=[self.buildFromNode(c) for c in node]
+            erg= OMA(children[0],children[1:])
+        if (node.tag=="OMOBJ"):
+            children=[self.buildFromNode(c) for c in node]
+            erg= OMOBJ(children)
+        if (node.tag=="OMBIND"):
+            children=[self.buildFromNode(c) for c in node]
+            erg= OMBIND(children[0],children[1:-1],children[-1])
+        if (node.tag=="OMF"):
+            if (node.hasAttribute("dec")):
+                erg=float(node.getAttribute("dec"))
+            else:
+                raise NotImplementedError
+            
+        if (node.tag=="OMR"):
+            erg=OMRef(node.get("xref"))
+            self.refs.append(erg)
+        if (node.tag=="OMATP"):
+            children=[self.buildFromNode(c) for c in node]
+            assert(len(children)==2)
+            erg=OMAttributePair(children[0],children[1])
+        if (node.tag=="OMATTR"):
+            children=[self.buildFromNode(c) for c in node]
+            erg=OMAttribution(*children)
+        if None==erg:
+            raise NotImplementedError
+        else:
+            if "id" in node.attrib:
+                id=node.get("id")
+                self.ids[id]=erg
+        return erg
+    def __init__(self):
+        self.refs=[]
+        self.ids={}
+    def build(self, tree):
+        root=tree.getroot()
+        #remove_white_space(root)
+        erg=self.buildFromNode(root)
+        for r in self.refs:
+            r.ref=self.ids[r.ref]
+        return erg
+def decode(tree):
+    builder=OMFromXMLBuilder()
+    om=builder.build(tree)
+    return om
Index: dyn_modules/openmath/lxmlencoder.py
===================================================================
--- dyn_modules/openmath/lxmlencoder.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/lxmlencoder.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,73 @@
+import lxml.etree as et
+from objects import OMV, OMS, OMA, OMBIND
+
+
+def encodeSub(om, parent):
+    #print om
+    if isinstance(om, int):
+        sub=et.SubElement(parent, "OMI")
+        sub.text=str(om)
+        return
+    if isinstance(om, long):
+        sub=et.SubElement(parent, "OMI")
+        sub.text=str(om)
+        return
+    if isinstance(om, OMV):
+        sub=et.SubElement(parent, "OMV")
+        sub.set("name",om.name)
+        return
+    if isinstance(om, OMS):
+        
+        sub=et.SubElement(parent,"OMS")
+        sub.set("name",om.name)
+        sub.set("cdbase", om.cd.base)
+        sub.set("cd",om.cd.name)
+        return
+    if isinstance(om, OMA):
+        top=et.SubElement(parent, "OMA")
+        encodeSub(om.func,top)
+        for a in om.args:
+            encodeSub(a,top)
+        return
+    if isinstance(om, OMBIND):
+        top=et.SubElement(parent, "OMBIND")
+        encodeSub(om.binder,top)
+        for a in om.variables:
+            encodeSub(a,top)
+        encodeSub(om.block,top)
+        return
+    print om
+    raise Exception
+        
+def encodeTop(om):
+    if isinstance(om, int):
+        sub=et.Element("OMI")
+        sub.text=str(om)
+        return sub
+    if isinstance(om, long):
+        sub=et.Element("OMI")
+        sub.text=str(om)
+        return sub
+    if isinstance(om, OMV):
+        sub=et.Element("OMV")
+        sub.set("name",om.name)
+        return sub
+    if isinstance(om, OMS):
+        sub=et.Element("OMS")
+        sub.set("name",om.name)
+        sub.set("cdbase", om.cd.base)
+        sub.set("cd",om.cd.name)
+        return sub
+    if isinstance(om, OMA):
+        top=et.Element("OMA")
+        encodeSub(om.func, top)
+        for a in om.args:
+            encodeSub(a,top)
+        return top
+    #print om.__class__
+    raise Exception
+def encode(om):
+    root=encodeTop(om)
+    tree = et.ElementTree(root)
+    return tree
+    
Index: dyn_modules/openmath/objectbsp
===================================================================
--- dyn_modules/openmath/objectbsp	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/objectbsp	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,26 @@
+<OMOBJ>
+	<OMA>
+		<OMBIND id="lala">
+			<OMS name="lambda" cd="fns1" cdbase="http://www.openmath.org/cd"></OMS>
+			<OMA>
+				<OMS name="plus" cdbase="http://www.openmath.org/cd" cd="arith1"></OMS>
+				<OMV name="x"></OMV>
+				<OMI>1</OMI>
+			</OMA>
+		</OMBIND>
+	</OMA>
+	<OMA>
+		<OMBIND>
+			<OMS name="lambda" cd="fns1" cdbase="http://www.openmath.org/cd"></OMS>
+			<OMV name="x"/>
+			<OMA>
+				<OMR xref="lala"/>
+			</OMA>
+		</OMBIND>
+		<OMI>1</OMI>
+	</OMA>
+	<OMI>3</OMI>
+	<OMA>
+		<OMR xref="lala"/>
+	</OMA>
+</OMOBJ>
Index: dyn_modules/openmath/objects.bpl
===================================================================
--- dyn_modules/openmath/objects.bpl	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/objects.bpl	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,2 @@
+(dp1
+.
Index: dyn_modules/openmath/objects.py
===================================================================
--- dyn_modules/openmath/objects.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/objects.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,300 @@
+"""Implementation of openmath basic objects"""
+from omexceptions import UnsupportedOperationError 
+from  omexceptions import OutOfScopeError, EvaluationFailedError
+from exceptions import NotImplementedError
+from copy import copy
+from xml.sax.xmlreader import AttributesImpl as attr
+from itertools import izip
+import base64
+
+raiseException=True
+#TODO: OMOBJ, OME, OMATTR
+#from cd import *
+try:
+    import psyco
+    def optimize(f):
+        psyco.bind(f)
+except:
+    def optimize(f):
+        pass
+
+class OMCD(object):
+    def __init__(self, name, base="http://www.openmath.org/cd"):
+        self.name = name
+        self.base = base
+    def  __eq__(self, other):
+        try:
+            return (self.name == other.name) and (self.base == other.base)
+        except:
+            return False
+    def __hash__(self):
+        return hash((self.name,self.base))
+
+
+        
+class OMCDImplementation(object):
+    converter=None
+    def __init__(self, cd):
+        object.__setattr__(self,"cd",cd)
+        #object.__setattr__(self,"converter",None)
+    def support(self,symbol):
+        setattr(self,symbol,OMS(symbol, self.cd))
+    def __setattr__(self, name,value):
+        if name=="converter":
+            object.__setattr__(self,name,value)
+            return
+        "FIXME: implements this later safer against name conflicts"
+        if callable(value) and (not isinstance(value, ImplementedSymbol)):
+            
+            if self.converter!=None:
+                object.__setattr__(
+                    self, 
+                    name, 
+                    ImplementedSymbol(
+                        OMS(name,self.cd), 
+                        self.converter(value)))
+            else:
+                object.__setattr__(self, name, ImplementedSymbol(OMS(name,self.cd), value))
+        else:
+            object.__setattr__(self,name,value)
+
+class OMS(object):
+    def __init__(self,name,cd = None):
+        #super(OMSymbol,self).__init__()
+        self.cd = cd
+        self.name = name
+    def __eq__(self, other):
+        try:
+            return bool(other.name == self.name and self.cd == other.cd)
+        except:
+            return False
+    def __str__(self):
+        return "OMS(" + self.name + ", " + self.cd.name + ")"
+    def __repr__(self):
+        return str(self)
+    def __hash__(self):#
+        return hash((self.name,self.cd.__hash__()))
+    def evaluate(self,context):
+        return context.evaluateSymbol(self)
+    XMLtag="OMS"
+    def getXMLAttributes(self):
+        #return [XMLAttribute("name", self.name),\
+        #         XMLAttribute("cdbase", self.cd.base),\
+        #         XMLAttribute("cd", self.cd.name)]
+        return {"name":self.name, "cdbase":self.cd.base, "cd": self.cd.name}
+    def setXMLAttributes(self):
+        raise UnsupportedOperationError
+
+
+class ImplementedSymbol(OMS):
+    def __init__(self,symbol, func):
+        super(ImplementedSymbol,self).__init__(symbol.name, symbol.cd)
+        self.implementation = func
+    def __str__(self):
+        return "OMS("+self.name+", " + self.cd.name +")"
+    def __call__(self, context, *args):
+        try:
+            erg=self.implementation(*args)
+        except KeyError:
+             raise EvaluationFailedError
+        return context.package(erg)
+
+cdFns1 = OMCD("fns1")
+lambdasym = OMS("lambda", cdFns1)
+
+def islambda(sym):
+    "return True, iff sym is the lambda binder"
+    return lambdasym == sym
+    
+class OMBIND(object):
+    """hopefully fixed possible problems: reevaluation writes new scope, 
+       if it isn't
+       meant so, references do not work correctly because of scopes
+       solve this by first evaluation to bounded OMBinding"""
+    def __init__(self, binder, variables, block):
+        #super(OMBinding, self).__init__()
+        self.block = block
+        self.binder = binder
+        self.variables = variables
+        self.bounded = False
+    def evaluate(self, context):
+        "evaluate the OMbinding in context"
+        assert islambda(self.binder)
+        if not self.bounded:
+            mycopy = copy(self)
+            mycopy.scope = context.scopeFromCurrentScope()
+            mycopy.bounded = True
+            return mycopy
+        else:
+            return self
+    def bind(self, args):
+        "bind arguments to values"
+        #print args, self.variables
+        assert len(args) == len(self.variables)
+        varBindings = dict(izip([i.name for i in self.variables], args))
+        self.scope.push(varBindings)
+    def unbind(self):
+        "unbind the arguments"
+        self.scope.pop()
+
+    def calcErg(self, context):
+        "do the actual computation"
+        return context.evaluateInScope(self.block, self.scope)
+    def __call__(self, context, *args):
+        assert self.bounded
+        self.bind(args)
+        erg = self.calcErg(context)
+        self.unbind()
+        #print "__call__ erg is", erg
+        return erg   
+        
+    XMLtag = "OMBIND"
+    def getChildren(self):
+        "get children for (XML) representation"
+        return [self.binder]+self.variables+[self.block]
+    
+    def __str__(self):
+        return "OMBIND(self.binder"+", "+str(self.variables) +", " + str(self.block) +")"
+        
+
+class OMOBJ(object):
+    def __init__(self, children):
+        #super(OMObject, self).__init__()
+        self.children = children
+    def getChildren(self):
+        return self.__children
+    def setChildren(self ,children):
+        self.__children=children
+    XMLtag = "OMOBJ"
+    def evaluate(self, context):
+        return OMObject([context.evaluate(c) for c in self.children])
+class OMV(object):
+    def __init__(self,name):
+        #super(OMVar, self).__init__()
+        self.name = name
+    def evaluate(self, context):
+        try:
+            return context[self.name]
+        except OutOfScopeError:
+            return self
+    def __str__(self):
+        return "OMV(" + self.name +")"
+    def __repr__(self):
+        return str(self)
+    XMLtag="OMV"
+class OMA(object):
+    def __init__(self, func, args):
+        #super(OMApply, self).__init__()
+        self.func = func
+        self.args = args
+        
+    def evaluate(self, context):
+        efunc = context.evaluate(self.func)
+        eargs = [context.evaluate(a) for a in self.args]
+        if callable(efunc):
+            if raiseException:
+                return context.apply(efunc,eargs)
+            else:
+                try:
+                    return context.apply(efunc, eargs)
+                except EvaluationFailedError, NotImplementedError:
+                    return OMA(efunc, eargs)
+                #return self
+        else:
+            #print efunc
+            return OMA(efunc, eargs)
+    def __str__ (self):
+        return "OMA"+"("+str(self.func)+str(self.args)
+    def __repr__ (self):
+        return "OMA"+"("+str(self.func)+str(self.args)
+    XMLtag="OMA"
+        
+
+# class OMB(SimpleValue):
+#     def __init__(self, value):
+#         #super(OMByteArray,self).__init__(value)
+#         self.value=value
+#     def __str__(self):
+#         return "OMByteArray(" + repr(self.value) + ")"
+#     def parse(self, value):
+#         return value
+#     XMLtag = "OMB"
+#     def getBody(self):
+#         return base64.encodestring(self.value)
+class OMRef(object):
+    def __init__(self, ref):
+        self.ref=ref
+    def evaluate(self, context):
+        return context.evaluate(self.ref)
+    def XMLEncode(self, context):
+        "FIXME: maybe it should also be able to encode as reference"
+        return context.XMLEncodeObject(self.ref)
+
+class OMATTR(object):
+    def __init__(self, *args):
+        #super(OMAttribution,self).__init__()
+        self.attr = list(args[:-1])
+        self.value = args[-1]
+    def getChildren(self):
+        #print type(self.attr)
+        #print type(self.value)
+        return self.attr+[self.value]
+    def evaluate(self, context):
+        value = copy(self.value)
+        value.attributes = copy(value.attributes)
+        for attribute in self.attr:
+            attribute_evaluated=context.evaluate(attribute)
+            value.attributes[attribute_evaluated.key] = attribute_evaluated.value
+        return value
+    XMLtag = "OMATTR"
+if __name__ == '__main__':
+    print OMV("x")
+    print OMA(OMV("x"),[OMV("y"),1])
+  
+
+    #from binding import OMBinding, lambdasym
+
+    
+    context["x"] = 1
+
+    x = OMV("x")
+
+    y = OMV("y")
+
+    print context.evaluate(x)
+    print context.evaluateVariable(x)
+    print context.evaluate(y)
+    import cd.arith1 as arith1
+    context.addCDImplementation(arith1.implementation)
+    print OMA(arith1.implementation.plus, [1,2])
+    print context.evaluate(OMA(arith1.implementation.plus, [1,2]))
+    application = OMA(OMS("plus", arith1.content), [1,2])
+    
+    print context.evaluate(application)
+    firstArg=OMBinding(lambdasym,[OMVar("x"), OMVar("y")], OMVar("x"))
+    #print context.evaluate(firstArg)
+    application = OMApply(firstArg, [x,y])
+    print context.evaluate(application)
+    application = OMApply(firstArg, [y,x])
+    print context.evaluate(application)
+    
+    #print type(context.lookupImplementation(arith1.plussym))
+    #application=OMApply(arith1.plussym,[x])
+    #application=OMApply(arith1.plussym,[x,x])
+    application = OMApply(OMS("plus", arith1.content), [x, x])
+    
+    print context.evaluate(application)
+    application = OMApply(OMS("plus", arith1.content), [x, x, x])
+    
+    print context.evaluate(application)
+    i =  OMint(22482489)
+    print i.body
+    print i.XMLEncode(context)
+    print context.XMLEncodeObject(OMS("plus", arith1.content))
+    #i.body="dshj"
+   
+#optimize(OMObjectBase.__init__)
+#optimize(OMObjectBase.XMLPreEncode)
+#optimize(SimpleValue.__init__)
+#optimize(OMint.__init__)
+#optimize(OMApply.__init__)
Index: dyn_modules/openmath/omexceptions.py
===================================================================
--- dyn_modules/openmath/omexceptions.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/omexceptions.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,12 @@
+class OutOfScopeError(Exception):
+    pass
+#class NotImplementedError(Exception):
+#    pass
+class EvaluationFailedError(Exception):
+    pass
+class PackagingFailedError(Exception):
+    pass
+class UnsupportedOperationError(Exception):
+    pass
+class UnresolvedReference(Exception):
+    pass
Index: dyn_modules/openmath/omxmlreader.py
===================================================================
--- dyn_modules/openmath/omxmlreader.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/omxmlreader.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,173 @@
+from xml.dom.xmlbuilder import *
+#from xml.dom.ext import PrettyPrint
+from xml.dom import Node
+import xml.dom as dom
+import base64
+#from 
+from StringIO import StringIO
+import re
+import sys
+import os.path
+from objects import *
+from binding import *
+from cd import *
+from exceptions import *
+from omexceptions import *
+def readFile(input_file_name):
+    docstream = open(input_file_name)
+    docIS=DOMInputSource()
+    docIS.byteStream=docstream
+    doc= DOMBuilder().parse(docIS)
+    docstream.close()
+    
+    root=doc.lastChild
+    return root
+
+def readStream(input_stream):
+    docIS=DOMInputSource()
+    docIS.byteStream=input_stream
+    doc= DOMBuilder().parse(docIS)
+    
+    root=doc.lastChild
+    return root
+def  get_text_in_children(n):
+    t = ""
+    for c in n.childNodes:
+        if c.nodeType== Node.TEXT_NODE:
+            t += c.nodeValue
+    return t
+def remove_white_space(node):
+    remove_list=[]
+    if node.nodeName=="OMC":
+        return
+    for child in node.childNodes:
+        if child.nodeType==dom.Node.TEXT_NODE and not child.data.strip():
+            remove_list.append(child)
+        elif child.hasChildNodes():
+            remove_white_space(child)
+    for node in remove_list:
+        node.parentNode.removeChild(node)
+        node.unlink()
+        
+class OMFromXMLBuilder:
+    def buildFromNode(self, node):
+        erg=None
+        if (node.nodeName=="OMI"):
+            content=get_text_in_children(node)
+            erg=OMint(content)
+        if (node.nodeName=="OMSTR"):
+            content=get_text_in_children(node)
+            #print "data", content
+            erg=OMString(content)
+        if (node.nodeName=="OMB"):
+            content=get_text_in_children(node)
+            #print "data", content
+            erg=OMByteArray(base64.decodestring(content))
+        if (node.nodeName=="OMV"):
+            name=node.getAttribute("name") #node.attributes["name"]
+            #print dir(name)
+            erg= OMVar(name)
+        if (node.nodeName=="OMS"):
+            if node.hasAttribute("cdbase"):
+                #FIXME: obtain from ancestors
+                cdbase=node.getAttribute("cdbase")
+            else: 
+                cdbase=None
+            cdname=node.getAttribute("cd")
+            name=node.getAttribute("name")
+            #print repr(node)
+            #print node.attributes
+            #print "cdbase", cdbase
+            if cdbase==None:
+                cd=OMCD(cdname)
+            else:
+                cd=OMCD(cdname,cdbase)
+            erg=OMSymbol(name,cd)
+        if (node.nodeName=="OMA"):
+            children=[self.buildFromNode(c) for c in node.childNodes]
+            erg= OMApply(children[0],children[1:])
+        if (node.nodeName=="OMOBJ"):
+            children=[self.buildFromNode(c) for c in node.childNodes]
+            erg= OMObject(children)
+        if (node.nodeName=="OMBIND"):
+            children=[self.buildFromNode(c) for c in node.childNodes]
+            erg= OMBinding(children[0],children[1:-1],children[-1])
+        if (node.nodeName=="OMF"):
+            if (node.hasAttribute("dec")):
+                value=float(node.getAttribute("dec"))
+            else:
+                raise NotImplementedError
+            erg=OMfloat(value)
+        if (node.nodeName=="OMR"):
+            if node.hasAttribute("xref"):
+                erg=OMRef(node.getAttribute("xref"))
+                self.refs.append(erg)
+            else:
+                raise UnresolvedReference
+        if (node.nodeName=="OMATP"):
+            children=[self.buildFromNode(c) for c in node.childNodes]
+            assert(len(children)==2)
+            erg=OMAttributePair(children[0],children[1])
+        if (node.nodeName=="OMATTR"):
+            children=[self.buildFromNode(c) for c in node.childNodes]
+            erg=OMAttribution(*children)
+        if None==erg:
+            raise NotImplementedError
+        else:
+            if node.hasAttribute("id"):
+                id=node.getAttribute("id")
+                self.ids[id]=erg
+            return erg
+    def __init__(self):
+        self.refs=[]
+        self.ids={}
+    def build(self, root):
+        remove_white_space(root)
+        erg=self.buildFromNode(root)
+        for r in self.refs:
+            r.ref=self.ids[r.ref]
+        return erg
+#TODO: handle hex floats
+#TODO: handle floats
+#TODO: handle ancestors cdbase
+if __name__=='__main__':
+    import CD.arith1 as arith1
+    
+    if len(sys.argv)<=2:
+        print "Usage: python omxmlreader [--evaluate] input output"
+    state=0
+    eval=False
+    #TODO: use optparse
+    for arg in sys.argv[1:]:
+        if state==0:
+            if arg=="--evaluate":
+                eval=True
+            else:
+                inputf=arg
+                state=1
+            continue
+        if state==1:
+            outputf=arg
+            continue
+        if state==2:
+            print "argument ignored:", arg
+    from context import Context
+    #inputf=sys.argv[1]
+    root=readFile(inputf)
+    builder=OMFromXMLBuilder()
+    context=Context()
+    context.addCDImplementation(arith1.implementation2)
+    doc=builder.build(root)
+    if eval:
+        doc=context.evaluate(doc)
+    #import profile
+    #profile.run('output=context.XMLEncodeObject(doc)','encodeprof')
+    output=context.XMLEncodeObject(doc)
+    try:
+        out=open(outputf,"w")
+    except NameError:
+        print "no output file"
+        sys.exit(1)
+    out.write(output)
+    out.close()
+    #print repr(root.getAttribute("blabla"))
Index: dyn_modules/openmath/openmathhashunger.py
===================================================================
--- dyn_modules/openmath/openmathhashunger.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/openmathhashunger.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,27 @@
+import sys
+sys.path.insert(0,"/Users/michael/sing3/modules/openmathserver")
+import CD.gametheory as gametheory
+import CAS.kuchenessen as kuchenessen
+
+kuchenessen.install_kuchenessen_plugin()
+
+from context import Context
+from omxmlreader import *
+import sys
+
+
+
+
+root=readStream(sys.stdin)
+builder=OMFromXMLBuilder()
+context=Context()
+
+context.addCDImplementation(gametheory.implementation)
+doc=builder.build(root)
+
+doc=context.evaluate(doc)
+
+output=context.XMLEncodeObject(doc)
+
+sys.stdout.write(output)
+
Index: dyn_modules/openmath/primdec.in
===================================================================
--- dyn_modules/openmath/primdec.in	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/primdec.in	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="us-ascii"?>
+<OMA><OMS name="list" cdbase="http://www.openmath.org/cd" cd="list1"/><OMA><OMS name="list" cdbase="http://www.openmath.org/cd" cd="list1"/><OMA><OMS name="DMPL" cdbase="http://www.openmath.org/cd" cd="polyd"/><OMA><OMS name="poly_ring_d" cdbase="http://www.openmath.org/cd" cd="polyd"/><OMS name="Q" cdbase="http://www.openmath.org/cd" cd="fieldname1"/><OMI>5</OMI></OMA><OMA><OMS name="SDMP" cdbase="http://www.openmath.org/cd" cd="polyd"/><OMA><OMS name="term" cdbase="http://www.openmath.org/cd" cd="polyd"/><OMI>1</OMI><OMI>2</OMI><OMI>0</OMI><OMI>0</OMI><OMI>0</OMI><OMI>0</OMI></OMA></OMA></OMA><OMA><OMS name="DMPL" cdbase="http://www.openmath.org/cd" cd="polyd"/><OMA><OMS name="poly_ring_d" cdbase="http://www.openmath.org/cd" cd="polyd"/><OMS name="Q" cdbase="http://www.openmath.org/cd" cd="fieldname1"/><OMI>5</OMI></OMA><OMA><OMS name="SDMP" cdbase="http://www.openmath.org/cd" cd="polyd"/><OMA><OMS name="term" cdbase="http://www.openmath.org/cd" cd="polyd"/><OMI>1</OMI><OMI>1</OMI><OMI>0</OMI><OMI>0</OMI><OMI>0</OMI><OMI>0</OMI></OMA></OMA></OMA></OMA><OMA><OMS name="list" cdbase="http://www.openmath.org/cd" cd="list1"/><OMA><OMS name="DMPL" cdbase="http://www.openmath.org/cd" cd="polyd"/><OMA><OMS name="poly_ring_d" cdbase="http://www.openmath.org/cd" cd="polyd"/><OMS name="Q" cdbase="http://www.openmath.org/cd" cd="fieldname1"/><OMI>5</OMI></OMA><OMA><OMS name="SDMP" cdbase="http://www.openmath.org/cd" cd="polyd"/><OMA><OMS name="term" cdbase="http://www.openmath.org/cd" cd="polyd"/><OMI>1</OMI><OMI>0</OMI><OMI>2</OMI><OMI>0</OMI><OMI>0</OMI><OMI>0</OMI></OMA><OMA><OMS name="term" cdbase="http://www.openmath.org/cd" cd="polyd"/><OMI>-10</OMI><OMI>0</OMI><OMI>1</OMI><OMI>0</OMI><OMI>0</OMI><OMI>0</OMI></OMA><OMA><OMS name="term" cdbase="http://www.openmath.org/cd" cd="polyd"/><OMI>25</OMI><OMI>0</OMI><OMI>0</OMI><OMI>0</OMI><OMI>0</OMI><OMI>0</OMI></OMA></OMA><OMA><OMS name="SDMP" cdbase="http://www.openmath.org/cd" cd="polyd"/><OMA><OMS name="term" cdbase="http://www.openmath.org/cd" cd="polyd"/><OMI>1</OMI><OMI>1</OMI><OMI>0</OMI><OMI>0</OMI><OMI>0</OMI><OMI>0</OMI></OMA><OMA><OMS name="term" cdbase="http://www.openmath.org/cd" cd="polyd"/><OMI>-1</OMI><OMI>0</OMI><OMI>0</OMI><OMI>0</OMI><OMI>0</OMI><OMI>0</OMI></OMA></OMA></OMA><OMA><OMS name="DMPL" cdbase="http://www.openmath.org/cd" cd="polyd"/><OMA><OMS name="poly_ring_d" cdbase="http://www.openmath.org/cd" cd="polyd"/><OMS name="Q" cdbase="http://www.openmath.org/cd" cd="fieldname1"/><OMI>5</OMI></OMA><OMA><OMS name="SDMP" cdbase="http://www.openmath.org/cd" cd="polyd"/><OMA><OMS name="term" cdbase="http://www.openmath.org/cd" cd="polyd"/><OMI>1</OMI><OMI>0</OMI><OMI>1</OMI><OMI>0</OMI><OMI>0</OMI><OMI>0</OMI></OMA><OMA><OMS name="term" cdbase="http://www.openmath.org/cd" cd="polyd"/><OMI>-5</OMI><OMI>0</OMI><OMI>0</OMI><OMI>0</OMI><OMI>0</OMI><OMI>0</OMI></OMA></OMA><OMA><OMS name="SDMP" cdbase="http://www.openmath.org/cd" cd="polyd"/><OMA><OMS name="term" cdbase="http://www.openmath.org/cd" cd="polyd"/><OMI>1</OMI><OMI>1</OMI><OMI>0</OMI><OMI>0</OMI><OMI>0</OMI><OMI>0</OMI></OMA><OMA><OMS name="term" cdbase="http://www.openmath.org/cd" cd="polyd"/><OMI>-1</OMI><OMI>0</OMI><OMI>0</OMI><OMI>0</OMI><OMI>0</OMI><OMI>0</OMI></OMA></OMA></OMA></OMA></OMA>
Index: dyn_modules/openmath/pseudocode.py
===================================================================
--- dyn_modules/openmath/pseudocode.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/pseudocode.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,19 @@
+content = OMCD("arith1")
+content.add("bla", "blupp", "blipper")
+OMCD.implement
+implementation = OMCDImplementation(content)
+
+implementation.groebner=singular.groebner
+#does the default mapping, forgets about attributes
+
+@keep_attributions
+def attr_play(a,b):
+    attribs=attributes(a)
+    #...
+
+implementation.attr=attr_play
+
+
+def evaluate(object, attributes):
+    pass
+
Index: dyn_modules/openmath/pseudocode_notes.txt
===================================================================
--- dyn_modules/openmath/pseudocode_notes.txt	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/pseudocode_notes.txt	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,2 @@
+symbols in a CD shouldn't be member variables, but  be listed in global array belonging to every CD with same name
+there should also be the possibility of dynamic CDs
Index: dyn_modules/openmath/refbsp
===================================================================
--- dyn_modules/openmath/refbsp	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/refbsp	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,15 @@
+<OMA>
+	<OMBIND>
+		<OMS name="lambda" cd="fns1" cdbase="http://www.openmath.org/cd"></OMS>
+		<OMV name="x"/>
+		<OMV name="y"/>
+		<OMA>
+			<OMS name="plus" cdbase="http://www.openmath.org/cd" cd="arith1"></OMS>
+			<OMV name="x"></OMV>
+			<OMV name="y"></OMV>
+			<OMI>1</OMI>
+		</OMA>
+	</OMBIND>
+	<OMI id="banal">3</OMI>
+	<OMR xref="banal"></OMR>
+</OMA>
Index: dyn_modules/openmath/scopebsp
===================================================================
--- dyn_modules/openmath/scopebsp	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/scopebsp	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,27 @@
+<OMA>
+	<OMS name="tuple" cd="test"></OMS>
+	<OMA>
+		<OMBIND id="lala">
+			<OMS name="lambda" cd="fns1" cdbase="http://www.openmath.org/cd"></OMS>
+			<OMA>
+				<OMS name="plus" cdbase="http://www.openmath.org/cd" cd="arith1"></OMS>
+				<OMV name="x"></OMV>
+				<OMI>1</OMI>
+			</OMA>
+		</OMBIND>
+	</OMA>
+	<OMA>
+		<OMBIND>
+			<OMS name="lambda" cd="fns1" cdbase="http://www.openmath.org/cd"></OMS>
+			<OMV name="x"/>
+			<OMA>
+				<OMR xref="lala"/>
+			</OMA>
+		</OMBIND>
+		<OMI>1</OMI>
+	</OMA>
+	<OMI>3</OMI>
+	<OMA>
+		<OMR xref="lala"/>
+	</OMA>
+</OMA>
Index: dyn_modules/openmath/singularserver.sing
===================================================================
--- dyn_modules/openmath/singularserver.sing	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/singularserver.sing	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,41 @@
+ring r=0,(x,y,z,a,b),lp;
+poly f=37x3y+x2yz;
+ideal i=x*(x-1),y;
+LIB "primdec.lib";
+//LIB "poly.lib";
+ideal p1=x2,y;
+ideal p2=(x-1),(y-5)^2;
+ideal p3=(x)^2;
+ideal big=intersect(intersect(p1,p2),p3);
+ideal i2=cyclic(5);
+
+print(i2);
+LIB("/Users/michael/sing2/modules/python/python_module.so");
+Python_module::python("from interpreter import SingularGlobalsProxy
+#import psyco
+import sys
+sys.argv=['Singular']
+#import sre_compile
+#psyco.bind(sre_compile._optimize_charset)
+#psyco.log()
+#psyco.profile()
+from cas.singular import *
+from context import *
+context=Context()
+from lxmlencoder import encode as xml
+
+import cd.polyd as polyd
+import cd.fieldname1 as fieldname1
+import cas.singular
+import cd.list1
+import cd.arith1
+import cd.primdec
+context.addCDImplementation(cd.list1.implementation)
+context.addCDImplementation(cd.primdec.implementation)
+context.addCDImplementation(polyd.implementation)
+context.addCDImplementation(fieldname1.implementation)
+context.addCDImplementation(cd.arith1.implementation)
+import server
+server.run_OM_server(context)
+");
+$
Index: dyn_modules/openmath/singulartest.sing
===================================================================
--- dyn_modules/openmath/singulartest.sing	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/singulartest.sing	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,115 @@
+ring r=0,(x,y,z,a,b),lp;
+poly f=37x3y+x2yz;
+ideal i=x*(x-1),y;
+LIB "primdec.lib";
+//LIB "poly.lib";
+ideal p1=x2,y;
+ideal p2=(x-1),(y-5)^2;
+ideal p3=(x)^2;
+ideal big=intersect(intersect(p1,p2),p3);
+ideal i2=cyclic(5);
+
+print(i2);
+LIB("/Users/michael/sing2/modules/python/python_module.so");
+Python_module::python("from interpreter import SingularGlobalsProxy
+#import psyco
+import sys
+sys.argv=['Singular']
+#import sre_compile
+#psyco.bind(sre_compile._optimize_charset)
+#psyco.log()
+#psyco.profile()
+from cas.singular import *
+from context import *
+context=Context()
+from lxmlencoder import encode as xml
+
+import cd.polyd as polyd
+import cd.fieldname1 as fieldname1
+import cas.singular
+import cd.list1
+import cd.primdec
+context.addCDImplementation(cd.list1.implementation)
+context.addCDImplementation(cd.primdec.implementation)
+context.addCDImplementation(polyd.implementation)
+context.addCDImplementation(fieldname1.implementation)
+from cd.polyd import groebnersym
+r=singular.r
+inter=SingularGlobalsProxy()
+
+
+
+easy=ideal2OM(singular.i)
+call=OMA(cd.primdec.implementation.minAss, [easy])
+print call
+print context.evaluate(call)
+r.set()
+
+
+easy=ideal2OM(singular.i)
+call=OMA(cd.primdec.implementation.primdecGTZ, [easy])
+print call
+print context.evaluate(call)
+r.set()
+
+
+easy=ideal2OM(singular.i)
+call=OMA(cd.primdec.implementation.minAssGTZ, [ideal2OM(singular.big)])
+print call
+#print encode(call)
+print context.evaluate(call)
+print
+print
+out=open('blupper','w')
+xml(context.evaluate(call)).write(out)
+out.close()
+print 'ARG'
+r.set()
+
+easy=ideal2OM(singular.i)
+call=OMA(cd.primdec.implementation.primdecGTZ, [ideal2OM(singular.big)])
+print call
+#print lxmlencoder.encode(call).tostring
+xml(context.evaluate(call)).write(open('primdec.in', 'w'))
+print context.evaluate(call)
+r.set()
+cyc5=ideal2OM(singular.i2)
+ord=ordering2OM(singular.r)
+gcall=OMA(groebnersym,[ord,cyc5])
+
+
+print gcall
+
+def myblock(i):
+    out=open('blipper'+str(i),'w')
+    xml(context.evaluate(gcall)).write(out)
+    out.close()
+    r.set()
+
+for i in range(20):
+    myblock(i)
+#from timeit import Timer
+
+#print 'Timing:', t.timeit(1)
+#gcout=open('cyc3om','w')
+#gcout.write(context.XMLEncodeObject(gcall))
+#gcout.close()
+
+#print 'now calculating GB'
+#omin=context.XMLEncodeObject(gcall)
+#from omxmlreader import *
+def inout(context, infn):
+  doc=readFile(infn)
+  builder=OMFromXMLBuilder()
+  doc=builder.build(doc)
+  doc=context.evaluate(doc)
+  output=context.XMLEncodeObject(doc)
+  gcout=open('cyc3om.out','w')
+  gcout.write(output)
+  gcout.close()
+
+#inout(context,'cyc3om')
+
+
+");
+$
Index: dyn_modules/openmath/strbsp
===================================================================
--- dyn_modules/openmath/strbsp	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/strbsp	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,1 @@
+<OMSTR>foo</OMSTR>
Index: dyn_modules/openmath/symbolbsp
===================================================================
--- dyn_modules/openmath/symbolbsp	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/symbolbsp	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,1 @@
+<OMS name="plus"  cd="arith1"></OMS>
Index: dyn_modules/openmath/test_read.py
===================================================================
--- dyn_modules/openmath/test_read.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/test_read.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,15 @@
+import lxmlencoder
+import lxmldecoder
+import lxml.etree as et
+import sys
+from cd.arith1 import implementation as arith1
+from context import Context
+
+tree=et.parse("bindingbsp")
+inp= lxmldecoder.decode(tree)
+h=lxmlencoder.encode(inp)
+print h.__class__
+h.write(open("hallo", "w"))
+c=Context()
+c.addCDImplementation(arith1)
+lxmlencoder.encode(c.evaluate(inp)).write(open("hallo.eval", "w"))
Index: dyn_modules/openmath/tester.py
===================================================================
--- dyn_modules/openmath/tester.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/tester.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,38 @@
+from context import Context
+from objects import *
+context = Context()
+
+#context.push({})
+print OMV("x")
+print OMA(OMV("x"),[OMV("y"),1])
+
+
+#from binding import OMBinding, lambdasym
+
+
+context["x"] = 1
+
+x = OMV("x")
+
+y = OMV("y")
+
+print context.evaluate(x)
+print context.evaluateVariable(x)
+print context.evaluate(y)
+import cd.arith1 as arith1
+context.addCDImplementation(arith1.implementation)
+def test(expr):
+    print "Original: ", expr
+    print "Evaluated: ", context.evaluate(expr)
+test(OMA(arith1.implementation.plus, [1,2]))
+test(OMA(arith1.implementation.unary_minus, [10]))
+test(OMA(arith1.implementation.times, [3,4]))
+test(OMA(arith1.implementation.abs, [-123]))
+print context.evaluate(OMA(arith1.implementation.plus, [1,2]))
+application = OMA(OMS("plus", arith1.content), [1,2])
+
+print context.evaluate(application)
+firstArg=OMBIND(lambdasym,[OMV("x"), OMV("y")], OMV("x"))
+#print context.evaluate(firstArg)
+test(OMA(firstArg, [37,777777]))
+
Index: dyn_modules/openmath/tests/basic1.py
===================================================================
--- dyn_modules/openmath/tests/basic1.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/tests/basic1.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,31 @@
+import unittest
+from objects import *
+from context import Context
+
+from cd.arith1 import implementation as arith1
+
+class OMTestCase1(unittest.TestCase):
+            def assertResult(self,expression, result):
+                self.assertEqual(context.evaluate(expression),result)
+            def testAddition(self):
+                expr=OMA(arith1.plus,[2,3])
+                self.assertEqual(len(expr.args),2)
+                self.assertResult(expr,5)
+            def testMultiplication(self):
+                expr=OMA(arith1.times,[4,3])
+                self.assertResult(expr,12)
+            def testPower(self):
+                expr=OMA(arith1.power,[2,3])
+                self.assertResult(expr,8)
+            def testAbs(self):
+                expr=OMA(arith1.abs,[-349])
+                self.assertResult(expr,349)
+            #def testSub(self):
+            #    expr=OMA(arith1.minus,[2,3])
+            #    self.assertResult(expr,-1)
+                
+                
+if __name__=='__main__':
+    context=Context()
+    context.addCDImplementation(arith1)
+    unittest.main()
Index: dyn_modules/openmath/tests/xmlcoding.py
===================================================================
--- dyn_modules/openmath/tests/xmlcoding.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/tests/xmlcoding.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,25 @@
+import unittest
+from objects import *
+from context import Context
+import lxmlencoder
+import lxmldecoder
+
+from cd.arith1 import implementation as arith1
+
+class OMTestCase1(unittest.TestCase):
+    def assertEncodeDecodeOK(self, expr):
+        orig=repr(expr)
+        new=repr(lxmldecoder.decode(lxmlencoder.encode(expr)))
+        self.assertEqual(new,orig)
+    def testOMI(self):
+        self.assertEncodeDecodeOK(1)
+        self.assertEncodeDecodeOK(1233593883529)
+    def testOMA(self):
+        self.assertEncodeDecodeOK(OMA(arith1.plus,[OMA(arith1.plus,[1,2]),3]))
+        
+                
+                
+if __name__=='__main__':
+    context=Context()
+    context.addCDImplementation(arith1)
+    unittest.main()
Index: dyn_modules/openmath/xmlencodetest.py
===================================================================
--- dyn_modules/openmath/xmlencodetest.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
+++ dyn_modules/openmath/xmlencodetest.py	(revision 3c473cd1025f9dec9b7bf4cbe33d713158cac80f)
@@ -0,0 +1,28 @@
+from objects import *
+from context import *
+import CD.arith1 as arith1
+context=Context()
+context.push({})
+i=OMint(22482489)
+#print i.body
+print i.XMLEncode(context)
+print context.XMLEncodeObject(i)
+v=OMVar("x")
+print v.XMLEncode(context)
+x=v
+y=OMVar("y")
+a=OMApply(OMSymbol("plus",arith1.content),[x,y,i])
+print a.XMLEncode(context)
+print context.XMLEncodeObject(context.evaluate(a))
+a1=OMApply(OMSymbol("plus",arith1.content),[OMint(1),OMint(2)])
+a2=OMApply(OMSymbol("plus",arith1.content),[a1,OMint(2)])
+a3=OMApply(OMSymbol("plus",arith1.content),[a2,x])
+context.addCDImplementation(arith1.implementation)
+print "a3", context.XMLEncodeObject(context.evaluate(a3))
+print "a2", context.XMLEncodeObject(context.evaluate(a2))
+print "a1", context.XMLEncodeObject(context.evaluate(a1))
+
+f=OMfloat(1.23434)
+print context.XMLEncodeObject(f)
+#print v.XMLAttributes
+
