aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMasaya Tojo <masaya@tojo.tokyo>2021-09-09 15:49:44 +0900
committerMasaya Tojo <masaya@tojo.tokyo>2021-09-09 15:49:44 +0900
commita51be68a1b9c1c2c4e720b49190fdd89a86885bb (patch)
tree097f709d45b1418e43ab9b398c7428cb69f321da
parente7c237de367db261b80b60588ac89926345751aa (diff)
flist: Add `flist.lisp` file.
-rw-r--r--flist.lisp45
1 files changed, 45 insertions, 0 deletions
diff --git a/flist.lisp b/flist.lisp
new file mode 100644
index 0000000..dc6ffe7
--- /dev/null
+++ b/flist.lisp
@@ -0,0 +1,45 @@
+(defun true-flistp (x)
+ (if (endp x)
+ (null x)
+ (and (consp x)
+ (true-flistp (car x)))))
+
+(defun list-to-flist (x)
+ (if (endp x)
+ nil
+ (cons (list-to-flist (cdr x))
+ (car x))))
+
+(defun flist-to-list (x)
+ (if (endp x)
+ nil
+ (cons (cdr x)
+ (flist-to-list (car x)))))
+
+(defthm flist-to-list-to-flist
+ (implies (true-flistp x)
+ (equal (list-to-flist (flist-to-list x))
+ x)))
+
+(defthm list-to-flist-to-list
+ (implies (true-listp x)
+ (equal (flist-to-list (list-to-flist x))
+ x)))
+
+
+(defun fappend (x y)
+ (if (endp x)
+ y
+ (cons (fappend (car x) y)
+ (cdr x))))
+
+(defthm assocativity-of-append
+ (equal (fappend (fappend x y) z)
+ (fappend x (fappend y z))))
+
+(defthm fappend-append
+ (implies (and (true-listp x)
+ (true-listp y))
+ (equal (flist-to-list (fappend (list-to-flist x)
+ (list-to-flist y)))
+ (append x y))))