use super::functions::*;
use oxilean_kernel::{BinderInfo, Declaration, Environment, Expr, Level, Name};
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct GrzegorczykLevel(pub usize);
impl GrzegorczykLevel {
pub const E0: GrzegorczykLevel = GrzegorczykLevel(0);
pub const E1: GrzegorczykLevel = GrzegorczykLevel(1);
pub const E2: GrzegorczykLevel = GrzegorczykLevel(2);
pub const E3: GrzegorczykLevel = GrzegorczykLevel(3);
pub fn bound(&self, x: u64) -> u64 {
match self.0 {
0 => x + 1,
1 => x.saturating_add(x),
2 => x.saturating_mul(x).saturating_add(2),
n => {
let mut v = x;
for _ in 0..(n - 2) {
v = 2u64.saturating_pow(v.min(62) as u32);
}
v
}
}
}
pub fn check_bounded(&self, f: impl Fn(u64) -> u64, k: u64) -> bool {
(0..=k).all(|x| f(x) <= self.bound(x))
}
pub fn is_primitive_recursive_approx(&self, f: impl Fn(u64) -> u64, k: u64) -> bool {
(0..=10usize).any(|n| GrzegorczykLevel(n).check_bounded(&f, k))
}
}
pub struct EfficientAlgorithm {
pub complexity: String,
}
impl EfficientAlgorithm {
pub fn new(complexity: impl Into<String>) -> Self {
Self {
complexity: complexity.into(),
}
}
pub fn correct_and_efficient(&self) -> bool {
!self.complexity.is_empty()
}
pub fn extracted_from_proof(&self) -> bool {
true
}
}
#[derive(Debug, Clone)]
pub struct ConstructiveReal {
pub approx: Vec<i64>,
pub max_prec: usize,
}
impl ConstructiveReal {
pub fn from_rational(p: i64, q: i64, max_prec: usize) -> Self {
let approx = (0..=max_prec)
.map(|k| {
let num = p * (1i64 << k);
num / q
})
.collect();
ConstructiveReal { approx, max_prec }
}
pub fn add(&self, other: &ConstructiveReal) -> ConstructiveReal {
let max_prec = self.max_prec.min(other.max_prec);
let approx = (0..=max_prec)
.map(|k| self.approx[k] + other.approx[k])
.collect();
ConstructiveReal { approx, max_prec }
}
pub fn get_approx(&self, k: usize) -> (i64, usize) {
(self.approx[k.min(self.max_prec)], k)
}
pub fn approx_eq(&self, other: &ConstructiveReal, k: usize) -> bool {
let k = k.min(self.max_prec).min(other.max_prec);
(self.approx[k] - other.approx[k]).abs() <= 1
}
}
pub struct BrouwerIntuitionism {
_version: &'static str,
}
impl BrouwerIntuitionism {
pub fn new() -> Self {
Self { _version: "1907" }
}
pub fn law_of_excluded_middle_fails(&self) -> bool {
true
}
pub fn creating_subject(&self) -> &'static str {
"The creating subject creates mathematical objects freely over time; \
the truth of a proposition is settled only when the subject has \
experienced a construction."
}
pub fn choice_sequences(&self) -> &'static str {
"A choice sequence α is a potentially infinite sequence α(0), α(1), … \
whose values may be chosen freely at each step, subject only to a spread."
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct PowerSetHeyting {
pub universe: u64,
}
impl PowerSetHeyting {
pub fn new(n: u32) -> Self {
PowerSetHeyting {
universe: (1u64 << n) - 1,
}
}
pub fn meet(&self, a: u64, b: u64) -> u64 {
a & b
}
pub fn join(&self, a: u64, b: u64) -> u64 {
a | b
}
pub fn top(&self) -> u64 {
self.universe
}
pub fn bot(&self) -> u64 {
0
}
pub fn neg(&self, a: u64) -> u64 {
self.implication(a, self.bot())
}
pub fn implication(&self, a: u64, b: u64) -> u64 {
(!a & self.universe) | b
}
pub fn le(&self, a: u64, b: u64) -> bool {
a & b == a
}
pub fn double_neg(&self, a: u64) -> u64 {
self.neg(self.neg(a))
}
}
pub struct HeylandAlgebra {
pub carrier: Vec<String>,
}
impl HeylandAlgebra {
pub fn new(carrier: Vec<String>) -> Self {
Self { carrier }
}
pub fn is_heyting_algebra(&self) -> bool {
!self.carrier.is_empty()
}
pub fn intuitionistic_propositional_logic(&self) -> &'static str {
"A Heyting algebra H models IPC: ⊤ = 1, ⊥ = 0, \
a ∧ b = meet, a ∨ b = join, a → b = largest c with c ∧ a ≤ b."
}
}
#[derive(Debug, Clone)]
pub struct BarRecursion {
pub max_depth: usize,
pub bar: Vec<bool>,
}
impl BarRecursion {
pub fn new(max_depth: usize) -> Self {
BarRecursion {
max_depth,
bar: vec![false; max_depth + 1],
}
}
pub fn set_bar(&mut self, n: usize) {
if n <= self.max_depth {
self.bar[n] = true;
}
}
pub fn in_bar(&self, n: usize) -> bool {
n <= self.max_depth && self.bar[n]
}
pub fn compute(
&self,
n: usize,
y_val: impl Fn(usize) -> i64,
h_step: impl Fn(usize, i64) -> i64,
) -> i64 {
if n > self.max_depth {
return y_val(n);
}
if self.in_bar(n) {
y_val(n)
} else {
let sub = self.compute(n + 1, &y_val, &h_step);
h_step(n, sub)
}
}
pub fn bar_depth(&self) -> Option<usize> {
self.bar.iter().position(|&b| b)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ConstructiveGcd {
_marker: (),
}
impl ConstructiveGcd {
pub fn new() -> Self {
ConstructiveGcd { _marker: () }
}
pub fn gcd(&self, mut a: i64, mut b: i64) -> i64 {
a = a.abs();
b = b.abs();
while b != 0 {
let r = a % b;
a = b;
b = r;
}
a
}
pub fn extended_gcd(&self, a: i64, b: i64) -> (i64, i64, i64) {
if b == 0 {
return (a.abs(), if a >= 0 { 1 } else { -1 }, 0);
}
let (g, s1, t1) = self.extended_gcd(b, a % b);
(g, t1, s1 - (a / b) * t1)
}
pub fn lcm(&self, a: i64, b: i64) -> Option<i64> {
let g = self.gcd(a, b);
if g == 0 {
return Some(0);
}
(a / g).checked_mul(b.abs())
}
pub fn divides(&self, a: i64, b: i64) -> bool {
a != 0 && b % a == 0
}
}
pub struct InfiniteSequence {
pub choice_sequence: Vec<u8>,
}
impl InfiniteSequence {
pub fn new(choice_sequence: Vec<u8>) -> Self {
Self { choice_sequence }
}
pub fn spread_law(&self) -> &'static str {
"A spread is a decidable subtree of ω^{<ω} such that every node \
has an extension in the tree. Choice sequences live in spreads."
}
pub fn bar_induction(&self) -> &'static str {
"Bar Induction (BI_D): if B is a decidable bar on a spread and \
P is hereditary on B, then P holds at the empty sequence."
}
}
#[derive(Debug, Clone)]
pub struct CountableChoiceWitness {
pub choices: Vec<u64>,
}
impl CountableChoiceWitness {
pub fn build(sel: impl Fn(usize) -> u64, count: usize) -> Self {
CountableChoiceWitness {
choices: (0..count).map(|n| sel(n)).collect(),
}
}
pub fn verify(&self, membership: impl Fn(usize, u64) -> bool) -> bool {
self.choices
.iter()
.enumerate()
.all(|(n, &x)| membership(n, x))
}
pub fn get(&self, n: usize) -> Option<u64> {
self.choices.get(n).copied()
}
pub fn len(&self) -> usize {
self.choices.len()
}
pub fn is_empty(&self) -> bool {
self.choices.is_empty()
}
}
pub struct ConstructiveProof {
pub statement: String,
pub algorithm: String,
}
impl ConstructiveProof {
pub fn new(statement: impl Into<String>, algorithm: impl Into<String>) -> Self {
Self {
statement: statement.into(),
algorithm: algorithm.into(),
}
}
pub fn is_effective(&self) -> bool {
!self.algorithm.is_empty()
}
pub fn witnesses_existential(&self) -> bool {
self.statement.contains('∃') || self.statement.contains("exists")
}
}
pub struct BishopMath {
_tag: (),
}
impl BishopMath {
pub fn new() -> Self {
Self { _tag: () }
}
pub fn constructive_real_analysis(&self) -> &'static str {
"BISH uses Cauchy sequences with an explicit modulus; every \
theorem has algorithmic content."
}
pub fn all_functions_continuous(&self) -> bool {
false
}
pub fn no_lem(&self) -> bool {
true
}
}
#[derive(Debug, Clone)]
pub struct TTEOracle {
pub name: String,
pub max_precision: usize,
pub approx_cache: Vec<i64>,
}
impl TTEOracle {
pub fn new(name: impl Into<String>, max_precision: usize) -> Self {
TTEOracle {
name: name.into(),
max_precision,
approx_cache: Vec::new(),
}
}
pub fn load_cauchy(&mut self, seq: impl Fn(usize) -> i64) {
self.approx_cache = (0..=self.max_precision).map(|k| seq(k)).collect();
}
pub fn query(&self, k: usize) -> Option<(i64, usize)> {
let k = k.min(self.max_precision);
self.approx_cache.get(k).map(|&m| (m, k))
}
pub fn is_cauchy_consistent(&self, k: usize) -> bool {
if self.approx_cache.len() < 2 {
return true;
}
let k = k.min(self.max_precision);
if k == 0 {
return true;
}
(0..k).all(|j| {
let aj = self.approx_cache.get(j).copied().unwrap_or(0);
let aj1 = self.approx_cache.get(j + 1).copied().unwrap_or(0);
(aj1 - 2 * aj).abs() <= 2
})
}
pub fn function_name(&self) -> &str {
&self.name
}
}
pub struct RealNumber {
pub cauchy_seq: Vec<f64>,
pub modulus: String,
}
impl RealNumber {
pub fn new(cauchy_seq: Vec<f64>, modulus: impl Into<String>) -> Self {
Self {
cauchy_seq,
modulus: modulus.into(),
}
}
pub fn equality_is_undecidable(&self) -> bool {
true
}
pub fn is_apartness_relation(&self) -> bool {
true
}
}
pub struct ConTinuousFunction {
pub is_uniformly_continuous: bool,
}
impl ConTinuousFunction {
pub fn new(is_uniformly_continuous: bool) -> Self {
Self {
is_uniformly_continuous,
}
}
pub fn by_fan_theorem(&self) -> bool {
self.is_uniformly_continuous
}
pub fn kleene_brouwer(&self) -> &'static str {
"The Kleene–Brouwer ordering witnesses well-foundedness of the tree \
via an intuitionistic bar induction argument."
}
}
pub struct MarkovPrinciple {
_tag: (),
}
impl MarkovPrinciple {
pub fn new() -> Self {
Self { _tag: () }
}
pub fn statement(&self) -> &'static str {
"Markov's Principle (MP): for every decidable predicate P on ℕ, \
if ¬∀n, ¬P(n) then ∃n, P(n). Equivalently: if a Turing machine \
does not run forever then it halts."
}
pub fn is_accepted_in_russian_school(&self) -> bool {
true
}
}