code
stringlengths
26
870k
docstring
stringlengths
1
65.6k
func_name
stringlengths
1
194
language
stringclasses
1 value
repo
stringlengths
8
68
path
stringlengths
5
194
url
stringlengths
46
254
license
stringclasses
4 values
def remove_generated_cells(term: KInner) -> KInner: """Remove <generatedTop> and <generatedCounter> from a configuration. Args: term: A term. Returns: The term with those cells removed. """ rewrite = KRewrite(KApply('<generatedTop>', [KVariable('CONFIG'), KVariable('_')]), KVariable('CONFIG')) return rewrite(term)
Remove <generatedTop> and <generatedCounter> from a configuration. Args: term: A term. Returns: The term with those cells removed.
remove_generated_cells
python
runtimeverification/k
pyk/src/pyk/kast/manip.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/manip.py
BSD-3-Clause
def remove_useless_constraints(constraints: Iterable[KInner], initial_vars: Iterable[str]) -> list[KInner]: """Remove constraints that do not depend on a given iterable of variables (directly or indirectly). Args: constraints: Iterable of constraints to filter. initial_vars: Initial iterable 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. """ used_vars = list(initial_vars) prev_len_used_vars = 0 new_constraints = [] while len(used_vars) > prev_len_used_vars: prev_len_used_vars = len(used_vars) for c in constraints: if c not in new_constraints: new_vars = free_vars(c) if any(v in used_vars for v in new_vars): new_constraints.append(c) used_vars.extend(new_vars) used_vars = list(set(used_vars)) return new_constraints
Remove constraints that do not depend on a given iterable of variables (directly or indirectly). Args: constraints: Iterable of constraints to filter. initial_vars: Initial iterable 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.
remove_useless_constraints
python
runtimeverification/k
pyk/src/pyk/kast/manip.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/manip.py
BSD-3-Clause
def 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]: """Return a `KClaim` between the supplied initial and final states. Args: 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: A tuple ``(claim, var_map)`` where - ``claim``: A `KClaim` with variable naming conventions applied so that it should be parseable by the K Frontend. - ``var_map``: The variable renamings applied to make the claim parseable by the K Frontend (which can be undone to recover the original variables). """ rule, var_map = build_rule( claim_id, init_config, final_config, init_constraints, final_constraints, keep_vars=keep_vars ) claim = KClaim(rule.body, requires=rule.requires, ensures=rule.ensures, att=rule.att) return claim, var_map
Return a `KClaim` between the supplied initial and final states. Args: 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: A tuple ``(claim, var_map)`` where - ``claim``: A `KClaim` with variable naming conventions applied so that it should be parseable by the K Frontend. - ``var_map``: The variable renamings applied to make the claim parseable by the K Frontend (which can be undone to recover the original variables).
build_claim
python
runtimeverification/k
pyk/src/pyk/kast/manip.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/manip.py
BSD-3-Clause
def 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] = (), defunc_with: KDefinition | None = None, ) -> tuple[KRule, Subst]: """Return a `KRule` between the supplied initial and final states. Args: 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: Priority index to assign to generated rules. keep_vars: Variables to leave in the side-conditions even if not bound in the configuration. defunc_with: KDefinition for filtering out function symbols on LHS of rules. Returns: A tuple ``(rule, var_map)`` where - ``rule``: A `KRule` with variable naming conventions applied so that it should be parseable by the K Frontend. - ``var_map``: The variable renamings applied to make the rule parseable by the K Frontend (which can be undone to recover the original variables). """ init_constraints = [normalize_ml_pred(c) for c in init_constraints] final_constraints = [normalize_ml_pred(c) for c in final_constraints] final_constraints = [c for c in final_constraints if c not in init_constraints] if defunc_with is not None: init_config, new_constraints = defunctionalize(defunc_with, init_config) init_constraints = init_constraints + new_constraints init_term = mlAnd([init_config] + init_constraints) final_term = mlAnd([final_config] + final_constraints) lhs_vars = free_vars(init_term) rhs_vars = free_vars(final_term) occurrences = var_occurrences( mlAnd( [push_down_rewrites(KRewrite(init_config, final_config))] + init_constraints + final_constraints, GENERATED_TOP_CELL, ) ) sorted_vars = keep_vars_sorted(occurrences) v_subst: dict[str, KVariable] = {} vremap_subst: dict[str, KVariable] = {} for v in occurrences: new_v = v if len(occurrences[v]) == 1: new_v = '_' + new_v if v in rhs_vars and v not in lhs_vars: new_v = '?' + new_v if new_v != v: v_subst[v] = KVariable(new_v, sorted_vars[v].sort) vremap_subst[new_v] = sorted_vars[v] new_init_config = Subst(v_subst)(init_config) new_init_constraints = [Subst(v_subst)(c) for c in init_constraints] new_final_config, new_final_constraints = apply_existential_substitutions( Subst(v_subst)(final_config), [Subst(v_subst)(c) for c in final_constraints] ) rule_body = push_down_rewrites(KRewrite(new_init_config, new_final_config)) rule_requires = simplify_bool(ml_pred_to_bool(mlAnd(new_init_constraints))) rule_ensures = simplify_bool(ml_pred_to_bool(mlAnd(new_final_constraints))) att_entries = [] if priority is None else [Atts.PRIORITY(str(priority))] rule_att = KAtt(entries=att_entries) rule = KRule(rule_body, requires=rule_requires, ensures=rule_ensures, att=rule_att) rule = rule.update_atts([Atts.LABEL(rule_id)]) return (rule, Subst(vremap_subst))
Return a `KRule` between the supplied initial and final states. Args: 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: Priority index to assign to generated rules. keep_vars: Variables to leave in the side-conditions even if not bound in the configuration. defunc_with: KDefinition for filtering out function symbols on LHS of rules. Returns: A tuple ``(rule, var_map)`` where - ``rule``: A `KRule` with variable naming conventions applied so that it should be parseable by the K Frontend. - ``var_map``: The variable renamings applied to make the rule parseable by the K Frontend (which can be undone to recover the original variables).
build_rule
python
runtimeverification/k
pyk/src/pyk/kast/manip.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/manip.py
BSD-3-Clause
def no_cell_rewrite_to_dots(term: KInner) -> KInner: """Transform 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. Args: term: The term to be transformed. Returns: The transformed term, where specific cell contents have been replaced with dots. """ def _no_cell_rewrite_to_dots(_term: KInner) -> KInner: if type(_term) is KApply and _term.is_cell: lhs = extract_lhs(_term) rhs = extract_rhs(_term) if lhs == rhs: return KApply(_term.label, [DOTS]) return _term config, _subst = split_config_from(term) subst = Subst({cell_name: _no_cell_rewrite_to_dots(cell_contents) for cell_name, cell_contents in _subst.items()}) return subst(config)
Transform 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. Args: term: The term to be transformed. Returns: The transformed term, where specific cell contents have been replaced with dots.
no_cell_rewrite_to_dots
python
runtimeverification/k
pyk/src/pyk/kast/manip.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/manip.py
BSD-3-Clause
def defunctionalize(defn: KDefinition, kinner: KInner) -> tuple[KInner, list[KInner]]: """Turn non-constructor arguments into side-conditions so that a term is only constructor-like. Args: defn: The definition to pull function label information from. kinner: The term to defunctionalize. Returns: A tuple of the defunctionalized term and the list of constraints generated. """ function_symbols = [prod.klabel for prod in defn.functions if prod.klabel is not None] constraints: list[KInner] = [] def _defunctionalize(_kinner: KInner) -> KInner: if type(_kinner) is KApply and _kinner.label in function_symbols: sort = defn.sort(_kinner) assert sort is not None new_var = abstract_term_safely(_kinner, base_name='F', sort=sort) var_constraint = mlEquals(new_var, _kinner, arg_sort=sort) constraints.append(var_constraint) return new_var return _kinner new_kinner = top_down(_defunctionalize, kinner) return (new_kinner, list(unique(constraints)))
Turn non-constructor arguments into side-conditions so that a term is only constructor-like. Args: defn: The definition to pull function label information from. kinner: The term to defunctionalize. Returns: A tuple of the defunctionalized term and the list of constraints generated.
defunctionalize
python
runtimeverification/k
pyk/src/pyk/kast/manip.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/manip.py
BSD-3-Clause
def __init__(self, name: str): """Construct a new sort given the name.""" object.__setattr__(self, 'name', name)
Construct a new sort given the name.
__init__
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def let(self, *, name: str | None = None) -> KSort: """Return a new `KSort` with the name potentially updated.""" name = name if name is not None else self.name return KSort(name=name)
Return a new `KSort` with the name potentially updated.
let
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def __init__(self, name: str, *args: Any, **kwargs: Any): """Construct a new `KLabel`, with optional sort parameters.""" if kwargs: bad_arg = next((arg for arg in kwargs if arg != 'params'), None) if bad_arg: raise TypeError(f'KLabel() got an unexpected keyword argument: {bad_arg}') if args: raise TypeError('KLabel() got multiple values for argument: params') params = kwargs['params'] elif ( len(args) == 1 and isinstance(args[0], Iterable) and not isinstance(args[0], str) and not isinstance(args[0], KInner) ): params = args[0] else: params = args params = tuple(KSort(param) if type(param) is str else param for param in params) object.__setattr__(self, 'name', name) object.__setattr__(self, 'params', params)
Construct a new `KLabel`, with optional sort parameters.
__init__
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def __iter__(self) -> Iterator[str | KSort]: """Return this symbol as iterator with the name as the head and the parameters as the tail.""" return chain([self.name], self.params)
Return this symbol as iterator with the name as the head and the parameters as the tail.
__iter__
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def let(self, *, name: str | None = None, params: Iterable[str | KSort] | None = None) -> KLabel: """Return a copy of this `KLabel` with potentially the name or sort parameters updated.""" name = name if name is not None else self.name params = params if params is not None else self.params return KLabel(name=name, params=params)
Return a copy of this `KLabel` with potentially the name or sort parameters updated.
let
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def apply(self, *args: Any, **kwargs: Any) -> KApply: """Construct a `KApply` with this `KLabel` as the AST head and the supplied parameters as the arguments.""" return KApply(self, *args, **kwargs)
Construct a `KApply` with this `KLabel` as the AST head and the supplied parameters as the arguments.
apply
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def from_dict(dct: Mapping[str, Any]) -> KInner: """Deserialize a given `KInner` into a more specific type from a dictionary.""" stack: list = [dct, KInner._extract_dicts(dct), []] while True: terms = stack[-1] dcts = stack[-2] dct = stack[-3] idx = len(terms) - len(dcts) if not idx: stack.pop() stack.pop() stack.pop() cls = globals()[dct['node']] term = cls._from_dict(dct, terms) if not stack: return term stack[-1].append(term) else: dct = dcts[idx] stack.append(dct) stack.append(KInner._extract_dicts(dct)) stack.append([])
Deserialize a given `KInner` into a more specific type from a dictionary.
from_dict
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def terms(self) -> tuple[KInner, ...]: """Returns the children of this given `KInner`.""" ...
Returns the children of this given `KInner`.
terms
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def let_terms(self: KI, terms: Iterable[KInner]) -> KI: """Set children of this given `KInner`.""" ...
Set children of this given `KInner`.
let_terms
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def map_inner(self: KI, f: Callable[[KInner], KInner]) -> KI: """Apply a transformation to all children of this given `KInner`.""" return self.let_terms(f(term) for term in self.terms)
Apply a transformation to all children of this given `KInner`.
map_inner
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def match(self, term: KInner) -> Subst | None: """Perform syntactic pattern matching and return the substitution. Args: term: Term to match. Returns: A substitution instantiating `self` to `term` if one exists, ``None`` otherwise. """ ...
Perform syntactic pattern matching and return the substitution. Args: term: Term to match. Returns: A substitution instantiating `self` to `term` if one exists, ``None`` otherwise.
match
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def __init__(self, token: str, sort: str | KSort): """Construct a new `KToken` with a given string representation in the supplied sort.""" if type(sort) is str: sort = KSort(sort) object.__setattr__(self, 'token', token) object.__setattr__(self, 'sort', sort)
Construct a new `KToken` with a given string representation in the supplied sort.
__init__
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def let(self, *, token: str | None = None, sort: str | KSort | None = None) -> KToken: """Return a copy of the `KToken` with the token or sort potentially updated.""" token = token if token is not None else self.token sort = sort if sort is not None else self.sort return KToken(token=token, sort=sort)
Return a copy of the `KToken` with the token or sort potentially updated.
let
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def __init__(self, name: str, sort: str | KSort | None = None): """Construct a new `KVariable` with a given name and optional sort.""" if type(sort) is str: sort = KSort(sort) object.__setattr__(self, 'name', name) object.__setattr__(self, 'sort', sort)
Construct a new `KVariable` with a given name and optional sort.
__init__
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def __lt__(self, other: Any) -> bool: """Lexicographic comparison of `KVariable` based on name for sorting.""" if not isinstance(other, KAst): return NotImplemented if type(other) is KVariable: if (self.sort is None or other.sort is None) and self.name == other.name: return self.sort is None return super().__lt__(other)
Lexicographic comparison of `KVariable` based on name for sorting.
__lt__
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def let(self, *, name: str | None = None, sort: str | KSort | None = None) -> KVariable: """Return a copy of this `KVariable` with potentially the name or sort updated.""" name = name if name is not None else self.name sort = sort if sort is not None else self.sort return KVariable(name=name, sort=sort)
Return a copy of this `KVariable` with potentially the name or sort updated.
let
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def let_sort(self, sort: KSort | None) -> KVariable: """Return a copy of this `KVariable` with just the sort updated.""" return KVariable(self.name, sort=sort)
Return a copy of this `KVariable` with just the sort updated.
let_sort
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def __init__(self, label: str | KLabel, *args: Any, **kwargs: Any): """Construct a new `KApply` given the input `KLabel` or str, applied to arguments.""" if type(label) is str: label = KLabel(label) if kwargs: bad_arg = next((arg for arg in kwargs if arg != 'args'), None) if bad_arg: raise TypeError(f'KApply() got an unexpected keyword argument: {bad_arg}') if args: raise TypeError('KApply() got multiple values for argument: args') _args = kwargs['args'] elif len(args) == 1 and isinstance(args[0], Iterable) and not isinstance(args[0], KInner): _args = args[0] else: _args = args object.__setattr__(self, 'label', label) object.__setattr__(self, 'args', tuple(_args))
Construct a new `KApply` given the input `KLabel` or str, applied to arguments.
__init__
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def arity(self) -> int: """Return the count of the arguments.""" return len(self.args)
Return the count of the arguments.
arity
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def is_cell(self) -> bool: """Return whether this is a cell-label application (based on heuristic about label names).""" return len(self.label.name) > 1 and self.label.name[0] == '<' and self.label.name[-1] == '>'
Return whether this is a cell-label application (based on heuristic about label names).
is_cell
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def let(self, *, label: str | KLabel | None = None, args: Iterable[KInner] | None = None) -> KApply: """Return a copy of this `KApply` with either the label or the arguments updated.""" label = label if label is not None else self.label args = args if args is not None else self.args return KApply(label=label, args=args)
Return a copy of this `KApply` with either the label or the arguments updated.
let
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def __init__(self, pattern: KInner, alias: KInner): """Construct a new `KAs` given the original pattern and the alias.""" object.__setattr__(self, 'pattern', pattern) object.__setattr__(self, 'alias', alias)
Construct a new `KAs` given the original pattern and the alias.
__init__
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def let(self, *, pattern: KInner | None = None, alias: KInner | None = None) -> KAs: """Return a copy of this `KAs` with potentially the pattern or alias updated.""" pattern = pattern if pattern is not None else self.pattern alias = alias if alias is not None else self.alias return KAs(pattern=pattern, alias=alias)
Return a copy of this `KAs` with potentially the pattern or alias updated.
let
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def __init__(self, lhs: KInner, rhs: KInner): """Construct a `KRewrite` given the LHS (left-hand-side) and RHS (right-hand-side) to use.""" object.__setattr__(self, 'lhs', lhs) object.__setattr__(self, 'rhs', rhs)
Construct a `KRewrite` given the LHS (left-hand-side) and RHS (right-hand-side) to use.
__init__
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def __iter__(self) -> Iterator[KInner]: """Return a two-element iterator with the LHS first and RHS second.""" return iter([self.lhs, self.rhs])
Return a two-element iterator with the LHS first and RHS second.
__iter__
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def let( self, *, lhs: KInner | None = None, rhs: KInner | None = None, ) -> KRewrite: """Return a copy of this `KRewrite` with potentially the LHS or RHS updated.""" lhs = lhs if lhs is not None else self.lhs rhs = rhs if rhs is not None else self.rhs return KRewrite(lhs=lhs, rhs=rhs)
Return a copy of this `KRewrite` with potentially the LHS or RHS updated.
let
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def apply_top(self, term: KInner) -> KInner: """Rewrite a given term at the top. Args: term: Term to rewrite. Returns: The term with the rewrite applied once at the top. """ subst = self.lhs.match(term) if subst is not None: return subst(self.rhs) return term
Rewrite a given term at the top. Args: term: Term to rewrite. Returns: The term with the rewrite applied once at the top.
apply_top
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def apply(self, term: KInner) -> KInner: """Attempt rewriting once at every position in a term bottom-up. Args: term: Term to rewrite. Returns: The term with rewrites applied at every node once starting from the bottom. """ return bottom_up(self.apply_top, term)
Attempt rewriting once at every position in a term bottom-up. Args: term: Term to rewrite. Returns: The term with rewrites applied at every node once starting from the bottom.
apply
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def replace_top(self, term: KInner) -> KInner: """Similar to apply_top but using exact syntactic matching instead of pattern matching.""" if self.lhs == term: return self.rhs return term
Similar to apply_top but using exact syntactic matching instead of pattern matching.
replace_top
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def replace(self, term: KInner) -> KInner: """Similar to apply but using exact syntactic matching instead of pattern matching.""" return bottom_up(self.replace_top, term)
Similar to apply but using exact syntactic matching instead of pattern matching.
replace
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def __init__(self, *args: Any, **kwargs: Any): """Construct a new `KSequence` given the arguments.""" if kwargs: bad_arg = next((arg for arg in kwargs if arg != 'items'), None) if bad_arg: raise TypeError(f'KSequence() got an unexpected keyword argument: {bad_arg}') if args: raise TypeError('KSequence() got multiple values for argument: items') items = kwargs['items'] elif len(args) == 1 and isinstance(args[0], Iterable) and not isinstance(args[0], KInner): items = args[0] else: items = args _items: list[KInner] = [] for i in items: if type(i) is KSequence: _items.extend(i.items) else: _items.append(i) items = tuple(_items) object.__setattr__(self, 'items', tuple(items))
Construct a new `KSequence` given the arguments.
__init__
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def arity(self) -> int: """Return the count of `KSequence` items.""" return len(self.items)
Return the count of `KSequence` items.
arity
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def let(self, *, items: Iterable[KInner] | None = None) -> KSequence: """Return a copy of this `KSequence` with the items potentially updated.""" items = items if items is not None else self.items return KSequence(items=items)
Return a copy of this `KSequence` with the items potentially updated.
let
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def __init__(self, subst: Mapping[str, KInner] = EMPTY_FROZEN_DICT): """Construct a new `Subst` given a mapping fo variable names to `KInner`.""" object.__setattr__(self, '_subst', FrozenDict(subst))
Construct a new `Subst` given a mapping fo variable names to `KInner`.
__init__
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def __iter__(self) -> Iterator[str]: """Return the underlying `Subst` mapping as an iterator.""" return iter(self._subst)
Return the underlying `Subst` mapping as an iterator.
__iter__
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def __len__(self) -> int: """Return the length of the underlying `Subst` mapping.""" return len(self._subst)
Return the length of the underlying `Subst` mapping.
__len__
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def __getitem__(self, key: str) -> KInner: """Get the `KInner` associated with the given variable name from the underlying `Subst` mapping.""" return self._subst[key]
Get the `KInner` associated with the given variable name from the underlying `Subst` mapping.
__getitem__
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def __mul__(self, other: Subst) -> Subst: """Overload for `Subst.compose`.""" return self.compose(other)
Overload for `Subst.compose`.
__mul__
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def __call__(self, term: KInner) -> KInner: """Overload for `Subst.apply`.""" return self.apply(term)
Overload for `Subst.apply`.
__call__
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def from_dict(d: Mapping[str, Any]) -> Subst: """Deserialize a `Subst` from a given dictionary representing it.""" return Subst({k: KInner.from_dict(v) for k, v in d.items()})
Deserialize a `Subst` from a given dictionary representing it.
from_dict
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def to_dict(self) -> dict[str, Any]: """Serialize a `Subst` to a dictionary representation.""" return {k: v.to_dict() for k, v in self.items()}
Serialize a `Subst` to a dictionary representation.
to_dict
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def minimize(self) -> Subst: """Return a new substitution with any identity items removed.""" return Subst({k: v for k, v in self.items() if type(v) is not KVariable or v.name != k})
Return a new substitution with any identity items removed.
minimize
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def compose(self, other: Subst) -> Subst: """Union two substitutions together, preferring the assignments in `self` if present in both.""" from_other = ((k, self(v)) for k, v in other.items()) from_self = ((k, v) for k, v in self.items() if k not in other) return Subst(dict(chain(from_other, from_self)))
Union two substitutions together, preferring the assignments in `self` if present in both.
compose
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def union(self, other: Subst) -> Subst | None: """Union two substitutions together, failing with `None` if there are conflicting assignments.""" subst = dict(self) for v in other: if v in subst and subst[v] != other[v]: return None subst[v] = other[v] return Subst(subst)
Union two substitutions together, failing with `None` if there are conflicting assignments.
union
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def apply(self, term: KInner) -> KInner: """Apply the given substitution to `KInner`, replacing free variable occurances with their valuations defined in this `Subst`.""" def replace(term: KInner) -> KInner: if type(term) is KVariable and term.name in self: return self[term.name] return term return bottom_up(replace, term)
Apply the given substitution to `KInner`, replacing free variable occurances with their valuations defined in this `Subst`.
apply
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def unapply(self, term: KInner) -> KInner: """Replace occurances of valuations from this `Subst` with the variables that they are assigned to.""" new_term = term for var_name in self: lhs = self[var_name] rhs = KVariable(var_name) new_term = KRewrite(lhs, rhs).replace(new_term) return new_term
Replace occurances of valuations from this `Subst` with the variables that they are assigned to.
unapply
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def from_pred(pred: KInner) -> Subst: """Given a generic matching logic predicate, attempt to extract a `Subst` from it.""" from .manip import flatten_label subst: dict[str, KInner] = {} for conjunct in flatten_label('#And', pred): match conjunct: case KApply(KLabel('#Equals'), [KVariable(var), term]): subst[var] = term case _: raise ValueError(f'Invalid substitution predicate: {conjunct}') return Subst(subst)
Given a generic matching logic predicate, attempt to extract a `Subst` from it.
from_pred
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def pred(self) -> KInner: """Turn this `Subst` into a boolean predicate using `_==K_` operator.""" conjuncts = [ KApply('_==K_', KVariable(name), val) for name, val in self.items() if type(val) is not KVariable or val.name != name ] if not conjuncts: return KToken('true', 'Bool') return reduce(KLabel('_andBool_'), conjuncts)
Turn this `Subst` into a boolean predicate using `_==K_` operator.
pred
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def bottom_up_with_summary(f: Callable[[KInner, list[A]], tuple[KInner, A]], kinner: KInner) -> tuple[KInner, A]: """Traverse a term from the bottom moving upward, collecting information about it. Args: f: Function to apply at each AST node to transform it and collect summary. kinner: Term to apply this transformation to. Returns: A tuple of the transformed term and the summarized results. """ stack: list = [kinner, [], []] while True: summaries = stack[-1] terms = stack[-2] term = stack[-3] idx = len(terms) - len(term.terms) if not idx: stack.pop() stack.pop() stack.pop() term, summary = f(term.let_terms(terms), summaries) if not stack: return term, summary stack[-1].append(summary) stack[-2].append(term) else: stack.append(term.terms[idx]) stack.append([]) stack.append([])
Traverse a term from the bottom moving upward, collecting information about it. Args: f: Function to apply at each AST node to transform it and collect summary. kinner: Term to apply this transformation to. Returns: A tuple of the transformed term and the summarized results.
bottom_up_with_summary
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def bottom_up(f: Callable[[KInner], KInner], kinner: KInner) -> KInner: """Transform a term from the bottom moving upward. Args: f: Function to apply to each node in the term. kinner: Original term to transform. Returns: The transformed term. """ stack: list = [kinner, []] while True: terms = stack[-1] term = stack[-2] idx = len(terms) - len(term.terms) if not idx: stack.pop() stack.pop() term = f(term.let_terms(terms)) if not stack: return term stack[-1].append(term) else: stack.append(term.terms[idx]) stack.append([])
Transform a term from the bottom moving upward. Args: f: Function to apply to each node in the term. kinner: Original term to transform. Returns: The transformed term.
bottom_up
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def top_down(f: Callable[[KInner], KInner], kinner: KInner) -> KInner: """Transform a term from the top moving downward. Args: f: Function to apply to each node in the term. kinner: Original term to transform. Returns: The transformed term. """ stack: list = [f(kinner), []] while True: terms = stack[-1] term = stack[-2] idx = len(terms) - len(term.terms) if not idx: stack.pop() stack.pop() term = term.let_terms(terms) if not stack: return term stack[-1].append(term) else: stack.append(f(term.terms[idx])) stack.append([])
Transform a term from the top moving downward. Args: f: Function to apply to each node in the term. kinner: Original term to transform. Returns: The transformed term.
top_down
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def var_occurrences(term: KInner) -> dict[str, list[KVariable]]: """Collect the list of occurrences of each variable in a given term. Args: term: Term to collect variables from. Returns: A dictionary with variable names as keys and the list of all occurrences of the variable as values. """ _var_occurrences: dict[str, list[KVariable]] = {} # TODO: should treat #Exists and #Forall specially. def _var_occurence(_term: KInner) -> None: if type(_term) is KVariable: if _term.name not in _var_occurrences: _var_occurrences[_term.name] = [] _var_occurrences[_term.name].append(_term) collect(_var_occurence, term) return _var_occurrences
Collect the list of occurrences of each variable in a given term. Args: term: Term to collect variables from. Returns: A dictionary with variable names as keys and the list of all occurrences of the variable as values.
var_occurrences
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def keep_vars_sorted(occurrences: dict[str, list[KVariable]]) -> dict[str, KVariable]: """Keep the sort of variables from the occurrences dictionary.""" occurrences_sorted: dict[str, KVariable] = {} for k, vs in occurrences.items(): sort = None for v in vs: if v.sort is not None: if sort is None: sort = v.sort elif sort != v.sort: sort = None break occurrences_sorted[k] = KVariable(k, sort) return occurrences_sorted
Keep the sort of variables from the occurrences dictionary.
keep_vars_sorted
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def collect(callback: Callable[[KInner], None], kinner: KInner) -> None: """Collect information about a given term traversing it top-down using a function with side effects. Args: callback: Function with the side effect of collecting desired information at each AST node. kinner: The term to traverse. """ subterms = [kinner] while subterms: term = subterms.pop() subterms.extend(reversed(term.terms)) callback(term)
Collect information about a given term traversing it top-down using a function with side effects. Args: callback: Function with the side effect of collecting desired information at each AST node. kinner: The term to traverse.
collect
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def build_assoc(unit: KInner, label: str | KLabel, terms: Iterable[KInner]) -> KInner: """Build an associative list. Args: unit: The empty variant of the given list type. label: The associative list join operator. terms: List (potentially empty) of terms to join in an associative list. Returns: The list of terms joined using the supplied label, or the unit element in the case of no terms. """ _label = label if type(label) is KLabel else KLabel(label) res: KInner | None = None for term in reversed(list(terms)): if term == unit: continue if not res: res = term else: res = _label(term, res) return res or unit
Build an associative list. Args: unit: The empty variant of the given list type. label: The associative list join operator. terms: List (potentially empty) of terms to join in an associative list. Returns: The list of terms joined using the supplied label, or the unit element in the case of no terms.
build_assoc
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def build_cons(unit: KInner, label: str | KLabel, terms: Iterable[KInner]) -> KInner: """Build a cons list. Args: unit: The empty variant of the given list type. label: The associative list join operator. terms: List (potentially empty) of terms to join in an associative list. Returns: The list of terms joined using the supplied label, terminated with the unit element. """ it = iter(terms) try: fst = next(it) return KApply(label, (fst, build_cons(unit, label, it))) except StopIteration: return unit
Build a cons list. Args: unit: The empty variant of the given list type. label: The associative list join operator. terms: List (potentially empty) of terms to join in an associative list. Returns: The list of terms joined using the supplied label, terminated with the unit element.
build_cons
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def flatten_label(label: str, kast: KInner) -> list[KInner]: """Given a cons list, return a flat Python list of the elements. Args: label: The cons operator. kast: The cons list to flatten. Returns: Items of cons list. """ flattened_args = [] rest_of_args = [kast] # Rest of arguments in reversed order while rest_of_args: current_arg = rest_of_args.pop() if isinstance(current_arg, KApply) and current_arg.label.name == label: rest_of_args.extend(reversed(current_arg.args)) else: flattened_args.append(current_arg) return flattened_args
Given a cons list, return a flat Python list of the elements. Args: label: The cons operator. kast: The cons list to flatten. Returns: Items of cons list.
flatten_label
python
runtimeverification/k
pyk/src/pyk/kast/inner.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/inner.py
BSD-3-Clause
def _id_or_token(la: str, it: Iterator[str]) -> tuple[Token, str]: """Match an ID or token. Corresponds to regex: [#a-z](a-zA-Z0-9)* """ assert la == '#' or la in _LOWER buf = [la] la = next(it, '') while la in _ID_CHARS: buf += la la = next(it, '') text = ''.join(buf) if text == '#token': return _TOKENS[TokenType.TOKEN], la return Token(text, TokenType.ID), la
Match an ID or token. Corresponds to regex: [#a-z](a-zA-Z0-9)*
_id_or_token
python
runtimeverification/k
pyk/src/pyk/kast/lexer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/lexer.py
BSD-3-Clause
def unique_id(self) -> str | None: """Return the unique ID assigned to this sentence, or None.""" return self.att.get(Atts.UNIQUE_ID)
Return the unique ID assigned to this sentence, or None.
unique_id
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause
def source(self) -> str | None: """Return the source assigned to this sentence, or None.""" if Atts.SOURCE in self.att and Atts.LOCATION in self.att: return f'{self.att[Atts.SOURCE]}:{self.att[Atts.LOCATION]}' return None
Return the source assigned to this sentence, or None.
source
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause
def label(self) -> str: """Return a (hopefully) unique label associated with the given `KSentence`. :return: Unique label for the given sentence, either (in order): - User supplied `label` attribute (or supplied in rule label),or - Unique identifier computed and inserted by the frontend. """ label = self.att.get(Atts.LABEL, self.unique_id) if label is None: raise ValueError(f'Found sentence without label or UNIQUE_ID: {self}') return label
Return a (hopefully) unique label associated with the given `KSentence`. :return: Unique label for the given sentence, either (in order): - User supplied `label` attribute (or supplied in rule label),or - Unique identifier computed and inserted by the frontend.
label
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause
def as_subsort(self) -> tuple[KSort, KSort] | None: """Return a pair `(supersort, subsort)` if `self` is a subsort production, and `None` otherwise.""" if self.klabel: return None if len(self.items) != 1: return None item = self.items[0] if not isinstance(item, KNonTerminal): return None assert not self.klabel return self.sort, item.sort
Return a pair `(supersort, subsort)` if `self` is a subsort production, and `None` otherwise.
as_subsort
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause
def non_terminals(self) -> tuple[KNonTerminal, ...]: """Return the non-terminals of the production.""" return tuple(item for item in self.items if isinstance(item, KNonTerminal))
Return the non-terminals of the production.
non_terminals
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause
def argument_sorts(self) -> list[KSort]: """Return the sorts of the non-terminal positions of the productions.""" return [knt.sort for knt in self.non_terminals]
Return the sorts of the non-terminal positions of the productions.
argument_sorts
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause
def is_prefix(self) -> bool: """The production is of the form ``t* "(" (n ("," n)*)? ")"``. Here, ``t`` is a terminal other than ``"("``, ``","`` or ``")"``, and ``n`` a non-terminal. Example: ``syntax Int ::= "mul" "(" Int "," Int ")"`` """ def encode(item: KProductionItem) -> str: match item: case KTerminal(value): if value in ['(', ',', ')']: return value return 't' case KNonTerminal(): return 'n' case KRegexTerminal(): return 'r' case _: raise AssertionError() string = ''.join(encode(item) for item in self.items) pattern = r't*\((n(,n)*)?\)' return bool(re.fullmatch(pattern, string))
The production is of the form ``t* "(" (n ("," n)*)? ")"``. Here, ``t`` is a terminal other than ``"("``, ``","`` or ``")"``, and ``n`` a non-terminal. Example: ``syntax Int ::= "mul" "(" Int "," Int ")"``
is_prefix
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause
def is_record(self) -> bool: """The production is prefix with labelled nonterminals.""" return bool(self.is_prefix and self.non_terminals and all(item.name is not None for item in self.non_terminals))
The production is prefix with labelled nonterminals.
is_record
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause
def is_circularity(self) -> bool: """Return whether this claim is a circularity (must be used coinductively to prove itself).""" return Atts.CIRCULARITY in self.att
Return whether this claim is a circularity (must be used coinductively to prove itself).
is_circularity
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause
def is_trusted(self) -> bool: """Return whether this claim is trusted (does not need to be proven to be considered true).""" return Atts.TRUSTED in self.att
Return whether this claim is trusted (does not need to be proven to be considered true).
is_trusted
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause
def dependencies(self) -> list[str]: """Return the dependencies of this claim (list of other claims needed to help prove this one or speed up this ones proof).""" deps = self.att.get(Atts.DEPENDS) if deps is None: return [] return [x.strip() for x in deps.split(',')]
Return the dependencies of this claim (list of other claims needed to help prove this one or speed up this ones proof).
dependencies
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause
def productions(self) -> tuple[KProduction, ...]: """Return all the `KProduction` sentences from this module.""" return tuple(sentence for sentence in self if type(sentence) is KProduction)
Return all the `KProduction` sentences from this module.
productions
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause
def syntax_productions(self) -> tuple[KProduction, ...]: """Return all the `KProduction` sentences from this module that contain `KLabel` (are EBNF syntax declarations).""" return tuple(prod for prod in self.productions if prod.klabel)
Return all the `KProduction` sentences from this module that contain `KLabel` (are EBNF syntax declarations).
syntax_productions
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause
def functions(self) -> tuple[KProduction, ...]: """Return all the `KProduction` sentences from this module that are function declarations.""" return tuple(prod for prod in self.syntax_productions if self._is_function(prod))
Return all the `KProduction` sentences from this module that are function declarations.
functions
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause
def constructors(self) -> tuple[KProduction, ...]: """Return all the `KProduction` sentences from this module that are constructor declarations.""" return tuple(prod for prod in self.syntax_productions if not self._is_function(prod))
Return all the `KProduction` sentences from this module that are constructor declarations.
constructors
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause
def cell_collection_productions(self) -> tuple[KProduction, ...]: """Return all the `KProduction` sentences from this module that are cell collection declarations.""" return tuple(prod for prod in self.syntax_productions if Atts.CELL_COLLECTION in prod.att)
Return all the `KProduction` sentences from this module that are cell collection declarations.
cell_collection_productions
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause
def syntax_sorts(self) -> tuple[KSyntaxSort, ...]: """Return all the `KSyntaxSort` sentences from this module.""" return tuple(sentence for sentence in self if isinstance(sentence, KSyntaxSort))
Return all the `KSyntaxSort` sentences from this module.
syntax_sorts
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause
def rules(self) -> tuple[KRule, ...]: """Return all the `KRule` declared in this module.""" return tuple(sentence for sentence in self if type(sentence) is KRule)
Return all the `KRule` declared in this module.
rules
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause
def claims(self) -> tuple[KClaim, ...]: """Return all the `KClaim` declared in this module.""" return tuple(sentence for sentence in self if type(sentence) is KClaim)
Return all the `KClaim` declared in this module.
claims
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause
def all_module_names(self) -> tuple[str, ...]: """Return the name of all modules in this `KDefinition`.""" return tuple(module.name for module in self.all_modules)
Return the name of all modules in this `KDefinition`.
all_module_names
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause
def module_names(self) -> tuple[str, ...]: """Return the list of module names transitively imported by the main module of this definition.""" module_names = [self.main_module_name] seen_modules = [] while len(module_names) > 0: mname = module_names.pop(0) if mname not in seen_modules: seen_modules.append(mname) module_names.extend([i.name for i in self.all_modules_dict[mname].imports]) return tuple(seen_modules)
Return the list of module names transitively imported by the main module of this definition.
module_names
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause
def all_modules_dict(self) -> dict[str, KFlatModule]: """Returns a dictionary of all the modules (with names as keys) defined in this definition.""" return {m.name: m for m in self.all_modules}
Returns a dictionary of all the modules (with names as keys) defined in this definition.
all_modules_dict
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause
def modules(self) -> tuple[KFlatModule, ...]: """Returns the list of modules transitively imported by th emain module of this definition.""" return tuple(self.all_modules_dict[mname] for mname in self.module_names)
Returns the list of modules transitively imported by th emain module of this definition.
modules
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause
def productions(self) -> tuple[KProduction, ...]: """Returns the `KProduction` transitively imported by the main module of this definition.""" return tuple(prod for module in self.modules for prod in module.productions)
Returns the `KProduction` transitively imported by the main module of this definition.
productions
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause
def syntax_productions(self) -> tuple[KProduction, ...]: """Returns the `KProduction` which are syntax declarations transitively imported by the main module of this definition.""" return tuple(prod for module in self.modules for prod in module.syntax_productions)
Returns the `KProduction` which are syntax declarations transitively imported by the main module of this definition.
syntax_productions
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause
def functions(self) -> tuple[KProduction, ...]: """Returns the `KProduction` which are function declarations transitively imported by the main module of this definition.""" return tuple(func for module in self.modules for func in module.functions)
Returns the `KProduction` which are function declarations transitively imported by the main module of this definition.
functions
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause
def function_labels(self) -> tuple[str, ...]: """Returns the label names of all the `KProduction` which are function symbols for all modules in this definition.""" return tuple(not_none(func.klabel).name for func in self.functions)
Returns the label names of all the `KProduction` which are function symbols for all modules in this definition.
function_labels
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause
def constructors(self) -> tuple[KProduction, ...]: """Returns the `KProduction` which are constructor declarations transitively imported by the main module of this definition.""" return tuple(ctor for module in self.modules for ctor in module.constructors)
Returns the `KProduction` which are constructor declarations transitively imported by the main module of this definition.
constructors
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause
def cell_collection_productions(self) -> tuple[KProduction, ...]: """Returns the `KProduction` which are cell collection declarations transitively imported by the main module of this definition.""" return tuple(prod for module in self.modules for prod in module.cell_collection_productions)
Returns the `KProduction` which are cell collection declarations transitively imported by the main module of this definition.
cell_collection_productions
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause
def rules(self) -> tuple[KRule, ...]: """Returns the `KRule` sentences transitively imported by the main module of this definition.""" return tuple(rule for module in self.modules for rule in module.rules)
Returns the `KRule` sentences transitively imported by the main module of this definition.
rules
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause
def alias_rules(self) -> tuple[KRule, ...]: """Returns the `KRule` sentences which are `alias` transitively imported by the main module of this definition.""" return tuple(rule for rule in self.rules if Atts.ALIAS in rule.att)
Returns the `KRule` sentences which are `alias` transitively imported by the main module of this definition.
alias_rules
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause
def macro_rules(self) -> tuple[KRule, ...]: """Returns the `KRule` sentences which are `alias` or `macro` transitively imported by the main module of this definition.""" return tuple(rule for rule in self.rules if Atts.MACRO in rule.att) + self.alias_rules
Returns the `KRule` sentences which are `alias` or `macro` transitively imported by the main module of this definition.
macro_rules
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause
def semantic_rules(self) -> tuple[KRule, ...]: """Returns the `KRule` sentences which are topmost transitively imported by the main module of this definition.""" def is_semantic(rule: KRule) -> bool: return (type(rule.body) is KApply and rule.body.label.name == '<generatedTop>') or ( type(rule.body) is KRewrite and type(rule.body.lhs) is KApply and rule.body.lhs.label.name == '<generatedTop>' ) return tuple(rule for rule in self.rules if is_semantic(rule))
Returns the `KRule` sentences which are topmost transitively imported by the main module of this definition.
semantic_rules
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause
def production_for_cell_sort(self, sort: KSort) -> KProduction: """Return the production for a given cell-declaration syntax from the cell's declared sort.""" # Typical cell production has 3 productions: # syntax KCell ::= "project:KCell" "(" K ")" [function, projection] # syntax KCell ::= "initKCell" "(" Map ")" [function, initializer, noThread] # syntax KCell ::= "<k>" K "</k>" [cell, cellName(k), format(%1%i%n%2%d%n%3), maincell, org.kframework.definition.Production(syntax #RuleContent ::= #RuleBody [klabel(#ruleNoConditions), symbol])] # And it may have a 4th: # syntax GeneratedCounterCell ::= "getGeneratedCounterCell" "(" GeneratedTopCell ")" [function] # We want the actual label one (3rd one in the list). if not sort.name.endswith('Cell'): raise ValueError( f'Method production_for_cell_sort only intended to be called on sorts ending in "Cell", not: {sort}' ) try: return single(prod for prod in self.productions if prod.sort == sort and Atts.CELL in prod.att) except ValueError as err: raise ValueError(f'Expected a single cell production for sort {sort}') from err
Return the production for a given cell-declaration syntax from the cell's declared sort.
production_for_cell_sort
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause
def module(self, name: str) -> KFlatModule: """Return the module associated with a given name.""" return self.all_modules_dict[name]
Return the module associated with a given name.
module
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause
def subsort_table(self) -> FrozenDict[KSort, frozenset[KSort]]: """Return a mapping from sorts to all their proper subsorts.""" poset = POSet(subsort for prod in self.productions if (subsort := prod.as_subsort) is not None) return poset.image
Return a mapping from sorts to all their proper subsorts.
subsort_table
python
runtimeverification/k
pyk/src/pyk/kast/outer.py
https://github.com/runtimeverification/k/blob/master/pyk/src/pyk/kast/outer.py
BSD-3-Clause