updated
authorChristian Urban <urbanc@in.tum.de>
Fri, 17 Mar 2017 12:15:58 +0000
changeset 479 52aa298211f6
parent 478 48b842c997c7
child 481 acd8780bfc8b
updated
handouts/ho02.pdf
handouts/ho02.tex
progs/dfa.scala
progs/re1.scala
Binary file handouts/ho02.pdf has changed
--- a/handouts/ho02.tex	Wed Mar 15 14:34:10 2017 +0000
+++ b/handouts/ho02.tex	Fri Mar 17 12:15:58 2017 +0000
@@ -265,6 +265,22 @@
 $\ZERO$s, therefore simplifying them away will make the
 algorithm quite a bit faster.
 
+Finally here are three equivalences between regulare expressions which are
+not so obvious:
+
+\begin{center}
+\begin{tabular}{rcl}
+$r^*$  & $\equiv$ & $1 + r\cdot r^*$\\
+$(r_1 + r_2)^*$  & $\equiv$ & $r_1^* \cdot (r_2\cdot r_1^*)^*$\\
+$(r_1 \cdot r_2)^*$ & $\equiv$ & $1 + r_1\cdot (r_2 \cdot r_1)^* \cdot r_2$\\
+\end{tabular}
+\end{center}
+
+\noindent
+You can try to establish them. As an aside, there has been a lot of research
+in questions like: Can one always decide when two regular expressions are
+equivalent or not? What does an algorithm look like to decide this?
+
 \subsection*{The Matching Algorithm}
 
 The algorithm we will define below consists of two parts. One
--- a/progs/dfa.scala	Wed Mar 15 14:34:10 2017 +0000
+++ b/progs/dfa.scala	Fri Mar 17 12:15:58 2017 +0000
@@ -1,3 +1,71 @@
+// convert normal string to hex bytes string
+def string2hex(str: String): String = {
+  str.toList.map(_.toInt.toHexString).mkString
+}
+    
+// convert hex bytes string to normal string
+
+
+val byteArray: Array[Byte] = List.range(1, 255).map(_.toByte).toArray
+val bos = new BufferedOutputStream(new FileOutputStream("test.txt"))
+bos.write(byteArray)
+bos.close() 
+
+
+def string2int(hex: String) = {
+  hex.sliding(2, 2).map(Integer.parseInt(_, 16)).toArray
+}
+
+def test(l: List[Int]) = {
+  l.map(_.toChar).mkString
+}
+
+
+import java.io._
+val writer = new PrintWriter(new File("test.txt" ))
+
+//writer.write(string2int("cafebabe"))
+writer.write(test(List.range(1, 255)))
+writer.close()
+
+import scalax.io._
+import scalax.io.Resource
+
+FileOutputStream fos = new FileOutputStream("test");
+fos.write(bytesArray);
+fos.close();
+
+
+string2int("cafebabe")
+
+202.toHexString
+
+"cafebabe".sliding(1, 1).toList.map(Integer.parseInt(_, 16)).map(_.toByte).map(_.toChar)
+
+hex2string("ca")
+string2hex("ca")
+hex2string("cafebabe")
+
+    
+val appkey = "9GLV//lv/kYFW2o3/bihxwnMcmo="
+        
+        // string to hex
+        val appkey_hex = string2hex(appkey)
+        // 39474c562f2f6c762f6b594657326f332f62696878776e4d636d6f3d
+        println(appkey_hex)
+        
+        // hex to string
+        val appkey_string_again = hex2string(appkey_hex)
+        // 9GLV//lv/kYFW2o3/bihxwnMcmo=
+        println(appkey_string_again)
+    }
+
+
+List("ca", "fe", "ba", "be").map(_.toByte)
+
+"ca".toByte
+
+
 // DFAs
 import scala.util._
 
--- a/progs/re1.scala	Wed Mar 15 14:34:10 2017 +0000
+++ b/progs/re1.scala	Fri Mar 17 12:15:58 2017 +0000
@@ -115,3 +115,23 @@
 size(EVIL1(3))  // 17
 size(EVIL1(5))  // 29
 size(EVIL1(7))  // 41
+
+
+// given a regular expression and building successive
+// derivatives might result into bigger and bigger
+// regular expressions...here is an example for this:
+
+val BIG_aux = STAR(ALT(CHAR('a'), CHAR('b')))
+val BIG = SEQ(BIG_aux, SEQ(CHAR('a'),SEQ(CHAR('b'), BIG_aux)))
+
+size(ders("".toList, BIG))              // 13
+size(ders("ab".toList, BIG))            // 51
+size(ders("abab".toList, BIG))          // 112
+size(ders("ababab".toList, BIG))        // 191
+size(ders("abababab".toList, BIG))      // 288
+size(ders("ababababab".toList, BIG))    // 403
+size(ders("abababababab".toList, BIG))  // 536
+
+
+size(ders(("ab" * 200).toList, BIG))    // 366808
+