<jupyter_start><jupyter_text>Assignment 1 Target date: Thursday 9/9/21 11:59pm (+5 points) Due date: Sunday 9/12/21 11:59pm **Instructions:**  Complete your answers to the questions below by double-clicking on each box and writing your answers. Use "Shift-Return" to store your new in each answer box. Feel free to add additional notebook cells as you develop your answers. To submit, download the notebook (as .ipynb), change the file name to your team name, then upload the file to Canvas on the Assignment page. That's it!**NOTE:** You only need to upload one notebook for your group, but ***each*** group member should complete the peer evaluation. All peer evaluation feedback will remain anonymous.--- **Question 1** In GEB Chapter 1, Hofstadter presents **MIU** strings and rules to operate on them. For a given **MIU** string *miu_str*, write a logical statement for each **MIU** rule that evaluates to *True* if the **MIU** rule can be applied to the string and to *False* otherwise. If the logical statement evaluates to *True*, print that the **MIU** rule can be applied and its result; if *False* print that the **MIU** rule cannot be applied. The cells below have been started for you. Replace the ellipses '...' with your code that implements each solution. To verify each rule, change the contents of *miu_str* to test various **MIU** strings. Your solution should be generalized so that it works correctly for any **MIU** string assigned to *miu_str* without changing the rest of your code.**Concepts:** variable assignment, variable equality, string indexing, string search, substring extraction, printing, printing using variables*Ponderable:* can you find a example **MIU** string derived from **MI** for each rule where the rule cannot be applied?<jupyter_code>miu_str = "MI"

# check Rule I: If you posses a string whose last letter is 'I', you can add on a 'U' at the end.
if (...): 
  new_miu_str = ... 
  print(f"Rule I can be applied to '{miu_str}' to make '{new_miu_str}'")
else:
  print(f"Rule I cannot be applied to '{miu_str}'")


miu_str = "MIU"

# check Rule II: Suppose you have 'Mx'. Then you may add 'Mxx' to your collection.
if (...):
  new_miu_str = ...
  print(f"Rule II can be applied to '{miu_str}' to make '{new_miu_str}'")
else:
  print(f"Rule II cannot be applied to '{miu_str}'")
miu_str = "MIIIIU"

# check Rule III: If 'III' occurs in one of the strings in your collection, you may make a new string with 'U' in place of 'III'.
if (...): 
  new_miu_str = ...
  print(f"Rule III can be applied to '{miu_str}' to make '{new_miu_str}'")
else:
  print(f"Rule III cannot be applied to '{miu_str}'")
miu_str = "MUUUIII"

# check Rule IV: If 'UU' occurs inside one of your stirngs, you can drop it.
if (...):
  new_miu_str = ...
  print(f"Rule IV can be applied to '{miu_str}' to make '{new_miu_str}'")
else:
  print(f"Rule IV cannot be applied to '{miu_str}'")<jupyter_output><empty_output><jupyter_text>**Question 2**In GEB Chapter 2, Hofstadter presents the pq-system. For a given hyphen string *x*, and a candidate theorem string *t_maybe*, construct a loop that uses the pq-system rule of inference to determine if *t_maybe* is a theorem that can be derived from the axiom using *x*. Print a congratulatory success message if *t_maybe* can be derived using *x*, and a consolatory failure message if not.The cell below have been started for you. Replace the ellipses '...' with your code that implements the solution. To verify your solution, uncomment each test and re-run the cell to verify you receive the success or failure message.  Your solution should be generalized so that it works correctly for each test case without changing the rest of your code.**Concepts:** string length, string concatination, while loop, nested logic, iteration variables, variable value updates, loop termination condition, test cases, code comments<jupyter_code>x, t_maybe = '--', '--p-q---'       # test 1 - success
#x, t_maybe = '-', '-p----q-----'  # test 2 - success
#x, t_maybe = '--', '-p--q---'     # test 3 - failure
#x, t_maybe = '---', '---p--q----' # test 4 - failure
#x, t_maybe = '--', '--p--q-----'  # test 5 - failure

# hint: use the 'y' and 'z' to build the axiom and construct theorems
y = ...  # for axiom
z = ...  # for axiom
t = ...  # construct axiom string

# hint: no need to derive theorems longer than the candidate theorem t_maybe
while ... :
  if ... :
    print(f"huzzah! '{t_maybe}' can be derived from '{x}'")
    break
  # hint: update y and z using the rule of inference and construct a new theorem
  y = ...
  z = ...
  t = ...
