CSE390D Notes for Monday, 11/25/24

Equivalence relation: reflexive, symmetric, transitive congruence mod n on Z: R = {(a, b) | a == b (mod n)} -- yes R = {(a, b) | a - b is an integer} on reals -- yes divides on Z+: no (not symmetric) talk about how equivalence relation leads to equivalence classes reflexive, so all the self loops are there what if (a, b)? then (b, a) what if (a, c)? then all interconnections with c what if (a, d)? then all interconnections with d leads to an interconnected component of the graph--equivalence class partial ordering: reflexive, antisymmetric, transitive divides on Z+: yes >= on Z: yes on String objects, {(s1, s2) | s1.compareTo(s2) <= 0} -- yes partial ordering leads to chains example: divides on 2--12 2, 4, 8 2, 6, 12 2, 10 3, 6, 12 3, 9 4, 8 4, 12 5, 10 6, 12 total ordering: for every (a, b), either (a, b) in R or (b, a) in R divides -- no <= -- yes compareTo <= 0 -- yes ---------------------------------------------------------------------- Bertrand Russell understood the problem with self-reference liar's paradox p: p is false p is true => p is false p is false => p is true 1900 David Hilbert problem 2: math is in good shape math is consistent: no contradictions (no p and !p) math is complete: every true statement can be proven true math is decidable: a program can prove/disprove propositions why would an inconsistency be so bad? 2 + 2 = 5 add this to math 2 + 2 = 4 we know this 5 = 4 1 = 0 n * 1 = n n * 0 = 0 n = 0 (for all n) set paradox: S: {set of all sets} is S contained in S? (is it a member?) X: {1, 2, 3} does X contain X? NO..that would be weird S': {set of all sets that do not contain themselves} X is in S' does S' contain S'? yes (S' contains S') => S' does not contain S' no (S' does not contain S') => S' belongs in S' Russell: came up with Principia Mathematica (PM) thought he had solved self reference level n statements can only refer to statements < n Kurt Goedel showed that propositions can be encoded as integers that means that a proposition can say something about it's number showed that you can construct a statement that says: p: I cannot be proven true in PM p is false => PM is inconsistent p is true => PM is incomplete ---------------------------------------------------------------------- Halting problem. When does this program go into an infinite loop? import java.util.*; public class Foo { public static void main(String[] args) { Scanner input = new Scanner(System.in); String next = input.next(); int x = 3; if (next.startsWith("imp")) { while (2 + 2 == 4) { x = x; } } System.out.println("bye bye"); } } When input begins with "imp". To simplify: does it go into an infinite loop when given itself as input? Yes. So we say it is "self-looping". If it doesn't loop, we say it is "self-halting." ---------------------------------------------------------------------- Can we write a program to decide if a given program is self-halting versus self-looping? If so, we could write it like this: public class H { public static void main(String[] args) { // program = ... if (halts(program)) { System.out.println("self halting"); } else { System.out.println("self infinite"); } } public static boolean halts(String program) { ... } } ---------------------------------------------------------------------- But then we can create the evil twin H2.java: public class H2 { public static void main(String[] args) { // program = ... if (halts(program)) { while (true); } else { System.out.println("ha ha"); } } public static boolean halts(String program) { ... } } Is H self-halting? It better be. Otherwise it's not a solution to the halting problem. What about H2? If it is self-halting, then the call on the halts method must have returned false. But then H would have said this is self-looping. If it is self-looping, then the call on the halts method must have returned true. But then H would have said that this is self-halting. That's a contradiction or a paradox or you can just think of it as H giving the wrong answer no matter what. There are infinitely many programs like H2, so there is no solution to the halting problem. We say that the halting problem is undecidable. There are many related problems, like trying to decide if two programs have the same behavior.
Stuart Reges
Last modified: Mon Nov 25 15:35:00 PST 2024