CCongrua
Product

Product features · Pairwise-coprime congruence merging

01

Review congruences.py for the coprime assumption before using a combined residue as a schedule or index.

01

Connection

Base URL, credentials and a reachable server.

02

Selection

A model available through the configured endpoint.

03

Capabilities

Context limits and tool support are determined by the model and server.

Pairwise-coprime congruence merging

● ● ●Congrua●
A concrete starting point · Pairwise-coprime congruence merging ×
import math

def merge_congruences(pairs):
    if type(pairs) is not list or len(pairs) > 8:
        raise ValueError("crt.input")
    answer, period = 0, 1
    for pair in pairs:
        if type(pair) not in (list, tuple) or len(pair) != 2 or any(type(x) is not int for x in pair):
            raise ValueError("crt.pair")
        residue, modulus = pair
        if abs(residue) > 10**9 or not 2 <= modulus <= 10**6 or math.gcd(period, modulus) != 1:
            raise ValueError("crt.modulus")
        step = ((residue-answer)*pow(period, -1, modulus)) % modulus
        answer += period*step
        period *= modulus
        answer %= period
    return answer, period
✳Pairwise-coprime congruence merging
✓ ChangesReview before applying ↗
Illustrative workspace
AI coding workspace

Your next change starts here.

Get the Windows app ↗