Can I believe the values of these large integers?
Mostra commenti meno recenti
% coinStackv4
%
% Geoffrey T Fox
%
% https://projecteuler.net/problem=78
%
% Based on Bob's Excel work
%
% 27 December 2022
%
clear; clc; tic;
mAx = 10000;
daTa = zeros(mAx,mAx);
daTa(:,2) = 2;
daTa(:,1) = 1;
daTa(1,:) = 1;
daTa(3,3) = 3;
for idx = 3:mAx
daTa(2,idx) = 1 + floor(idx/2);
end
for idx = 3:mAx % mAx
jMid = 1 + idx;
for jdx = 3:mAx
if idx < jdx
daTa(idx,jdx) = daTa(idx-1,jdx)+ daTa(idx,jdx-idx);
elseif idx == jdx
daTa(idx,jdx) = daTa(idx-1,idx) + 1;
elseif idx > jdx
daTa(idx,jdx) = daTa(idx-1,jdx);
end
end
end
for idx = 1:mAx
if mod(daTa(idx,idx), 1000000) == 0
fprintf("%3.0f yields %15.0f\n",idx,daTa(idx,idx))
fprintf("above line is divisable by 1,000,000\n")
end
end
toc
3 Commenti
Jan
il 28 Dic 2022
For which reasons do you hesitate to believe what?
Geoffrey Fox
il 28 Dic 2022
"...which I understand to be the largest integer possibe under 64 bit."
The largest possible integer using DOUBLE() class is:
realmax()
Possibly you are actually thinking of the largest contiguous integer, which is 2^53:
flintmax()
"Can I believe the values of these large integers?"
You should never believe anything that any calculation tells you.
Risposta accettata
Più risposte (2)
Image Analyst
il 28 Dic 2022
Your data is double. You can make it 64 bit unsigned integer like
daTa = zeros(mAx,mAx, 'uint64'); % Pass in the option to make it 'uint64'.
3 Commenti
Geoffrey Fox
il 28 Dic 2022
John D'Errico
il 28 Dic 2022
Modificato: John D'Errico
il 28 Dic 2022
The uint64 value you got is the largest integer you can compute using a uint64.
intmax('uint64')
Essentially, you caused an overflow. and uint64 just maxes out at that value when you do. The number you got was actually just 2^64-1.
sym(2)^64
However, the "number" you computed as a double is meaningless, if you think the lower order digits of that number have any meaning.
Jan
il 28 Dic 2022
Remember, that Matlab stores numbers with about 16 valid digits as doubles in the IEEE754 format. This means, that the trailing zeros of 17022871133751703055227888846952967314604032000000 are not meaningful.
The used approach is not applicable.
Paul
il 28 Dic 2022
What happens if you change this line to work in symbolic world? It will be slow .... (couldn't run here, exceeded the 55 second limit)
%daTa = zeros(mAx,mAx);
daTa = zeros(mAx,mAx,'sym');
4 Commenti
Geoffrey Fox
il 28 Dic 2022
Spostato: John D'Errico
il 28 Dic 2022
Actually
A = zeros(5,5,'sym')
is allowed in current releases. However, for large arrays, it WILL be slow.
How about
daTa = sym(zeros(mAx,mAx));
Geoffrey Fox
il 28 Dic 2022
Categorie
Scopri di più su Logical in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
