430 def check_all(){ |
430 def check_all(){ |
431 |
431 |
432 weak_sub_check(big_panda, str_panda, 6, size_expansion_rate) |
432 weak_sub_check(big_panda, str_panda, 6, size_expansion_rate) |
433 |
433 |
434 } |
434 } |
|
435 def bstostick(bs: List[Bit]): Element = bs match { |
|
436 //case b::Nil => elem(b.toString) |
|
437 case b::bs1 => elem(b.toString) beside bstostick(bs1) |
|
438 case Nil => elem(' ', 1, 1) |
|
439 } |
|
440 def bits_print(r: ARexp): Element = r match { |
|
441 case AALTS(bs,rs) => { |
|
442 val bitstick = bstostick(bs) |
|
443 rs match { |
|
444 case r::rs1 => |
|
445 rs1.foldLeft( |
|
446 ((elem("(") left_align bitstick) beside |
|
447 bits_print(r)) )( (acc, r2) => acc beside ((elem(" + ") above elem(" ")) beside bits_print(r2) )) beside |
|
448 elem(")") |
|
449 case Nil => elem(' ', 1, 1) |
|
450 } |
|
451 } |
|
452 case ASEQ(bs, r1, r2) => { |
|
453 ((elem("[") left_align bstostick(bs)) beside bits_print(r1) beside elem("~") beside bits_print(r2)) |
|
454 } |
|
455 case ASTAR(bs, r) => { |
|
456 r match { |
|
457 case AONE(_) | AZERO | ACHAR(_, _) => { |
|
458 (elem("{") left_align bstostick(bs)) beside (bits_print(r) beside elem("}*")) |
|
459 } |
|
460 case _ => { |
|
461 (elem("{") left_align bstostick(bs)) beside (bits_print(r) beside elem("}*")) |
|
462 } |
|
463 } |
|
464 } |
|
465 case AONE(bs) => { |
|
466 elem("1") left_align bstostick(bs) |
|
467 } |
|
468 case ACHAR(bs, c) => { |
|
469 elem(c, 1, 1) left_align bstostick(bs) |
|
470 } |
|
471 case AZERO => |
|
472 { |
|
473 elem ("0") above elem(" ") |
|
474 } |
|
475 } |
|
476 def happy_print(r: Rexp): Unit = r match { |
|
477 case ALTS( r::rs ) => { |
|
478 print("(") |
|
479 happy_print(r) |
|
480 rs.map(r2=>{ |
|
481 print(" + ") |
|
482 happy_print(r2) |
|
483 }) |
|
484 print(")") |
|
485 } |
|
486 case SEQ(r1, r2) => { |
|
487 happy_print(r1) |
|
488 print("~") |
|
489 happy_print(r2) |
|
490 } |
|
491 case STAR(r) => { |
|
492 r match { |
|
493 case ONE | ZERO | CHAR(_) => { |
|
494 happy_print(r) |
|
495 print("*") |
|
496 } |
|
497 case _ => { |
|
498 print("[") |
|
499 happy_print(r) |
|
500 print("]*") |
|
501 } |
|
502 } |
|
503 } |
|
504 case ONE => { |
|
505 print("1") |
|
506 } |
|
507 case ZERO => { |
|
508 print("0") |
|
509 } |
|
510 case CHAR(c) =>{ |
|
511 print(c) |
|
512 } |
|
513 } |
|
514 def bits_slide(s: String, r: Rexp){ |
|
515 val nangao = ders_simp(internalise(r), s.toList) |
|
516 val easy = bsimp(bders(s.toList, internalise(r))) |
|
517 println(s) |
|
518 println(r) |
|
519 happy_print(r) |
|
520 println() |
|
521 print(bits_print(nangao)) |
|
522 println() |
|
523 print(bits_print(easy)) |
|
524 println() |
|
525 } |
|
526 //found r = SEQ(ALTS(List(CHAR(c), CHAR(a))),SEQ(ALTS(List(CHAR(a), CHAR(c))),ALTS(List(CHAR(b), CHAR(c))))) s = "aa" |
|
527 def bsimp_print(r: ARexp): Unit = r match { |
|
528 case ASEQ(bs, r1, r2) => |
|
529 { |
|
530 println("0.r or r.0 to 0 or bs1 1.r to fuse bs++bs1 r") |
|
531 bits_print(bsimp(r1)) |
|
532 bits_print(bsimp(r2)) |
|
533 } |
|
534 case AALTS(bs, rs) => { |
|
535 println("rs.map(bsimp) equals *************") |
|
536 val rs_simp = rs.map(bsimp) |
|
537 for(r <- rs_simp){ |
|
538 println(bits_print(r)) |
|
539 } |
|
540 println("*************") |
|
541 println("flts(rs_simp)") |
|
542 val flat_res = flats(rs_simp) |
|
543 for(r <- flat_res){ |
|
544 println(bits_print(r)) |
|
545 } |
|
546 println("dB(flat_res)") |
|
547 val dist_res = distinctBy(flat_res, erase) |
|
548 for(r <- dist_res){ |
|
549 println(bits_print(r)) |
|
550 } |
|
551 dist_res match { |
|
552 case Nil => println("AZERO") |
|
553 case r::Nil => println("fuse(bs, r)") |
|
554 case rs => println("AALTS(bs, rs)") |
|
555 } |
|
556 } |
|
557 case _ => println("No simp at this level") |
|
558 } |
|
559 def tellmewhy(){ |
|
560 //val r = SEQ(ALTS(List(CHAR('a'), CHAR('b'))),ALTS(List(ALTS(List(CHAR('a'), CHAR('a'))), STAR(CHAR('a'))))) |
|
561 val r = SEQ(ALTS(List(CHAR('a'), CHAR('b'))),ALTS(List(CHAR('a'), STAR(CHAR('a')) ) )) |
|
562 //val r = ("a"|"b")~("a") |
|
563 val s = "aa" |
|
564 for(i <- 0 to s.length-1){ |
|
565 val ss = s.slice(0, i+1) |
|
566 val nangao = ders_simp(internalise(r), ss.toList) |
|
567 val easy = (bders(ss.toList, internalise(r))) |
|
568 println(bits_print(nangao)) |
|
569 println(bits_print(easy)) |
|
570 println() |
|
571 bsimp_print(easy) |
|
572 } |
|
573 println(bits_print(bsimp(bders(s.toList, internalise(r))))) |
|
574 println(bits_print(ders_simp(internalise(r), s.toList)) |
|
575 } |
|
576 def find_re(){ |
|
577 for (i <- 1 to 10000){ |
|
578 val r = balanced_struct_gen(3) |
|
579 val s = rd_string_gen(2,1) |
|
580 val nangao = ders_simp(internalise(r), s.toList) |
|
581 val easy = bsimp(bders(s.toList, internalise(r))) |
|
582 if(nangao != easy){ |
|
583 bits_slide(s, r) |
|
584 } |
|
585 } |
|
586 } |
435 //simplified regex size 291, so called pd_simp size 70 (did not do simplification to terms in the PD set) |
587 //simplified regex size 291, so called pd_simp size 70 (did not do simplification to terms in the PD set) |
436 def pushbits(r: ARexp): ARexp = r match { |
588 def pushbits(r: ARexp): ARexp = r match { |
437 case AALTS(bs, rs) => AALTS(Nil, rs.map(r=>fuse(bs, pushbits(r)))) |
589 case AALTS(bs, rs) => AALTS(Nil, rs.map(r=>fuse(bs, pushbits(r)))) |
438 case ASEQ(bs, r1, r2) => ASEQ(bs, pushbits(r1), pushbits(r2)) |
590 case ASEQ(bs, r1, r2) => ASEQ(bs, pushbits(r1), pushbits(r2)) |
439 case r => r |
591 case r => r |
440 } |
592 } |
441 def correctness_proof_convenient_path(){ |
593 def correctness_proof_convenient_path(){ |
442 for(i <- 1 to 10000) |
|
443 { |
|
444 val s = "abab"//rd_string_gen(alphabet_size, 3)//"abaa"//rd_string_gen(alphabet_size, 3) |
594 val s = "abab"//rd_string_gen(alphabet_size, 3)//"abaa"//rd_string_gen(alphabet_size, 3) |
445 val r = ("ab"| SEQ(ONE, "ab"))//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) |
595 val r = ("ab"| SEQ(ONE, "ab"))//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) |
446 for(j <- 0 to s.length - 1){ |
596 for(j <- 0 to s.length - 1){ |
447 val ss = s.slice(0, j+ 1) |
597 val ss = s.slice(0, j+ 1) |
448 val nangao = ders_simp(internalise(r), ss.toList) |
598 val nangao = ders_simp(internalise(r), ss.toList) |