-
Notifications
You must be signed in to change notification settings - Fork 29
Improve minimize performance #94
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5150,6 +5150,92 @@ 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] = 1; | ||
|
||
|
||
if (!mathboxFlag && k >= g_mathboxStmt && k < thisMathboxStartStmt) { | ||
usefulStatements[k] = 0; | ||
continue; | ||
} | ||
|
||
if (g_Statement[k].type != (char)p_ && g_Statement[k].type != (char)a_) { | ||
usefulStatements[k] = 0; | ||
continue; | ||
} | ||
if (!matchesList(g_Statement[k].labelName, g_fullArg[1], '*', '?')) { | ||
usefulStatements[k] = 0; | ||
continue; | ||
} | ||
|
||
if (exceptPos != 0) { | ||
/* Skip any match to the EXCEPT argument */ | ||
if (matchesList(g_Statement[k].labelName, g_fullArg[exceptPos + 1], | ||
'*', '?')) { | ||
usefulStatements[k] = 0; | ||
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, '*', '?')) { | ||
usefulStatements[k] = 0; | ||
continue; | ||
} | ||
} | ||
|
||
/* Check to see if statement comment specified a usage | ||
restriction */ | ||
if (!overrideFlag) { | ||
if (getMarkupFlag(k, USAGE_DISCOURAGED)) { | ||
usefulStatements[k] = 0; | ||
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); | ||
|
||
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. |
||
} | ||
} | ||
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 +5268,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 +5622,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 */ | ||
|
||
|
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).