it's probably easier to see just see it in action instead of tryign to explain the symbols and notation : here, I've automated a process that incorporates the Homer nested formatting with the binary-squaring algorithm.
The generated algebraic statement could be directly plugged into bc
or Wolfram Alpha to confirm the result. Modify those ^
to **
if you wanna plug them into python
or perl
.
- all the "1" bits reside on the left half of the formula, and
- all the squarings reside on the right
I preferred using LSB
bit-string instead of MSB
in this structure because it's a lot easier to read -
17^1
| expn LSB bitstring := 1
| 17
17^2
| expn LSB bitstring := 01
| (17)^2
17^3
| expn LSB bitstring := 11
| 17*(17)^2
17^5
| expn LSB bitstring := 101
| 17*((17)^2)^2
17^7
| expn LSB bitstring := 111
| 17*(17*(17)^2)^2
17^11
| expn LSB bitstring := 1101
| 17*(17*((17)^2)^2)^2
17^13
| expn LSB bitstring := 1011
| 17*((17*(17)^2)^2)^2
17^17
| expn LSB bitstring := 10001
| 17*((((17)^2)^2)^2)^2
17^19
| expn LSB bitstring := 11001
| 17*(17*(((17)^2)^2)^2)^2
17^23
| expn LSB bitstring := 11101
| 17*(17*(17*((17)^2)^2)^2)^2
17^29
| expn LSB bitstring := 10111
| 17*((17*(17*(17)^2)^2)^2)^2
17^31
| expn LSB bitstring := 11111
| 17*(17*(17*(17*(17)^2)^2)^2)^2
17^37
| expn LSB bitstring := 101001
| 17*((17*(((17)^2)^2)^2)^2)^2
17^41
| expn LSB bitstring := 100101
| 17*(((17*((17)^2)^2)^2)^2)^2
17^43
| expn LSB bitstring := 110101
| 17*(17*((17*((17)^2)^2)^2)^2)^2
17^47
| expn LSB bitstring := 111101
| 17*(17*(17*(17*((17)^2)^2)^2)^2)^2
17^53
| expn LSB bitstring := 101011
| 17*((17*((17*(17)^2)^2)^2)^2)^2
17^59
| expn LSB bitstring := 110111
| 17*(17*((17*(17*(17)^2)^2)^2)^2)^2
17^61
| expn LSB bitstring := 101111
| 17*((17*(17*(17*(17)^2)^2)^2)^2)^2
17^67
| expn LSB bitstring := 1100001
| 17*(17*(((((17)^2)^2)^2)^2)^2)^2
17^71
| expn LSB bitstring := 1110001
| 17*(17*(17*((((17)^2)^2)^2)^2)^2)^2
17^73
| expn LSB bitstring := 1001001
| 17*(((17*(((17)^2)^2)^2)^2)^2)^2
17^79
| expn LSB bitstring := 1111001
| 17*(17*(17*(17*(((17)^2)^2)^2)^2)^2)^2
17^83
| expn LSB bitstring := 1100101
| 17*(17*(((17*((17)^2)^2)^2)^2)^2)^2
17^89
| expn LSB bitstring := 1001101
| 17*(((17*(17*((17)^2)^2)^2)^2)^2)^2
17^97
| expn LSB bitstring := 1000011
| 17*(((((17*(17)^2)^2)^2)^2)^2)^2
17^101
| expn LSB bitstring := 1010011
| 17*((17*(((17*(17)^2)^2)^2)^2)^2)^2
17^103
| expn LSB bitstring := 1110011
| 17*(17*(17*(((17*(17)^2)^2)^2)^2)^2)^2
17^107
| expn LSB bitstring := 1101011
| 17*(17*((17*((17*(17)^2)^2)^2)^2)^2)^2
17^109
| expn LSB bitstring := 1011011
| 17*((17*(17*((17*(17)^2)^2)^2)^2)^2)^2
17^113
| expn LSB bitstring := 1000111
| 17*((((17*(17*(17)^2)^2)^2)^2)^2)^2
17^127
| expn LSB bitstring := 1111111
| 17*(17*(17*(17*(17*(17*(17)^2)^2)^2)^2)^2)^2
# gawk profile, created Wed Nov 1 18:44:07 2023
# Rule(s)
32 _ = NF { # 32
32 printf("\f %11s^%-5s \f\r\t| expn "\
"LSB bitstring := %*s\f\f\r\t| ",
__ = $!!_, $!_ = $_, _ = !_, $_ = ____($_)) >> ("/dev/stdout")
32 print($!(NF=(gsub(/[^01]+/,"")^_ * gsub(_,
"(") + gsub(!_,(__)"*(") * sub(/[^0-9]*$/, "")) "\n") >> ("/dev/stdout")
}
32 NF { # 32
32 print
}
# Functions, listed alphabetically
176 function ____(__, ___, _) {
176 if (_ == "") {
32 ___ = length(__ = (_) __)
32
if ((__ *= _++ < (__ = int(__))) < ++_)
1 return __
31 _^= (___ += __+__ < (_+_)^_^_ \
? _*--___ \
: _*___-_^(__ < (_*_^_^_)^_))
31 if (__ < _)
___ -= __ < (__ += __)
31 if (_+_ <= __)
while ((_ += _+!++___)+_ <= __) { }
31 return (_<__ ? ____(__ -= _, ___, _) \
: sprintf("%.*d", ___, !_)) !!_
}
144 return \
(!--___ ? !! +__ : (__ += __)<_ \
? ____(__, ___, _) !_ \
: ____(__-=_, ___, _) !!_ )
}
1 664612181399115898708880371971190911115999473: 17^127
2 845524284376730618271605950983326957831601937: 17^113
3 064844117339164721813894369152081312807052497: 17^109
4 484653439852384653016657073941702703504522673: 17^107
5 861142522879753024803977642234575037448108913: 17^103
6 861111219802352086591017223675552162759336017: 17^101
7 0473579831553978069612272255088225422973416977: 17^97
8 8773613853135920674790271577278638959930577297: 17^89
9 5753941864386337047277655624320393544131928113: 17^83
10 5405894971825820887406128729967604798715821553: 17^79
11 3616579424626190476175164425470051684475963537: 17^73
12 7348154254064450486076730672752491528319986033: 17^71
13 6645123360044229169316532090500266429898209073: 17^67
14 1303399553000691993639838764066592228085041617: 17^61
15 7305548095339102740462421587418915544041816753: 17^59
16 4628544709931149045668299921272999257668224337: 17^53
17 9730995471356071936289402038303854098687372273: 17^47
18 0641272625991922463475488672334362661535406513: 17^43
19 5607755268602048174614102036928492604365174417: 17^41
20 3362095853201812742282475234995233875224247377: 17^37
21 139288917338851014461418017489467720433: 17^31
22 481968572106750915091411825223071697: 17^29
23 19967568900859523802559065713: 17^23
24 239072435685151324847153: 17^19
25 827240261886336764177: 17^17
26 9904578032905937: 17^13
27 34271896307633: 17^11
28 410338673: 17^7
29 1419857: 17^5
30 4913: 17^3
31 289: 17^2
32 17: 17
I kept all the extry layers of nesting brackets for clarity purposes only, and there are obvious ways to further streamline the statements :
say
17^89 := LSB : 1 001 1 01
\
MSB : 10 1 100 1
/ | \
[4] __/ [2] \__ [8]
LSB | 1 0..0..1 1 0..1
-----------------------
=> 17*( ( (17*(17*( (17) ^ 2) ^ 2) ^ 2) ^ 2) ^ 2 ) ^ 2
=> 17*( 17*(17* (17) ^ [4] ) ^ 2) ^ [8]
=> 17*(17*(17*(17)^4)^2)^8