MCPcopy Create free account
hub / github.com/argumentcomputer/ix / try_def_eq_offset

Method try_def_eq_offset

crates/kernel/src/def_eq.rs:971–991  ·  view source on GitHub ↗

M2: Nat offset reduction for lazy delta loop (lean4lean isDefEqOffset). Returns Some(true/false) if both are nat-zero or nat-succ, None otherwise.

(
    &mut self,
    a: &KExpr<M>,
    b: &KExpr<M>,
  )

Source from the content-addressed store, hash-verified

969 return id.addr == p.nat_zero.addr
970 || id.addr == p.nat_succ.addr
971 || id.addr == p.nat_add.addr;
972 },
973 ExprData::App(f, _, _) => cur = f,
974 _ => return false,
975 }
976 }
977 }
978
979 /// If expression is nat-succ, return the predecessor.
980 /// Matches both `Nat(n+1)` → `Nat(n)` and `Nat.succ e` → `e`.
981 fn nat_succ_of(&mut self, e: &KExpr<M>) -> Option<KExpr<M>> {
982 match e.data() {
983 ExprData::Nat(v, _, _) => {
984 if v.0 == num_bigint::BigUint::ZERO {
985 return None;
986 }
987 let pred = bignat::Nat(&v.0 - num_bigint::BigUint::from(1u64));
988 let pred_addr = ix_common::address::Address::hash(&pred.to_le_bytes());
989 Some(self.env.intern.intern_expr(KExpr::nat(pred, pred_addr)))
990 },
991 ExprData::App(f, arg, _) => match f.data() {
992 ExprData::Const(id, _, _) if id.addr == self.prims.nat_succ.addr => {
993 Some(arg.clone())
994 },

Callers 1

is_def_eq_innerMethod · 0.80

Calls 4

is_nat_zeroMethod · 0.80
nat_succ_ofMethod · 0.80
dataMethod · 0.45
is_def_eqMethod · 0.45

Tested by

no test coverage detected