Skip to content

Commit

Permalink
bug: Fix theorems with no Proof. parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
K-dizzled committed Nov 21, 2023
1 parent fdbd350 commit 9c8cebb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log

### 1.4.6
- Fix issue with plugin breaking after parsing a file containing theorem without `Proof.` keyword.

### 1.4.5
- Fix formatting issues when inserting the proof into the editor.

Expand Down
9 changes: 6 additions & 3 deletions src/coqLlmInteraction/llmPromptInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class SeparatedTheorems {
constructor(
public readonly admittedTheorems: Theorem[],
public readonly trainingTheorems: Theorem[],
public readonly cleanedFileTheorems: Theorem[],
) {}
}

Expand Down Expand Up @@ -35,11 +36,11 @@ export class LlmPromptBase {
parsedFile: Theorem[],
tokenLimit: number,
) {
this.theoremsFromFile = parsedFile;
this.promptStrategy = this.constructor.name;
const separatedTheorems = this.computeTrainingTheorems(this.theoremsFromFile, tokenLimit);
const separatedTheorems = this.computeTrainingTheorems(parsedFile, tokenLimit);
this.trainingTheorems = separatedTheorems.trainingTheorems;
this.admittedTheorems = separatedTheorems.admittedTheorems;
this.theoremsFromFile = separatedTheorems.cleanedFileTheorems;
}

countTokens = (str: string): number => {
Expand Down Expand Up @@ -86,12 +87,14 @@ export class LlmPromptBase {
let theoremsTokensSum = 0;
let provenTheorems: Theorem[] = [];
let admittedTheorems: Theorem[] = [];
let cleanedFileTheorems: Theorem[] = [];

for (const theorem of theorems) {
if (!theorem.proof) {
continue;
}

cleanedFileTheorems.push(theorem);
if (theorem.proof.is_incomplete) {
admittedTheoremsMaxTokenCount = Math.max(
admittedTheoremsMaxTokenCount,
Expand All @@ -118,7 +121,7 @@ export class LlmPromptBase {
theoremsTokensSum -= this.countTokens(theorem.statement) + this.countTokens(theorem.proof.onlyText());
}

const separated = new SeparatedTheorems(admittedTheorems, provenTheorems);
const separated = new SeparatedTheorems(admittedTheorems, provenTheorems, cleanedFileTheorems);
logger.info(`Admitted theorems: ${separated.admittedTheorems.map((th) => th.name)}`);
logger.info(`Training theorems: ${separated.trainingTheorems.map((th) => th.name)}`);
return separated;
Expand Down

0 comments on commit 9c8cebb

Please sign in to comment.