Answers to Assignments

9/11 9/25 10/4 10/25 10/30 11/13


A - 1 (Sept 11, 2002)

1. Lab 1.2
1.a. The URL for lab 8.3 is:
http://www.brookscole.com/compsci_d/templates/student_resources/0534953654_decke
rhirchfield/aeonline/course/8/3/index.html

This URL can be found in the status bar at the bottom of the browser when you mouse over the anchor; You can also right click the anchor, select "property", and find the URL in the property window.

1b. There are 5 labs for module 7.

1c. The title of Lab 9.4 is "Decisions, decisions..."

3. Creating Unix folders and setting permissions (A typescript example)

(1) unixs1 $ mkdir is2000
(2) unixs1 $ cd is2000
(3) unixs1 $ mkdir public
(4) unixs1 $ fs la public

Access list for public is
Normal rights:
system:anyuser rl
username rlidwka

(5) unixs1 $ mkdir private
(6) unixs1 $ fs la private

Access list for private is

Normal rights:
system:anyuser rl
username rlidwka

(7) unixs1 $ fs setacl private system:anyuser none
(8) unixs1 $ fs la private

Access list for private is
Normal rights:
username rlidwka

(9) unixs1 $ exit
exit


A - 3 (Oct 4, 2002)

3(a) Informally explain the following equivalences:

~ Ex P(x) = Ax ~P(x)

If there does not exist some x such that P(x) is true, then for all x P(x) is false.

~ Ax P(x) = Ex ~P(x)

If it isn't the case that P is true for all x, then it must be that some x exists for which it P(x) is false.

3(b) Prove the following with a truth table: ~(PvQ)=(~P&~Q)
_________________________________
P | Q | ~P |~Q | PvQ | ~(PvQ) | ~P&~Q
-----------------------------------------------
T | T |   F  |  F  |   T  |     F     |    F
T | F |   F  |  T  |   T  |     F     |    F
F | T |   T  |  F  |   T  |     F     |    F
F | F |   T  |  T  |   F  |     T     |    T
-----------------------------------------------

3(c) Express each of the following using predicate logic.

All turtles are slow.
Ax T(x) -> S(x), where T = turtle and S = slow

Mary likes all slow things.
Ax S(x) -> L(Mary,x), where S = slow and L = like

3(d) Informally show how the preceeding two expressions can be used to derive a new statement.

Mary likes all turtles.


A - 5 (Oct 25, 2002)

Lab 5.4.2

a. b. Write a statement that will present an alert box announcing “ZERO!!!” if the value of text element “Number 1” is zero, and will present an alert box announcing “NOT ZERO!!!” if it isn’t.

if (document.myForm.tf1.value == "0" )
{
      alert("ZERO!!!");
}
else
      alert("NOT ZERO");

c. Write a statement that will display the string “Number 1 is bigger” inthe text element Result if the value of element Number 1 is greater than the value of element Number 2; otherwise it should display the message “Number 2 is bigger" in element Result.

if (document.myForm.tf1.value > document.myForm.tf2.value )
{
      document.myForm.tfr.value = "Number 1 is bigger";
}
else
      document.myForm.tfr.value = "Number 2 is bigger";

d. Write a statement that displays the message "Both Positive!" in the Result text element if the values of elements Number 1 and Number 2 are both greater than zero.

if (document.myForm.tf1.value > 0 && document.myForm.tf2.value > 0)
      document.myForm.tfr.value = "Both Positive";
else
      document.myForm.tfr.value = " ";

e. Write JavaScript statements that display the sum of the integers 1-1000 in the Result text element.

var result = 0;
for (i=0; i<= 1000; i++){
      result = result + i;}
document.myForm.tfr.value = result;

f. Write JavaScript statements that display the average of the integers 1-1000 in the Result text element.

var result = 0;
for (var i=1; i<= 1000; i++)
      result = result + i;
result = result / 1000;
document.myForm.tfr.value = result;

g. Write the JavaScript statements needed to present a prompt box and two buttons, one for “Number 1” and one for “Number 2”. If the user clicks onbutton “Number 1”, the value of text element “Number 1” should be copied in the Result element. If the user clicks on button “Number 2”, the value of text element “Number 2” should be copied into Result.

Add two new buttons each with ONCLICK="num(1);" and ONCLICK="num(2);"

Javascript code:

alert("Which number into Result?");
function num(i)
{
   if (i == 1)
      document.myForm.tfr.value = document.myForm.tf1.value;
   else
      document.myForm.tfr.value = document.myForm.tf2.value;
}

Lab 5.5.2

a.Write a statement that displays in text area "tf" the name of the current background color.
document.myForm.tf.value = document.bgColor;

