-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve minimize performance #94
Open
savask
wants to merge
2
commits into
metamath:master
Choose a base branch
from
savask:minimize-speedup
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5150,6 +5150,86 @@ void command(int argc, char *argv[]) { | |
print2("Bytes refer to compressed proof size, " | ||
"steps to uncompressed length.\n"); | ||
|
||
/* Clear tmp for all math tokens */ | ||
for (k = 0; k < g_mathTokens; k++) | ||
g_MathToken[k].tmp = 0; | ||
|
||
long step, mlen; | ||
nmbrString *mString; | ||
|
||
/* Set tmp to 1 for math tokens present in the proof */ | ||
m = nmbrLen(g_ProofInProgress.proof); | ||
for (step = 0; step < m; step++) { | ||
mString = (g_ProofInProgress.target)[step]; | ||
mlen = nmbrLen(mString); | ||
|
||
for (i = 0; i < mlen; i++) { | ||
g_MathToken[mString[i]].tmp = 1; | ||
} | ||
} | ||
|
||
/* usefulStatements is a boolean array, where usefulStatements[k] == 1 | ||
iff statement k might be useful in minimization */ | ||
char *usefulStatements; | ||
usefulStatements = poolMalloc(g_proveStatement*sizeof(char)); | ||
long usefulCount = 0; | ||
|
||
/* Fill the usefulStatements array */ | ||
for (k = 1; k < g_proveStatement; k++) { | ||
usefulStatements[k] = 0; | ||
|
||
if (!mathboxFlag && k >= g_mathboxStmt && k < thisMathboxStartStmt) | ||
continue; | ||
|
||
if (g_Statement[k].type != (char)p_ && g_Statement[k].type != (char)a_) | ||
continue; | ||
|
||
if (!matchesList(g_Statement[k].labelName, g_fullArg[1], '*', '?')) | ||
continue; | ||
|
||
if (exceptPos != 0) { | ||
/* Skip any match to the EXCEPT argument */ | ||
if (matchesList(g_Statement[k].labelName, g_fullArg[exceptPos + 1], | ||
'*', '?')) | ||
continue; | ||
} | ||
|
||
if (forbidMatchList[0]) { /* User provided a /FORBID list */ | ||
/* First, we check to make sure we're not trying a statement | ||
in the forbidMatchList directly (traceProof() won't find | ||
this) */ | ||
if (matchesList(g_Statement[k].labelName, forbidMatchList, '*', '?')) | ||
continue; | ||
} | ||
|
||
/* Check to see if statement comment specified a usage | ||
restriction */ | ||
if (!overrideFlag) { | ||
if (getMarkupFlag(k, USAGE_DISCOURAGED)) | ||
continue; | ||
} | ||
|
||
/* Check if all math constants used in statement k are present | ||
in the minimized proof. Hypotheses are not checked. */ | ||
mString = g_Statement[k].mathString; | ||
mlen = nmbrLen(mString); | ||
|
||
usefulStatements[k] = 1; | ||
for (i = 0; i < mlen; i++) { | ||
if (g_MathToken[mString[i]].tokenType == (char)con_) { | ||
if (!g_MathToken[mString[i]].tmp) | ||
{ | ||
usefulStatements[k] = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be followed by a break; instruction There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
break; | ||
} | ||
} | ||
} | ||
|
||
usefulCount += usefulStatements[k]; | ||
} | ||
if (verboseMode) | ||
print2("Found %ld potentially useful theorems.\n", usefulCount); | ||
|
||
/* Scan forward, then reverse, then pick best result */ | ||
for (forwRevPass = 1; forwRevPass <= 2; forwRevPass++) { | ||
|
||
|
@@ -5182,38 +5262,9 @@ void command(int argc, char *argv[]) { | |
for (k = forwFlag ? 1 : (g_proveStatement - 1); | ||
k * (forwFlag ? 1 : -1) < (forwFlag ? g_proveStatement : 0); | ||
k = k + (forwFlag ? 1 : -1)) { | ||
if (!mathboxFlag && k >= g_mathboxStmt && k < thisMathboxStartStmt) { | ||
continue; | ||
} | ||
|
||
if (g_Statement[k].type != (char)p_ && g_Statement[k].type != (char)a_) | ||
continue; | ||
if (!matchesList(g_Statement[k].labelName, g_fullArg[1], '*', '?')) | ||
if(!usefulStatements[k]) | ||
continue; | ||
|
||
if (exceptPos != 0) { | ||
/* Skip any match to the EXCEPT argument */ | ||
if (matchesList(g_Statement[k].labelName, g_fullArg[exceptPos + 1], | ||
'*', '?')) | ||
continue; | ||
} | ||
|
||
if (forbidMatchList[0]) { /* User provided a /FORBID list */ | ||
/* First, we check to make sure we're not trying a statement | ||
in the forbidMatchList directly (traceProof() won't find | ||
this) */ | ||
if (matchesList(g_Statement[k].labelName, forbidMatchList, '*', '?')) | ||
continue; | ||
} | ||
|
||
/* Check to see if statement comment specified a usage | ||
restriction */ | ||
if (!overrideFlag) { | ||
if (getMarkupFlag(k, USAGE_DISCOURAGED)) { | ||
continue; | ||
} | ||
} | ||
|
||
/* Print individual labels */ | ||
if (prntStatus == 0) prntStatus = 1; /* Matched at least one */ | ||
|
||
|
@@ -5565,6 +5616,8 @@ void command(int argc, char *argv[]) { | |
g_Statement[g_proveStatement].labelName); | ||
} | ||
|
||
poolFree(usefulStatements); /* Deallocate memory */ | ||
|
||
free_vstring(str1); /* Deallocate memory */ | ||
free_nmbrString(nmbrSaveProof); /* Deallocate memory */ | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use
bool
,true
,false
as advised in #17 (comment) ? Then a few statements below have minor modifications, e.g.,usefulCount += usefulStatements[k];
has to be replaced by something likeif (usefulStatements[k]) {usefulCount += 1}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think originally I used
char
for consistency, for example, the.tmp
field uses0
and1
instead ofbool
. As a positive side effect,usefulCount
can be updated without branching (although I don't think it makes any great difference in this case).