Skip to content

Commit

Permalink
branch on small domains
Browse files Browse the repository at this point in the history
  • Loading branch information
breandan committed May 25, 2024
1 parent f4c9841 commit 789f398
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ class PTree(val root: String = ".ε", val branches: List<Π2A<PTree>> = listOf()
}

fun sampleStrWithoutReplacement(stride: Int = 1, offset: Int = 0): Sequence<String> =
bigLFSRSequence(totalTrees)
if (totalTrees.bitLength() < 5) sequence {
var i = BigInteger.ZERO
while (i < totalTrees) { yield(newDecoder(i)); i++}
} else bigLFSRSequence(totalTrees)
.mapIndexedNotNull { index, i -> if (index % stride == offset) newDecoder(i) else null }

fun sampleStrWithPCFG5(pcfgTable: Map<Int, Int>): Sequence<String> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,13 @@ class BarHillelTest {
val origStr = "T and ! ( F )"
val levCFG = arithCFGNoEps.intersectLevFSA(makeLevFSA(origStr, 1))

val lbhSet = levCFG.toPTree().sampleStrWithoutReplacement().toSet()//.onEach { println(it) }
val lbhSet = levCFG.toPTree().sampleStrWithoutReplacement().toSet()
.onEach { println(levenshteinAlign(it, origStr).paintANSIColors()) }
.also { println("Found ${it.size} solutions using Levenshtein/Bar-Hillel") }

val efset = arithCFG.solveSeq(List(8) { "_" }).toList()
.filter { levenshtein(it, origStr) < 2 }.toSet()
// .onEach { println(it) }
.onEach { println(levenshteinAlign(it, origStr).paintANSIColors()) }
.also { println("Found ${it.size} solutions using enumerative filtering") }

assertEquals(lbhSet, efset, "Levenshtein/Bar-Hillel and enumerative filtering should return the same solutions")
Expand Down

0 comments on commit 789f398

Please sign in to comment.