Using your Knowledge of Mathematics and Logic, Inspect the Pre-Conditions and Block - IT/Computer Science Assignment Help

Download Solution Order New Solution
Assignment Task:

Task:

1 Induction 1. Prove ∀x ∈ Z + x 2 ≥ x using induction. You may want to use the fact (x + 1)2 = x 2 + 2x + 1. The base case is worth 1 mark (1 mark) and the inductive case is worth 1 mark. (1 mark) Yes, there are other ways to do this, but here we specifically ask that you use induction.

2 Program correctness Consider the following block of Python code: y = x ** 2 y = y + 1 1. This block of code will be run in a place where it is known that x is an integer and is at least

3. Write pre-conditions for this block of code, using notation similar to that used in the lectures. (1 mark)

2. Using your knowledge of mathematics and logic, inspect the pre-conditions and block of code and determine five post-conditions that will hold for this block of code. These post-conditions should encode: 

• what kind of object is x, and any information on its size (two post-conditions)

• what kind of object is y, and any information on its size (two post-conditions)

• what is the relationship between x and y (one post-condition) (1 mark)

3. Write two assertions that describe the changes to y, one after each line of code in the block. Include the lines of code in your solution to show the proper order of the code and assertions. (1 mark)

4. Using your solutions to the previous three questions, give a complete proof of correctness for the block of code. Other than the pre-conditions, mention the rule that is being used for each assertion. If the assertion is a pre- or post-condition, then also indicate this. (1 mark) 3 Relations, functions, recursion

1. Given some relation R ⊆ S × S, the transitive closure of R is the smallest relation Q such that R ⊆ Q and Q is transitive. Here smallest means that if there is any other relation P that is transitive and contains R, then Q ⊆ P. The transitive closure can be found mechanically by iteratively finding elements a, b, c such that aRb, bRc, ¬aRc, and adding (a, c) to the relation. This must be continued until there are no such a, b, c. Your task for this question: Find the transitive closure of R ⊆ S × S given by S = {1, 2, 3, 4, 5} R = {(1, 2),(1, 3),(2, 4),(3, 4),(4, 5)} (1 mark)

2. Suppose a set S and an equivalence relation R ⊆ S × S on S are given. Let us use the notation E(x) for the equivalence class of a set x ∈ S. Recall that E(x) is given by: E(x) := {y ∈ S : xRy} The set of all equivalence classes is then given by: {E(x) : x ∈ S} Your task for this question: Write a Python function that takes a set S and a relation R as arguments and returns a set containing all the equivalence classes of R. Your function should start with the line def equivClasses(S, R): Do not use any loops in your function.

Use only set comprehensions and set operations.

Note: for technical reasons Python won’t let you have normal sets inside a set. I.e. you can’t do Page 3 equivClasses = { {1} } # Gives error TypeError: unhashable type: ’set’ you need to use immutable (unchangeable) sets, like: equivClasses = { frozenset({1}) } Here the function frozenset() takes a set and returns an immutable copy. The following gives an example of the function working correctly which you may use for your development purposes. You do not need to show this in your solution. Remember that your function should work for any S and R, not just this one example. >>> S = {1,2,3} >>> R = { (1,2), (2,1), (3,3), (1,1), (2,2) } >>> equivClasses(S,R) {frozenset({3}), frozenset({1, 2})} (1 mark)

3. Let the function f : R → R be given by: f(x) = 3x + 7 5 Give the inverse of f, or explain why it doesn’t have an inverse. (1 mark)

4. Explain why the following Python function is not a function in the mathematical sense: def myAddition(x,y): print(’Doing some adding’) return x + y (1 mark)

