LBA
Linear Bounded Automaton (LBA) class in pykleene
states: set[str]
inputAlphabet: set[str]
tapeAlphabet: set[str]
startState: str
transitions: dict[tuple[str, str], tuple[str, str, str]]
leftEndMarker: str
rightEndMarker: str
blankSymbol: str
acceptState: str
rejectState: str
CONSTRUCTOR
Initialize a new Linear Bounded Automaton with specified parameters.
Parameters
states
: Set of states in the LBAinputAlphabet
: Set of input symbolstapeAlphabet
: Set of tape symbolsstartState
: Initial state of the LBAtransitions
: Mapping of state-symbol pairs to next state, write symbol, and directionleftEndMarker
: Marker for the left end of the taperightEndMarker
: Marker for the right end of the tapeblankSymbol
: Symbol used to represent empty tape cellsacceptState
: State indicating successful computationrejectState
: State indicating failed computation
Return Value
Creates a new LBA object with specified configuration
loadFromJSONDict
Load LBA configuration from a JSON dictionary.
# Example
{
"LBA_ADD": {
"states": ["q0", "q1", "q2", "t", "r"],
"inputAlphabet": ["0", "1"],
"tapeAlphabet": ["0", "1", "#", "♭", "⊢", "⊣"],
"startState": "q0",
"transitions": [
["q0", "⊢", "q0", "⊢", "R"],
["q0", "1", "q0", "1", "R"],
["q0", "#", "q0", "1", "R"],
["q0", "♭", "q1", "♭", "L"],
["q1", "1", "q2", "♭", "L"],
["q2", "1", "q2", "1", "L"],
["q2", "⊢", "t", "⊢", "S"]
],
"leftEndMarker": "⊢",
"rightEndMarker": "⊣",
"blankSymbol": "♭",
"acceptState": "t",
"rejectState": "r"
}
}
Parameters
jsonDict
: Dictionary containing LBA configuration
Return Value
Populates the LBA object with configuration from the dictionary
isValid
Validate the LBA configuration.
Parameters
None
Return Value
Boolean indicating whether the LBA configuration is valid
accepts
Determine if a given string is accepted by the LBA.
Parameters
inputString
: Input string to be processedverbose
: Boolean to enable detailed computation tracingtapeLenFunc
: Function to determine tape length based on input length
Return Value
Tuple of (acceptance boolean, final tape contents)
image
Generate a graphical representation of the LBA.
Parameters
dir
: Directory to save the imagesave
: Boolean to determine if image should be savedmonochrome
: Boolean to generate a black and white visualization
Return Value
Graphviz Digraph object representing the Linear Bounded Automaton