模乘与求阶

oracq.algorithms.basics.number_theory

Small-scale modular multiplication, quantum order finding, and classical factor post-processing.

oracq.algorithms.basics.number_theory.modular_multiply(multiplier, modulus, *, width=None, max_width=8)[源代码]

Generate a reversible bounded-size modular multiplication permutation.

参数:
  • multiplier -- Positive integer coprime with modulus.

  • modulus -- Modulus of at least two.

  • width -- Target bit width; when omitted, the smallest width that fits the modulus.

  • max_width -- Permutation synthesis budget, default 8, at most 12.

返回:

Maps x<modulus to multiplier*x mod modulus; other basis states are left unchanged.

返回类型:

Operation

The implementation enumerates a finite permutation and does not represent scalable Shor modular arithmetic.

oracq.algorithms.basics.number_theory.order_finding(multiplier, modulus, *, precision=3, max_width=8)[源代码]

Run quantum order finding on the modular multiplication unitary starting from the integer one.

参数:
  • multiplier -- Multiplier coprime with modulus.

  • modulus -- The modulus.

  • precision -- Phase bit width of the QPE.

  • max_width -- Bit width budget of the underlying modular multiplication permutation.

返回:

target/phase interface. phase carries fractional information about the order and needs classical post-processing.

返回类型:

Operation

oracq.algorithms.basics.number_theory.factors_from_phase(value, precision, multiplier, modulus)[源代码]

Attempt to obtain a nontrivial factor from the continued-fraction candidate order of a phase sample.

参数:
  • value -- Integer readout of the phase register.

  • precision -- Bit width of the phase register.

  • multiplier -- The multiplier used in quantum order finding.

  • modulus -- The integer to process.

返回:

A verified factor pair, or None when this sample yields no factor.

返回类型:

tuple or None