To program a function that tests whether all elements in an array are greater than 5, the straightforward way will be:
bool test(std::vector<int> arr){
int number = 0;
for(auto i:arr){ // Iterate over all elements
if(i>5){
number++;
}
}
return arr.size() == number;
}
However, we can also achieve the function in this way:
bool test2(std::vector<int> arr){
for(auto i:arr){ // Iterate over all elements
if(i<=5){
return false;
}
}
return true;
}
Why is test2 functionally equivalent to test? How to interpret them from a mathematical perspective?
test do the things like ∀x ∈ arr, if x > 5, the result is true while test2 do the things like ∃x ∈ arr, if x<=5, the result is false. How do such two propositions mutually exclusive? Or, they are not propositions?

!(∀x ∈ arr, if x > 5, the result is true)is equivalent to∃x ∈ arr, if x<=5, the result is false, if so, which formulation in your mentioned link is used here? – xmh0511 Aug 15 '23 at 14:14for all x in arr, if x >5, the result is trueis equivalent tothere is no x that is less or equal than 5 such that the result is not true. I still didn't understand whytestandtest2can do the same things.test2meansthere is x that is less or equal than 5 such that the result is true, which is not logically equivalent totest. – xmh0511 Aug 16 '23 at 01:20