Documentation

CslibFrontier.Computability.Machines.Turing.MultiTape.Complexity.PolyTime.Rat

Polynomial-time primitives and arithmetic on rational numbers #

Polynomial-time certificates for Turing.MultiTapeTM.encRat: extracting the signed binary numerator and binary denominator, casting integers, constructing normalized quotients Rat.divInt, arithmetic (-, ⁻¹, +, -, *, /), and zero/order comparisons.

Main results #

Projecting a rational number q to its numerator-denominator pair (q.num, q.den) is computable in polynomial time under encRat and encRatData.

Extracting the binary numerator q.num from encRat q is computable in polynomial time.

Extracting the binary denominator q.den from encRat q is computable in polynomial time.

Casting a binary integer z : ℤ to (z : ℚ) is computable in polynomial time under encIntBin and encRat.

Casting a binary natural n : ℕ to (n : ℚ) is computable in polynomial time under encNat and encRat.

Forming the normalized rational quotient Rat.divInt p.1 p.2 from signed binary integers is computable in polynomial time under encRat.

theorem Turing.MultiTapeTM.ComputableInPolyTime.rat_divInt' {α : Type} {input : α ↪ List Bool} {num den : α → ℤ} (hnum : ComputableInPolyTime num input encIntBin) (hden : ComputableInPolyTime den input encIntBin) :
ComputableInPolyTime (fun (x : α) => Rat.divInt (num x) (den x)) input encRat

Normalized quotient Rat.divInt of computed binary integers.

Negation on ℚ is computable in polynomial time.

theorem Turing.MultiTapeTM.ComputableInPolyTime.rat_neg' {α : Type} {input : α ↪ List Bool} {f : α → ℚ} (hf : ComputableInPolyTime f input encRat) :
ComputableInPolyTime (fun (x : α) => -f x) input encRat

Negation of a computed rational number.

Multiplicative inverse on ℚ is computable in polynomial time.

theorem Turing.MultiTapeTM.ComputableInPolyTime.rat_inv' {α : Type} {input : α ↪ List Bool} {f : α → ℚ} (hf : ComputableInPolyTime f input encRat) :
ComputableInPolyTime (fun (x : α) => (f x)⁻¹) input encRat

Multiplicative inverse of a computed rational number.

Addition on ℚ is computable in polynomial time.

theorem Turing.MultiTapeTM.ComputableInPolyTime.rat_add' {α : Type} {input : α ↪ List Bool} {left right : α → ℚ} (hleft : ComputableInPolyTime left input encRat) (hright : ComputableInPolyTime right input encRat) :
ComputableInPolyTime (fun (x : α) => left x + right x) input encRat

Addition of computed rational numbers.

Subtraction on ℚ is computable in polynomial time.

theorem Turing.MultiTapeTM.ComputableInPolyTime.rat_sub' {α : Type} {input : α ↪ List Bool} {left right : α → ℚ} (hleft : ComputableInPolyTime left input encRat) (hright : ComputableInPolyTime right input encRat) :
ComputableInPolyTime (fun (x : α) => left x - right x) input encRat

Subtraction of computed rational numbers.

Multiplication on ℚ is computable in polynomial time.

theorem Turing.MultiTapeTM.ComputableInPolyTime.rat_mul' {α : Type} {input : α ↪ List Bool} {left right : α → ℚ} (hleft : ComputableInPolyTime left input encRat) (hright : ComputableInPolyTime right input encRat) :
ComputableInPolyTime (fun (x : α) => left x * right x) input encRat

Multiplication of computed rational numbers.

Division on ℚ is computable in polynomial time.

theorem Turing.MultiTapeTM.ComputableInPolyTime.rat_div' {α : Type} {input : α ↪ List Bool} {left right : α → ℚ} (hleft : ComputableInPolyTime left input encRat) (hright : ComputableInPolyTime right input encRat) :
ComputableInPolyTime (fun (x : α) => left x / right x) input encRat

Division of computed rational numbers.

Raising a rational number to a unary natural exponent is computable in polynomial time.

theorem Turing.MultiTapeTM.ComputableInPolyTime.rat_pow' {α : Type} {input : α ↪ List Bool} {base : α → ℚ} {exponent : α → ℕ} (hbase : ComputableInPolyTime base input encRat) (hexponent : ComputableInPolyTime exponent input encUnary) :
ComputableInPolyTime (fun (x : α) => base x ^ exponent x) input encRat

Raising a computed rational number to a computed unary exponent.

Zero test on ℚ is computable in polynomial time.

theorem Turing.MultiTapeTM.ComputableInPolyTime.rat_isZero' {α : Type} {input : α ↪ List Bool} {f : α → ℚ} (hf : ComputableInPolyTime f input encRat) :
ComputableInPolyTime (fun (x : α) => decide (f x = 0)) input encBool

Zero test on a computed rational number.

Strict order comparison (<) on ℚ is computable in polynomial time.

theorem Turing.MultiTapeTM.ComputableInPolyTime.rat_lt' {α : Type} {input : α ↪ List Bool} {left right : α → ℚ} (hleft : ComputableInPolyTime left input encRat) (hright : ComputableInPolyTime right input encRat) :
ComputableInPolyTime (fun (x : α) => decide (left x < right x)) input encBool

Strict order comparison on computed rational numbers.

Non-strict order comparison (≤) on ℚ is computable in polynomial time.

theorem Turing.MultiTapeTM.ComputableInPolyTime.rat_le' {α : Type} {input : α ↪ List Bool} {left right : α → ℚ} (hleft : ComputableInPolyTime left input encRat) (hright : ComputableInPolyTime right input encRat) :
ComputableInPolyTime (fun (x : α) => decide (left x ≤ right x)) input encBool

Non-strict order comparison on computed rational numbers.

Equality test on ℚ is computable in polynomial time.

theorem Turing.MultiTapeTM.ComputableInPolyTime.rat_eq' {α : Type} {input : α ↪ List Bool} {left right : α → ℚ} (hleft : ComputableInPolyTime left input encRat) (hright : ComputableInPolyTime right input encRat) :
ComputableInPolyTime (fun (x : α) => decide (left x = right x)) input encBool

Equality test on computed rational numbers.

Rational floor Rat.floor is computable in polynomial time under encRat and encIntBin.

theorem Turing.MultiTapeTM.ComputableInPolyTime.rat_floor' {α : Type} {input : α ↪ List Bool} {f : α → ℚ} (hf : ComputableInPolyTime f input encRat) :
ComputableInPolyTime (fun (x : α) => (f x).floor) input encIntBin

Rational floor of a computed rational number.