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

Method get_major_inductive_id

crates/kernel/src/whnf.rs:1616–1663  ·  view source on GitHub ↗

Get the major premise's inductive KId from a recursor type. Strategy: peel `skip` foralls per Lean's stored `params + motives + minors + indices` count, then expect the next forall's domain to have an inductive `Const` head. For well-formed Lean recursors this lands exactly on the major premise. Resilience: if the strict `skip` position's domain head is not an inductive `Const`, peel up to `MAX_

(
    &mut self,
    rec_ty: &KExpr<M>,
    skip: u64,
  )

Source from the content-addressed store, hash-verified

1614 let Some((base, offset)) = self.nat_offset(e, 0)? else {
1615 return Ok(None);
1616 };
1617 if offset.0 == num_bigint::BigUint::ZERO {
1618 return Ok(None);
1619 }
1620
1621 let pred_offset = Nat(&offset.0 - 1u64);
1622 let pred = if pred_offset.0 == num_bigint::BigUint::ZERO {
1623 base
1624 } else {
1625 let pred_lit = self.nat_expr_from_value(pred_offset);
1626 self.mk_nat_add(base, pred_lit)
1627 };
1628 Ok(Some(self.mk_nat_succ(pred)))
1629 }
1630
1631 fn nat_offset(
1632 &mut self,
1633 e: &KExpr<M>,
1634 depth: u16,
1635 ) -> Result<Option<(KExpr<M>, Nat)>, TcError<M>> {
1636 const MAX_NAT_OFFSET_DEPTH: u16 = 256;
1637 if depth >= MAX_NAT_OFFSET_DEPTH {
1638 return Ok(None);
1639 }
1640
1641 let (head, args) = collect_app_spine(e);
1642 let ExprData::Const(id, _, _) = head.data() else {
1643 return Ok(None);
1644 };
1645
1646 if id.addr == self.prims.nat_succ.addr && args.len() == 1 {
1647 let (base, offset) = self.nat_offset_or_zero(&args[0], depth + 1)?;
1648 return Ok(Some((base, Nat(offset.0 + 1u64))));
1649 }
1650
1651 if id.addr == self.prims.nat_add.addr && args.len() == 2 {
1652 let Some(rhs) = self.eval_nat_offset_literal(&args[1], depth + 1) else {
1653 return Ok(None);
1654 };
1655 let (base, offset) = self.nat_offset_or_zero(&args[0], depth + 1)?;
1656 return Ok(Some((base, Nat(offset.0 + rhs.0))));
1657 }
1658
1659 Ok(None)
1660 }
1661
1662 fn nat_offset_or_zero(
1663 &mut self,
1664 e: &KExpr<M>,
1665 depth: u16,
1666 ) -> Result<(KExpr<M>, Nat), TcError<M>> {

Callers 6

try_struct_eta_iotaMethod · 0.80
synth_ctor_when_kMethod · 0.80
find_peer_recursorsMethod · 0.80
check_recursor_memberMethod · 0.80
gather_peer_majorsMethod · 0.80

Calls 4

collect_app_spineFunction · 0.85
whnfMethod · 0.80
cloneMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected