pyk.kast.manip module¶
- abstract_term_safely(kast: KInner, base_name: str = 'V', sort: KSort | None = None, existing_var_names: set[str] | None = None) KVariable [source]¶
- apply_existential_substitutions(state: KInner, constraints: Iterable[KInner]) tuple[KInner, Iterable[KInner]] [source]¶
- build_claim(claim_id: str, init_config: KInner, final_config: KInner, init_constraints: Iterable[KInner] = (), final_constraints: Iterable[KInner] = (), keep_vars: Iterable[str] = ()) tuple[KClaim, Subst] [source]¶
Return a KClaim between the supplied initial and final states.
- Parameters:
claim_id – Label to give the claim.
init_config – State to put on LHS of the rule.
final_config – State to put on RHS of the rule.
init_constraints – Constraints to use as requires clause.
final_constraints – Constraints to use as ensures clause.
keep_vars – Variables to leave in the side-conditions even if not bound in the configuration.
- Returns:
tuple claim: KClaim, var_map: Subst: - claim: A KClaim with variable naming conventions applied so that it should be parseable by K frontend. - var_map: The variable renamings that happened to make the claim parseable by K frontend (which can be undone to recover original variables).
- build_rule(rule_id: str, init_config: KInner, final_config: KInner, init_constraints: Iterable[KInner] = (), final_constraints: Iterable[KInner] = (), priority: int | None = None, keep_vars: Iterable[str] = ()) tuple[KRule, Subst] [source]¶
Return a KRule between the supplied initial and final states.
- Parameters:
rule_id – Label to give the rule.
init_config – State to put on LHS of the rule.
final_config – State to put on RHS of the rule.
init_constraints – Constraints to use as requires clause.
final_constraints – Constraints to use as ensures clause.
priority – Rule priority to give to the generated KRule.
keep_vars – Variables to leave in the side-conditions even if not bound in the configuration.
- Returns:
tuple claim: KRule, var_map: Subst such that: - rule: A KRule with variable naming conventions applied so that it should be parseable by K frontend. - var_map: The variable renamings that happened to make the claim parseable by K frontend (which can be undone to recover original variables).
- collapse_dots(kast: KInner) KInner [source]¶
Given a configuration with structural frames …, minimize the structural frames needed.
Input: a configuration, potentially with structural frames.
Output: the same configuration, with the amount of structural framing minimized.
- flatten_label(label: str, kast: KInner) list[KInner] [source]¶
Given a cons list, return a flat Python list of the elements.
Input: Cons operation to flatten.
Output: Items of cons list.
- inline_cell_maps(kast: KInner) KInner [source]¶
Ensure that cell map collections are printed nicely, not as Maps.”
Input: kast term.
Output: kast term with cell maps inlined.
- labels_to_dots(kast: KInner, labels: Collection[str]) KInner [source]¶
Abstract specific labels for printing.
Input: kast term, and list of labels to abstract.
Output: kast term with those labels abstracted.
- minimize_rule(rule: RL, keep_vars: Iterable[str] = ()) RL [source]¶
Minimize a K rule or claim for pretty-printing.
Input: kast representing a K rule or claim.
Output: kast with the rule or claim minimized: - Variables only used once will be removed. - Unused cells will be abstracted. - Attempt to remove useless side-conditions.
- minimize_term(term: KInner, keep_vars: Iterable[str] = (), abstract_labels: Collection[str] = (), keep_cells: Collection[str] = ()) KInner [source]¶
Minimize a K term for pretty-printing.
Input: kast term, and optionally requires and ensures clauses with constraints.
Output: kast term minimized. - Variables only used once will be removed. - Unused cells will be abstracted. - Attempt to remove useless conditions.
- no_cell_rewrite_to_dots(term: KInner) KInner [source]¶
Transforms a given term by replacing the contents of each cell with dots if the LHS and RHS are the same.
This function recursively traverses the cells in a term. When it finds a cell whose left-hand side (LHS) is identical to its right-hand side (RHS), it replaces the cell’s contents with a predefined DOTS.
Parameters: - term (KInner): The term to be transformed.
Returns: - KInner: The transformed term, where specific cell contents have been replaced with dots.
- remove_generated_cells(term: KInner) KInner [source]¶
Remove <generatedTop> and <generatedCounter> from a configuration.
Input: Constrained term.
Output: Constrained term with those cells removed.
- remove_semantic_casts(kast: KInner) KInner [source]¶
Remove injected #SemanticCast* nodes in AST.
Input: kast (possibly) containing automatically injected #SemanticCast* KApply nodes.
Output: kast without the #SemanticCast* nodes.
- remove_source_map(definition: KDefinition) KDefinition [source]¶
- remove_useless_constraints(constraints: Iterable[KInner], initial_vars: Iterable[str]) list[KInner] [source]¶
Given a list of constraints and a list of variables, return an updated list with only constraints that depend on these variables (directly or indirectly).
- Parameters:
constraints – Original list of constraints to remove from.
initial_vars – Initial list of variables to keep constraints for.
- Returns:
A list of constraints with only those constraints that contain the initial variables or variables that depend on those through other constraints in the list.
- split_config_from(configuration: KInner) tuple[KInner, dict[str, KInner]] [source]¶
Split the substitution from a given configuration.
Given an input configuration config, will return a tuple (symbolic_config, subst), where:
config == substitute(symbolic_config, subst)
symbolic_config is the same configuration structure, but where the contents of leaf cells is replaced with a fresh KVariable.
subst is the substitution for the generated KVariables back to the original configuration contents.
- undo_aliases(definition: KDefinition, kast: KInner) KInner [source]¶