Fallbackk faster than constraint handler native version
I maintainer di solito rispondono entro 1 giorno
@AbdallahS ci sta già lavorando.
Dal 11/9/2026.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Problem
Translating round(value, ndigits) becomes very expensive when value is a nonlinear expression over several variables.
There are three cases:
- Native arithmetic expands the round operation and repeats the nonlinear operand.
operation(python("round"), ...)hides only the final call. Its argument is still grounded.statement_python(...)hides the complete expression.
Reproducer
clingo native.lp tests/correctness/boilerplate.lp --stats=2
clingo python_operation.lp tests/correctness/boilerplate.lp --stats=2
clingo fallback.lp tests/correctness/boilerplate.lp --stats=2
Encoding 1: native round expansion
The native version repeats the nonlinear operand inside the round branches.
% Issue 414: native round expansion with the nonlinear operand repeated.
variable_declare("input_a","input_a",fromFacts).
variable_declare(execution_input(calc,"input_a"),execution_input(calc,"input_a"),fromFacts).
variable_domain("input_a",val(float,float("600.0"))).
variable_domain("input_a",val(float,float("602.0"))).
variable_domain("input_a",val(float,float("604.0"))).
variable_domain(execution_input(calc,"input_a"),variable("input_a")).
variable_declare("input_b","input_b",fromFacts).
variable_declare(execution_input(calc,"input_b"),execution_input(calc,"input_b"),fromFacts).
variable_domain("input_b",val(float,float("100.0"))).
variable_domain("input_b",val(float,float("102.0"))).
variable_domain("input_b",val(float,float("104.0"))).
variable_domain(execution_input(calc,"input_b"),variable("input_b")).
variable_declare("input_c","input_c",fromFacts).
variable_declare(execution_input(calc,"input_c"),execution_input(calc,"input_c"),fromFacts).
variable_domain("input_c",val(float,float("120.0"))).
variable_domain("input_c",val(float,float("122.0"))).
variable_domain("input_c",val(float,float("124.0"))).
variable_domain(execution_input(calc,"input_c"),variable("input_c")).
execution_declare(calc,calc,assign("result",RESULT),("input_a",("input_b",("input_c",()))),("result",())) :-
SIDE_B = operation(add,(operation(float_div,(variable("input_a"),(val(int,2),()))),(operation(float_div,(variable("input_b"),(val(int,2),()))),()))),
SIDE_C = operation(add,(operation(float_div,(variable("input_a"),(val(int,2),()))),(operation(float_div,(variable("input_c"),(val(int,2),()))),()))),
SIDE_A = operation(add,(operation(float_div,(variable("input_b"),(val(int,2),()))),(operation(float_div,(variable("input_c"),(val(int,2),()))),(val(int,280),())))),
NUMERATOR = operation(sub,(operation(add,(operation(pow,(SIDE_B,(val(int,2),()))),(operation(pow,(SIDE_C,(val(int,2),()))),()))),(operation(pow,(SIDE_A,(val(int,2),()))),()))),
DENOMINATOR = operation(mult,(val(int,2),(operation(mult,(SIDE_B,(SIDE_C,()))),()))),
ANGLE_PART = operation(acos,(operation(float_div,(NUMERATOR,(DENOMINATOR,()))),())),
ANGLE = operation(sub,(val(float,float("360.0")),(operation(mult,(ANGLE_PART,(operation(float_div,(val(float,float("180.0")),(val(float,float("3.141592653589793")),()))),()))),()))),
SCALE = operation(pow,(val(float,float("10.0")),(val(int,3),()))),
A = ANGLE_PART,
SCALED = operation(mult,(ANGLE,(SCALE,()))),
ROUND_FLOOR = operation(floor,(operation(add,(SCALED,(val(float,float("0.5")),()))),())),
ROUND_CEIL = operation(ceil,(operation(sub,(SCALED,(val(float,float("0.5")),()))),())),
ROUND_CHOICE = operation(ite,(operation(geq,(A,(val(float,float("0.0")),()))),(ROUND_FLOOR,(ROUND_CEIL,())))),
POSITIVE = operation(float_div,(ROUND_CHOICE,(SCALE,()))),
NEGATIVE_INPUT = operation(float_div,(ANGLE,(SCALE,()))),
NEGATIVE_SHIFTED = operation(sub,(NEGATIVE_INPUT,(val(float,float("0.5")),()))),
NEGATIVE = operation(mult,(operation(ceil,(NEGATIVE_SHIFTED,())),(SCALE,()))),
RESULT = operation(ite,(operation(geq,(val(int,3),(val(int,0),()))),(POSITIVE,(NEGATIVE,())))).
execution_run(calc,calc).
Encoding 2: Python operation around the nonlinear operand
The Python operation hides only the final round call; its nonlinear argument is still grounded.
% Issue 414: only the final round call is delegated to Python.
variable_declare("input_a","input_a",fromFacts).
variable_declare(execution_input(calc,"input_a"),execution_input(calc,"input_a"),fromFacts).
variable_domain("input_a",val(float,float("600.0"))).
variable_domain("input_a",val(float,float("602.0"))).
variable_domain("input_a",val(float,float("604.0"))).
variable_domain(execution_input(calc,"input_a"),variable("input_a")).
variable_declare("input_b","input_b",fromFacts).
variable_declare(execution_input(calc,"input_b"),execution_input(calc,"input_b"),fromFacts).
variable_domain("input_b",val(float,float("100.0"))).
variable_domain("input_b",val(float,float("102.0"))).
variable_domain("input_b",val(float,float("104.0"))).
variable_domain(execution_input(calc,"input_b"),variable("input_b")).
variable_declare("input_c","input_c",fromFacts).
variable_declare(execution_input(calc,"input_c"),execution_input(calc,"input_c"),fromFacts).
variable_domain("input_c",val(float,float("120.0"))).
variable_domain("input_c",val(float,float("122.0"))).
variable_domain("input_c",val(float,float("124.0"))).
variable_domain(execution_input(calc,"input_c"),variable("input_c")).
execution_declare(calc,calc,assign("result",RESULT),("input_a",("input_b",("input_c",()))),("result",())) :-
SIDE_B = operation(add,(operation(float_div,(variable("input_a"),(val(int,2),()))),(operation(float_div,(variable("input_b"),(val(int,2),()))),()))),
SIDE_C = operation(add,(operation(float_div,(variable("input_a"),(val(int,2),()))),(operation(float_div,(variable("input_c"),(val(int,2),()))),()))),
SIDE_A = operation(add,(operation(float_div,(variable("input_b"),(val(int,2),()))),(operation(float_div,(variable("input_c"),(val(int,2),()))),(val(int,280),())))),
NUMERATOR = operation(sub,(operation(add,(operation(pow,(SIDE_B,(val(int,2),()))),(operation(pow,(SIDE_C,(val(int,2),()))),()))),(operation(pow,(SIDE_A,(val(int,2),()))),()))),
DENOMINATOR = operation(mult,(val(int,2),(operation(mult,(SIDE_B,(SIDE_C,()))),()))),
ANGLE_PART = operation(acos,(operation(float_div,(NUMERATOR,(DENOMINATOR,()))),())),
ANGLE = operation(sub,(val(float,float("360.0")),(operation(mult,(ANGLE_PART,(operation(float_div,(val(float,float("180.0")),(val(float,float("3.141592653589793")),()))),()))),()))),
RESULT = operation(python("round"),(ANGLE,(val(int,3),()))).
execution_run(calc,calc).
Encoding 3: complete Python fallback
The complete fallback hides the full calculation from grounding.
% Issue 414: evaluate the complete calculation in Python.
variable_declare("input_a","input_a",fromFacts).
variable_declare(execution_input(calc,"input_a"),execution_input(calc,"input_a"),fromFacts).
variable_domain("input_a",val(float,float("600.0"))).
variable_domain("input_a",val(float,float("602.0"))).
variable_domain("input_a",val(float,float("604.0"))).
variable_domain(execution_input(calc,"input_a"),variable("input_a")).
variable_declare("input_b","input_b",fromFacts).
variable_declare(execution_input(calc,"input_b"),execution_input(calc,"input_b"),fromFacts).
variable_domain("input_b",val(float,float("100.0"))).
variable_domain("input_b",val(float,float("102.0"))).
variable_domain("input_b",val(float,float("104.0"))).
variable_domain(execution_input(calc,"input_b"),variable("input_b")).
variable_declare("input_c","input_c",fromFacts).
variable_declare(execution_input(calc,"input_c"),execution_input(calc,"input_c"),fromFacts).
variable_domain("input_c",val(float,float("120.0"))).
variable_domain("input_c",val(float,float("122.0"))).
variable_domain("input_c",val(float,float("124.0"))).
variable_domain(execution_input(calc,"input_c"),variable("input_c")).
execution_declare(
calc,
calc,
statement_python("import math\nside_b = input_a / 2 + input_b / 2\nside_c = input_a / 2 + input_c / 2\nside_a = input_b / 2 + input_c / 2 + 280\nangle = math.acos((side_b**2 + side_c**2 - side_a**2) / (2*side_b*side_c))\nresult = round(360 - math.degrees(angle), 3)"),
("input_a",("input_b",("input_c",()))),
("result",())
).
execution_run(calc,calc).
Result
The corrected encodings all produce the same 27 public result atoms. The measurements below were generated in the constraint-handler Conda environment using the commands above.
| Representation | Ground lines | Rules | Atoms | Solve time |
|---|---|---|---|---|
| Native expansion | 314,562 | 314,586 | 191,125 | 4.833s |
| Python operation | 177,227 | 177,251 | 109,695 | 2.632s |
| Complete fallback | 4,152 | 4,176 | 3,499 | 0.153s |
- Lingua principale
- Python
- Stelle
- 4
- Fork
- 0
- Merge medio
- 2g 9h
- PR unite (30g)
- 19
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di potassco/constraint-handler
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
potassco/constraint-handler#276 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
potassco/constraint-handler#216 · 6 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
constraint-handler 2
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
potassco/constraint-handler#491 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Multiple definitions that agree with each otherForse già presa @AbdallahS l’ha presa 1 giorno fa. Apertaconstraint-handler 2
potassco/constraint-handler#490 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 55/100
potassco/constraint-handler#489 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di potassco/constraint-handler
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
521xueweihan/HelloGitHub#4729 ·
-
auto-reported bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
cliproxy-quota: a tab around a credential email skips own-accounts and paced-accounts matchingApertaneeds-triage type:bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
pollen-robotics/reachy_mini_conversation_app#631 ·
I maintainer di solito rispondono entro 7 giorni
-
stix-atlas.json: the same relationship id is used for several different mitigates relationshipsAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100