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

Function good_rtree_rec_reduction

crates/kernel/src/tutorial/reduction.rs:902–971  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

900 // (fun children _ih => children true) t
901 let motive = nlam("_", rt(), rt());
902 let leaf_case = cnst("RTree.leaf", &[]);
903 // node case: fun children ih => children Bool.true
904 // depth 2: ih=var(0), children=var(1)
905 let ih_ty = npi("b", cnst("Bool", &[]), rt()); // simplified: ∀ b, RTree
906 let node_case = nlam(
907 "children",
908 pi(cnst("Bool", &[]), rt()),
909 nlam("_ih", ih_ty, app(var(1), cnst("Bool.true", &[]))),
910 );
911
912 let left_val = nlam(
913 "t",
914 rt(),
915 apps(
916 cnst("RTree.rec", &[usucc(uzero())]),
917 &[motive, leaf_case, node_case, var(0)],
918 ),
919 );
920 let (left_id, left_c) = mk_defn(
921 "RTree.left",
922 0,
923 vec![],
924 pi(rt(), rt()),
925 left_val,
926 ReducibilityHints::Abbrev,
927 );
928 env.insert(left_id, left_c);
929
930 // Test: ∀ (t1 t2 : RTree), (RTree.node (Bool.rec t2 t1)).left = t1
931 // Bool.rec.{1} (fun _ => RTree) t2 t1 : Bool → RTree
932 // Then RTree.node applied to this, then .left
933 // depth 2: t1=var(1), t2=var(0)... wait, t1 first then t2:
934 // ∀ (t1 : RTree) (t2 : RTree), ...
935 // depth 2: t2=var(0), t1=var(1)
936 let bool_rec_app = apps(
937 cnst("Bool.rec", &[usucc(uzero())]),
938 &[
939 nlam("_", cnst("Bool", &[]), rt()), // motive: fun _ => RTree
940 var(0), // false case = t2
941 var(1), // true case = t1
942 ],
943 );
944 // RTree.node (Bool.rec ...) : RTree
945 let node_app = app(cnst("RTree.node", &[]), bool_rec_app);
946 // RTree.left (RTree.node ...) should reduce to t1
947 let lhs = app(cnst("RTree.left", &[]), node_app);
948 let ty = npi(
949 "t1",
950 rt(),
951 npi("t2", rt(), eq_expr(usucc(uzero()), rt(), lhs, var(1))),
952 );
953 let val = nlam(
954 "t1",
955 rt(),
956 nlam("t2", rt(), eq_refl_expr(usucc(uzero()), rt(), var(1))),
957 );
958
959 let (id, c) = mk_thm("rtreeRecReduction", 0, vec![], ty, val);

Callers

nothing calls this directly

Calls 15

rtree_envFunction · 0.85
nlamFunction · 0.85
npiFunction · 0.85
appsFunction · 0.85
usuccFunction · 0.85
uzeroFunction · 0.85
mk_defnFunction · 0.85
eq_exprFunction · 0.85
eq_refl_exprFunction · 0.85
mk_thmFunction · 0.85
check_acceptsFunction · 0.85
cnstFunction · 0.50

Tested by

no test coverage detected