libminizinc icon indicating copy to clipboard operation
libminizinc copied to clipboard

Unintuitive result of arg_max with generator call expression

Open anonymous192837 opened this issue 1 year ago • 2 comments

Consider:

array[1..9] of int: arr = [10, 20, 30, 40, 50, 60, 70, 80, 90];

Then arg_max(arr) equals 9, which makes sense.

However, arg_max(i in 6..8)(arr[i]) equals 3, which is unintuitive to me. The expected result is 8. Technically, 3 is correct, because the specification states this is equivalent to arg_max([arr[i] | i in 6..8]), without an index set.

Is it possible to copy the index set in this case, so that it is equivalent to arg_max(array1d(6..8, [arr[i] | i in 6..8])) instead?

anonymous192837 avatar Feb 26 '23 11:02 anonymous192837

If you use an array slice, then the index set will be preserved

arg_max(arr[6..8])

zayenz avatar Feb 26 '23 11:02 zayenz

Thanks, that works.

Still, I would like to propose arg_max(i in 6..8)(arr[i]) to also be 8, or perhaps to give a warning.

anonymous192837 avatar Feb 26 '23 12:02 anonymous192837