progs/scala/re.scala
changeset 81 7ac7782a7318
parent 78 279d0bc48308
child 156 6a43ea9305ba
--- a/progs/scala/re.scala	Mon Jul 06 20:44:30 2015 +0100
+++ b/progs/scala/re.scala	Thu Dec 17 13:14:36 2015 +0000
@@ -39,7 +39,7 @@
   def | (r: String) = ALT(s, r)
   def % = STAR(s)
   def ~ (r: Rexp) = SEQ(s, r)
-  def ~ (r: String) = SEQ(s, r)n jjjjjjj=99999ij9999ijn0n
+  def ~ (r: String) = SEQ(s, r)
   def $ (r: Rexp) = RECD(s, r)
 }
 
@@ -255,7 +255,7 @@
 
 def lexing_simp(r: Rexp, s: String) : Val = lex_simp(r, s.toList)
 
-
+lexing_sim(("a" + "ab") | ("b" + ""), "ab")
 // brute force search infrastructure
 
 // enumerates regular expressions until a certain depth
@@ -323,13 +323,38 @@
 def transitivity_test(r: Rexp)(v1: Val)(v2: Val)(v3: Val) : Boolean = 
   ord(v1, v2) && ord(v2, v3) && !ord(v1, v3)
 
+val test0 = enum(3, "a").flatMap(vfilter3(transitivity_test))
+val test0_smallest = test0.toList.sortWith { (x,y) => size(x._1) < size(y._1) }.head
+
+pretty(test0_smallest._1)
+vpretty(test0_smallest._2)
+vpretty(test0_smallest._3)
+vpretty(test0_smallest._4)
+
+/* Counter example for simple transitivity:
+
+ r = a | ((a | a)(a | e))
+
+ v1 = Left(a)
+ v2 = Right(Left(a) ~ Right(()))
+ v3 = Right(Right(a) ~ Left(a))
+
+*/ 
+
+def is_seq(v: Val) : Boolean = v match {
+  case Seq(_, _) => true
+  case _ => false
+}
+
 def transitivity_test_extended(r: Rexp)(v1: Val)(v2: Val)(v3: Val) : Boolean = {
-  flatten(v1) == flatten(v2) && flatten(v2) == flatten(v3) && 
+  //flatten(v1).size >= flatten(v2).size && 
+  //flatten(v2).size >= flatten(v3).size && 
+  is_seq(v1) &&
   ord(v1, v2) && ord(v2, v3) && !ord(v1, v3)
 }
 
 // smallest(?) example where simple transitivity fails 
-val test1 = enum(3, "a").flatMap(vfilter3(transitivity_test))
+val test1 = enum(3, "a").flatMap(vfilter3(transitivity_test_extended))
 val test1_smallest = test1.toList.sortWith { (x,y) => size(x._1) < size(y._1) }.head
 
 pretty(test1_smallest._1)
@@ -342,6 +367,17 @@
 ord(test1_smallest._2, test1_smallest._4)
 ordr(test1_smallest._3, test1_smallest._1, test1_smallest._4)
 
+/* Counter example for extended transitivity:
+
+ r = ((e | e)(e | a)) | a
+
+ v1 = Left(Right(()) ~ Right(a))
+ v2 = Right(a)
+ v3 = Left(Left(()) ~ Left(()))
+
+*/ 
+
+
 // with flatten test
 enum(3, "a").flatMap(vfilter3(transitivity_test_extended))