0
$\begingroup$

Precondition: true
int i = 0;
while (i < a.length && a[i] != x) {
i++;
}
Postcondition: (∀ j : 0 ≤ j < i : a[j] ≠ x) ⋀ (i = a.length ∨ a[i] = x) }

As I read it, the program has no precondition to be established, thus the precondition is always true? Is it like an indicator: "This program has no precondition"?

asked May 18, 2022 at 21:42
$\endgroup$
1
  • 2
    $\begingroup$ You have answered your question correctly. $\endgroup$ Commented May 18, 2022 at 22:47

1 Answer 1

2
$\begingroup$

The program does have a precondition: true. Which means that it is fulfilled, regardless the state variables.

The annotation would still be correct with a stronger precondition, such as a.length > 0. truecannot be weakened, so it is the weakest precondition.

answered May 19, 2022 at 12:10
$\endgroup$
4
  • $\begingroup$ But true & a.length > 0 would only be true if a.length > 0. If a.length > 0 is the precondition it wouldn't make sense to use true as precondition too? $\endgroup$ Commented May 19, 2022 at 12:41
  • $\begingroup$ @Rubus: true is a valid precondition and so is a.length > 0. Besides this, I have no idea what you are trying to say. $\endgroup$ Commented May 19, 2022 at 13:32
  • 1
    $\begingroup$ I understand it now. I though you meant true AND a.length > 0 need to be true which would render true useless since the truth value of the statement would then only depend on a.length > 0. I'm sorry I find this topic confusing... $\endgroup$ Commented May 19, 2022 at 13:32
  • $\begingroup$ @Rubus: I never wrote true AND a.length > 0 (nor with && nor $\land$). $\endgroup$ Commented May 19, 2022 at 13:34

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.