Quiz. Weakest precondition for assert and assume [004r]
- December 12, 2025
Quiz. Weakest precondition for assert and assume [004r]
- December 12, 2025
Answer the following:
- What's \(\texttt {wp}(\texttt {assert}(P), Q)\)
- What's \(\texttt {wp}(\texttt {assume}(P), Q)\)
- Given a statement \(s\), can we transform it into a statement \(s'\) such that: \[ \vDash \{P\}\ s\ \{Q\} \iff \{\top \}\ s'\ \{\top \} \]
Solution.
- December 12, 2025
Solution.
- December 12, 2025
We can remember that the weakest precondition is simply what we can derive reasoning backwards from the formulaic expression of a hoare triple.
-
Considering our wp formula we have
\[
\texttt {wp}(\texttt {assert}(b), Q)(\sigma ) \to (\texttt {assert}(b), \sigma ) \Downarrow \texttt {.ok}\ \sigma \to Q(\sigma )
\]
reasoning backwards we can start with a case split on the evaluation of the assertion, this leads to two cases
- \(b\) evaluates to true, as this case trivially implies that the assertion evaluates into \(\texttt {.ok}\ \sigma \) it means we must prove \(Q(\sigma )\). The only way we can prove this is by having our weakest precondition be a witness to this assertion.
- \(b\) evaluates to false, as this would imply a contradiction since the assertion evaluates to \(\texttt {.ok}\ \sigma \), more specifically we know have to prove the contradiction that \(\texttt {.ok}\ \sigma = \texttt {.fail} \sigma \), we know (i.e. have a hypothesis) by inversion that \(b \Downarrow ^f \sigma \) since we know \(b\) has to be true to prove the contradiction we also must ensure the weakest precondition states that \(b \Downarrow ^t \sigma \)
- We can just use the more intuitive reasoning here, we know the weakest precondition characterizes a set of states where terminating executions end in a state satisfying \(Q\). The only way for something being assumed to be true leading to some other else is it if implies something else, thus our \(\texttt {wp}\) becomes \[ \texttt {wp}(\texttt {assume}(b), Q)(\sigma ) \equiv (b \Downarrow ^t \sigma ) \to Q(\sigma ) \] in terms of backward reasoning the idea is that \(\texttt {assume}(p)\) essentially just adds a raw hypothesis \((b \Downarrow ^t \sigma )\) but clearly that by itself doesn't somehow allow me to just manifest \(Q(\sigma )\), the only way we could possibly get \(Q\) from \(b\) being true is if we have a function which states that \(b\) being true implies \(Q\).