From 5fdad527e2099450024f88d110e49d2ab304ba77 Mon Sep 17 00:00:00 2001 From: odow Date: Fri, 4 Nov 2022 11:00:12 +1300 Subject: [PATCH] Change MutableArithmetics.rewrite to move_factors_into_sums=false --- Project.toml | 2 +- docs/src/manual/expressions.md | 2 +- src/complement.jl | 2 +- src/macros.jl | 14 +++++++------- test/test_macros.jl | 2 +- test/test_print.jl | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Project.toml b/Project.toml index 35f79aab36f..07ec053d810 100644 --- a/Project.toml +++ b/Project.toml @@ -14,7 +14,7 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" [compat] MathOptInterface = "1.14" -MutableArithmetics = "1" +MutableArithmetics = "1.1" OrderedCollections = "1" SnoopPrecompile = "1" julia = "1.6" diff --git a/docs/src/manual/expressions.md b/docs/src/manual/expressions.md index 3afff752ee2..56023a8c084 100644 --- a/docs/src/manual/expressions.md +++ b/docs/src/manual/expressions.md @@ -195,7 +195,7 @@ julia> @variable(model, y) y julia> ex = @expression(model, x^2 + 2 * x * y + y^2 + x + y - 1) -x² + 2 y*x + y² + x + y - 1 +x² + 2 x*y + y² + x + y - 1 ``` ### Operator overloading diff --git a/src/complement.jl b/src/complement.jl index 0f8c782c8c3..67e352c40fb 100644 --- a/src/complement.jl +++ b/src/complement.jl @@ -70,6 +70,6 @@ function parse_constraint_call( F, x, ) - f, parse_code = _MA.rewrite(F) + f, parse_code = _MA.rewrite(F; move_factors_into_sums = false) return parse_code, :(_build_complements_constraint($errorf, $f, $(esc(x)))) end diff --git a/src/macros.jl b/src/macros.jl index f682beb7f56..46e443c8f32 100644 --- a/src/macros.jl +++ b/src/macros.jl @@ -500,9 +500,9 @@ function parse_constraint_head( "`$ub >= ... >= $lb`.", ) end - new_aff, parse_aff = _MA.rewrite(aff) - new_lb, parse_lb = _MA.rewrite(lb) - new_ub, parse_ub = _MA.rewrite(ub) + new_aff, parse_aff = _MA.rewrite(aff; move_factors_into_sums = false) + new_lb, parse_lb = _MA.rewrite(lb; move_factors_into_sums = false) + new_ub, parse_ub = _MA.rewrite(ub; move_factors_into_sums = false) parse_code = quote $parse_aff $parse_lb @@ -583,7 +583,7 @@ function parse_constraint_call( func, set, ) - f, parse_code = _MA.rewrite(func) + f, parse_code = _MA.rewrite(func; move_factors_into_sums = false) build_call = if vectorized :(build_constraint.($_error, _desparsify($f), Ref($(esc(set))))) else @@ -617,7 +617,7 @@ function parse_constraint_call( rhs, ) func = vectorized ? :($lhs .- $rhs) : :($lhs - $rhs) - f, parse_code = _MA.rewrite(func) + f, parse_code = _MA.rewrite(func; move_factors_into_sums = false) set = operator_to_set(_error, operator) # `_functionize` deals with the pathological case where the `lhs` is a # `VariableRef` and the `rhs` is a summation with no terms. @@ -1496,7 +1496,7 @@ macro objective(model, args...) end sense, x = args sense_expr = _moi_sense(_error, sense) - newaff, parsecode = _MA.rewrite(x) + newaff, parsecode = _MA.rewrite(x; move_factors_into_sums = false) code = quote $parsecode # Don't leak a `_MA.Zero` if the objective expression is an empty @@ -1585,7 +1585,7 @@ macro expression(args...) "different name for the index.", ) end - code = _MA.rewrite_and_return(x) + code = _MA.rewrite_and_return(x; move_factors_into_sums = false) code = quote # Don't leak a `_MA.Zero` if the expression is an empty summation, or # other structure that returns `_MA.Zero()`. diff --git a/test/test_macros.jl b/test/test_macros.jl index 991736357d4..61e9d3dc2d3 100644 --- a/test/test_macros.jl +++ b/test/test_macros.jl @@ -603,7 +603,7 @@ end function test_Error_on_unexpected_comparison() m = Model() @variable(m, x) - @test_macro_throws ErrorException @expression(m, x <= 1) + @test_throws ErrorException @expression(m, x <= 1) return end diff --git a/test/test_print.jl b/test/test_print.jl index 46e162d6b10..d5ca78222b7 100644 --- a/test/test_print.jl +++ b/test/test_print.jl @@ -180,7 +180,7 @@ function test_printing_expressions() "x_{1}\\times y_{2,2} + x_{2}\\times y_{2,2} + z$ijulia_sq + 3 x_{1} + 3 x_{2} - 1", ) - ex = @expression(mod, -z * x[1] - x[1] * z + x[1] * x[2] + 0 * z^2) + ex = @expression(mod, -z * x[1] - z * x[1] + x[1] * x[2] + 0 * z^2) io_test(MIME("text/plain"), ex, "-2 z*x[1] + x[1]*x[2]") io_test(MIME("text/latex"), ex, "-2 z\\times x_{1} + x_{1}\\times x_{2}")