progs/thompson.scala
author Christian Urban <urbanc@in.tum.de>
Tue, 08 Oct 2019 21:12:52 +0100
changeset 649 e83afb44f276
parent 586 451a95e1bc25
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
487
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
     1
// Thompson Construction
491
d5776c6018f0 updated
Christian Urban <urbanc@in.tum.de>
parents: 489
diff changeset
     2
// (needs  :load dfa.scala
d5776c6018f0 updated
Christian Urban <urbanc@in.tum.de>
parents: 489
diff changeset
     3
//         :load nfa.scala
487
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
     4
//         :load enfa.scala)
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
     5
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
     6
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
     7
// states for Thompson construction
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
     8
case class TState(i: Int) extends State
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
     9
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    10
object TState {
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    11
  var counter = 0
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    12
  
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    13
  def apply() : TState = {
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    14
    counter += 1;
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    15
    new TState(counter - 1)
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    16
  }
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    17
}
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    18
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    19
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    20
// some types abbreviations
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    21
type NFAt = NFA[TState, Char]
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    22
type NFAtrans = (TState, Char) :=> Set[TState]
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    23
type eNFAtrans = (TState, Option[Char]) :=> Set[TState]
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    24
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    25
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    26
// for composing an eNFA transition with a NFA transition
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    27
implicit class RichPF(val f: eNFAtrans) extends AnyVal {
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    28
  def +++(g: NFAtrans) : eNFAtrans = 
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    29
  { case (q, None) =>  applyOrElse(f, (q, None)) 
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    30
    case (q, Some(c)) => applyOrElse(f, (q, Some(c))) | applyOrElse(g, (q, c))  }
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    31
}
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    32
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    33
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    34
// NFA that does not accept any string
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    35
def NFA_ZERO(): NFAt = {
486
8178fcf377dc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
  val Q = TState()
8178fcf377dc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
  NFA(Set(Q), { case _ => Set() }, Set())
8178fcf377dc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
}
8178fcf377dc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
487
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    40
// NFA that accepts the empty string
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    41
def NFA_ONE() : NFAt = {
486
8178fcf377dc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
  val Q = TState()
8178fcf377dc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
  NFA(Set(Q), { case _ => Set() }, Set(Q))
8178fcf377dc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
}
8178fcf377dc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
487
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    46
// NFA that accepts the string "c"
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    47
def NFA_CHAR(c: Char) : NFAt = {
486
8178fcf377dc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
  val Q1 = TState()
8178fcf377dc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
  val Q2 = TState()
8178fcf377dc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
  NFA(Set(Q1), { case (Q1, d) if (c == d) => Set(Q2) }, Set(Q2))
8178fcf377dc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
}
8178fcf377dc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
487
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    53
// sequence of two NFAs
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    54
def NFA_SEQ(enfa1: NFAt, enfa2: NFAt) : NFAt = {
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    55
  val new_delta : eNFAtrans = 
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    56
    { case (q, None) if enfa1.fins(q) => enfa2.starts }
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    57
  
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    58
  eNFA(enfa1.starts, new_delta +++ enfa1.delta +++ enfa2.delta, 
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    59
       enfa2.fins)
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    60
}
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    61
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    62
// alternative of two NFAs
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    63
def NFA_ALT(enfa1: NFAt, enfa2: NFAt) : NFAt = {
489
e28d7a327870 updated
Christian Urban <urbanc@in.tum.de>
parents: 488
diff changeset
    64
  val new_delta : NFAtrans = { 
e28d7a327870 updated
Christian Urban <urbanc@in.tum.de>
parents: 488
diff changeset
    65
    case (q, c) =>  applyOrElse(enfa1.delta, (q, c)) | 
e28d7a327870 updated
Christian Urban <urbanc@in.tum.de>
parents: 488
diff changeset
    66
                    applyOrElse(enfa2.delta, (q, c)) }
486
8178fcf377dc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
  val new_fins = (q: TState) => enfa1.fins(q) || enfa2.fins(q)
8178fcf377dc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
489
e28d7a327870 updated
Christian Urban <urbanc@in.tum.de>
parents: 488
diff changeset
    69
  NFA(enfa1.starts | enfa2.starts, new_delta, new_fins)
486
8178fcf377dc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
}
8178fcf377dc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
487
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    72
// star of a NFA
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    73
def NFA_STAR(enfa: NFAt) : NFAt = {
486
8178fcf377dc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
  val Q = TState()
8178fcf377dc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
  val new_delta : eNFAtrans = 
8178fcf377dc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
    { case (Q, None) => enfa.starts
8178fcf377dc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
      case (q, None) if enfa.fins(q) => Set(Q) }
8178fcf377dc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
487
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    79
  eNFA(Set(Q), new_delta +++ enfa.delta, Set(Q))
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    80
}
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    81
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    82
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    83
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    84
// regular expressions
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    85
abstract class Rexp
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    86
case object ZERO extends Rexp                    // matches nothing
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    87
case object ONE extends Rexp                     // matches the empty string
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    88
case class CHAR(c: Char) extends Rexp            // matches a character c
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    89
case class ALT(r1: Rexp, r2: Rexp) extends Rexp  // alternative
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    90
case class SEQ(r1: Rexp, r2: Rexp) extends Rexp  // sequence
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    91
case class STAR(r: Rexp) extends Rexp            // star
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    92
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    93
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    94
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    95
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    96
// thompson construction 
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    97
def thompson (r: Rexp) : NFAt = r match {
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    98
  case ZERO => NFA_ZERO()
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
    99
  case ONE => NFA_ONE()
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   100
  case CHAR(c) => NFA_CHAR(c)  
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   101
  case ALT(r1, r2) => NFA_ALT(thompson(r1), thompson(r2))
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   102
  case SEQ(r1, r2) => NFA_SEQ(thompson(r1), thompson(r2))
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   103
  case STAR(r1) => NFA_STAR(thompson(r1))
486
8178fcf377dc updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
}
487
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   105
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   106
//optional regular expression (one or zero times)
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   107
def OPT(r: Rexp) = ALT(r, ONE)
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   108
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   109
//n-times regular expression (explicitly expanded)
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   110
def NTIMES(r: Rexp, n: Int) : Rexp = n match {
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   111
  case 0 => ONE
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   112
  case 1 => r
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   113
  case n => SEQ(r, NTIMES(r, n - 1))
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   114
}
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   115
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   116
488
598741d39d21 updated
Christian Urban <urbanc@in.tum.de>
parents: 487
diff changeset
   117
