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

Function nat_rec_rules

crates/kernel/src/inductive.rs:4873–4928  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4871 lvls: 1,
4872 params: 0,
4873 indices: 0,
4874 motives: 1,
4875 minors: 2,
4876 block: rec_block.clone(),
4877 member_idx: 0,
4878 ty: rec_ty,
4879 rules: vec![
4880 super::super::constant::RecRule {
4881 ctor: (),
4882 fields: 0,
4883 rhs: rule_zero_rhs,
4884 },
4885 super::super::constant::RecRule {
4886 ctor: (),
4887 fields: 1,
4888 rhs: rule_succ_rhs,
4889 },
4890 ],
4891 lean_all: (),
4892 },
4893 );
4894
4895 env
4896 .blocks
4897 .insert(block, vec![mk_id("Nat"), mk_id("Nat.zero"), mk_id("Nat.succ")]);
4898 env.blocks.insert(rec_block, vec![mk_id("Nat.rec")]);
4899 env
4900 }
4901
4902 #[test]
4903 fn check_nat_rec() {
4904 let mut env = nat_env();
4905 let mut tc = TypeChecker::new(&mut env);
4906 tc.check_const(&mk_id("Nat")).unwrap();
4907 assert!(tc.check_const(&mk_id("Nat.rec")).is_ok(), "Nat.rec should pass");
4908 }
4909
4910 #[test]
4911 fn nat_rec_rules() {
4912 // Nat.rec has 2 rules (one per ctor):
4913 // Rule 0 (Nat.zero): fields=0, rhs = λ (motive) (h_zero) (h_succ), h_zero
4914 // Rule 1 (Nat.succ): fields=1, rhs = λ (motive) (h_zero) (h_succ) (n),
4915 // h_succ n (Nat.rec.{Param(0), ...} motive h_zero h_succ n)
4916 let mut env = nat_env();
4917 let mut tc = TypeChecker::new(&mut env);
4918 tc.check_const(&mk_id("Nat")).unwrap();
4919 tc.check_const(&mk_id("Nat.rec")).unwrap();
4920
4921 let block = mk_id("Nat");
4922 let generated = tc.env.recursor_cache.get(&block).unwrap();
4923 let rules = &generated[0].rules;
4924
4925 assert_eq!(rules.len(), 2, "Nat.rec should have 2 rules");
4926
4927 // Rule 0 (zero): fields=0
4928 assert_eq!(rules[0].fields, 0);
4929 // rhs = λ (motive) (h_zero) (h_succ), h_zero
4930 // = Lam(_, Lam(_, Lam(_, Var(1))))

Callers

nothing calls this directly

Calls 13

sortFunction · 0.85
check_constMethod · 0.80
nat_envFunction · 0.70
mk_idFunction · 0.70
lamFunction · 0.70
piFunction · 0.70
cnstFunction · 0.70
paramFunction · 0.70
appFunction · 0.70
varFunction · 0.70
getMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected