def from_natural(cls, s: str, context=None, in_math=False): if not in_math: match = re.fullmatch(r"\$\\frac\{ ?(.+)\}\{ ?(.+)\}\$", s) else: match = re.fullmatch(r"\\frac\{ ?(.+)\}\{ ?(.+)\}", s) if not match: return None sentence1 = from_natural(match[1], context, _sentences_match_div(), True) if not sentence1: return None sentence2 = from_natural(match[2], context, _sentences_match_div(), True) if not sentence2: return None return cls(sentence1, sentence2)
def add_proof_line(self, nat): nat = preprocess(nat) tactics_match = [ DoAllSubgoals, LetGoalLimit, ChooseNEpsilonLimitWith, ChooseNEpsilonLimit, LetMax, Use, ByInequalityProperties, LetNInequality, BySentenceWith, LetsChooseIn, AbsoluteValueIneqProperty, Cases, SplitGoal, LinearArithmetic, ByWith, ByDefinitionOfAddFunction, GoalInequalityProperties, ] match = from_natural(nat, self.context, tactics_match) if not match: raise NaturalToLeanError("Unrecognized tactic {}".format(nat)) # TODO get lean response if needed self.proof.append({"type": "user", "obj": match}) self.contexts.append(deepcopy(self.context)) self.to_extract.append(match.to_extract())
def from_natural(cls, s: str, context=None, in_math=False): ineq_symbols = r">|\\geq|\\ge|<|\\leq|\\le" if not in_math: match = re.fullmatch(r"\$(.+) (" + ineq_symbols + r") (.+)\$", s) else: match = re.fullmatch(r"(.+) (" + ineq_symbols + r") (.+)", s) if not match: return None ident1 = from_natural(match[1], context, _sentences_match_inequality(), True) if not ident1: return None ident2 = from_natural(match[3], context, _sentences_match_inequality(), True) if not ident2: return None return cls(ident1, MAP_NAT_INEQ[match[2]], ident2)
def from_natural(cls, s: str, context=None, in_math=False): match = re.fullmatch(r"(.+) and do on all subgoals", s) if not match: return None tactic = from_natural(match[1], context, _sentences_match_doallsubgoals()) if not tactic: return None return cls(tactic)
def set_initial_goal(self, nat): nat = preprocess(nat) goals_match = [SequenceLimit, ComposedSequenceLimit] match = from_natural(nat, self.context, goals_match) if not match: raise NaturalToLeanError("Unrecognized goal {}".format(nat)) self.initial_goal = match self.context.current_goal = match self.initial_context = deepcopy(self.context)
def add_hypothesis(self, nat): nat = preprocess(nat) sentences_match = [ RealValuedSequences, RealDeclaration, SequenceLimit, ForAll ] match = from_natural(nat, self.context, sentences_match) if not match: raise NaturalToLeanError("Unrecognized hypothesis {}".format(nat)) self.hypotheses.append(match)
def from_natural(cls, s: str, context=None, in_math=False): if not in_math: match = re.fullmatch(r"\$ ?(.+) ?- ?(.+) ?\$", s) else: match = re.fullmatch(r" ?(.+) ?- ?(.+) ?", s) if not match: return None match1 = match[1].strip() sentence1 = from_natural(match1, context, _sentences_match_diff(), True) if not sentence1: return None match2 = match[2].strip() sentence2 = from_natural(match2, context, _sentences_match_diff(), True) if not sentence2: return None return cls(sentence1, sentence2)
def from_natural(cls, s: str, context=None, in_math=False): match = re.fullmatch(r"(.+) by (\w+) with (\w+)", s) if not match: return None sentence = from_natural(match[1], context, _sentences_match_bysentencewith()) if not sentence: return None ident = context.next_anonymous() return cls(ident, sentence, match[2], match[3])
def from_natural(cls, s: str, context=None, in_math=False): match = re.fullmatch(r"By inequality properties, (.+)", s) if not match: return None sentence = from_natural( match[1], context, _sentences_match_byinequalityproperties(), in_math ) if not sentence: return None ident = context.next_anonymous() return cls(ident, sentence)
def from_natural(cls, s: str, context=None, in_math=False): if not in_math: match = re.fullmatch(r"\$ ?(?:\\left)?\| ?(.+) ?- ?(.+)\|\$", s) else: match = re.fullmatch(r"(?:\\left)?\| ?(.+) ?- ?(.+)\|", s) if not match: return None match1 = match[1].strip() sentence1 = from_natural(match1, context, _sentences_match_absolutediff(), True) if not sentence1: return None match2 = match[2].strip() match2_match = re.fullmatch(r"(.+) \\right", match2) if match2_match: match2 = match2_match[1] sentence2 = from_natural(match2, context, _sentences_match_absolutediff(), True) if not sentence2: return None return cls(sentence1, sentence2)
def from_natural(cls, s: str, context=None, in_math=False): if not in_math: match = re.fullmatch(r"\$\\forall (\w+) : (.+)\$", s) else: match = re.fullmatch(r"\\forall (\w+) : (.+)", s) if not match: return None sentence = from_natural(match[2], context, _sentences_match_forall(), True) if not sentence: return None return cls(match[1], sentence)
def from_natural(cls, s: str, context=None, in_math=False): match = re.fullmatch(r"Let \$(\\?\w+)\$", s) if not match: return None if not isinstance(context.current_goal, SequenceLimit) and not isinstance( context.current_goal, ComposedSequenceLimit ): return None ident = from_natural( match[1], context, _sentences_match_letgoallimit(), in_math ) if not ident: return None hyp = context.next_anonymous() context.associate(ident.to_lean(), hyp) return cls(ident, hyp)
def from_natural(cls, s: str, context=None, in_math=False): match = re.fullmatch( r"Let's choose \$(\w+)\$ such that (\w+) uses \$(.+)\$ \(with (\w+)\)", s ) if not match: return None n_chosen = match[1] limit_def = match[2] eps = from_natural( match[3], context, _sentences_match_choosenepsilonlimit(), True ) if not eps: return None hyp_eps = match[4] hyp_n = context.next_anonymous() context.associate(n_chosen, hyp_n) return cls(limit_def, eps, hyp_eps, n_chosen, hyp_n)