def print_type_constr(constr): """Print a given type constructor.""" argsT, _ = constr['type'].strip_type() assert len(argsT) == len( constr['args']), "print_type_constr: unexpected number of args." res = pprint.N(constr['name']) for i, arg in enumerate(constr['args']): res += pprint.N(' (' + arg + ' :: ') + print_type( argsT[i]) + pprint.N(')') return res
def output_step(state, step): """Obtain the string explaining the step in the user interface.""" try: method = global_methods[step['method_name']] res = method.display_step(state, step) except Exception as e: res = pprint.N(step['method_name']) res += pprint.N(' on ' + step['goal_id']) if 'fact_ids' in step and len(step['fact_ids']) > 0: res += pprint.N(' using ' + ','.join(step['fact_ids'])) return res
def print_thm(th): """Print the given theorem with highlight.""" typecheck.checkinstance('print_thm', th, Thm) turnstile = pprint.N("⊢") if settings.unicode else pprint.N("|-") if th.hyps: str_hyps = commas_join(print_term(hyp) for hyp in th.hyps) return str_hyps + pprint.N(" ") + turnstile + pprint.N( " ") + print_term(th.prop) else: return turnstile + pprint.N(" ") + print_term(th.prop)
def str_val(val): if isinstance(val, Inst): items = sorted(val.items(), key=lambda pair: pair[0]) return pprint.N('{') + commas_join( pprint.N(key + ': ') + str_val(val) for key, val in items) + pprint.N('}') elif isinstance(val, Term): if th and val == th.prop and rule != 'assume' and settings.highlight: return pprint.Gray("⟨goal⟩") else: return print_term(val) elif isinstance(val, Type): return print_type(val) else: return pprint.N(str(val))
def print_str_args(rule, args, th): def str_val(val): if isinstance(val, Inst): items = sorted(val.items(), key=lambda pair: pair[0]) return pprint.N('{') + commas_join( pprint.N(key + ': ') + str_val(val) for key, val in items) + pprint.N('}') elif isinstance(val, Term): if th and val == th.prop and rule != 'assume' and settings.highlight: return pprint.Gray("⟨goal⟩") else: return print_term(val) elif isinstance(val, Type): return print_type(val) else: return pprint.N(str(val)) # Print var :: T for variables if rule == 'variable' and settings.highlight: return pprint.N(args[0] + ' :: ') + str_val(args[1]) if isinstance(args, tuple) or isinstance(args, list): return commas_join(str_val(val) for val in args) elif args: return str_val(args) else: return [] if settings.highlight else ""
def get_display(self): Targs = [TVar(arg) for arg in self.args] T = TConst(self.name, *Targs) constrs = [] for constr in self.constrs: argsT, _ = constr['type'].strip_type() res = pprint.N(constr['name']) for i, arg in enumerate(constr['args']): res += pprint.N(' (' + arg + ' :: ') + printer.print_type( argsT[i]) + pprint.N(')') constrs.append(res) return { 'ty': 'type.ind', 'type': printer.print_type(T), 'constrs': constrs if settings.highlight else '\n'.join(constrs) }
def display_step(self, state, data): res = "introduction" if 'names' in data and data['names'] != "": names = [name.strip() for name in data['names'].split(',')] if len(names) > 1: res += " with names " + ", ".join(names) else: res += " with name " + ", ".join(names) return pprint.N(res)
def get_display(self): if self.error: disp_vars = [ pprint.N(nm + ' :: ' + T) for nm, T in self.vars.items() ] disp_prop = display_raw(self.prop) else: disp_vars = [ pprint.N(nm + ' :: ') + printer.print_type(T) for nm, T in self.vars.items() ] disp_prop = display_term(self.prop) return { 'ty': 'thm.ax', 'name': self.name, 'vars': disp_vars if settings.highlight else '\n'.join(disp_vars), 'prop': disp_prop, 'attributes': self.attributes }
def get_display(self): if self.error: disp_type = display_raw(self.type) disp_rules = [ pprint.N(rule['name'] + ": " + rule['prop']) for rule in self.rules ] else: disp_type = printer.print_type(self.type) with global_setting(line_length=None): disp_rules = [ pprint.N(rule['name'] + ": ") + printer.print_term(rule['prop']) for rule in self.rules ] return { 'ty': 'def.pred', 'name': self.name, 'type': disp_type, 'rules': disp_rules if settings.highlight else '\n'.join(disp_rules) }
def commas_join(strs): """Given a list of output (with or without highlight), join them with commas, adding commas with normal color in the highlight case. """ strs = list(strs) # convert possible generator to concrete list if settings.highlight: if strs: res = strs[0] for s in strs[1:]: res.extend(pprint.N(', ')) res.extend(s) return res else: return [] else: return ', '.join(strs)
def display_step(self, state, data): return pprint.N("Resolve using " + data['theorem'])
def display_step(self, state, data): return pprint.N(data['theorem'] + " (b)")
def display_step(self, state, data): return pprint.N("rewrite fact with fact")
def display_step(self, state, data): if 'sym' in data and data['sym'] == 'true': return pprint.N(data['theorem'] + " (sym, r)") else: return pprint.N(data['theorem'] + " (r)")
def display_step(self, state, data): return pprint.N("Apply VCG")
def display_step(self, state, data): if 'var' in data: return pprint.N("Induction " + data['theorem'] + " var: " + data['var']) else: return pprint.N("Induction " + data['theorem'])
def display_step(self, state, data): id = data['goal_id'] with context.fresh_context(vars=state.get_vars(id)): goal = parser.parse_term(data['goal']) return pprint.N("have ") + printer.print_term(goal)
def display_step(self, state, data): return pprint.N("revert intro")
def display_step(self, state, data): return pprint.N("real_norm: (solves)")
def display_raw(s): """Display unparsed type or term.""" if isinstance(s, str): return [pprint.N(s)] else: return [pprint.N(line) for line in s]
def display_step(self, state, data): return pprint.N("Forall elimination")
def display_step(self, state, data): return pprint.N("Apply fact (f) %s onto %s" % (data['fact_ids'][0], ", ".join(data['fact_ids'][1:])))
def display_step(self, state, data): return pprint.N("Instantiate exists goal")
def display_step(self, state, data): return pprint.N("prove_avalI: (solves)")
def display_step(self, state, data): T = parser.parse_type(data['type']) return pprint.N("Variable " + data['name'] + " :: ") + printer.print_type(T)
def display_step(self, state, data): return pprint.N("eval_Sem: (solves)")
def display_step(self, state, data): return pprint.N("Apply fact (b)")
def display_step(self, state, data): return pprint.N("nat_const_ineq: (solves)")