Take the following C++14 code snippet:
unsigned int f(unsigned int a, unsigned int b){
if(a>b)return a;
return b;
}
Statement: the function f
returns the maximum of its arguments.
Now, the statement is "obviously" true, yet I failed to prove it rigorously with respect to the ISO/IEC 14882:2014(E) specification.
First: I cannot state the property in a formal way.
A formalized version could be: For every statement s, when the abstract machine (which is defined in the spec.) is in state P and s looks like "f(expr_a,expr_b)" and 'f' in s is resolved to the function in question, s(P).return=max(expr_a(P).return, expr_b(P).return).
Here for a state P and expression s, s(P) is the state of the machine after evaluation of s.
Question: What would be a correctly formalized version of the statement? How to prove the statement using the properties imposed by the above mentioned specification? For each deductive step please reference the applicable snippet from the standard allowing said step (the number of the segment is enough).
Edit: Maybe formalized in Coq
f
returns maximum of its arguments when they are not equal and second argument when they are equal". – Jaquith+0
and-0
values ofint
such that+0
and-0
. may compare equal. All modern computers just use two’s-complement signed numbers, but some early CPUs supported one’s-complement or sign-and-magnitude arithmetic where that makes sense. IEEE floating-point explicitly has+0.0
and-0.0
. – Minimalistx
isn’t even necessarily the supremum. For the set S = {∑ⁿᵢ₌₀ 2ⁱ| n ∈ ℕ} = {1,1.5,1.75,1.875,...} and x = 17, we have ∀ y ∈ S . x ≥ y, but y is definitely not the supremum. (This works for finite sets too, but is clearer with infinite sets because only then do people usually talk about suprema) – Cavern(a>b) ? a : b
) to write your proof elegantly. – Minimalist