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

Function env_with_id

crates/kernel/src/whnf.rs:3096–3151  ·  view source on GitHub ↗

Build a minimal env with a single definition: `id := λ x. x : Sort 0 → Sort 0`

()

Source from the content-addressed store, hash-verified

3094 (3usize, 4usize)
3095 } else {
3096 return Ok(None);
3097 };
3098
3099 let major_whnf = self.whnf(&args[major_idx])?;
3100 let (mk_head, mk_args) = collect_app_spine(&major_whnf);
3101 let mk_addr = match mk_head.data() {
3102 ExprData::Const(id, _, _) => &id.addr,
3103 _ => return Ok(None),
3104 };
3105 if *mk_addr != self.prims.quot_ctor.addr {
3106 return Ok(None);
3107 }
3108
3109 // Quot.mk has exactly 3 args: (α, r, a). Value is the last.
3110 if mk_args.len() != 3 {
3111 return Ok(None);
3112 }
3113 let quot_val = mk_args[2].clone();
3114
3115 let mut result = self.intern(KExpr::app(args[f_idx].clone(), quot_val));
3116 for arg in args.iter().skip(major_idx + 1) {
3117 result = self.intern(KExpr::app(result, arg.clone()));
3118 }
3119 Ok(Some(result))
3120 }
3121
3122 // -----------------------------------------------------------------------
3123 // BitVec reduction
3124 // -----------------------------------------------------------------------
3125
3126 /// Reduce the small BitVec fragment that is definitionally Nat-backed:
3127 /// - `BitVec.toNat (BitVec.ofNat w n)` reduces to `n % 2^w`
3128 /// - `BitVec.ult w x y` reduces by evaluating `x.toNat < y.toNat`
3129 /// - `decide (x < y)` for BitVec reduces through the same comparison
3130 fn try_reduce_bitvec(
3131 &mut self,
3132 e: &KExpr<M>,
3133 ) -> Result<Option<KExpr<M>>, TcError<M>> {
3134 let (head, args) = collect_app_spine(e);
3135 let ExprData::Const(id, _, _) = head.data() else {
3136 return Ok(None);
3137 };
3138
3139 if id.addr == self.prims.bit_vec_to_nat.addr && args.len() >= 2 {
3140 if let Some(result) = self.try_reduce_bitvec_to_nat(&args[1])? {
3141 return Ok(Some(self.finish_app_result(result, &args, 2)));
3142 }
3143 return Ok(None);
3144 }
3145
3146 if id.addr == self.prims.bit_vec_ult.addr && args.len() >= 3 {
3147 if let Some(result) =
3148 self.try_reduce_bitvec_ult(&args[0], &args[1], &args[2])?
3149 {
3150 return Ok(Some(self.finish_app_result(result, &args, 3)));
3151 }
3152 return Ok(None);
3153 }

Callers 10

whnf_var_identityFunction · 0.70
whnf_sort_identityFunction · 0.70
whnf_lam_identityFunction · 0.70
whnf_beta_simpleFunction · 0.70
whnf_beta_multiFunction · 0.70
whnf_zetaFunction · 0.70
whnf_deltaFunction · 0.70
whnf_cache_hitFunction · 0.70

Calls 6

sort0Function · 0.70
lamFunction · 0.70
varFunction · 0.70
mk_idFunction · 0.70
sort1Function · 0.70
insertMethod · 0.45

Tested by 10

whnf_var_identityFunction · 0.56
whnf_sort_identityFunction · 0.56
whnf_lam_identityFunction · 0.56
whnf_beta_simpleFunction · 0.56
whnf_beta_multiFunction · 0.56
whnf_zetaFunction · 0.56
whnf_deltaFunction · 0.56
whnf_cache_hitFunction · 0.56