def tmatches(r: Rexp, s: String) : Boolean =
598741d39d21 updated
Christian Urban <urbanc@in.tum.de>
parents: 487
diff changeset
   118
  thompson(r).accepts(s.toList)
598741d39d21 updated
Christian Urban <urbanc@in.tum.de>
parents: 487
diff changeset
   119
598741d39d21 updated
Christian Urban <urbanc@in.tum.de>
parents: 487
diff changeset
   120
def tmatches2(r: Rexp, s: String) : Boolean =
598741d39d21 updated
Christian Urban <urbanc@in.tum.de>
parents: 487
diff changeset
   121
  thompson(r).accepts2(s.toList)
598741d39d21 updated
Christian Urban <urbanc@in.tum.de>
parents: 487
diff changeset
   122
491
d5776c6018f0 updated
Christian Urban <urbanc@in.tum.de>
parents: 489
diff changeset
   123
// dfa via subset construction
d5776c6018f0 updated
Christian Urban <urbanc@in.tum.de>
parents: 489
diff changeset
   124
def tmatches_dfa(r: Rexp, s: String) : Boolean =
d5776c6018f0 updated
Christian Urban <urbanc@in.tum.de>
parents: 489
diff changeset
   125
  subset(thompson(r)).accepts(s.toList)
488
598741d39d21 updated
Christian Urban <urbanc@in.tum.de>
parents: 487
diff changeset
   126
487
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   127
// Test Cases
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   128
488
598741d39d21 updated
Christian Urban <urbanc@in.tum.de>
parents: 487
diff changeset
   129
487
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   130
// the evil regular expression  a?{n} a{n}
489
e28d7a327870 updated
Christian Urban <urbanc@in.tum.de>
parents: 488
diff changeset
   131
