potassco / potassco/constraint-handler

Minus operator not working as intended? Engine interaction?

Open
#105 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
3
Forks
0
Avg merge
1d 19h
Merged PRs (30d)
20

Description

While looking for outdated python syntax, I found example3.lp.

However, after fixing the syntax, the example still didn't run for me.

There seem to be multiple issues at play with the line:

variable_define(assign_z, z, operation(minus,(variable(y),
                                        (variable(f), ())))).

Minus is not a Binary Operator

My first thought was "wait, why does minus have two arguments? Shouldn't it just negate the input?". But, when looking for minus we find the expected UnaryOperator and another OtherOperator for it.

I don't know what this OtherOperator is, but I found that it apparently returns "the first argument minus the sum of all other arguments".

Trying to use simpler input variables:

variable_define(assign_f, f, val(float,float("1.0"))).
variable_define(assign_y, y, val(float,float("2.0"))).

results in no value for the variable z appearing in the output.

Switching to the ground engine reveals an issue:

warning((operation(minus,(variable(y),(variable(f),()))),((y,val(float,float("2.0"))),((f,val(float,float("1.0"))),())),"NotImplementedError('binary operator minus')"))

So we do have minus as OtherOperator but it is not used for this operation. Instead, it is expected as a BinaryOperator, which it isn't.

Next step, remove the second argument, so the full test now looks like:

variable_define(assign_y, y, val(float,float("2.0"))).
variable_define(assign_z, z, operation(minus,(variable(y),()))).
requestEngine(assign_z,ground).

This now works, which brings me to the second issue I've found.

Engine Interaction

In the original example file, some declarations use a specific engine. This also holds true for assign_y and assign_z, that use ground and compile, respectively.

Introducing this to the above example

variable_define(assign_y, y, val(float,float("2.0"))).
variable_define(assign_z, z, operation(minus,(variable(y),()))).
requestEngine(assign_y,ground).
requestEngine(assign_z,compile).

again, yields no output for z.

I've found that requesting different engines yields different results. More specifically, all combinations of ground and compile engines for assign_y and assign_z yield the correct result, except for the one outlined above, which is the one used in the example.

This is also no longer related to the minus operator at all.

The following will not show a value for x:

variable_define(assign_y, y, val(int,2)).
variable_define(assign_x, x, variable(y)).
requestEngine(assign_y, ground).

Summary

  • example3.lp still contains outdated syntax for the 'python' operator
  • in example3.lp minus is used with two arguments, but is not defined as a binary operator. Instead, it appears as "other" operator
  • it appears that declarations that use the compile engine may not depend on variables created using the ground engine

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with tests/example/example3.lp and reproduce the shown ground and compile engine combinations, including the minus examples. Then trace how the ground and compile engines resolve variable dependencies and how minus operators are classified. Done means the example uses current syntax, minus behaves consistently, and declarations depending on ground-engine variables produce their expected values.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.