else:
  print(f"womp womp. '{t_maybe}' cannot be derived from '{x}'")<jupyter_output><empty_output><jupyter_text>**Question 3**In GEB Chapter 3, Hofstadter presents the tq-system. Encode a decision procedure the tq-system that checks whether a given candidate theorem string *t_maybe* is a valid theorem of the tq-system. Print a congratulatory success message if *t_maybe* is a valid tq-system theorem, and a consolatory failure message if not.The cell below have been started for you. Replace the ellipses '...' with your code that implements the solution. To verify your solution, uncomment each test and re-run the cell to verify you receive the success or failure message.  Your solution should be generalized so that it works correctly for each test case without changing the rest of your code.**Concepts:** string parsing, string length, test cases, code comments<jupyter_code>t_maybe = '--t-q--'             # test 1 - valid
#t_maybe = '---t--q------'      # test 2 - valid
#t_maybe = '-t-----q---'        # test 3 - invalid
#t_maybe = '---t---q----------' # test 4 - invalid
#t_maybe = '--t----q--------'   # test 5 - valid

# hint: use the tq-system isomorphism to validate t_maybe
x = ...
y = ...
z = ...
if ... : 
  print(f"joy! '{t_maybe}' is a valid tq-system theorem!")
else:
  print(f"sadness. '{t_maybe}' is not a valid tq-system theorem.")<jupyter_output><empty_output><jupyter_text>**Question 4**In GEB Chapter 2, Hofstadter presented a variant of Euclid's proof that there are infinitely many prime numbers (a number divisible only by 1 and itself). Write two loops, one that for a given *n* computes *n!* and one that checks whether the resulting *n! + 1* is prime. If *n! + 1* is prime, print a message stating so. If it is not prime, print the divisors found as you find them. The cell below have been started for you. Replace the ellipses '...' with your code that implements the solution. To verify your solution, uncomment each test and re-run the cell to verify you receive the success or failure message.  Your solution should be generalized so that it works correctly for each test case without changing the rest of your code.**Concepts:** for loop, range() function, iteration variable, variable accumulation, modulo*Ponderable:* what is the next value of *n* that results in a prime number? how could you change your solution to find it?<jupyter_code>n = 2  # test  1 - prime
#n = 3  # test  2 - prime
#n = 4  # test  3 - not prime
#n = 5  # test  4 - not prime
#n = 6  # test  5 - not prime

# hint: use range() to compute n_bang (n!)
n_bang = ...
for i in range(...):
  n_bang = ...

# hint: use range() to help perform Euclid's proof
for i in range(...):
  if ... :
    print(f"{i} is a divisor of {n_bang+1}")
    break
else:
  print(f"wow! {n_bang+1} is prime!")<jupyter_output><empty_output><jupyter_text>**Question 5**In GEB Chapter 5, Hofstadter describes the Fibonacci and Lucas sequences. Let us define a *Wettlaufer* sequence as having the short genotype (1,11). Thus, the phenotype of this sequence would be: 1, 11, 12, 23, .... Write a loop that can produce the *nth* element of our Wettlaufer sequence phenotype (defined as *w*) for a given value of *n*. In the cells below, demonstrate that your general solution can successfully produce the 10th, 50th, and 100th element of the Wettlaufer sequence.The cell below have been started for you. Replace the ellipses '...' with your code that implements the solution. To verify your solution, uncomment each test and re-run the cell to verify you receive the correct Wettlaufer number.  Your solution should be generalized so that it works correctly for each test case without changing the rest of your code.**Concepts:** if-else statement, for loop, range() function, iteration variable, variable accumulation, temporary variables, left-hand value, right-hand value, variable evaluation order in assignment*Ponderable:* how many digits does the 1000th Wettlaufer number have? the 10000th? the millionth? how could you change your solution to find them?<jupyter_code>n = 5     # w = 35
#n = 8    # w = 151
#n = 10   # w = 395
#n = 50   # w = 90373689515
#n = 100  # w = 2543454806524813605335 
#n = 1000 # w = ???

if n == 1:
  w = 1
elif n == 2:
  w = 11
else:
  # hint: use accumulation variables to track the last two Wettlaufer numbers
  w_p = 1  # previous Wettlaufer number
  w   = 11 # current Wettlaufer number
  for i in range(...):
    # hint: use Python variable unpacking to avoid using a temp variable
    w, w_p = ...

print(f"For n = {n}, w = {w}")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10878569871375626, 'fraction_numerical': 0.015478526269893177, 'mean_word_length': 3.7123780174627634, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '136622', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 2873, 'n_tokens_neox': 2703, 'n_words': 1336, 'path': '2021-Fall/assignment1/assignment1_TeamName.ipynb', 'repo_name': 'pnav/planiilogic', 'size': '9174'}