# ECMAScript, NPCG+ dependent ^ (?=(x*)\1(x*)) # \1 = floor(tail/2); \2 = \1.remainder == tail%2 (?=\2*(x?)) # \3 = 1-(tail%2) \1\2 # tail = \1 # Assert that tail*2+\2 == N^K where N>=2 and K>=2 (\3(x*)) # \4 = floor( (potential Kth perfect root of tail*2+\2) /2); # \4.remainder = \2; # \5 = floor(((potential Kth perfect root of tail*2+\2) - 1)/2); # \5.remainder = \3; tail.remainder = 0 (?: # tail == floor((N^J-N)/2) == floor((N^(J-1)-1)*N/2); # tail.remainder == 0 (?= (?= \4$\2 # only needed in the case of N==2 | (?=(\4\4\2)+(x*)) # \6 = \4*2+\2; \7 = remainder (?=.*(?=\6)\7(x*)) # \8 = \6 - \7 \8\6*$ ) ((x*)(x|(?=(x)))) # \9 = floor(((N^J-N) / (\4*2+\2) )/2) # \9.remainder = \12; # \10 = floor(((N^J-N) / (\4*2+\2)-1)/2) # \10.remainder = \11; # tail -= \9; tail.remainder = \12 (?= \12 ( (?=\9$) # only needed in the case of N==2 | (?=(\9\9\12)) # \14 = \9*2+\12 (?= \9\9 # do first subtraction without remainder, because # tail.remainder - \9.remainder == \12 - \12 == 0 \14* (x*) # \15 = remainder ) (?=.*(?=\14)\15(x*)) # \16 = \14 - \15 (?=\16\14*$) ) ) ( # \17 = tool to make tail = \9 (?= .*(?=\12$) \3(x*) # \18 | (x) # \19 ) (?=(\18\19)) # \20 = \18+\19 \12 \5\19 # tail -= \5; tail.remainder = \20 ( (?=.*(?=\20$)\11$) \10$ | (?= (\10\10\11)+ # \22 = \10*2+\11 (x*) # \23 = remainder ) (?=.*(?=\22)\20\23(x*)) # \24 = \22 - \23 - \20 \24\22*$ ) ) ) (?=.*(?=\12$)\3$) \17\5 # tail = floor((\9*2+\3 + 1 - N)/2); tail.remainder = 0 )+ $