ArgMin does not evaluate when asked to minimize using a function that contains Take (and in some other cases where small spans are being taken from a larger array. I enclose a Notebook that demonstrates this apparent paradox (it is a possible Bug?) Consider this example (we will use 'testarray' later but it is used here to make the example easy to compare):
testarray = {1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1} (* some test data *)
Let us start with something that is 'obvious'
f1[x_, tstarr_] := Abs[x - 6] (* easy to find the minimum here! *)
ArgMin[{f1[x, testarray], x \[Element] Integers}, x]`
Also:
f1[x_] := Abs[x - 6] (* easy to find the minimum here! *)
ArgMin[{f1[x], x \[Element] Integers}, x]`
Obviously both of these evaluate to '6'. So far this is as expected. So now let us try this new function (and a test that I have added to it):
f2[x_, tstarr_] :=
If[
x > 0 \[And] x < 11,
Total[Take[tstarr, {x, x + 2}]],
999
];
f2[6, testarray]
(The test response is '1' as expected) Now let's find the value of x that gives the minimum of f2[] ...
ArgMin[{f2[x, testarray], x \[Element] Integers}, x]
Unexpectedly you get "ArgMin[{If[x > 0 && x < 11, Total[Take[{1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1}, {x, x + 2}]], 999], x [Element] Integers}, x]" It does not evaluate
Just to prove that the function can be minimised we can use brute force:
Map[{f2[#, testarray], #} &, Range[1, 11]]
To which we get a sensible answer (and the minimum is 5).
Is this a bug or am I doing something wrong?
Attachments: