From e8443cd07126425aad3f97fd734582e48e4bf712 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Sun, 3 May 2015 16:19:23 +0200 Subject: [PATCH] Fixed wrong step in max_length proof --- src/extmatch.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/extmatch.c b/src/extmatch.c index 486a612..f03154d 100644 --- a/src/extmatch.c +++ b/src/extmatch.c @@ -218,21 +218,26 @@ static int transform(const char *pattern, char *result, const char **errmsg) { * We must now find the maximal length L such as ∀s, L >= length(T(s)) * * It is immediately apparent that the largest string will depend on the number - * of occurrences of '!()'. Hence, let s be a string that is a repeating - * sequence of '!()', + * of occurrences of '!()'. Hence, let u be a string that is a repeating + * sequence of '!()' padded by '.' to a multiple of 3, * - * let N = floor(length(s) / 3), - * let Q = length(s) mod 3, - * ∀s, num('!()') = N (1) + * let N = floor(length(u) / 3), + * let Q = length(u) mod 3, + * hence num('!()') = N. * - * ∀s, length(T(s)) <= length(s) + 4 * N - * <= 3 * N + Q + 4 * N - * <= 7 * N + 2 - * <= 7 * floor(length(s) / 3) + 2 + * ∀s | lenght(s) = length(u), + * length(T(s)) <= length(T(u)) + * <= length(u) | the original length + * + 4 * N | the expansion of all '!()' + * + Q * diff('.') | the expansion of Q '.' + * <= 3 * N + Q + 4 * N + Q + * <= 7 * N + 4 + * <= 7 * floor(length(u) / 3) + 4 + * <= 7 * floor(length(s) / 3) + 4 * */ static inline size_t max_length(size_t len) { - return 7 * len / 3 + 2; + return 7 * len / 3 + 4; } int extmatch(const char *pattern, const char *string, const char **errmsg) {