def option_printer(struct: FirstOrderStructure, s: SortDecl, elt: str, args: List[str]) -> str: assert len(args) == 2 is_none_name, value_name = args is_none = get_relation(is_none_name) value = get_function(value_name) option_sort = UninterpretedSort(s.name) assert not is_none.mutable and not value.mutable and \ is_none.arity == (option_sort,) and value.arity == (option_sort,) elt_sort = syntax.get_decl_from_sort(value.sort) none: Optional[str] = None for tup, b in struct.rel_interps[is_none].items(): if b: assert none is None and len(tup) == 1 none = tup[0] assert none is not None if elt == none: return 'None' else: the_value: Optional[str] = None for tup, res in struct.func_interps[value].items(): assert len(tup) == 1 if tup[0] == elt: assert the_value is None the_value = res assert the_value is not None return 'Some(%s)' % (print_element(struct, elt_sort, the_value))
def entry_to_str(e: LogEntry, wf: bool) -> str: entry_strs = [ value_to_str(e.values[idx], sort) for idx, sort in enumerate(value_sorts) ] if not wf: entry_strs.insert( 0, 'index |-> %s' % print_element(struct, index_sort, e.index)) return '[%s]' % (', '.join(entry_strs))
def set_printer(struct: FirstOrderStructure, s: SortDecl, elt: str, args: List[str]) -> str: assert len(args) == 1 member_name = args[0] member = get_relation(member_name) assert len(member.arity) == 2 and not member.mutable set_sort = UninterpretedSort(s.name) assert member.arity[1] == set_sort item_sort = member.arity[0] item_sort_decl = syntax.get_decl_from_sort(item_sort) items: Set[str] = set() for tup, b in struct.rel_interps[member].items(): assert len(tup) == 2 item, set_id = tup if b and set_id == elt: items.add(item) return '{' + ','.join( sorted(print_element(struct, item_sort_decl, x) for x in items)) + '}'
def value_to_str(vs: List[str], sort: SortDecl) -> str: return '%s |-> %s' % ( sort.name, print_element(struct, sort, vs[0]) if len(vs) == 1 else '[%s]' % (', '.join(print_element(struct, sort, v) for v in vs)))