Last active
April 8, 2022 05:02
-
-
Save bitRAKE/d1d768de771bd760941ba6b89904dc4b to your computer and use it in GitHub Desktop.
Euler's sum of powers conjecture, k=5
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
; couldn't help myself after watching the video: | |
; https://www.youtube.com/watch?v=YMpdGLvqlrM | |
; (there is a better way, tomorrow perhaps) | |
; Euler's sum of powers conjecture. | |
; https://en.wikipedia.org/wiki/Euler%27s_sum_of_powers_conjecture | |
; | |
; It is unknown whether the conjecture fails or holds for any value k ≥ 6. | |
; | |
; Euler's conjecture was disproven by L. J. Lander and T. R. Parkin in 1966 when, | |
; through a direct computer search on a CDC 6600, they found a counterexample for | |
; k = 5. This was published in a paper comprising just two sentences. A total of | |
; three primitive (that is, in which the summands do not all have a common factor) | |
; counterexamples are known: | |
; 27^5 + 84^5 + 110^5 + 133^5 = 144^5 (Lander & Parkin, 1966), | |
; (−220)^5 + 5027^5 + 6237^5 + 14068^5 = 14132^5 (Scher & Seidl, 1996), | |
; 55^5 + 3183^5 + 28969^5 + 85282^5 = 85359^5 (Frye, 2004). | |
format PE64 CONSOLE 6.0 at 0x10000 | |
include '~\mywin.inc' ; in my repos | |
main: entry $ | |
virtual at RBP-.FRAME | |
.e: dd ?,? | |
.a: dd ?,? | |
.b: dd ?,? | |
.c: dd ?,? | |
.d: dd ?,? | |
.e5.0 dq ? | |
.e5.1 dq ? | |
_align 16 | |
.FRAME := $ - $$ | |
end virtual | |
enter .FRAME,0 | |
mov ecx,2 | |
.e_begin: | |
mov [.e],rcx | |
pow5 [.e],1 ; halt on overflow | |
mov [.e5.0],rax | |
mov [.e5.1],rdx | |
mov qword [.a],1 | |
.a_begin: | |
pow5 [.a] | |
push rdx rax | |
p2p [.b],[.a] | |
.b_begin: | |
pow5 [.b] | |
add rax,[rsp] | |
adc rdx,[rsp+8] | |
push rdx rax | |
p2p [.c],[.b] | |
.c_begin: | |
pow5 [.c] | |
add rax,[rsp] | |
adc rdx,[rsp+8] | |
push rdx rax | |
p2p [.d],[.c] | |
.d_begin: | |
pow5 [.d] | |
add rax,[rsp] | |
adc rdx,[rsp+8] | |
cmp [.e5.1],rdx | |
jc .d_end | |
jnz .next | |
cmp [.e5.0],rax | |
jc .d_end | |
jnz .next | |
OUTPUT | |
jmp .d_end | |
.next: | |
add dword [.d],1 | |
cmp [.d],ecx | |
jc .d_begin | |
.d_end: | |
add dword [.c],1 | |
add rsp,16 | |
cmp [.c],ecx | |
jc .c_begin | |
.c_end: | |
add dword [.b],1 | |
add rsp,16 | |
cmp [.b],ecx | |
jc .b_begin | |
.b_end: | |
add dword [.a],1 | |
add rsp,16 | |
cmp [.a],ecx | |
jc .a_begin | |
add ecx,1 | |
jmp .e_begin | |
.e_end: | |
@@: ExitProcess 0 | |
int3 | |
dq main ; force relocations :/ | |
_end _winx.entry ; create import section | |
section '.data' data readable writeable | |
_CONST_ | |
align 64 | |
label buffer:1024 ; limited at API level | |
rb sizeof buffer | |
macro p2p dest*,src* | |
push src | |
pop dest | |
end macro | |
macro m2m dest*,src* | |
mov eax,src | |
mov dest,eax | |
end macro | |
macro pow5 regmem*,halt:0 | |
; 2^16 limit | |
; mov eax,regmem | |
; imul eax,eax | |
; imul rax,rax | |
; mul qword regmem | |
; ??? limit | |
mov eax,regmem | |
imul eax,eax | |
mul rax | |
xchg rbx,rax | |
xchg rax,rdx | |
mul qword regmem ; Z:Y:0 | |
if halt | |
local okay | |
jno okay | |
HALTED | |
okay: | |
end if | |
xchg rax,rbx | |
; discard RDX | |
mul qword regmem | |
add rdx,rbx | |
end macro | |
macro OUTPUT | |
; stack is aligned at this point, but no parameter space | |
; only need to store RCX | |
local llocal | |
virtual at RSP | |
rq 4 | |
.P5 dq ? | |
.char_count dq ? | |
_align 16 | |
llocal := $ - $$ | |
end virtual | |
sub rsp,llocal | |
wvsprintfW ADDR buffer,<_T "%d^5 = %d^5 + %d^5 + %d^5 + %d^5",10>,ADDR .e | |
mov [.char_count],rax | |
GetStdHandle STD_OUTPUT_HANDLE | |
xchg rcx,rax | |
WriteConsoleW rcx,ADDR buffer,[.char_count],0,0 | |
add rsp,llocal | |
mov ecx,[.e] | |
end macro | |
macro HALTED | |
; stack is aligned at this point, but no parameter space | |
; only need to store RCX | |
local llocal | |
virtual at RSP ; must mirror frame in OUTPUT | |
rq 6 | |
_align 16 | |
llocal := $ - $$ | |
end virtual | |
sub rsp,llocal | |
wvsprintfW ADDR buffer,<_T "HALTED e = %d",10>,ADDR .e | |
mov [.char_count],rax | |
GetStdHandle STD_OUTPUT_HANDLE | |
xchg rcx,rax | |
WriteConsoleW rcx,ADDR buffer,[.char_count],0,0 | |
add rsp,llocal | |
jmp .e_end | |
end macro |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment