LMU ☀️ CMSI 585
PROGRAMMING LANGUAGE FOUNDATIONS
HOMEWORK #1 PARTIAL ANSWERS
  1. Answers vary.
  2. Sentences and areas of concern for the four theories of computation. (Complete sentences are required for credit. Correct areas of concern are required for credit.)
    1. Language Theory is concerned with how computations are expressed and deals with syntax, semantics, and pragmatics.
    2. Automata Theory is concerned with how computations are carried out by machine and deals with formal models of computation that we can reason about.
    3. Computability theory is concerned with what can and cannot be computed.
    4. Complexity Theory is concerned with how efficiently (in terms of time and space) certain functions can be computed.
  3. Cube function in several languages. Best to use the exponentiation operator if the language has it; it will generally be ** but will sometimes be ^. Math.pow is or x*x*x are both okay if the language does not have the symbolic operator.
    Notation or
    Language
    Cube Function
    Lambda Calculus$(\lambda x.\,\textrm{power}\;x\;3)$
    $\lambda x.\,\textrm{power}\;x\;3$
    $\lambda x.\,x^3$
    Lisp(LAMBDA (x) (* x x x))
    Pythonlambda x: x ** 3
    JavaScriptx => x ** 3
    Javax -> x * x * x
    Ruby->(x) {x ** 3}
    Clojure#(* % % %)
    Swift{ $0 * $0 * $0 }
    Rust|x| {x * x * x}
    Kotlin{x: Double -> x * x * x}
    Gofunc(x float64)float64 {return x * x * x}
    Haskell\x -> x ^ 3
  4. Logic!
    1. If you don't leave now, you will not win the prize. $u$: you. $p$: the prize. $Lx$: $x$ leaves now. $W\!xy$: $x$ wins $y$.

      $\boxed{\neg Lu \rightarrow \neg W\!up}$

    2. Ani or her sisters might have been late. $a$: Ani. $Sxy$: $x$ and $y$ are sisters. $Lx$: x is late.

      $\boxed{\lozenge \mathbf{P}(La \vee \forall p. (Sap \supset Lp))}$

    3. Some dogs like cats who live in the capital of Turkey. $t$: Turkey. $Cxy$: The capital of $x$ is $y$. $Dx$: $x$ is a dog. $Cx$: $x$ is a cat. $Kxy$: $x$ likes $y$. $Lxy$: $x$ lives in $y$. There are actually two ways to interpret this. It could be read “some dogs like ALL the cats who live in Ankara” or “some dogs like all the cats living in Ankara.”

      $\boxed{\exists d. (Dd \wedge \forall c. (Cc \wedge Lc(\iota c.Ctc)) \supset Kdc)}$

      or

      $\boxed{\exists d. (Dd \wedge \exists c. (Cc \wedge Lc(\iota c.Ctc) \wedge Kdc))}$

    4. The person who won the race prefers orange juice to tea. $r$: the race. $Wxy$: the winner of $x$ is $y$. $o$: orange juice. $t$: tea. $Pxyz$: $x$ prefers $y$ to $z$.

      $\boxed{P(\iota p.Wrp)ot}$

    5. 3 will never be greater be 7.

      $\boxed{\mathbf{G}(\neg (3 > 7))}$

      or

      $\boxed{\neg \mathbf{F}(3 > 7)}$

    6. Not every odd number is greater than its own square. $Ox$: $x$ is odd.

      $\boxed{\neg \forall x.(Ox \supset x > x^2)}$

      or

      $\boxed{\exists x.(Ox \wedge \neg(x > x^2))}$

    7. Something evil caused all evil things except itself. $Ex$: $x$ is evil. $Cxy$: $x$ caused $y$.

      $\boxed{\exists x. (Ex \wedge \forall y. (Ey \wedge \neg(y=x)) \supset Cxy)}$

    8. Some day, it will be possible that all players will have the same score. $Sps$: player $p$ has score $s$.

      $\boxed{\mathbf{F} \lozenge \exists s. (\forall p. Sps)}$

    9. War is peace, freedom is slavery, and ignorance is strength. $w$: war. $p$: peace. $f$: freedom. $s$: slavery. $i$: ignorance. $g$: strength.

      $\boxed{(w = p) \wedge (f = s) \wedge (i = g)}$

    10. All that was once true will someday necessarily be forever false.

      $\boxed{\forall Q.(\mathbf{P}Q \supset \mathbf{F} \square \mathbf{G}(\neg Q))}$

      Tricky! This is a second-order statement, because the statement is being made about predicates and not about individuals. It’s possible, but super clunky, to do it this way: Let $Vx$ mean “verily $x$“ and $Nx$ mean “$x$ is Not so” which gives us: $\forall x.(\mathbf{P}(Vx) \supset \mathbf{F} \square \mathbf{G}(Nx))$.

  5. Yes. $\neg (\mathbf{F}A) \equiv \mathbf{G}(\neg A)$ is true: it expresses the equivalence of “It is not true that A will be true at some point in the future” and “It will always be the case from now on that A is not true.” Furthermore, $\neg (\mathbf{G}A) \equiv \mathbf{F}(\neg A)$ is also true: it expresses the equivalence of “It is not true that A will be now and forever true” and “There will be some time in the future that A will be not true.”

    temporalduals.png

  6. We are given that the system is bivalent, so every formula will have a truth value that is either true or false, exclusively. There are no other possibilities. Now let $G$ be the sentence “I am not provable.” We have two things to prove (consistent implies complete, and complete implies consistent). For each part, we can consider the two subparts of $G$ being true or false.:
    • Assume the system is consistent.
      • Assume $G$ is true.
        $G$ says it is not provable.
        This is a true statement that has no proof.
        So in this case the system is incomplete.
      • Assume $G$ is false.
        Then the opposite of what it says is true, namely $G$ is provable.
        So we have a proof of $G$.
        Because of consistency, we must not have a proof of $\neg G$.
        But $\neg G$ is true. And we have no proof of it. So again, the system is incomplete.
    • Assume the system is complete.
      • Assume $G$ is true.
        $G$ says it is not provable.
        But because we assumed completeness, we cannot have this!
        Therefore $G$ must be false.
      • So $G$ is false.
        Then the opposite of what it says is true, namely $G$ is provable.
        So we have a proof of $G$.
        But we assumed completeness, so we have a proof of every true statement.
        $\neg G$ is true, so we must have a proof of $\neg G$.
        So we have a proof of both $G$ and $\neg G$.
        So the system is inconsistent
    We have proved both parts: If the system is consistent, then it is incomplete. If the system is complete, then it is inconsistent.
  7. What is the Big Deal?

    What this means is that any system of logic powerful enough to make statements about itself has no consistent, complete axiomatization! Once you create a system powerful enough to do self-reference, you cannot have both consistency and completeness.

    You simply cannot prove all the true statements, unless you have an inconsistent system which proves everything.

  8. True or false?
    1. $\varnothing \in \varnothing$ is FALSE since $\varnothing$ has no elements
    2. $\varnothing \in \{ \varnothing \}$ is TRUE just by looking at it
    3. $\varnothing \subseteq \varnothing$ is TRUE because $\varnothing$ is a subset of every set
    4. $\varnothing \subseteq \{ \varnothing \}$ is TRUE because $\varnothing$ is a subset of every set
    5. $\{ x, y \} \subseteq \mathcal{P}(\{ x, y, \{x,y\} \})$ is TRUE
    6. $\mathcal{P}(\varnothing) = \{ \varnothing \}$ is TRUE
    7. $\{ x, y, z\}^3 - \{ s \;\mid\; |s| \leq 3 \} \neq \varnothing$ is TRUE since the left operand of the subtraction is a set of tuples and the operation is subtracting a set of sets; therefore, the subtraction removes nothing, leaving you with $\{ x, y, z\}^3$, which is not empty. At least in this class, sets and tuples are different things.
    8. $\bigcup \{ \mathbb{N}, \mathbb{B}, \mathbb{Q} \} - \mathbb{B} = \mathbb{Q}$ is TRUE (since $\mathbb{Q} \cup \mathbb{N} = \mathbb{Q}$)
    9. $(9, 3, F) \in \mathbb{Z} \times \mathbb{B} \times \mathbb{R} \wedge (1,2)\!\downarrow\!1 = 2$ is FALSE because tuples are ordered
    10. $|\mathcal{P}(\{a,b,c\}) - \mathcal{P}(\{a,b\})| = 5$ is FALSE because the left hand side equals 4
  9. First, please note that this question referred to two partial orders, not two partially ordered sets! A partial order is a kind of relation so it is a set of ordered pairs. With that out of the way, on to the proof! Let $R_1$ and $R_2$ each be partial orders.
    • Suppose $(x,y)$ is some arbitrary element of $R_1 \cap R_2$. Since $(x,y)$ is in the intersection, it will have been in both $R_1$ and $R_2$. Since it is in $R_1$, $R_1$ also contains $(x,x)$ and $(y,y)$. $R_2$ contains them too. So does the intersection. So out of all the possible values $x$ that can appear in any position of any tuple in $R_1 \cap R_2$, $(x,x) \in R_1 \cap R_2$, so the intersection is reflexive.
    • Suppose $(x,y) \in R_1 \cap R_2$, where $x \neq y$. $(x,y)$ was a member of both $R_1$ and $R_2$. Since $R_1$ and $R_2$ were both partial orders, neither of them contain $(y,x)$, so neither does $R_1 \cap R_2$, so the intersection is also antisymmetric.
    • Now suppose $(x,y)$ and $(y,z)$ are in $R_1 \cap R_2$. Will $(x,z)$ be there as well? Yep! Because $(x,y)$ and $(y,z)$ were both in $R_1$ and both in $R_2$, and because $R_1$ and $R_2$ are partial orders, they both contain $(x,z)$ and so the intersection does as well. Therefore $R_1 \cap R_2$ is transitive.
    And so $R_1 \cap R_2$ is a partial order. $\square$
  10. Computation time! Given that $f = \lambda x. 2x + 1$ and $g = \lambda x. \lambda y. 3xy$, we compute:
    1. $f^5(20)$
      $= f(f(f(f(f(20)))))$
      $= f(f(f(f(41))))$
      $= f(f(f(83)))$
      $= f(f(167))$
      $= f(335)$
      $= \boxed{671}$
    2. $f \circ f$
      $= \lambda x.f(f(x))$
      $= \lambda x.f(2x + 1)$
      $= \lambda x.\,2(2x + 1)+1$
      $= \boxed{\lambda x.\,4x+3}$
    3. $g(f[5/3](3) - f[5/3](2))$
      $= g(5 - (2 \cdot 2 + 1))$
      $= g(5-5)$
      $= g(0)$
      $= \lambda y.\,3 \cdot 0 \cdot y$
      $= \boxed{\lambda y.\,0}$
    4. $(\lambda w. (f^{-1}(71), w(5), w(1)))(f \circ (g\:1))$
      $= (\lambda w. (f^{-1}(71), w(5), w(1)))(f \circ \lambda y.\,3y)$
      $= (\lambda w. (f^{-1}(71), w(5), w(1)))(\lambda x.\,6x+1)$
      $= (f^{-1}(71), (\lambda x.\,6x+1)(5), (\lambda x.\,6x+1)(1))$
      $= (\frac{71-1}{2}, 5 \cdot 6 + 1, 6 \cdot 1 + 1)$
      $= \boxed{(35, 31, 7)}$
    5. $(\lambda x. (x\:x))(\lambda x. (x\:x))$
      $= (\lambda x. (x\:x))(\lambda x. (x\:x))$
      $= (\lambda x. (x\:x))(\lambda x. (x\:x))$
      $= \ldots$
      This goes on forever, so it cannot be reduced to anything.
  11. Math! You were not asked to show work, so Wolfram Alpha would have been fine here. Writing programs to help works too. I hope you did not use ChatGPT for this. It is not a calculator. When you want precise answers, use calculators. Some day it will never occur to people to use generative AI for questions like this.
    1. $3 \uparrow \uparrow 2$
      $= 3 \uparrow 3$
      $= 3^3$
      $= \boxed{27}$
    2. $2 \uparrow \uparrow \uparrow 3$
      $= 2 \uparrow \uparrow 2 \uparrow \uparrow 2$
      $= 2 \uparrow \uparrow 4$
      $= 2 \uparrow 2 \uparrow 2 \uparrow 2$ $= 2^{2^4} = 2^{16}$
      $= \boxed{65536}$
    3. $790912853^{3892359} \;\mathtt{mod}\; 90277$
      $= \boxed{66207}$
      (Command line: python3 -c 'print(pow(790912853,3892359,90277))')
    4. $(3 + 2i - 8k) \times (8i + 2j -k)$
      $= 24i+6j-3k+16i^2+4ij-2ik-64ki-16kj+8k^2$
      $= 24i+6j-3k-16+4k+2j-64j+16i-8$
      $= \boxed{-24 + 40i - 56j + k}$
    5. $\log_8{2^{333333333}}$
      $= \log_8{2^{3 \cdot 111111111}}$
      $= \log_8{(2^3)^{111111111}}$
      $= \log_8{8^{111111111}}$
      $= \boxed{111111111}$