Skip to content

Commit 76d5bf6

Browse files
committed
Fix the issue using __radd__
1 parent 255c612 commit 76d5bf6

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pindakaas.solver
22

33
from .encoding import CNF, WCNF, ClauseDatabase, Constraint
4-
from .pindakaas import Formula, Lit, Encoder, BoolLinExp
4+
from .pindakaas import Formula, Lit, Encoder
55

66
__doc__ = pindakaas.__doc__
77
__all__ = ["Constraint", "ClauseDatabase", "CNF", "Encoder", "Formula", "Lit", "WCNF"]

crates/pyndakaas/python/tests/test_modelling.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
def test_bool_lin():
55
f = pindakaas.CNF()
66
x, y, z = f.new_vars(3)
7+
assert str(x + 2) == "x₁ + 2"
8+
assert str(2 + x) == "x₁ + 2"
79
c = x + y - z + 2
810
assert str(c) == "-x₃ + x₂ + x₁ + 2"
9-
c = sum([x, y, z], pindakaas.BoolLinExp())
11+
c = sum([x, y, z])
1012
assert str(c) == "x₃ + x₂ + x₁"
11-
c = sum([y, y, z], x)
12-
assert str(c) == "x₃ + x₂ + x₂ + x₁"
1313
c *= 2
14-
assert str(c) == "2*x₃ + 2*x₂ + 2*x₂ + 2*x₁"
14+
assert str(c) == "2*x₃ + 2*x₂ + 2*x₁"
1515
c = x + y + z
1616
d = c == 2
1717
assert str(d) == "x₃ + x₂ + x₁ == 2"

crates/pyndakaas/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,10 @@ mod pindakaas {
412412
self.as_bool_lin_exp().__add__(other)
413413
}
414414

415+
fn __radd__(&self, other: i64) -> BoolLinExp {
416+
self.as_bool_lin_exp().__add__(BoolLinArg::Int(other))
417+
}
418+
415419
fn __and__(&self, other: FormulaArg) -> Formula {
416420
Formula(self.as_formula()).__and__(other)
417421
}

0 commit comments

Comments
 (0)