Skip to content

Commit

Permalink
AffineExpr: set constraint operator precedence
Browse files Browse the repository at this point in the history
  • Loading branch information
gruhn committed Apr 28, 2024
1 parent 1313196 commit 5d4e86d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Theory/LinearArithmatic/Constraint.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,20 @@ instance Num AffineExpr where
negate (AffineExpr constant coeffs) =
AffineExpr (negate constant) (M.map negate coeffs)

-- Same precedence as the usual comparison operators (==, <=, ...).
-- Otherwise arithmatic expressions have to be bracketed,
-- e.g. like this: `(x + y) .<= 3`.
infix 4 .==
infix 4 .<=
infix 4 .>=
infix 4 .>
infix 4 .<

-- | Construct `Equals` constraint.
(.==) :: AffineExpr -> AffineExpr -> Constraint
(.==) lhs_expr rhs_expr = (lhs_expr - rhs_expr, Equals)


-- | Construct `LessEquals` constraint.
(.<=) :: AffineExpr -> AffineExpr -> Constraint
(.<=) lhs_expr rhs_expr = (lhs_expr - rhs_expr, LessEquals)
Expand Down

0 comments on commit 5d4e86d

Please sign in to comment.