Spiral.scala
author Chengsong
Wed, 10 Apr 2019 16:34:34 +0100
changeset 11 9c1ca6d6e190
parent 10 2b95bcd2ac73
child 12 768b833d6230
permissions -rwxr-xr-x
The C(Char) construct is incompatible with the code and retrieve in Fahad's thesis. This causes the exception. Two ways of fixing this: delete C(C) construct (easy way around) or amend retrieve code etc. since the C(C) construct is intended for decoding Pred, and we don't use pred now, we shall delete this. This is the last veersion that contains C(CHAR)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
Chengsong
parents:
diff changeset
     1
import Element.elem
Chengsong
parents:
diff changeset
     2
import RexpRelated._
Chengsong
parents:
diff changeset
     3
import RexpRelated.Rexp._
Chengsong
parents:
diff changeset
     4
import Partial._
Chengsong
parents:
diff changeset
     5
import BRexp._
Chengsong
parents:
diff changeset
     6
import scala.collection.mutable.ListBuffer
Chengsong
parents:
diff changeset
     7
object Spiral{
Chengsong
parents:
diff changeset
     8
Chengsong
parents:
diff changeset
     9
  val space = elem(" ")
Chengsong
parents:
diff changeset
    10
  val corner = elem("+")
Chengsong
parents:
diff changeset
    11
Chengsong
parents:
diff changeset
    12
  def spiral(nEdges: Int, direction: Int): Element = {
Chengsong
parents:
diff changeset
    13
    if(nEdges == 1)
Chengsong
parents:
diff changeset
    14
      elem("+")
Chengsong
parents:
diff changeset
    15
    else {
Chengsong
parents:
diff changeset
    16
      val sp = spiral(nEdges - 1, (direction + 3) % 4)
Chengsong
parents:
diff changeset
    17
      def verticalBar = elem('|', 1, sp.height)
Chengsong
parents:
diff changeset
    18
      def horizontalBar = elem('-', sp.width, 1)
Chengsong
parents:
diff changeset
    19
      if(direction == 0)
Chengsong
parents:
diff changeset
    20
        (corner beside horizontalBar) above sp//(sp beside space)
Chengsong
parents:
diff changeset
    21
      else if (direction == 1)
Chengsong
parents:
diff changeset
    22
        sp beside (corner above verticalBar)
Chengsong
parents:
diff changeset
    23
      else if (direction == 2)
Chengsong
parents:
diff changeset
    24
        (space beside sp) above (horizontalBar beside corner)
Chengsong
parents:
diff changeset
    25
      else
Chengsong
parents:
diff changeset
    26
        (verticalBar above corner) beside (space above sp)
Chengsong
parents:
diff changeset
    27
    }
Chengsong
parents:
diff changeset
    28
  }
Chengsong
parents:
diff changeset
    29
  val alphabet = ("""abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.:"=()\;-+*!<>\/%{} """+"\n\t").toSet//Set('a','b','c')
Chengsong
parents:
diff changeset
    30
  def bregx_tree(r: BRexp): Element = regx_tree(berase(r))
Chengsong
parents:
diff changeset
    31
  def regx_tree(r: Rexp): Element = aregx_tree(internalise(r))
5
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
    32
  def annotated_tree(r: ARexp): Element = {
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
    33
    r match {
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
    34
      case ACHAR(bs, d) => {
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
    35
        //val Some(d) = alphabet.find(f)
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
    36
        d match {
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
    37
          case '\n' => elem("\\n")
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
    38
          case '\t' => elem("\\t")
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
    39
          case ' ' => elem("space")
7
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
    40
          case d => if(bs.isEmpty)  elem(d.toString) else elem(d.toString++" ") beside elem(bs.toString)
5
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
    41
        }   
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
    42
      }
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
    43
      case AONE(bs) => {
7
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
    44
        if(bs.isEmpty)  elem("ONE") else elem("ONE ") beside elem(bs.toString)
5
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
    45
      }
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
    46
      case AZERO => {
7
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
    47
        elem("ZERO") 
5
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
    48
      }
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
    49
      case ASEQ(bs, r1, r2) => {
7
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
    50
        annotated_binary_print("SEQ", r1, r2, bs)
5
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
    51
      }
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
    52
      case AALTS(bs, rs) => {
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
    53
        //elem("Awaiting completion")
7
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
    54
        annotated_list_print("ALT", rs, bs)  
5
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
    55
      }
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
    56
      case ASTAR(bs, r) => {
7
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
    57
        annotated_list_print("STA", List(r), bs)
5
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
    58
      }
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
    59
    } 
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
    60
  }
0
Chengsong
parents:
diff changeset
    61
  def aregx_tree(r: ARexp): Element = {
Chengsong
parents:
diff changeset
    62
    r match {
Chengsong
parents:
diff changeset
    63
      case ACHAR(bs, d) => {
Chengsong
parents:
diff changeset
    64
        //val Some(d) = alphabet.find(f)
Chengsong
parents:
diff changeset
    65
        d match {
Chengsong
parents:
diff changeset
    66
          case '\n' => elem("\\n")
Chengsong
parents:
diff changeset
    67
          case '\t' => elem("\\t")
Chengsong
parents:
diff changeset
    68
          case ' ' => elem("space")
Chengsong
parents:
diff changeset
    69
          case d => elem(d.toString)
Chengsong
parents:
diff changeset
    70
        }   
Chengsong
parents:
diff changeset
    71
      }
Chengsong
parents:
diff changeset
    72
      case AONE(bs) => {
Chengsong
parents:
diff changeset
    73
        elem("ONE")
Chengsong
parents:
diff changeset
    74
      }
Chengsong
parents:
diff changeset
    75
      case AZERO => {
Chengsong
parents:
diff changeset
    76
        elem("ZERO")
Chengsong
parents:
diff changeset
    77
      }
Chengsong
parents:
diff changeset
    78
      case ASEQ(bs, r1, r2) => {
Chengsong
parents:
diff changeset
    79
        binary_print("SEQ", r1, r2)
Chengsong
parents:
diff changeset
    80
      }
Chengsong
parents:
diff changeset
    81
      case AALTS(bs, rs) => {
Chengsong
parents:
diff changeset
    82
        //elem("Awaiting completion")
Chengsong
parents:
diff changeset
    83
        list_print("ALT", rs)
Chengsong
parents:
diff changeset
    84
      }
Chengsong
parents:
diff changeset
    85
      case ASTAR(bs, r) => {
Chengsong
parents:
diff changeset
    86
        list_print("STA", List(r))
Chengsong
parents:
diff changeset
    87
      }
Chengsong
parents:
diff changeset
    88
    }
Chengsong
parents:
diff changeset
    89
  }
Chengsong
parents:
diff changeset
    90
  val port = elem(" └-")
Chengsong
parents:
diff changeset
    91
  def list_print(name: String, rs: List[ARexp]): Element = {
Chengsong
parents:
diff changeset
    92
    rs match {
Chengsong
parents:
diff changeset
    93
      case r::Nil => {
Chengsong
parents:
diff changeset
    94
        val pref = aregx_tree(r)
Chengsong
parents:
diff changeset
    95
        val head = elem(name)
Chengsong
parents:
diff changeset
    96
        (head left_align (port up_align pref) ) 
Chengsong
parents:
diff changeset
    97
      }
Chengsong
parents:
diff changeset
    98
      case r2::r1::Nil => {
Chengsong
parents:
diff changeset
    99
        binary_print(name, r2, r1)
Chengsong
parents:
diff changeset
   100
      }
Chengsong
parents:
diff changeset
   101
      case r::rs1 => {
Chengsong
parents:
diff changeset
   102
        val pref = aregx_tree(r)
Chengsong
parents:
diff changeset
   103
        val head = elem(name)
Chengsong
parents:
diff changeset
   104
        if (pref.height > 1){
Chengsong
parents:
diff changeset
   105
          val link = elem('|', 1, pref.height - 1)
Chengsong
parents:
diff changeset
   106
          (head left_align ((port above link) beside pref)) left_align tail_print(rs1)    
Chengsong
parents:
diff changeset
   107
        }
Chengsong
parents:
diff changeset
   108
        else{
Chengsong
parents:
diff changeset
   109
          (head left_align (port beside pref) ) left_align tail_print(rs1)
Chengsong
parents:
diff changeset
   110
        }
Chengsong
parents:
diff changeset
   111
      }
Chengsong
parents:
diff changeset
   112
    }
Chengsong
parents:
diff changeset
   113
  }
7
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   114
    def annotated_list_print(name: String, rs: List[ARexp], bs: List[Bit]): Element = {
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   115
    rs match {
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   116
      case r::Nil => {
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   117
        val pref = annotated_tree(r)
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   118
        val head = if(bs.isEmpty) elem(name) else elem(name ++ " ") beside elem(bs.toString)
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   119
        (head left_align (port up_align pref) ) 
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   120
      }
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   121
      case r2::r1::Nil => {
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   122
        annotated_binary_print(name, r2, r1, bs)
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   123
      }
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   124
      case r::rs1 => {
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   125
        val pref = annotated_tree(r)
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   126
        val head = if (bs.isEmpty) elem(name) else elem(name ++ " ") beside elem(bs.toString)
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   127
        if (pref.height > 1){
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   128
          val link = elem('|', 1, pref.height - 1)
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   129
          (head left_align ((port above link) beside pref)) left_align annotated_tail_print(rs1)    
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   130
        }
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   131
        else{
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   132
          (head left_align (port beside pref) ) left_align annotated_tail_print(rs1)
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   133
        }
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   134
      }
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   135
    }
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   136
  }
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   137
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   138
  def annotated_tail_print(rs: List[ARexp]): Element = {
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   139
    rs match {
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   140
      case r2::r1::Nil => {
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   141
        val pref = annotated_tree(r2)
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   142
        val suff = annotated_tree(r1)
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   143
        if (pref.height > 1){
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   144
          val link = elem('|', 1, pref.height - 1)
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   145
          ((port above link) beside pref) left_align (port up_align suff)
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   146
        }
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   147
        else{
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   148
          (port beside pref) left_align (port up_align suff)
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   149
        } 
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   150
      }
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   151
      case r2::rs1 => {
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   152
        val pref = annotated_tree(r2)
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   153
        
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   154
        if (pref.height > 1){
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   155
          val link = elem('|', 1, pref.height - 1)
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   156
          ((port above link) beside pref) left_align annotated_tail_print(rs1)//(port up_align tail_print(rs1) )
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   157
        }
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   158
        else{
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   159
          (port beside pref) left_align annotated_tail_print(rs1)//(port up_align tail_print(rs1))
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   160
        } 
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   161
        //pref left_align tail_print(rs1)
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   162
      }
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   163
    }
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   164
  }
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   165
0
Chengsong
parents:
diff changeset
   166
  def tail_print(rs: List[ARexp]): Element = {
Chengsong
parents:
diff changeset
   167
    rs match {
Chengsong
parents:
diff changeset
   168
      case r2::r1::Nil => {
Chengsong
parents:
diff changeset
   169
        val pref = aregx_tree(r2)
Chengsong
parents:
diff changeset
   170
        val suff = aregx_tree(r1)
Chengsong
parents:
diff changeset
   171
        if (pref.height > 1){
Chengsong
parents:
diff changeset
   172
          val link = elem('|', 1, pref.height - 1)
Chengsong
parents:
diff changeset
   173
          ((port above link) beside pref) left_align (port up_align suff)
Chengsong
parents:
diff changeset
   174
        }
Chengsong
parents:
diff changeset
   175
        else{
Chengsong
parents:
diff changeset
   176
          (port beside pref) left_align (port up_align suff)
Chengsong
parents:
diff changeset
   177
        } 
Chengsong
parents:
diff changeset
   178
      }
Chengsong
parents:
diff changeset
   179
      case r2::rs1 => {
Chengsong
parents:
diff changeset
   180
        val pref = aregx_tree(r2)
Chengsong
parents:
diff changeset
   181
        
Chengsong
parents:
diff changeset
   182
        if (pref.height > 1){
Chengsong
parents:
diff changeset
   183
          val link = elem('|', 1, pref.height - 1)
Chengsong
parents:
diff changeset
   184
          ((port above link) beside pref) left_align tail_print(rs1)//(port up_align tail_print(rs1) )
Chengsong
parents:
diff changeset
   185
        }
Chengsong
parents:
diff changeset
   186
        else{
Chengsong
parents:
diff changeset
   187
          (port beside pref) left_align tail_print(rs1)//(port up_align tail_print(rs1))
Chengsong
parents:
diff changeset
   188
        } 
Chengsong
parents:
diff changeset
   189
        //pref left_align tail_print(rs1)
Chengsong
parents:
diff changeset
   190
      }
Chengsong
parents:
diff changeset
   191
    }
Chengsong
parents:
diff changeset
   192
  }
Chengsong
parents:
diff changeset
   193
Chengsong
parents:
diff changeset
   194
  def binary_print(name: String, r1: ARexp, r2: ARexp): Element = {
Chengsong
parents:
diff changeset
   195
    val pref = aregx_tree(r1)
Chengsong
parents:
diff changeset
   196
    val suff = aregx_tree(r2)
7
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   197
    val head = elem(name) 
0
Chengsong
parents:
diff changeset
   198
    if (pref.height > 1){
Chengsong
parents:
diff changeset
   199
      val link = elem('|', 1, pref.height - 1)
Chengsong
parents:
diff changeset
   200
      (head left_align ((port above link) beside pref) ) left_align (port up_align suff)
Chengsong
parents:
diff changeset
   201
    }
Chengsong
parents:
diff changeset
   202
    else{
Chengsong
parents:
diff changeset
   203
      (head left_align (port beside pref) ) left_align (port up_align suff)
Chengsong
parents:
diff changeset
   204
    }
Chengsong
parents:
diff changeset
   205
  }
7
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   206
  def annotated_binary_print(name: String, r1: ARexp, r2: ARexp, bs: List[Bit]): Element = {
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   207
    val pref = annotated_tree(r1)
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   208
    val suff = annotated_tree(r2)
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   209
    val head = if (bs.isEmpty) elem(name) else elem(name ++ " ") beside elem(bs.toString)
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   210
    if (pref.height > 1){
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   211
      val link = elem('|', 1, pref.height - 1)
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   212
      (head left_align ((port above link) beside pref) ) left_align (port up_align suff)
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   213
    }
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   214
    else{
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   215
      (head left_align (port beside pref) ) left_align (port up_align suff)
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   216
    }
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   217
  }
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   218
0
Chengsong
parents:
diff changeset
   219
  val arr_of_size = ListBuffer.empty[Int]
2
cf169411b771 more comments
Chengsong
parents: 1
diff changeset
   220
0
Chengsong
parents:
diff changeset
   221
  def pC(r: Rexp): Set[Rexp] = {//PD's companion
Chengsong
parents:
diff changeset
   222
    r match {
Chengsong
parents:
diff changeset
   223
      case SEQ(r1, r2) => pC(r2)
Chengsong
parents:
diff changeset
   224
      case ALTS(rs) => rs.flatMap(a => pC(a) ).toSet
Chengsong
parents:
diff changeset
   225
      case CHAR(c) => Set(r)
Chengsong
parents:
diff changeset
   226
      case r => Set()
Chengsong
parents:
diff changeset
   227
    }
Chengsong
parents:
diff changeset
   228
  }
Chengsong
parents:
diff changeset
   229
  def illustration(r: Rexp, s: String){
Chengsong
parents:
diff changeset
   230
    var i_like_imperative_style = internalise(r)
Chengsong
parents:
diff changeset
   231
    val all_chars = s.toList
Chengsong
parents:
diff changeset
   232
    for (i <- 0 to s.length - 1){
Chengsong
parents:
diff changeset
   233
      val der_res =  bder(all_chars(i), i_like_imperative_style)
Chengsong
parents:
diff changeset
   234
      val simp_res = bsimp(der_res)
Chengsong
parents:
diff changeset
   235
      println("The original regex, the regex after derivative w.r.t " + all_chars(i) + " and the simplification of the derivative.")
Chengsong
parents:
diff changeset
   236
      println(aregx_tree(i_like_imperative_style) up_align aregx_tree(der_res) up_align aregx_tree(simp_res))
Chengsong
parents:
diff changeset
   237
      //println(asize(i_like_imperative_style), asize(der_res), asize(simp_res))
Chengsong
parents:
diff changeset
   238
      arr_of_size += asize(i_like_imperative_style)
Chengsong
parents:
diff changeset
   239
      //println(asize(simp_res), asize(simp_res) / arr_of_size(0) )
Chengsong
parents:
diff changeset
   240
      i_like_imperative_style = simp_res
Chengsong
parents:
diff changeset
   241
    }
Chengsong
parents:
diff changeset
   242
    arr_of_size += asize(i_like_imperative_style)
Chengsong
parents:
diff changeset
   243
  }
Chengsong
parents:
diff changeset
   244
  val ran = scala.util.Random
Chengsong
parents:
diff changeset
   245
  var alphabet_size = 3
Chengsong
parents:
diff changeset
   246
  def balanced_seq_star_gen(depth: Int, star: Boolean): Rexp = {
Chengsong
parents:
diff changeset
   247
    if(depth == 1){
Chengsong
parents:
diff changeset
   248
      ((ran.nextInt(4) + 97).toChar).toString
Chengsong
parents:
diff changeset
   249
    }
Chengsong
parents:
diff changeset
   250
    else if(star){
Chengsong
parents:
diff changeset
   251
      STAR(balanced_seq_star_gen(depth - 1, false))
Chengsong
parents:
diff changeset
   252
    }
Chengsong
parents:
diff changeset
   253
    else{
Chengsong
parents:
diff changeset
   254
      SEQ(balanced_seq_star_gen(depth - 1, true), balanced_seq_star_gen(depth - 1, true))
Chengsong
parents:
diff changeset
   255
    }
Chengsong
parents:
diff changeset
   256
  }
Chengsong
parents:
diff changeset
   257
  def max(i: Int, j: Int): Int = {
Chengsong
parents:
diff changeset
   258
    if(i > j)
Chengsong
parents:
diff changeset
   259
      i
Chengsong
parents:
diff changeset
   260
    else 
Chengsong
parents:
diff changeset
   261
      j
Chengsong
parents:
diff changeset
   262
  }
Chengsong
parents:
diff changeset
   263
  def random_struct_gen(depth:Int): Rexp = {
Chengsong
parents:
diff changeset
   264
    val dice = ran.nextInt(3)
Chengsong
parents:
diff changeset
   265
    val dice2 = ran.nextInt(3)
Chengsong
parents:
diff changeset
   266
    (dice, depth) match {
Chengsong
parents:
diff changeset
   267
      case (_, 0) => ((ran.nextInt(3) + 97).toChar).toString
Chengsong
parents:
diff changeset
   268
      case (0, i) => STAR(random_struct_gen(max(0, i - 1 - dice2)))
Chengsong
parents:
diff changeset
   269
      case (1, i) => SEQ(random_struct_gen(max(0, i - 1 - dice2)), random_struct_gen(max(0, i - 1 - dice2)))
Chengsong
parents:
diff changeset
   270
      case (2, i) => ALTS( List(random_struct_gen(max(0, i - 1 - dice2)), random_struct_gen(max(0, i - 1 - dice2))) )
Chengsong
parents:
diff changeset
   271
    }
Chengsong
parents:
diff changeset
   272
  }
Chengsong
parents:
diff changeset
   273
  def balanced_struct_gen(depth: Int): Rexp = {
Chengsong
parents:
diff changeset
   274
    val dice = ran.nextInt(3)
Chengsong
parents:
diff changeset
   275
    (dice, depth) match {
Chengsong
parents:
diff changeset
   276
      case (_, 0) => ((ran.nextInt(3) + 97).toChar).toString
Chengsong
parents:
diff changeset
   277
      case (0, i) => STAR(random_struct_gen(depth - 1))
Chengsong
parents:
diff changeset
   278
      case (1, i) => SEQ(random_struct_gen(depth - 1), random_struct_gen(depth - 1))
Chengsong
parents:
diff changeset
   279
      case (2, i) => ALTS( List(random_struct_gen(depth - 1), random_struct_gen(depth - 1) ) )
Chengsong
parents:
diff changeset
   280
    }
Chengsong
parents:
diff changeset
   281
  }
6
26b40a985622 random test failed
Chengsong
parents: 5
diff changeset
   282
  def random_pool(n: Int, d: Int) : Stream[Rexp] = n match {
26b40a985622 random test failed
Chengsong
parents: 5
diff changeset
   283
    case 0 => (for (i <- 1 to 10) yield balanced_struct_gen(d)).toStream
26b40a985622 random test failed
Chengsong
parents: 5
diff changeset
   284
    case n => {  
26b40a985622 random test failed
Chengsong
parents: 5
diff changeset
   285
      val rs = random_pool(n - 1, d)
26b40a985622 random test failed
Chengsong
parents: 5
diff changeset
   286
      rs #:::
26b40a985622 random test failed
Chengsong
parents: 5
diff changeset
   287
      (for (i <- (1 to 10).toStream) yield balanced_struct_gen(d)) #::: 
26b40a985622 random test failed
Chengsong
parents: 5
diff changeset
   288
      (for (i <- (1 to 10).toStream) yield random_struct_gen(d))
26b40a985622 random test failed
Chengsong
parents: 5
diff changeset
   289
    }
26b40a985622 random test failed
Chengsong
parents: 5
diff changeset
   290
  }
26b40a985622 random test failed
Chengsong
parents: 5
diff changeset
   291
0
Chengsong
parents:
diff changeset
   292
  def rd_string_gen(alp_size: Int, len: Int): String = {
Chengsong
parents:
diff changeset
   293
    if( len > 0)
Chengsong
parents:
diff changeset
   294
      ((ran.nextInt(alp_size) + 97).toChar).toString + rd_string_gen(alp_size, len - 1)
Chengsong
parents:
diff changeset
   295
    else
Chengsong
parents:
diff changeset
   296
      ((ran.nextInt(alp_size) + 97).toChar).toString
Chengsong
parents:
diff changeset
   297
  }
Chengsong
parents:
diff changeset
   298
  def plot(b: List[Int]){
Chengsong
parents:
diff changeset
   299
    println(b(0),b.max)
Chengsong
parents:
diff changeset
   300
Chengsong
parents:
diff changeset
   301
  }
Chengsong
parents:
diff changeset
   302
  def dep_exp(depth: List[Int]){
Chengsong
parents:
diff changeset
   303
    for(i <- depth){
Chengsong
parents:
diff changeset
   304
      arr_of_size.clear()
Chengsong
parents:
diff changeset
   305
      val s = rd_string_gen(alphabet_size, (i-8)*(i-8)+10)
Chengsong
parents:
diff changeset
   306
      val r = random_struct_gen(i)
Chengsong
parents:
diff changeset
   307
      println("depth: "+i)
Chengsong
parents:
diff changeset
   308
      illustration(r, s) //"abcabadaaadcabdbabcdaadbabbcbbdabdabbcbdbabdbcdb") 
Chengsong
parents:
diff changeset
   309
      //println("depth: " + i + " general stats:"+ arr_of_size(0), arr_of_size.max, arr_of_size.max/arr_of_size(0))
Chengsong
parents:
diff changeset
   310
      //println("x y label alignment")
Chengsong
parents:
diff changeset
   311
      /*for(i <- 0 to s.length - 1){
Chengsong
parents:
diff changeset
   312
        if(s(i) == '\n')
Chengsong
parents:
diff changeset
   313
          println(i+" "+arr_of_size(i)+" "+"nl"+" -140")
Chengsong
parents:
diff changeset
   314
        else if(s(i) ==  ' ')
Chengsong
parents:
diff changeset
   315
          println(i+" "+arr_of_size(i)+" "+"sp"+" -140")
Chengsong
parents:
diff changeset
   316
        else
Chengsong
parents:
diff changeset
   317
          println(i+" "+arr_of_size(i)+" "+s(i)+" -140")
Chengsong
parents:
diff changeset
   318
      }*/
Chengsong
parents:
diff changeset
   319
      //println(s.length + " " + arr_of_size(s.length) + " ]" + " -140")
Chengsong
parents:
diff changeset
   320
    }
Chengsong
parents:
diff changeset
   321
  }
Chengsong
parents:
diff changeset
   322
  def case_study(ss: List[String], r: Rexp){
Chengsong
parents:
diff changeset
   323
    for(s <- ss){
Chengsong
parents:
diff changeset
   324
      arr_of_size.clear()
Chengsong
parents:
diff changeset
   325
      illustration(r, s)
Chengsong
parents:
diff changeset
   326
      println("x y label alignment")
Chengsong
parents:
diff changeset
   327
      for(i <- 0 to s.length - 1){
Chengsong
parents:
diff changeset
   328
        if(s(i) == '\n')
Chengsong
parents:
diff changeset
   329
          println(i+" "+arr_of_size(i)+" "+"nl"+" -140")
Chengsong
parents:
diff changeset
   330
        else if(s(i) ==  ' ')
Chengsong
parents:
diff changeset
   331
          println(i+" "+arr_of_size(i)+" "+"sp"+" -140")
Chengsong
parents:
diff changeset
   332
        else
Chengsong
parents:
diff changeset
   333
          println(i+" "+arr_of_size(i)+" "+s(i)+" -140")
Chengsong
parents:
diff changeset
   334
      }
Chengsong
parents:
diff changeset
   335
    }
Chengsong
parents:
diff changeset
   336
  }
Chengsong
parents:
diff changeset
   337
  def star_gen(dp: Int): Rexp = {
Chengsong
parents:
diff changeset
   338
    if(dp > 0)
Chengsong
parents:
diff changeset
   339
      STAR(star_gen(dp - 1))
Chengsong
parents:
diff changeset
   340
    else
Chengsong
parents:
diff changeset
   341
      "a"
Chengsong
parents:
diff changeset
   342
  }
Chengsong
parents:
diff changeset
   343
  def strs_gen(len: Int, num: Int): List[String] = {
Chengsong
parents:
diff changeset
   344
    if(num > 0){
Chengsong
parents:
diff changeset
   345
      rd_string_gen(3, len)::strs_gen(len, num - 1)
Chengsong
parents:
diff changeset
   346
    }
Chengsong
parents:
diff changeset
   347
    else{
Chengsong
parents:
diff changeset
   348
      Nil
Chengsong
parents:
diff changeset
   349
    }
Chengsong
parents:
diff changeset
   350
  }
Chengsong
parents:
diff changeset
   351
  def regx_print(r: Rexp): String = {
Chengsong
parents:
diff changeset
   352
    r match {
Chengsong
parents:
diff changeset
   353
      case ZERO =>
Chengsong
parents:
diff changeset
   354
        "ZERO"
Chengsong
parents:
diff changeset
   355
      case CHAR(c) => {
Chengsong
parents:
diff changeset
   356
         //val Some(c) = alphabet.find(f)
Chengsong
parents:
diff changeset
   357
         "\"" + c.toString + "\""
Chengsong
parents:
diff changeset
   358
      }
Chengsong
parents:
diff changeset
   359
      case ONE => {
Chengsong
parents:
diff changeset
   360
        "ONE"
Chengsong
parents:
diff changeset
   361
      }
Chengsong
parents:
diff changeset
   362
      case ALTS(rs) => {
Chengsong
parents:
diff changeset
   363
        "ALTS(List("+(rs.map(regx_print)).foldLeft("")((a, b) => if(a == "") b else a + "," + b)+"))"
Chengsong
parents:
diff changeset
   364
      }
Chengsong
parents:
diff changeset
   365
      case SEQ(r1, r2) => {
Chengsong
parents:
diff changeset
   366
        "SEQ(" + regx_print(r1) + "," + regx_print(r2) + ")"
Chengsong
parents:
diff changeset
   367
      }
Chengsong
parents:
diff changeset
   368
      case STAR(r) => {
Chengsong
parents:
diff changeset
   369
        "STAR(" + regx_print(r) + ")"
Chengsong
parents:
diff changeset
   370
      }
Chengsong
parents:
diff changeset
   371
    }
Chengsong
parents:
diff changeset
   372
  }
Chengsong
parents:
diff changeset
   373
  val mkst = "abcdefghijklmnopqrstuvwxyz"
Chengsong
parents:
diff changeset
   374
  def weak_sub_check(r: Rexp, s: String, i: Int, f: (List[Rexp], Set[Rexp]) => Boolean){
Chengsong
parents:
diff changeset
   375
    //we first compute pders over the set of all strings on the alphabet
Chengsong
parents:
diff changeset
   376
    val pd = pderas(Set(r), i + 4)
Chengsong
parents:
diff changeset
   377
    //then "b-internalise" the regular expression into a brexp(this is essentially 
Chengsong
parents:
diff changeset
   378
    //attaching a bit Z to every alts to signify that they come from the original regular expression)
Chengsong
parents:
diff changeset
   379
    var old = brternalise(r)
Chengsong
parents:
diff changeset
   380
    //this is for comparison between normal simp and the weakened version of simp
Chengsong
parents:
diff changeset
   381
    //normal simp will be performed on syncold
Chengsong
parents:
diff changeset
   382
    //weakend simp will be performed on old
5
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
   383
    var syncold = internalise(r)
0
Chengsong
parents:
diff changeset
   384
    val all_chars = s.toList
Chengsong
parents:
diff changeset
   385
    for (i <- 0 to s.length - 1){
5
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
   386
      val syncder_res = bder(all_chars(i), syncold)
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
   387
      val syncsimp_res = super_bsimp(syncder_res)
0
Chengsong
parents:
diff changeset
   388
      //see brder for detailed explanation
Chengsong
parents:
diff changeset
   389
      //just changes bit Z to S when deriving an ALTS, 
Chengsong
parents:
diff changeset
   390
      //signifying that the structure has been "touched" and
Chengsong
parents:
diff changeset
   391
      //therefore able to be spilled in the bspill function
Chengsong
parents:
diff changeset
   392
      val der_res =  brder(all_chars(i), old)
Chengsong
parents:
diff changeset
   393
      val simp_res = br_simp(der_res)
Chengsong
parents:
diff changeset
   394
      val anatomy = bspill(simp_res)
Chengsong
parents:
diff changeset
   395
      //track if the number of regular expressions exceeds those in the PD set(remember PD means the pders over A*)
5
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
   396
      if(f(List(berase(simp_res)), pd)  == false ){
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
   397
        println(size(erase(syncsimp_res)))
0
Chengsong
parents:
diff changeset
   398
        println(size(berase(simp_res)))
3
f15dccc42c7b removing PRED
Chengsong
parents: 2
diff changeset
   399
        println(bregx_tree(simp_res))
5
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
   400
        println(s)
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
   401
        println(i)
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
   402
        println(r)
0
Chengsong
parents:
diff changeset
   403
        println(anatomy.map(size).sum)
Chengsong
parents:
diff changeset
   404
        println(pd.map(size).sum)
Chengsong
parents:
diff changeset
   405
      }  
Chengsong
parents:
diff changeset
   406
      old = simp_res
Chengsong
parents:
diff changeset
   407
      syncold = syncsimp_res
Chengsong
parents:
diff changeset
   408
    }
Chengsong
parents:
diff changeset
   409
  }
Chengsong
parents:
diff changeset
   410
  def inclusion_truth(anatomy: List[Rexp], pd: Set[Rexp]): Boolean = {
Chengsong
parents:
diff changeset
   411
    val aset = anatomy.toSet
Chengsong
parents:
diff changeset
   412
    if(aset subsetOf pd){
Chengsong
parents:
diff changeset
   413
      true
Chengsong
parents:
diff changeset
   414
    }
Chengsong
parents:
diff changeset
   415
    else{
Chengsong
parents:
diff changeset
   416
      println("inclusion not true")
Chengsong
parents:
diff changeset
   417
      false
Chengsong
parents:
diff changeset
   418
    }
Chengsong
parents:
diff changeset
   419
  }
Chengsong
parents:
diff changeset
   420
  def size_comp(anatomy: List[Rexp], pd: Set[Rexp]):Boolean = {println("size of PD and bspilled simp regx: ", pd.size, anatomy.size); true}
5
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
   421
  def size_expansion_rate(r: List[Rexp], pd: Set[Rexp]): Boolean = if(size(r(0)) > (pd.map(size).sum) * 3 ) { false }else {true}
4
7a349fe58bf4 :test whether bsimp(bders(r, s)) == ders_simp(r,s)
Chengsong
parents: 3
diff changeset
   422
  def ders_simp(r: ARexp, s: List[Char]): ARexp = {
7a349fe58bf4 :test whether bsimp(bders(r, s)) == ders_simp(r,s)
Chengsong
parents: 3
diff changeset
   423
    s match {
7a349fe58bf4 :test whether bsimp(bders(r, s)) == ders_simp(r,s)
Chengsong
parents: 3
diff changeset
   424
      case Nil => r 
7a349fe58bf4 :test whether bsimp(bders(r, s)) == ders_simp(r,s)
Chengsong
parents: 3
diff changeset
   425
      case c::cs => ders_simp(bsimp(bder(c, r)), cs)
7a349fe58bf4 :test whether bsimp(bders(r, s)) == ders_simp(r,s)
Chengsong
parents: 3
diff changeset
   426
    }
7a349fe58bf4 :test whether bsimp(bders(r, s)) == ders_simp(r,s)
Chengsong
parents: 3
diff changeset
   427
  }
5
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
   428
  val big_panda = STAR(STAR(STAR(ALTS(List(ALTS(List(CHAR('c'), CHAR('b'))), SEQ(CHAR('c'),CHAR('c')))))))
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
   429
  val str_panda = "ccccb"
0
Chengsong
parents:
diff changeset
   430
  def check_all(){
5
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
   431
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
   432
        weak_sub_check(big_panda, str_panda, 6, size_expansion_rate)
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
   433
0
Chengsong
parents:
diff changeset
   434
  }
5
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
   435
  //simplified regex size 291, so called pd_simp size 70 (did not do simplification to terms in the PD set)
10
2b95bcd2ac73 exp and proof
Chengsong
parents: 8
diff changeset
   436
  def pushbits(r: ARexp): ARexp = r match {
11
9c1ca6d6e190 The C(Char) construct is incompatible with the code and retrieve in Fahad's thesis.
Chengsong
parents: 10
diff changeset
   437
    case AALTS(bs, rs) => AALTS(Nil, rs.map(r=>fuse(bs, pushbits(r))))
9c1ca6d6e190 The C(Char) construct is incompatible with the code and retrieve in Fahad's thesis.
Chengsong
parents: 10
diff changeset
   438
    case ASEQ(bs, r1, r2) => ASEQ(bs, pushbits(r1), pushbits(r2))
10
2b95bcd2ac73 exp and proof
Chengsong
parents: 8
diff changeset
   439
    case r => r
2b95bcd2ac73 exp and proof
Chengsong
parents: 8
diff changeset
   440
  }
4
7a349fe58bf4 :test whether bsimp(bders(r, s)) == ders_simp(r,s)
Chengsong
parents: 3
diff changeset
   441
  def correctness_proof_convenient_path(){
11
9c1ca6d6e190 The C(Char) construct is incompatible with the code and retrieve in Fahad's thesis.
Chengsong
parents: 10
diff changeset
   442
    for(i <- 1 to 10000)
4
7a349fe58bf4 :test whether bsimp(bders(r, s)) == ders_simp(r,s)
Chengsong
parents: 3
diff changeset
   443
    {
11
9c1ca6d6e190 The C(Char) construct is incompatible with the code and retrieve in Fahad's thesis.
Chengsong
parents: 10
diff changeset
   444
        val s = rd_string_gen(alphabet_size, 3)//"abaa"//rd_string_gen(alphabet_size, 3)
9c1ca6d6e190 The C(Char) construct is incompatible with the code and retrieve in Fahad's thesis.
Chengsong
parents: 10
diff changeset
   445
        val r = internalise(random_struct_gen(4))//ASTAR(List(),AALTS(List(),List(ASTAR(List(Z),ACHAR(List(),'a')), ASEQ(List(S),ACHAR(List(),'a'),ACHAR(List(),'b')))))//internalise(balanced_struct_gen(3))//SEQ(ALTS(List(STAR("a"),ALTS(List("a","c")))),SEQ(ALTS(List("c","a")),ALTS(List("c","b")))) //random_struct_gen(7)
4
7a349fe58bf4 :test whether bsimp(bders(r, s)) == ders_simp(r,s)
Chengsong
parents: 3
diff changeset
   446
        for(j <- 0 to s.length - 1){
7a349fe58bf4 :test whether bsimp(bders(r, s)) == ders_simp(r,s)
Chengsong
parents: 3
diff changeset
   447
          val ss = s.slice(0, j+ 1)
7a349fe58bf4 :test whether bsimp(bders(r, s)) == ders_simp(r,s)
Chengsong
parents: 3
diff changeset
   448
          val nangao = ders_simp(r, ss.toList)
7a349fe58bf4 :test whether bsimp(bders(r, s)) == ders_simp(r,s)
Chengsong
parents: 3
diff changeset
   449
          val easy = bsimp(bders(ss.toList, r))
10
2b95bcd2ac73 exp and proof
Chengsong
parents: 8
diff changeset
   450
          if(!(nangao == easy || pushbits(nangao) == (easy))){
4
7a349fe58bf4 :test whether bsimp(bders(r, s)) == ders_simp(r,s)
Chengsong
parents: 3
diff changeset
   451
            println(j)
10
2b95bcd2ac73 exp and proof
Chengsong
parents: 8
diff changeset
   452
            println("not equal")
5
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
   453
            println("string")
4
7a349fe58bf4 :test whether bsimp(bders(r, s)) == ders_simp(r,s)
Chengsong
parents: 3
diff changeset
   454
            println(ss)
5
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
   455
            println("original regex")
10
2b95bcd2ac73 exp and proof
Chengsong
parents: 8
diff changeset
   456
            println(annotated_tree(r))
5
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
   457
            println("regex after ders simp")
10
2b95bcd2ac73 exp and proof
Chengsong
parents: 8
diff changeset
   458
            println(annotated_tree(nangao))
5
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
   459
            println("regex after ders")
8
Chengsong
parents: 7
diff changeset
   460
            println(annotated_tree(bders(ss.toList, r)))//flats' fuse when opening up AALTS causes the difference
5
622ddbb1223a correctness test with enumeration
Chengsong
parents: 4
diff changeset
   461
            println("regex after ders and then a single simp")
7
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   462
            println(annotated_tree(easy))
4
7a349fe58bf4 :test whether bsimp(bders(r, s)) == ders_simp(r,s)
Chengsong
parents: 3
diff changeset
   463
          }
7a349fe58bf4 :test whether bsimp(bders(r, s)) == ders_simp(r,s)
Chengsong
parents: 3
diff changeset
   464
        }
7a349fe58bf4 :test whether bsimp(bders(r, s)) == ders_simp(r,s)
Chengsong
parents: 3
diff changeset
   465
    }
7a349fe58bf4 :test whether bsimp(bders(r, s)) == ders_simp(r,s)
Chengsong
parents: 3
diff changeset
   466
  }
11
9c1ca6d6e190 The C(Char) construct is incompatible with the code and retrieve in Fahad's thesis.
Chengsong
parents: 10
diff changeset
   467
  def retrieve_experience(){
9c1ca6d6e190 The C(Char) construct is incompatible with the code and retrieve in Fahad's thesis.
Chengsong
parents: 10
diff changeset
   468
    val rg = ASTAR(List(),AALTS(List(),List(ASTAR(List(Z),ACHAR(List(),'a')), ASEQ(List(S),ACHAR(List(),'a'),ACHAR(List(),'b')))))//internalise(balanced_struct_gen(3))//SEQ(ALTS(List(STAR("a"),ALTS(List("a","c")))),SEQ(ALTS(List("c","a")),ALTS(List("c","b")))) 
9c1ca6d6e190 The C(Char) construct is incompatible with the code and retrieve in Fahad's thesis.
Chengsong
parents: 10
diff changeset
   469
    val st = "abaab"
9c1ca6d6e190 The C(Char) construct is incompatible with the code and retrieve in Fahad's thesis.
Chengsong
parents: 10
diff changeset
   470
    val vl = blexing_simp(erase(rg), st)
9c1ca6d6e190 The C(Char) construct is incompatible with the code and retrieve in Fahad's thesis.
Chengsong
parents: 10
diff changeset
   471
    val bts = retrieve(rg, vl)
9c1ca6d6e190 The C(Char) construct is incompatible with the code and retrieve in Fahad's thesis.
Chengsong
parents: 10
diff changeset
   472
    val cdbts = code(vl)
9c1ca6d6e190 The C(Char) construct is incompatible with the code and retrieve in Fahad's thesis.
Chengsong
parents: 10
diff changeset
   473
    if(bts != cdbts){//test of equality code v = retrieve internalise(r) v if |- v : r
9c1ca6d6e190 The C(Char) construct is incompatible with the code and retrieve in Fahad's thesis.
Chengsong
parents: 10
diff changeset
   474
      println(bts)
9c1ca6d6e190 The C(Char) construct is incompatible with the code and retrieve in Fahad's thesis.
Chengsong
parents: 10
diff changeset
   475
      println(cdbts)
9c1ca6d6e190 The C(Char) construct is incompatible with the code and retrieve in Fahad's thesis.
Chengsong
parents: 10
diff changeset
   476
      println("NOoooooo.....!")
9c1ca6d6e190 The C(Char) construct is incompatible with the code and retrieve in Fahad's thesis.
Chengsong
parents: 10
diff changeset
   477
    }
9c1ca6d6e190 The C(Char) construct is incompatible with the code and retrieve in Fahad's thesis.
Chengsong
parents: 10
diff changeset
   478
  }
7
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   479
  def radical_correctness(){
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   480
    enum(3, "abc").map(tests_blexer_simp(strs(3, "abc"))).toSet
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   481
    random_pool(1, 5).map(tests_blexer_simp(strs(5, "abc"))).toSet
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   482
  }
0
Chengsong
parents:
diff changeset
   483
  def main(args: Array[String]) {
4
7a349fe58bf4 :test whether bsimp(bders(r, s)) == ders_simp(r,s)
Chengsong
parents: 3
diff changeset
   484
    //check_all()   
7
1572760ff866 found the difference: caused by flats
Chengsong
parents: 6
diff changeset
   485
    //radical_correctness()
11
9c1ca6d6e190 The C(Char) construct is incompatible with the code and retrieve in Fahad's thesis.
Chengsong
parents: 10
diff changeset
   486
    //correctness_proof_convenient_path()
9c1ca6d6e190 The C(Char) construct is incompatible with the code and retrieve in Fahad's thesis.
Chengsong
parents: 10
diff changeset
   487
    retrieve_experience()
0
Chengsong
parents:
diff changeset
   488
  } 
Chengsong
parents:
diff changeset
   489
}
Chengsong
parents:
diff changeset
   490