Commits

Pierre Carbonnelle committed c1ca887

support for exponentials

  • Participants
  • Parent commits f5eab75

Comments (0)

Files changed (3)

File pyDatalog/examples/test.py

         assert ask((X==1) & (Y==2) & (X+2==Y+1)) == set([(1,2)])
         assert ask((X==2) & (Y==X/2)) == set([(2,1)])
         assert ask((X==2) & (Y==X//2)) == set([(2,1)])
+        assert ask((X==2) & (Y==X**2)) == set([(2,4)])
         
         assert ask((X==1) & (Y==1+X)) == set([(1,2)])
         assert ask((X==1) & (Y==1-X)) == set([(1,0)])
         assert ask((X==1) & (Y==2*X)) == set([(1,2)])
         assert ask((X==2) & (Y==2/X)) == set([(2,1)])
         assert ask((X==2) & (Y==2//X)) == set([(2,1)])
+        assert ask((X==2) & (Y==3**X)) == set([(2,9)])
         
         assert ask((Y==5) & (X==format_('5 is {}', Y))) == set([(5, '5 is 5')])
         assert ask(X==format_('5 is {} {}', 5, 'test'))  == set([('5 is 5 test',)])

File pyDatalog/pyEngine.py

                 return Interned.of(lhs.id / rhs.id)
             elif self.operator == '//':
                 return Interned.of(lhs.id // rhs.id)
+            elif self.operator == '**':
+                return Interned.of(lhs.id ** rhs.id)
             elif self.operator == '%':
                 return Interned.of(lhs.id.format(*(rhs.id)))
             elif isinstance(self.operator, type(lambda: None)):

File pyDatalog/pyParser.py

         return Operation(self, '/', other)
     def __floordiv__(self, other):
         return Operation(self, '//', other)
+    def __pow__(self, other):
+        return Operation(self, '**', other)
     
     # called by constant + Symbol (or lambda + symbol)
     def __radd__(self, other):
         return Operation(self, '/', other)
     def __rfloordiv__(self, other):
         return Operation(other, '//', self)
+    def __rpow__(self, other):
+        return Operation(other, '**', self)
 
     def __getitem__(self, keys):
         """ called when evaluating expression[keys] """