b.Write a statement that displays in text area "tf" the status (check or not checked) of the checkbox.
if (document.myform.cb1.checked == true)
      document.myform.tf.value = "checked";
else
      document.myform.tf.value = "not checked";

c.Write a statement that displays in text area "tf" the number of elements on the page.
document.myform.tf.value = document.myform.elements.length;

d.Write a statement that displays in text area "tf" the number of options in the select element.
document.myform.tf.value = document.myform.s1.length;

e.Write a statement that displays in text area "tf" the currently selected item in the select element.
document.myform.tf.value = document.myform.s1.value;

f.Write a statement that displays in text area "tf" the name of the third element in the only form on this page.
document.myform.tf.value = document.myform.elements[2].name;


A - 6 (Oct 30, 2002)

6.1 - 3

a. At what address is the MUL X instruction stored? How is that address represented in binary?
It is stored at location 4. Binary representation : 0000 0100

b. What is the binary operation code that corresponds to the symbolic instruction LOD?
Opcode for LOD : 0001 0100

c. How is the number 2 represented in binary?
0000 0010

d. At what address is variable Y stored, and how is that address represented in binary?
Y is stored at location 130, represented as 1000 0010

e. Answer question d, this time for variable X.
X is stored at location 129, represented as 1000 0001

f. Answer question d, this time for variable W.
W is stored at location 128, represented as 1000 0000

g. What are the binary operation codes corresponding to the symbolic PIPPIN instructions ADD? MUL? STO?
ADD: 0000 0000 MUL: 0000 0010 STO: 0000 0101

6.2 - 9

A: Y = X - 3 * Z
B: Y = ( X - 3 ) + Z
C: Y = X - ( 3 *( Z / 2 ))

6.4-8 Calculate average of 3 numbers stored in X,Y and Z and store result in W.

LOD X
ADD Y
ADD Z
DIV #3
STO W
HLT


A - 7 (Nov 13, 2002)

TM3

1. General statement of what TM3 does:
Addition. Takes two strings of 1s that are separated by a !.

2. Rules (numbers in the left column below are present states):
1 Change first 1 to b, go to state 2
2 Replace ! with 1 and halt
3 Move right past the 1s

3. Algorithm:
TM3 changes the first 1 to a b, then keeps moving right past all 1s until it finds the !. It changes the ! to 1 and halts. By doing this it adds up the two numbers.

------------------------------

TM4

1. General statement of what TM4 does:
Subtraction. Takes two strings of 1s that are separated by !.

2. Rules (numbers in the left column below are present states):
1 Consume the first 1. Move right
1 If !, go to state 6
2 Keep moving past 1s
2 If !, go to state 3
3 Keep moving past !s
3 If 1, change to !. goto state 4
3 If b (end) go to state 5
4 Move left past 1s
4 Move left past !s
4 If b go to state 1
5 Change ! to b. Move left
5 Move left past all 1s
5 If b, halt
6 If b, halt
6 Change 1s into b's
6 Change !s into b's

3. Algorithm:
TM4 changes the first 1 to b and move right until it finds the first 1 after !. It changes the 1 to !, then moves back until it finds b. On finding b it repeats the above process. It keeps repeating the process until all 1s in the first string are replaced by b's , if the first string is longer. The remainder is the result.

----------------------------------

TM5

1. General statement of what TM5 does:
Returns True for odd number of 1s and False otherwise.

2. Rules
1 If 1, go to state 2
1 If b, change it to F and halt
2 If 1, back to state 1
2 If b, change it to T and halt

3. Algorithm:
TM4 goes between state 1 and state 2, skipping 1s. If it finds b in state 1, it changes that b to F and stops. If it finds b in state 2, it changes it to T and stops. Which means if there are odd number of 1s, the string will end with T. Otherwise it ends with an F.

----------------------------

TM6

1. General statement of what TM6 does:
It checks if the input string is a palindrome (P is for palindrome)

2. Rules

3. Algorithm:
TM6 takes a string that ends with b. It starts from the left, changing the first symbol to b, then check the rightmost symbol before the ending b. If it is the same, change it to b. Then it goes left and repeats the process. It keeps moving rightward and leftward over the string inside b's, comparing the rightmost symbol to the leftmost one. On finding the first right symbol different from the left one after b, it writes N and halts. Otherwise on finding the last b it writes P.

-----------------------

Grading criteria: For each TM, we give 0.5 point for clearly and briefly stating what it does (e.g. addition, subtraction, etc), 1 point for the rules, and 1 point for giving a correct description of the algorithm.


[Home Page] [Course Schedule] [Weekly Assignments] [Answers to Homeworks] [Answers to Quizzes]
[Class Notes] [Class Member Posts] [Dr. Metzler & Hong's posts] [Class List]
[Web Resources] [Term Project Description] [Analytical Engine Page]