Question

1. Explain the function/purpose of the following sequence of program statements by expressing the postcondition and...

1. Explain the function/purpose of the following sequence of program statements by expressing the postcondition and then prove that the program is correct using the axiomatic verification method.

Precondition: {x = A and y = B}

t=x x=y y=t

Postcondition:________________

2. Prove that the following grammar is ambiguous.

    <stmt>    -> <assign> | <if-stmt>
    <assign>  -> <id> := <expr>
    <if-stmt> -> if <bool> then <stmt> |
                 if <bool> then <stmt> else <stmt>

Modify the grammar above to make it unambiguous:

3. In this question, you are required to develop two programs using the functional programming paradigm.

3.1 Write a functional program (e.g., Racket program) that integrates two sorted lists into a single sorted list. For instance, if the inputs to your function are the following two sorted lists, (3,6,8,12) and (1,2,7,15), the result should be (1,2,3,6,7,8,12,15). You can use only the following functions: car, cdr, cons, null?, eq? and the recursive use of theintegrate function.

(define (integrate L1 L2)
   (cond

) )

3.2 Write a high-order function multiple in Racket that takes as parameter a function of one argument and returns a function that represents the application of that function to its argument two times.

    (define (multiple .....
        .....

) )

Given the usual definition of the square function, what function is (multiple(multiple square))

4. In this question, you are required to demonstrate your understanding of the logic-based programming paradigm.

4.1 Consider the following append program, append(X, Y, Z) in Prolog, where Z is the result of appending list Y to list X:

    append([],Y,Y).
    append([H|T], L, [H|Result]) :- append(T,L, Result)

Suppose we want to develop a Prolog program to find the last item in a list. That is, last(X,Y)unifies X with the last element in list Y, or last(x,Y) returns true if x is the last item in list Y. How can you write this program in terms of the append program above.

last(X,Y) :-

4.2 Given the following Prolog clauses:

ancestor(X,Y) :- ancestor(Z,Y), parent(X,Z)
ancestor(X,X).
parent(amy,bob)

explain, why Prolog fails to answer given the goal ancestor(X,bob).

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
1. Explain the function/purpose of the following sequence of program statements by expressing the postcondition and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • Pull out question 8 on Exercises. See also: Program 4.16 invert (), Program 4.4 printList () Configuring -main () 1. Create a linked list 2. Function call of 8 (a) and (b) 3. Check the accuracy of th...

    Pull out question 8 on Exercises. See also: Program 4.16 invert (), Program 4.4 printList () Configuring -main () 1. Create a linked list 2. Function call of 8 (a) and (b) 3. Check the accuracy of the output of r list and l list 4. Repeat steps 1-3 above Please use c language void printlist(listPointer first) printf ("The list contains: ) for (; first; first = first→link) printf ("%4d", first-"data); printf("In") Program 4.4: Printing a list the nodes are...

  • Write a python program (recursive.py) that contains a main() function. The main() should test the following...

    Write a python program (recursive.py) that contains a main() function. The main() should test the following functions by calling each one with several different values. Here are the functions: 1) rprint - Recursive Printing: Design a recursive function that accepts an integer argument, n, and prints the numbers 1 up through n. 2) rmult - Recursive Multiplication: Design a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times...

  • Number 1) Which of the following statements imports a module into the default namespace? a. from...

    Number 1) Which of the following statements imports a module into the default namespace? a. from temperature import * b. import temperature as t c. import temperature as temp d. import temperature Number 2) Which of the following statements imports a module into the global namespace? a.from temperature import *   b. import temperature as temp c. import temperature as global d. import temperature Number 3) Code Example 4-2 def get_volume(width, height, length=2):     volume = width * height * length...

  • Need help with program. I'm stuck Objectives: In this assignment, we will practice manipulating lists of...

    Need help with program. I'm stuck Objectives: In this assignment, we will practice manipulating lists of data and arranging items in an ascending/descending order. you will also explore storing lists/arrays using different sorting algorithms including, the selection sort, bubble sort, and insertion sort algorithm. Comparison between the three algorithms are made based on the number of comparisons and item assignments (basic operations) each algorithms executes. Background: Ordering the elements of a list is a problem that occurs in many computer...

  • Consider the following program, written in JavaScript-like syntax: // main program var x, y, z; function...

    Consider the following program, written in JavaScript-like syntax: // main program var x, y, z; function sub1() { var a, y, z; . . . } function sub2() { var a, b, z; . . . } function sub3() { var a, x, w; . . . } Given the following calling sequences and assuming that dynamic scoping is used, what variables are visible during execution of the last subprogram activated? Include with each visible variable the name of the...

  • in c++ Program 1 Write a program that sorts a vector of names alphabetically using the...

    in c++ Program 1 Write a program that sorts a vector of names alphabetically using the selection sort and then searches the vector for a specific name using binary search. To do that, you need to write three functions I. void selSort (vector string &v: sorts the vector using selection sort 2. void display (const vector <string & v): displays the vector contents . int binSearch (const vector <ing& v, string key): searches the vector for a key returns the...

  • 1 Rewrite the following program so that it will use function. include <stdio.h> Int main) printf...

    1 Rewrite the following program so that it will use function. include <stdio.h> Int main) printf ("Hello!") return 0 2 Assume a program has the following declarations: short s- 4 int i--5; long m-3 float f-19.3f; double d-3.6; What are the following values? (a) s+m (b) (float) d (c) d s (e) (int) f 3 What will be the output of the following program: int x = 3 float a 2.76; y-2* x; print f("X-2d, y*ta, z»%d", x, y, z);...

  • (a) Consider the following C++ function: 1 int g(int n) { 2 if (n == 0)...

    (a) Consider the following C++ function: 1 int g(int n) { 2 if (n == 0) return 0; 3 return (n-1 + g(n-1)); 4} (b) Consider the following C++ function: 1 bool Function (const vector <int >& a) { 2 for (int i = 0; i < a. size ()-1; i ++) { 3 for (int j = i +1; j < a. size (); j ++) { 4 if (a[i] == a[j]) return false; 5 6 } 7 return...

  • C++. Difficulty with quickSort function. Code will not run quickSort function. The code I'm having trouble...

    C++. Difficulty with quickSort function. Code will not run quickSort function. The code I'm having trouble with is in bold. -------------------------------------------------------------------------------------------------driverProgram.cpp #include #include #include #include #include "quickSort.cpp" using namespace std; int main() { const int MIN_SIZE = 4; //Array size const int SIZE = 25; int theArray[SIZE] = {11, 22, 33, 44, 55, 66, 77, 88, 99, 12, 13, 14, 15, 16, 17, 18, 19, 18, 19, 20, 21, 22, 23, 24, 25}; cout << "List of 25 items: ";...

  • How to write the insert, search, and remove functions for this hash table program? I'm stuck......

    How to write the insert, search, and remove functions for this hash table program? I'm stuck... This program is written in C++ Hash Tables Hash Table Header File Copy and paste the following code into a header file named HashTable.h Please do not alter this file in any way or you may not receive credit for this lab For this lab, you will implement each of the hash table functions whose prototypes are in HashTable.h. Write these functions in a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT