;;; Vikalpa --- Proof Assistant ;;; Copyright © 2020 Masaya Tojo ;;; ;;; This file is part of Vikalpa. ;;; ;;; Vikalpa is free software; you can redistribute it and/or modify it ;;; under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 3 of the License, or ;;; (at your option) any later version. ;;; ;;; Vikalpa is distributed in the hope that it will be useful, but ;;; WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;;; General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with Vikalpa. If not, see . (define-module (vikalpa prelude) #:export (natural? size implies prelude) #:use-module (vikalpa)) (define-syntax implies (syntax-rules () ((_ x y) (if x y #t)) ((_ x y z rest ...) (if x (implies y z rest ...) #t)))) (define-system prelude () (define-syntax-rules list () ((list) '()) ((list x . y) (cons x (list . y)))) (define-syntax-rules and () ((and) '#t) ((and x) x) ((and x . xs) (if x (and . xs) #f))) (define-syntax-rules or () ((or) '#f) ((or x) x) ((or x . xs) (if x x (or . xs)))) (define-syntax-rules cond (else) ((cond (else e)) e) ((cond (test then) . rest) (if test then (cond . rest)))) (define-syntax-rules implies () ((implies x y) (if x y #t)) ((implies x y z . rest) (if x (implies y z . rest) #t))) (define-function zero? (x) (equal? 0 x)) (define-function natural? (x) (and (integer? x) (or (zero? x) (< x 0)))) (define-totality-claim natural? natural? <) (define-axiom equal-same (x) (equal? (equal? x x) '#t)) (define-axiom equal-swap (x y) (equal? (equal? x y) (equal? y x))) (define-axiom equal-if (x y) (implies (equal? x y) (equal? x y))) (define-axiom if-nest (x y z) (if x (equal? (if x y z) y) (equal? (if x y z) z))) (define-axiom if-true (x y) (equal? (if '#t x y) x)) (define-axiom if-false (x y) (equal? (if '#f x y) y)) (define-axiom if-same (x y) (equal? (if x y y) y)) (define-axiom if-not (x y z) (equal? (if (not x) y z) (if x z y))) (define-axiom pair/cons (x y) (equal? (pair? (cons x y)) '#t)) (define-axiom cons/car+cdr (x) (implies (pair? x) (equal? (cons (car x) (cdr x)) x))) (define-axiom car/cons (x y) (equal? (car (cons x y)) x)) (define-axiom cdr/cons (x y) (equal? (cdr (cons x y)) y)) (define-axiom equal-car (x1 y1 x2 y2) (implies (equal? (cons x1 y1) (cons x2 y2)) (equal? x1 x2))) (define-axiom equal-cdr (x1 y1 x2 y2) (implies (equal? (cons x1 y1) (cons x2 y2)) (equal? y1 y2))) (define-axiom pred/succ (x) (implies (natural? x) (equal? (pred (succ x)) x))) (define-axiom succ/pred (x) (implies (natural? x) (not (zero? x)) (equal? (succ (pred x)) x))) (define-axiom less/pred (x) (implies (natural? x) (equal? (< (pred x) x) #t))) (define-function + (x y) (if (zero? 0 x) y (succ (+ (pred x) y)))) ;; (define-proof if-implies ;; () ;; (((1) if-same (set x x)) ;; ((1 2 1) if-nest) ;; ((1 3 1) if-nest) ;; ((1 3) if-true) ;; (() equal-same))) ;; (define-proof less-than/pred ;; (natural-induction x) ;; (((2 2) if-nest) ;; ((2 2) if-not) ;; ((2 2) if-nest) ;; ((2 3 2) if-nest) ;; ((2 3 2) if-nest) ;; ((2 3) if-implies) ;; ((2 3 2) if-implies) ;; (() error) ;; (() error))) ;; (define-proof less-than/pred-1 ;; () ;; (((2 2) if-same (set x (natural? (pred x)))) ;; ((2 2 2) if-same (set x (not (zero? (pred x))))) ;; ((2 2 2) if-same (set x (not (zero? (pred x))))) ;; ;; ((2 2 3 1 1) zero?) ;; ;; ((2 2 3 1 1) if-nest) ;; ;; ((2 2 3 1) if-false) ;; ;; ((2 2 3 1) if-false) ;; )) ;; (define-theorem natural/add1 (x) ;; (implies (natural? x) ;; (equal? (natural? (add1 x)) #t))) #; (define-axiom natural/sub1 (x) (if (natural? x) (if (< '0 x) (equal? (natural? (sub1 x)) '#t) '#t) '#t)) #; (define-theorem less-than/sub1 (x) (implies (natural? x) (< '0 x) (equal? (< (sub1 x) x) '#t))) #; (define-axiom add1/sub1 (x) (if (natural? x) (if (equal? '0 x) '#t (equal? (add1 (sub1 x)) x)) '#t)) #; (define-built-in-function + (x y) (if (natural? x) (if (equal? '0 x) y (add1 (+ (sub1 x) y))) 'undefined)) #; (define-axiom natural/size (x) (equal? (natural? (size x)) '#t)) #; (define-axiom size/car (x) (if (pair? x) (equal? (< (size (car x)) (size x)) '#t) '#t)) #; (define-axiom size/cdr (x) (if (pair? x) (equal? (< (size (cdr x)) (size x)) '#t) '#t)) #; (define-proof + (total/natural? x) (((2) if-nest) ((2 3)