Arrays has helper methods that make simple operations quicker:
Arrays.equals(a, b) to compare arrays
Arrays.copyOf(arr, l) that returns a new copied array of length l
Sorting useing Arrays.sort(arr)
toString() and deepToString()
Back
ETH::1._Semester::EProg::4._Sequences
Arrays has helper methods that make simple operations quicker:
Arrays.equals(a, b) to compare arrays
Arrays.copyOf(arr, l) that returns a new copied array of length l
Sorting useing Arrays.sort(arr)
toString() and deepToString()
Field-by-field Comparison
Field
Before
After
Text
Arrays has helper methods that make simple operations quicker:<br><ul><li>{{c1:: <b>Arrays.equals(a, b)</b> to compare arrays}}<br></li><li>{{c2:: <b>Arrays.copyOf(arr, l)</b> that returns a new copied array of length l}}</li><li>{{c3:: Sorting useing <b>Arrays.sort(arr)</b>}}</li><li>{{c4:: <b>toString()</b> and <b>deepToString()</b>}}</li></ul>
i <= n (the equality holds as we execute + 1 after the final execution)
In general: a x < n becomes x <= n and x <= n becomes x <= n + 1!
Field-by-field Comparison
Field
Before
After
Front
while (i < n) {<br> result = result * k;<br> i = i + 1;<br>}<br><br>For the loop invariant, what bounds hold for i?
Back
<div><code>i <= n</code> (the equality holds as we execute <code>+ 1</code> after the final execution)<br><br><div>In general: a x < n becomes x <= n and x <= n becomes x <= n + 1!</div></div>
\(P \land \lnot a \implies Q\) when S2; is executed.
Dann kann man mit einem || beide Fälle in der Precondition verbinden: a && precondition1 OR !a && precondition2
Field-by-field Comparison
Field
Before
After
Front
<pre><code>// {P}
if (a) {
S1;
} else {
S2;
}
// {Q}
</code>
</pre>How to find the precondition?
Back
Muss man zwei Fälle checken:<br><ul><li>\(P \land a \implies Q\) when S1; is executed.</li><li>\(P \land \lnot a \implies Q\) when S2; is executed. </li></ul>Dann kann man mit einem <b>||</b> beide Fälle in der Precondition verbinden: <code>a && precondition1</code> OR <code>!a && precondition2</code>
If P_1impliesP_2 then we can say that P_1 is a stronger precondition than P_2.
Back
ETH::1._Semester::EProg::5._Logisches_Schliessen
If P_1impliesP_2 then we can say that P_1 is a stronger precondition than P_2.
Field-by-field Comparison
Field
Before
After
Text
<div>If <code>P_1</code> {{c1::implies}} <code>P_2</code> then we can say that <code>P_1</code> is {{c2::a stronger precondition}} than <code>P_2</code>.</div>