inducer / pymbolic

A simple package to do symbolic math (focus on code gen and DSLs)

Home Page:http://mathema.tician.de/software/pymbolic

Repository from Github https://github.cominducer/pymbolicRepository from Github https://github.cominducer/pymbolic

Pymbolic to SymEngine conversion error when using FloorDiv.

Ravindu-Hirimuthugoda opened this issue · comments

There was an error encountered while attempting to convert a Pymbolic floor division expression to a SymEngine expression.

import pymbolic.interop.symengine as mapper
import pymbolic.primitives as pr

a = pr.FloorDiv(pr.Sum((pr.Variable('x'),63)),64)
map = mapper.PymbolicToSymEngineMapper()
res = map(a)
print("res: ",res)
print(type(res))

Error:

return self.rec(expr.numerator) // self.rec(expr.denominator)
TypeError: unsupported operand type(s) for //: 'Add' and 'Integer'

I'd say this is a symengine issue. Are you sure that Symengine supports floordiv? @isuruf might know this off the top of his head.

Yes floordiv can be used in Symengine.

By adding following code in the pymbolic/interop/common.py under PymbolicToSympyLikeMapper class might be a fix.

def map_floor_div(self, expr):
        return self.sym.floor(self.rec(expr.numerator) / self.rec(expr.denominator))

I'd be happy to look at a PR. Make sure to include a test.

Sure. I'll do

symengine/symengine.py#441 should fix the // operator for symengine