Post Reply 
(32SII) Solving a Single Congruence Equation for the HP 32Sii
03-10-2019, 07:41 PM (This post was last modified: 08-23-2019 01:18 AM by Albert Chan.)
Post: #5
RE: (32SII) Solving a Single Congruence Equation for the HP 32Sii
With post #4 LC(), for solving A x ≡ B (mod N), we can do Simultaneuous Linear Congruence

Code:
def SLC(eqn1, eqn2):
    'Simultaneous Linear Congreuence Solver'
    try:
        (x1, m1), (x2, m2) = eqn1, eqn2
        (x3, m3) = LC(m1, x2-x1, m2)
    except ValueError: return ()    # no solution
    x3 = x1 + m1 * x3
    m3 = m1 * m3
    return (x3 % m3, m3)

Example: x≡3 (mod 7) AND x≡105 (mod 143) AND x≡27 (mod 312) AND x≡248 (mod 715)

>>> reduce(SLC, [(3,7), (105, 143), (27, 312), (248, 715)])
(35283, 120120)

>>> # Second congruence is covered by the fourth, and safe to eliminate
...
>>> reduce(SLC, [(3,7), (27, 312), (248, 715)])
(35283, 120120)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (32SII) Solving a Single Congruence Equation for the HP 32Sii - Albert Chan - 03-10-2019 07:41 PM



User(s) browsing this thread: 1 Guest(s)