[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Slowness in bignum mode ( gmp | gawk -M ) when doubling extremely la
From: |
pjfarley3 |
Subject: |
RE: Slowness in bignum mode ( gmp | gawk -M ) when doubling extremely large inputs |
Date: |
Thu, 27 Jan 2022 19:35:49 -0500 |
As an exercise for myself, I manually reformatted this _2x_ function converting
the "all underscore" names to names like _n1, _n2, etc. up to _n12 to make the
code a little easier to understand.
It would have been more helpful if the variable names had been chosen for what
function / intermediate result they represent rather than just arbitrary names.
Or the names could just have been any sequence of single-letter variable names
for more brevity.
Using absolutely minimal spacing everywhere reduces the byte space occupied but
is much harder for humans unfamiliar with the algorithm to understand.
Embedding assignments in "if" conditions may be optimal, but IMHO make the code
much harder to understand, especially with minimal spacing as well.
There are also several strange uses of the exclamation point operator (!) that
I do not understand, but that is probably just my lack of experience. Examples
of such use are:
_n1-!!_n1
-!-""
!+""
!--_n10
I THINK these are intended to be uses of the negation operator, but I don’t
understand what that operation is supposed to do to an empty string.
Reformatted results are pasted below. Corrections welcomed, if you are
interested. I may also run this copy through a pretty-printer to see what that
looks like.
Peter
Reformatted function _2x_:
function _2x_(_n2,_n1,_n7,_n4,_n9,
_n11,_n10,_n12,_n8,_n5,_n6,_n3) {
if(_n2!~/[1-9]/) {
return +_n1
}
_n3=(_n2~/^[-]/)
sub("^[+-]?["(-"")"]*","",_n2)
if (length(_n2)<(_n5=((_n1+=++_n1)^_n1^_n1-!!_n1))+_n1) {
if (_n9^((_n5+(_n1~_n4))^(_n5-_n1)<+_n2)) {
return (-!-"")^_n3*(+_n2+_n2)
}
}
_n3=substr("-",_n1~"",_n3)
if (_n2!~"[5-9]") {
gsub(/4/,"8",_n2)-gsub(/3/,"6",_n2)
gsub(/2/,"4",_n2)-gsub(/1/,"2",_n2)
return (_n3)_n2
};
_n7=_n4=_n8="";
_n2=(_n5=substr(_n8=(_n1++^_n1--+_n1)^_n5,_n1))(_n2)
gsub(/./,".",_n5)
sub("("(_n5)")+$","_&",_n2)
_n2=substr(_n2,index(_n2,"_")+!+"")
_n8+=+_n8;_n1="";
if ((gsub(_n5,"&_",_n2)+gsub(/[_n1][5-9]/,".5&",_n2)*(+""))%2) {
_n1=(":")(_n8+_n2+_n2)
_n2=substr(_n2,index(_n2,"_")+!+"")
}
for(_n5 in _n6) { }
if (_n6[_n5=split(_n2,_n6,/[_n1]/)]=="") {
delete _n6[_n5--]
};
_n2=_n4~_n4;
_n10=_n12*=\
_n12=_n11=_n9=32;
while(_n2<_n5) {
if(!--_n10){
_n10=_n12;_n7=(_n7)_n1;
_n1="";
if(!--_n11){
_n11=_n9;_n4=(_n4)_n7;_n7="";
}
}
_n1=(_n1)(":")(+_n6[_n2++]*2+_n8)\
(":")(+_n6[_n2++]*2+_n8)
}
_n4=(_n4)(_n7)(_n1)\
(_n2==_n5?(":")(_n8+2*_n6[_n5]):"")
gsub(/[:]+[^:]/,"",_n4)
sub(/^0*/,"",_n4);
return (_n3)_n4
}
- Slowness in bignum mode ( gmp | gawk -M ) when doubling extremely large inputs, Jason C. Kwan, 2022/01/26
- Re: Slowness in bignum mode ( gmp | gawk -M ) when doubling extremely large inputs, arnold, 2022/01/27
- Re: Slowness in bignum mode ( gmp | gawk -M ) when doubling extremely large inputs, Jason C. Kwan, 2022/01/27
- Re: Slowness in bignum mode ( gmp | gawk -M ) when doubling extremely large inputs, arnold, 2022/01/27
- Re: Slowness in bignum mode ( gmp | gawk -M ) when doubling extremely large inputs, Andrew J. Schorr, 2022/01/27
- Re: Slowness in bignum mode ( gmp | gawk -M ) when doubling extremely large inputs, Jason C. Kwan, 2022/01/27
- Re: Slowness in bignum mode ( gmp | gawk -M ) when doubling extremely large inputs, Andrew J. Schorr, 2022/01/27
- Re: Slowness in bignum mode ( gmp | gawk -M ) when doubling extremely large inputs, Wolfgang Laun, 2022/01/27
- RE: Slowness in bignum mode ( gmp | gawk -M ) when doubling extremely large inputs,
pjfarley3 <=
- Re: Slowness in bignum mode ( gmp | gawk -M ) when doubling extremely large inputs, arnold, 2022/01/28
- RE: Slowness in bignum mode ( gmp | gawk -M ) when doubling extremely large inputs, pjfarley3, 2022/01/28
- Use of !!, arnold, 2022/01/29