def EVIL1(n: Int) : Rexp = SEQ(NTIMES(OPT(CHAR('a')), n), NTIMES(CHAR('a'), n))
487
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   132
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   133
// the evil regular expression (a*)*b
489
e28d7a327870 updated
Christian Urban <urbanc@in.tum.de>
parents: 488
diff changeset
   134
val EVIL2 : Rexp = SEQ(STAR(STAR(CHAR('a'))), CHAR('b'))
487
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   135
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   136
//for measuring time
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   137
def time_needed[T](i: Int, code: => T) = {
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   138
  val start = System.nanoTime()
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   139
  for (j <- 1 to i) code
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   140
  val end = System.nanoTime()
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   141
  (end - start)/(i * 1.0e9)
488
598741d39d21 updated
Christian Urban <urbanc@in.tum.de>
parents: 487
diff changeset
   142
}
487
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   143
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   144
// the size of the NFA can be large, 
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   145
// thus slowing down the breadth-first search
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   146
489
e28d7a327870 updated
Christian Urban <urbanc@in.tum.de>
parents: 488
diff changeset
   147
for (i <- 1 to 13) {
487
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   148
  println(i + ": " + "%.5f".format(time_needed(2, tmatches(EVIL1(i), "a" * i))))
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   149
}
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   150
489
e28d7a327870 updated
Christian Urban <urbanc@in.tum.de>
parents: 488
diff changeset
   151
for (i <- 1 to 100 by 5) {
487
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   152
  println(i + " " + "%.5f".format(time_needed(2, tmatches(EVIL2, "a" * i))))
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   153
}
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   154
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   155
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   156
// the backtracking needed in depth-first search 
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   157
// can be painfully slow
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   158
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   159
for (i <- 1 to 8) {
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   160
  println(i + " " + "%.5f".format(time_needed(2, tmatches2(EVIL2, "a" * i))))
a697421eaa04 updated
Christian Urban <urbanc@in.tum.de>
parents: 486
diff changeset
   161
}
491
d5776c6018f0 updated
Christian Urban <urbanc@in.tum.de>
parents: 489
diff changeset
   162
d5776c6018f0 updated
Christian Urban <urbanc@in.tum.de>
parents: 489
diff changeset
   163
d5776c6018f0 updated
Christian Urban <urbanc@in.tum.de>
parents: 489
diff changeset
   164
586
Christian Urban <urbanc@in.tum.de>
parents: 521
diff changeset
   165
// while my thompson->enfa->subset->partial-function-chain
491
d5776c6018f0 updated
Christian Urban <urbanc@in.tum.de>
parents: 489
diff changeset
   166
// is probably not the most effcient way to obtain a fast DFA 
521
95af9beb4b7f updated
cu
parents: 491
diff changeset
   167
// (the test below should be much faster with a more direct 
95af9beb4b7f updated
cu
parents: 491
diff changeset
   168
// construction), in general the DFAs can be slow because of 
95af9beb4b7f updated
cu
parents: 491
diff changeset
   169
// the state explosion in the subset construction
491
d5776c6018f0 updated
Christian Urban <urbanc@in.tum.de>
parents: 489
diff changeset
   170
d5776c6018f0 updated
Christian Urban <urbanc@in.tum.de>
parents: 489
diff changeset
   171
for (i <- 1 to 13) {
d5776c6018f0 updated
Christian Urban <urbanc@in.tum.de>
parents: 489
diff changeset
   172
  println(i + ": " + "%.5f".format(time_needed(2, tmatches_dfa(EVIL1(i), "a" * i))))
d5776c6018f0 updated
Christian Urban <urbanc@in.tum.de>
parents: 489
diff changeset
   173
}
d5776c6018f0 updated
Christian Urban <urbanc@in.tum.de>
parents: 489
diff changeset
   174
d5776c6018f0 updated
Christian Urban <urbanc@in.tum.de>
parents: 489
diff changeset
   175
for (i <- 1 to 100 by 5) {
d5776c6018f0 updated
Christian Urban <urbanc@in.tum.de>
parents: 489
diff changeset
   176
  println(i + " " + "%.5f".format(time_needed(2, tmatches_dfa(EVIL2, "a" * i))))
d5776c6018f0 updated
Christian Urban <urbanc@in.tum.de>
parents: 489
diff changeset
   177
}