%mathpiper,def="FindIsq"

LocalSymbols(max,f,low,high,mid,current)
[
FindIsq(max,f)  :=
[
  Local(low,high,mid,current);
  low:=1;
  high:=max+1;
  Bind(mid,((high+low)>>1));
  While(high>low And mid>1)
  [
    Bind(mid,((high+low)>>1));
    Bind(current,Apply(f,{mid}));
//Echo({low,high,current});
    If(current = 0,
       high:=low-1,
       If(current > 0,
          Bind(high,mid),
          Bind(low,mid+1)
          )
       );
  ];
  mid;
];
];
UnFence("FindIsq",2);

%/mathpiper