Skip to content

Commit

Permalink
Fix subtraction precedence (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtth authored Jul 18, 2023
1 parent ede057b commit 7120786
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion opvious/modeling/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def render(self, _precedence=0) -> str:
"mul": (4, 4, 4),
"add": (1, 1, 1),
"mod": (3, 3, 3),
"sub": (1, 2, 2),
"sub": (1, 2, 1),
"div": (0, 0, 5),
"pow": (0, 0, 5),
}
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "opvious"
version = "0.16.5rc1"
version = "0.16.5rc2"
description = "Opvious Python SDK"
authors = ["Opvious Engineering <[email protected]>"]
readme = "README.md"
Expand Down
18 changes: 18 additions & 0 deletions tests/test_modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,3 +559,21 @@ def at_most_five_shifts_per_week(self):
text = spec.sources[0].text
assert r"\sum_{x \in \{ d \ldots d + 6 \}}" in text
assert spec.annotation.issue_count == 0

@pytest.mark.asyncio
async def test_sub_precedence(self):
class _Model(om.Model):
actual = om.Variable.indicator()

def opposite(self):
return 1 - self.actual()

@om.objective
def minimize(self):
return self.actual() - self.opposite()

model = _Model()
spec = await client.annotate_specification(model.specification())
text = spec.sources[0].text
assert r"\alpha - \left(1 - \alpha\right)" in text
assert spec.annotation.issue_count == 0

0 comments on commit 7120786

Please sign in to comment.