From 0546c892748c77595fbd10357ede60c53a745be4 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Thu, 19 Oct 2023 12:54:42 +0200 Subject: Added example mutual recurrence relations for y* --- samples/fun/mutrec.bruijn | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 samples/fun/mutrec.bruijn (limited to 'samples/fun/mutrec.bruijn') diff --git a/samples/fun/mutrec.bruijn b/samples/fun/mutrec.bruijn new file mode 100644 index 0000000..34042ff --- /dev/null +++ b/samples/fun/mutrec.bruijn @@ -0,0 +1,32 @@ +# some example usage of the variadic fixed point combinator + +:import std/List . +:import std/Logic . +:import std/Number . + +# generates odd? and even? function as list +odd-even? y* (even? : {}odd?) + even? [[[=?0 true (1 --0)]]] + odd? [[[=?0 false (2 --0)]]] + +:test (^odd-even? (+5)) (false) +:test (_odd-even? (+5)) (true) + +# calculates n % 3 +mod3 ^(y* (a : (b : {}c))) + a [[[[=?0 (+0) (2 --0)]]]] + b [[[[=?0 (+1) (1 --0)]]]] + c [[[[=?0 (+2) (3 --0)]]]] + +:test ((mod3 (+0)) =? (+0)) (true) +:test ((mod3 (+1)) =? (+1)) (true) +:test ((mod3 (+2)) =? (+2)) (true) +:test ((mod3 (+3)) =? (+0)) (true) +:test ((mod3 (+4)) =? (+1)) (true) +:test ((mod3 (+5)) =? (+2)) (true) +:test ((mod3 (+6)) =? (+0)) (true) +:test ((mod3 (+7)) =? (+1)) (true) +:test ((mod3 (+8)) =? (+2)) (true) +:test ((mod3 (+9)) =? (+0)) (true) + +main [[0]] -- cgit v1.2.3