5. Let’s explore some number theory. The greatest common divisor of x, y ∈ Z +, written gcd(x, y), is the largest number z such that z|x and z|y. A useful fact for computing GCD’s is that if x > y then gcd(x, y) = gcd(y, x mod y) Also note that if y|x then gcd(x, y) = y. We can use this to give a recursive definition for GCD when x ≥ y: gcd(x, y) = ( y if y|x gcd(y, x mod y) otherwise Your task for this question: Write a recursive Python function that computes gcd(x, y). You may assume that x ≥ y. (1 mark) Page 4

6. One set of axioms that is used to define the positive integers Z≥0 is the Peano Axioms. These axioms don’t define addition directly, but instead define the successor function S(x), which gives the next number after x. For example, S(1) = 2, S(2) = 3. In fact, in this formulation, 1 is defined to be S(0) and 2 is defined to be S(S(0)) and so on. Addition can then be defined by the following recursive definition: a + 0 = a a + S(b) = S(a + b) Your task for this question: Use the definition of above to find S(S(0)) + S(S(0)). Show all your steps. (1 mark) 4 Graphs

1. Consider the following graph: A C B E D This graph is a tree since it is connected and has no cycles. Recall that we can specify a root, which will allow us to define parents, children, descendants, ancestors and leaves. Suppose that we specify the root of the above tree to be E. What are the leaves of the tree?(1 mark)

2. A different way of representing a graph is as an adjacency list. Given a graph G = (V, E) the adjacency list for the graph is {(u, NG(u)) : u ∈ V } This representation is often used when defining data structures for graphs, and has the advantage that it is faster to find neighbours of a given vertex, especially if there are many vertices and the degree of vertices is relatively small (so-called sparse graphs). What is the adjacency list for the graph in question 1? (1 mark)

3. Graphs can be defined from mathematical structures, and such graphs can often be very interesting and useful. Cayley graphs are graphs that are defined on a set based on a mathematical operation, such as addition. The graph of Rubick’s cube configurations discussed in the lecture is one such graph. Page 5 Draw the graph on vertices V = {0, 1, 2, 3, 4} with edges set {(u, v) : (uv mod 5) ∈ {2, 3}} (1 mark)

4. Find a bipartition of the graph from the previous question. That is, find sets A, B such that A∩B = ∅, A ∪ B = {0, 1, 2, 3, 4} and there are no edges within A or within B. (1 mark)

5. Consider the graph in question

1. What is the order that the depth-first-traversal algorithm will process the vertices if it starts from vertex E? Assume that, within a neighbourhood, the vertices are processed in alphabetical order. (1 mark)

6. Recall the following facts about graphs:

• The distance classes Dj from a vertex u are found using a recursive algorithm

• The neighbourhood of a set NG(S) is the set of vertices that are adjacent to at least one vertex in S

• A graph is bipartite if and only if for an arbitrary u, the Dj ’s have no edges within them. I.e. ∀j ∈ Z≥0 NG(Dj ) ∩ Dj = ∅, in which case we say NG(Dj ) and Dj are disjoint. Additionally, here are some useful hints about Python:

• The Lecture 9 slides contain Python functions for calculating NG(S) and the Dj ’s

• In Python you can test if two sets A, B are disjoint using A.isdisjoint(B)

• In Python you can get an arbitrary element from a set A using u = A.pop(). Note that this removes the element from A, but you can put it back with A.push(u) if you need to.

• The Tutorial 5 solutions contain a Python function for evaluating ∀ type propositions. Note this works for Python lists as well as sets. The following construction may be useful: f = forall(S, lambda x : x.isdisjoint(N(V, E, x)))

The above  IT Assignment has been solved by our  IT Assignment  Experts at onlineassignmentbank. Our Assignment Writing Experts are efficient to provide a fresh solution to this question. We are serving more than 10000+ Students in Australia, UK & US by helping them to score HD in their academics. Our experts are well trained to follow all marking rubrics & referencing style.

Be it a used or new solution, the quality of the work submitted by our assignment experts remains unhampered. You may continue to expect the same or even better quality with the used and new assignment solution files respectively. There’s one thing to be noticed that you could choose one between the two and acquire an HD either way. You could choose a new assignment solution file to get yourself an exclusive, plagiarism (with free Turnitin file), expert quality assignment or order an old solution file that was considered worthy of the highest distinction.

Get It Done! Today

Country
Applicable Time Zone is AEST [Sydney, NSW] (GMT+11)
+

Every Assignment. Every Solution. Instantly. Deadline Ahead? Grab Your Sample Now.