Update 11/24: I asked this question as a 'side venture'. The start was my work on an algorithm that used the back substitution method for solving linear congruence equations; see this. I just posted a Python program to stackoveflow, explaining how it might be useful in some applications.
Update 11/23: After thinking about Daniel Fischer's comments this question can be closed. Without a doubt the idea here could not possibly speed up any state of the art computing algorithms that calculate the gcd of large numbers. What I was calling a turbo method actually performed the same number of residue calculations, but the subtraction $b - a$ seemed so 'light' I thought of it as executing with fewer computing cycles. Here we employ the 'turbo' method on a simple example:
Compute: $\text{gcd}(30,32)$. Since $2*30 \gt 32$, the problem is reduced to $\text{gcd}(32-30,30) = \text{gcd}(2,30)$ and since $2 \mid 30$ the gcd is $2$.
Update 11/22: Anybody who knows how to convert the Python code to pseudocode is welcome to edit this question to include it (see comment).
I created a Python program to compute the GCD of two numbers $(a,b)$ with $0 \lt a \lt b$.
The program counts how many modulus operations are used in the standard method and how many are used with my 'turbo' version.
Question:
Is the count of modulus operations for the turbo version always less than or equal to the count for the standard method?
Python program
def gcd(A,B):
# # Standard method
a = A
b = B
cnt = 0
while a:
a,b = b%a,a
cnt = cnt + 1
print('Standard:', 'answer =', b, 'modulus operations:', cnt)
# # Turbo method
a = A
b = B
cnt = 0
while True:
t = 2*a
if t > b:
a = b - a
a,b = b%a,a
cnt = cnt + 1
if a == 0:
break
print('TurboChg:', 'answer =', b, 'modulus operations:', cnt)
return
test_data = [
(32,82),
(24,56),
(36,60),
(227,2011),
(25,29),
(25527,53667),
(7,21),
]
for da_pair in test_data:
print()
print('***', 'WORKING ON', da_pair)
a, b = da_pair
gcd(a,b)
OUTPUT
*** WORKING ON (32, 82)
Standard: answer = 2 modulus operations: 5
TurboChg: answer = 2 modulus operations: 4
*** WORKING ON (24, 56)
Standard: answer = 8 modulus operations: 2
TurboChg: answer = 8 modulus operations: 2
*** WORKING ON (36, 60)
Standard: answer = 12 modulus operations: 3
TurboChg: answer = 12 modulus operations: 2
*** WORKING ON (227, 2011)
Standard: answer = 1 modulus operations: 6
TurboChg: answer = 1 modulus operations: 4
*** WORKING ON (25, 29)
Standard: answer = 1 modulus operations: 3
TurboChg: answer = 1 modulus operations: 2
*** WORKING ON (25527, 53667)
Standard: answer = 201 modulus operations: 5
TurboChg: answer = 201 modulus operations: 4
*** WORKING ON (7, 21)
Standard: answer = 7 modulus operations: 1
TurboChg: answer = 7 modulus operations: 1
TurboChrg
) stands every temptation to go greater than the other. – Spectre Nov 23 '20 at 17:26