/* Max should accept two integers and returns the larger one. For the specification, the method should ensure that the result is greater or equal to both inputs, and that it is equal to one of them. */ method Max(m : nat, n : nat) returns (result : nat) { result := 0; } /* LCM should accept two naturals and require the Least Common Multiple of the two numbers. For the specification, the method should ensure that the result is greater or equal to the larger of the two inputs and it must in fact be the *smallest/least* Common Multiple: Hints: 1. The GCD method from lecture is a helpful reference. 2. You may need to sprinkle assert(m*n % n == 0) (replace with other variables/expressions as appropriate) in the code base to help Dafny limit its search space. */ method LCM(m : nat, n : nat) returns (result : nat) { result := 0; } /* IT'S BACK. In CS321, you were asked to write a function that determines if a number is negative. A sample implementation is shown below. Complete the function isNegHelper and isNeg so that the ensure statement shown, which Dafny can't prove at the moment, is proven. - decreases * is there to ignore termination checking. While, similar to agda, a proof on a program is only correct insofar as it's underlying program terminates, this assignment assumes that it is known a priori that the function terminates - You may need to add additional argument(s) to isNegHelper that helps you establish certain invariants. However, these additional argument(s) should not be factored in the actual computation. In other words, the algorithm should remain faithful to its original implementation. */ method isNegHelper(countingUp : int, countingDown : int) returns (result : bool) decreases * { if (countingDown == 0) { result := false; } else { if (countingUp == 0) { result := true; } else { var induct := isNegHelper(countingUp + 1, countingDown - 1); result := induct; } } } method isNeg(number : int) returns (result : bool) decreases * ensures number < 0 <==> result == true { result := isNegHelper(number, number); } /* Complete isNegLoop, a while loop based implementation of the same function(s) as above. After you finish the function above, think about how the pre and post conditions of the isNegHelper helper could inform the invariants you place in the while loop. */ method isNegLoop(number : int) returns (result : bool) decreases * ensures number < 0 <==> result == true { var countingDown := number; var countingUp := number; while (countingDown != 0 && countingUp != 0) decreases *; { countingDown := countingDown - 1; countingUp := countingUp + 1; } if (countingDown == 0) { result := false; } else { result := true; } }