(load "utils.lsp")
(load "terms.lsp")
(load "init-term-constants")
(load "list-type.lsp")
(load "io-analysis.lsp")
(load "initial-term-computation.lsp")
;__________________________________________________________________________________________________
;
; IgorI Problem Repository - INITIAL FUNCTIONS AND SOLUTIONS
;__________________________________________________________________________________________________
;*******************************
;APPEND
;*******************************
; I/O examples:
(setf append-test
(list
(cons '( () () ) '())
(cons '( (a) (b) ) '(a b))
(cons '( (b) (a) ) '(b a))
(cons '( (a b) () ) '(a b))
(cons '( (a b) (c) ) '(a b c))
(cons '( (c) (b a) ) '(c b a))
(cons '( () (a b) ) '(a b))
(cons '( (a) (b c) ) '(a b c))
(cons '( (a b) (c d) ) '(a b c d))
)
)
;Initial Term : OMEGA
;*******************************
; AllOdds
;*******************************
; I/O examples:
(setf allodds-test
(list
(cons '() '())
(cons '( 0 ) '( 0 ))
(cons '( (0) ) '())
(cons '( ((0)) ) '( 0 ))
(cons '( (((0))) ) '())
(cons '( 0 0 ) '( 0 0 ))
(cons '( 0 (0) ) '( 0 (0) ))
(cons '( 0 ((0)) ) '( 0 ((0)) ))
(cons '( 0 (((0))) ) '( 0 (((0))) ))
(cons '( (0) 0 ) '( 0 ))
(cons '( (0) (0) ) '())
(cons '( (0) ((0)) ) '( 0 ))
(cons '( (0) (((0))) ) '())
(cons '( ((0)) 0 ) '( 0 0 ))
(cons '( ((0)) (0) ) '( 0 (0) ))
(cons '( ((0)) ((0)) ) '( 0 ((0)) ))
(cons '( ((0)) (((0))) ) '( 0 0 ))
(cons '( (((0))) 0 ) '( 0 ))
(cons '( (((0))) (0) ) '() )
(cons '( (((0))) ((0)) ) '( 0 ))
(cons '( (((0))) (((0))) ) '())
)
)
; Initial Term: (IF (ENDP X) NIL (IF (ENDP (REST X)) (CONS (FIRST X) NIL) OMEGA))
; Main Program: NIL
;*******************************
;CAR
;*******************************
; I/O examples:
(setf car-test
(list
(cons '(a) 'a)
(cons '(a b) 'a)
(cons '(b a c) 'b)
(cons '(d c b a) 'd)
)
)
; Initial Term: (FIRST X)
; Main Program:
;*******************************
;CDR
;*******************************
; I/O examples:
(setf cdr-test
(list
(cons '(a b) '(b ))
(cons '(a b c) '(b c))
(cons '(a b c d) '(b c d))
(cons '(a b c d e) '(b c d e))
)
)
; Initial Term: (IF (ENDP (REST (REST X))) (REST X) (IF (ENDP (REST (REST (REST X)))) (REST X) (IF (ENDP (REST (REST (REST (REST X))))) (REST X) OMEGA)))
; Main Program: (Sub1 X)
; Subprograms: (Sub1 x1) = (IF (ENDP (REST (REST x1)))
; (REST X)
; (Sub1 (REST x1)))
;*******************************
;EQ
;*******************************
; I/O examples:
(setf eq-test
(list
(cons '( () () ) '(0))
(cons '( (a) () ) '(()))
(cons '( () (a) ) '(()))
(cons '( (a) (a) ) '(0))
(cons '( (a) (b) ) '(()))
(cons '( (a b) () ) '(()))
(cons '( (a b) (a) ) '(()))
(cons '( (a b) (b) ) '(()))
(cons '( (a b) (a b) ) '(0))
)
)
; Initial Term: (CONS (IF (ENDP (FIRST (REST X))) NIL (IF (ENDP (REST (FIRST (REST X)))) NIL OMEGA))
; (IF (ENDP (FIRST (REST X))) NIL (IF (ENDP (REST (FIRST (REST X)))) NIL OMEGA)))
;Main Program: NIL
;*******************************
;EVENLIST
;*******************************
; I/O examples:
(setf evenlist-test
(list
(cons '() '(0))
(cons '(a) '( () ))
(cons '(a b) '( 0 ))
(cons '(a b c) '( () ))
(cons '(a b c d) '( 0 ))
(cons '(a b c d e) '( () ))
(cons '(a b c d e f) '( 0 ))
(cons '(a b c d e f g) '( () ))
(cons '(a b c d e f g h) '( 0 ))
(cons '(a b c d e f g h i ) '( () ))
(cons '(a b c d e f g h i j ) '( 0 ))
)
)
; Initial Term: NIL
; Main Program:
;*******************************
;EVENPOS
;*******************************
; I/O examples:
(setf evenpos-test
(list
(cons '() '())
(cons '(a) '())
(cons '(a b) '(b))
(cons '(a b c) '(b))
(cons '(a b c d) '(b d))
(cons '(a b c d e) '(b d))
(cons '(a b c d e f) '(b d f))
(cons '(a b c d e f g) '(b d f))
(cons '(a b c d e f g h) '(b d f h))
(cons '(a b c d e f g h i) '(b d f h))
(cons '(a b c d e f g h i j) '(b d f h j))
(cons '(a b c d e f g h i j k) '(b d f h j))
(cons '(a b c d e f g h i j k l) '(b d f h j l))
)
)
; Initial Term:
;(IF (ENDP X) NIL
; (IF (ENDP (REST X)) NIL
; (IF (ENDP (REST (REST X))) (REST X)
; (CONS (FIRST (REST X))
; (IF (ENDP (REST (REST (REST X)))) NIL
; (IF (ENDP (REST (REST (REST (REST X))))) (REST (REST (REST X)))
; (CONS (FIRST (REST (REST (REST X))))
; (IF (ENDP (REST (REST (REST (REST (REST X)))))) NIL
; (IF (ENDP (REST (REST (REST (REST (REST (REST X))))))) (REST (REST (REST (REST (REST X)))))
; (CONS (FIRST (REST (REST (REST (REST (REST X))))))
; (IF (ENDP (REST (REST (REST (REST (REST (REST (REST X)))))))) NIL
; (IF (ENDP (REST (REST (REST (REST (REST (REST (REST (REST X))))))))) (REST (REST (REST (REST (REST (REST (REST X)))))))
; (CONS (FIRST (REST (REST (REST (REST (REST (REST (REST X))))))))
; (IF (ENDP (REST (REST (REST (REST (REST (REST (REST (REST (REST X)))))))))) NIL
; (IF (ENDP (REST (REST (REST (REST (REST (REST (REST (REST (REST (REST X)))))))))))
; (REST (REST (REST (REST (REST (REST (REST (REST (REST X)))))))))
; (CONS (FIRST (REST (REST (REST (REST (REST (REST (REST (REST (REST X))))))))))
; (IF (ENDP (REST (REST (REST (REST (REST (REST (REST (REST (REST (REST (REST X)))))))))))) NIL OMEGA)))))))))))))))))
;
;Main Program: (IF (ENDP X)
; EMPTY-LIST
; (Sub1 X))
;Subprograms: (Sub1 x1) = (IF (ENDP (REST x1))
; EMPTY-LIST
; (IF (ENDP (REST (REST x1)))
; (REST x1)
; (CONS (FIRST (REST x1))
; (Sub1 (REST (REST x1))))))
;*******************************
;INSERT
;*******************************
; I/O examples:
(setf insert-test
(list
(cons '() '())
(cons '(a) '(a))
(cons '(a b) '(a))
(cons '(a b c) '(a c))
(cons '(a b c d) '(a c))
(cons '(a b c d e) '(a c e))
(cons '(a b c d e f) '(a c e))
)
)
; Initial Term:
;(IF (ENDP X) NIL
; (IF (ENDP (REST X)) X
; (CONS (FIRST X)
; (IF (ENDP (REST (REST X))) NIL
; (IF (ENDP (REST (REST (REST X)))) (REST (REST X))
; (CONS (FIRST (REST (REST X))) (IF (ENDP (REST (REST (REST (REST X))))) NIL (CONS (FIRST (REST (REST (REST (REST X))))) NIL))))))))
;
;Searching RPS for Initial Program:
; (IF (ENDP X)
; )
; (IF (ENDP (REST X))
; X
; (CONS (FIRST X)
; (IF (ENDP (REST (REST X)))
; )
; (IF (ENDP (REST (REST (REST X))))
; (REST (REST X))
; (CONS (FIRST (REST (REST X)))
; (IF (ENDP (REST (REST (REST (REST X)))))
; )
; (CONS (FIRST (REST (REST (REST (REST X)))))
; )))))))))
;SEARCH-RESULT for initial tree:
; #( ( (0))
; ( (IF (ENDP X)
; EMPTY-LIST
; (IF (ENDP (REST X))
; X
; (CONS (FIRST X)
; (IF (ENDP (REST (REST X)))
; EMPTY-LIST
; (IF (ENDP (REST (REST (REST X))))
; (REST (REST X))
; (CONS (FIRST (REST (REST X)))
; (IF (ENDP (REST (REST (REST (REST X)))))
; EMPTY-LIST
; (CONS (FIRST (REST (REST (REST (REST X)))))
; EMPTY-LIST))))))))))#
;*******************************
;Lasts
;*******************************
; I/O examples:
(setf llasts-test
(list
(cons '() '())
(cons '((a)) '((a)))
(cons '((a b)) '((b)))
(cons '((a b c)) '((c)))
(cons '((a b c d)) '((d)))
(cons '((a) (b)) '((a) (b)))
(cons '((a) (b c)) '((a) (c)))
(cons '((a b) (c) (d)) '((b) (c) (d)))
(cons '((a b) (c d) (e f)) '((b) (d) (f)))
(cons '((a) (b) (c) (d)) '((a) (b) (c) (d)))
)
)
;Initial Term:
;(IF (ENDP X) NIL
; (CONS
; (FIRST
; (IF (ENDP (REST (FIRST X))) (FIRST X)
; (IF (ENDP (REST (REST (FIRST X)))) (REST (FIRST X))
; (IF (ENDP (REST (REST (REST (FIRST X))))) (REST (REST (FIRST X)))
; OMEGA))))
; (IF (ENDP (REST X)) NIL
; (CONS (FIRST (IF (ENDP (REST (FIRST (REST X)))) (FIRST (REST X)) OMEGA))
; (IF (ENDP (REST (REST X))) NIL
; (CONS
; (FIRST
; (IF (ENDP (REST (FIRST (REST (REST X))))) (FIRST (REST (REST X)))
; OMEGA))
; (IF (ENDP (REST (REST (REST X)))) NIL OMEGA)))))))
;
;Main Program: (Sub1 X)
;Subprograms: (Sub1 x1) = (IF (ENDP x1)
; EMPTY-LIST
; (CONS (FIRST (Sub2 (FIRST x1)))
; (Sub1 (REST x1))))
; (Sub2 x1) = (IF (ENDP (REST x1))
; x1
; (Sub2 (REST x1)))
;*******************************
;Last
;*******************************
; I/O examples:
(setf last-test
(list
(cons '(a) 'a)
(cons '(a b) 'b)
(cons '(a b c) 'c)
(cons '(a b c d) 'd)
)
)
;Initial Term:
;(FIRST (IF (ENDP (REST X)) X (IF (ENDP (REST (REST X))) (REST X) (IF (ENDP (REST (REST (REST X)))) (REST (REST X)) OMEGA))))
;Main Program: (FIRST (Sub1 X))
;Subprograms: (Sub1 x1) = (IF (ENDP (REST x1))
; x1
; (Sub1 (REST x1)))
;*******************************
; MULTFIRST
;*******************************
; I/O examples:
(setf mult-first-test
(list
(cons '() '())
(cons '(a) '(a))
(cons '(b a) '(a a))
(cons '(c b a) '(c c c))
(cons '(d c b a) '(d d d d))
(cons '(e d c b a) '(e e e e e))
(cons '(f e d c b a) '(f f f f f f))
)
)
; Initial Term:
;(IF (ENDP X) NIL
; (IF (ENDP (REST X)) X
; (CONS
; (FIRST
; (IF (ENDP (REST (REST X))) (REST X)
; (IF (ENDP (REST (REST (REST X)))) X (IF (ENDP (REST (REST (REST (REST X))))) X (IF (ENDP (REST (REST (REST (REST (REST X)))))) X OMEGA)))))
; (IF (ENDP (REST (REST X))) (REST X) (CONS (FIRST X) (CONS (FIRST X) (CONS (FIRST X) (CONS (FIRST X) (CONS (FIRST X) NIL)))))))))
;Main Program: (IF (ENDP X)
; EMPTY-LIST
; (IF (ENDP (REST X))
; X
; (CONS (FIRST (Sub1 X
; (REST X)
; X))
; (IF (ENDP (REST (REST X)))
; (REST X)
; (CONS (FIRST X)
; (CONS (FIRST X)
; (CONS (FIRST X)
; (CONS (FIRST X)
; (CONS (FIRST X)
; EMPTY-LIST)))))))))
;Subprograms: (Sub1 x1 x2 x3) = (IF (ENDP (REST (REST x1)))
; x2
; (Sub1 (REST x1)
; x3
; x3))
;*******************************
; MultLast
;*******************************
; I/O examples:
(setf mult-last-test
(list
(cons '() '())
(cons '(a) '(a))
(cons '(a b) '(b b))
(cons '(a b c) '(c c c))
(cons '(a b c d) '(d d d d))
(cons '(a b c d e) '(e e e e e))
(cons '(a b c d e f) '(f f f f f f))
)
)
; Initial Term:
;(IF (ENDP X) NIL
; (IF (ENDP (REST X)) X
; (CONS
; (FIRST
; (IF (ENDP (REST (REST X))) (REST X)
; (IF (ENDP (REST (REST (REST X)))) (REST (REST X))
; (IF (ENDP (REST (REST (REST (REST X))))) (REST (REST (REST X)))
; (IF (ENDP (REST (REST (REST (REST (REST X))))))
; (REST (REST (REST (REST X)))) OMEGA)))))
; (IF (ENDP (REST (REST X))) (REST X)
; (CONS
; (FIRST
; (IF (ENDP (REST (REST (REST X)))) (REST (REST X))
; (IF (ENDP (REST (REST (REST (REST X))))) (REST (REST (REST X)))
; (IF (ENDP (REST (REST (REST (REST (REST X))))))
; (REST (REST (REST (REST X)))) OMEGA))))
; (IF (ENDP (REST (REST (REST X)))) (REST (REST X))
; (CONS
; (FIRST
; (IF (ENDP (REST (REST (REST (REST X))))) (REST (REST (REST X)))
; (IF (ENDP (REST (REST (REST (REST (REST X))))))
; (REST (REST (REST (REST X)))) OMEGA)))
; (IF (ENDP (REST (REST (REST (REST X))))) (REST (REST (REST X)))
; (CONS
; (FIRST
; (IF (ENDP (REST (REST (REST (REST (REST X))))))
; (REST (REST (REST (REST X)))) OMEGA))
; (IF (ENDP (REST (REST (REST (REST (REST X))))))
; (REST (REST (REST (REST X)))) OMEGA))))))))))
;Main Program: (IF (ENDP X)
; EMPTY-LIST
; (Sub1 X))
;Subprograms: (Sub1 x1) = (IF (ENDP (REST x1))
; x1
; (CONS (FIRST (Sub2 x1))
; (Sub1 (REST x1))))
; (Sub2 x1) = (IF (ENDP (REST (REST x1)))
; (REST x1)
; (Sub2 (REST x1)))
;*******************************
;ODDPOS
;*******************************
; I/O examples:
(setf oddpos-test
(list
(cons '() '())
(cons '(a) '(a))
(cons '(a b) '(a))
(cons '(a b c) '(a c))
(cons '(a b c d) '(a c))
(cons '(a b c d e) '(a c e))
(cons '(a b c d e f) '(a c e))
(cons '(a b c d e f g) '(a c e g))
(cons '(a b c d e f g h) '(a c e g))
(cons '(a b c d e f g h i) '(a c e g i))
(cons '(a b c d e f g h i j) '(a c e g i))
(cons '(a b c d e f g h i j k) '(a c e g i k))
)
)
; Initial Term:
;(IF (ENDP X) NIL
; (IF (ENDP (REST X)) X
; (CONS (FIRST X)
; (IF (ENDP (REST (REST X))) NIL
; (IF (ENDP (REST (REST (REST X)))) (REST (REST X))
; (CONS (FIRST (REST (REST X)))
; (IF (ENDP (REST (REST (REST (REST X))))) NIL
; (IF (ENDP (REST (REST (REST (REST (REST X)))))) (REST (REST (REST (REST X))))
; (CONS (FIRST (REST (REST (REST (REST X)))))
; (IF (ENDP (REST (REST (REST (REST (REST (REST X))))))) NIL
; (IF (ENDP (REST (REST (REST (REST (REST (REST (REST X)))))))) (REST (REST (REST (REST (REST (REST X))))))
; (CONS (FIRST (REST (REST (REST (REST (REST (REST X)))))))
; (IF (ENDP (REST (REST (REST (REST (REST (REST (REST (REST X))))))))) NIL
; (IF (ENDP (REST (REST (REST (REST (REST (REST (REST (REST (REST X)))))))))) (REST (REST (REST (REST (REST (REST (REST (REST X))))))))
; (CONS (FIRST (REST (REST (REST (REST (REST (REST (REST (REST X)))))))))
; (IF (ENDP (REST (REST (REST (REST (REST (REST (REST (REST (REST (REST X))))))))))) NIL OMEGA))))))))))))))))
; Main Program:
;Real time: 0.035256 sec.
;Run time: 0.032002 sec.
;Space: 225736 Bytes
;GC: 1, GC time: 0.016001 sec.
;Final Solution:
;Main Program: (Sub1 X)
;Subprograms: (Sub1 x1) = (IF (ENDP x1)
; EMPTY-LIST
; (IF (ENDP (REST x1))
; x1
; (CONS (FIRST x1)
; (Sub1 (REST (REST x1))))))
;*******************************
; Reverse
;*******************************
; I/O examples:
(setf reverse-test
(list
(cons '() '())
(cons '(a) '(a))
(cons '(a b) '(b a))
(cons '(a b c) '(c b a))
(cons '(a b c d) '(d c b a))
(cons '(a b c d e) '(e d c b a))
)
)
; Initial Term:
;(IF (ENDP X) NIL
; (IF (ENDP (REST X)) X
; (CONS
; (FIRST
; (IF (ENDP (REST (REST X))) (REST X)
; (IF (ENDP (REST (REST (REST X)))) (REST (REST X))
; (IF (ENDP (REST (REST (REST (REST X))))) (REST (REST (REST X))) OMEGA))))
; (CONS
; (FIRST
; (IF (ENDP (REST (REST X))) X
; (IF (ENDP (REST (REST (REST X)))) (REST X)
; (IF (ENDP (REST (REST (REST (REST X))))) (REST (REST X)) OMEGA))))
; (IF (ENDP (REST (REST X))) NIL
; (CONS
; (FIRST
; (IF (ENDP (REST (REST (REST X)))) X
; (IF (ENDP (REST (REST (REST (REST X))))) (REST X) OMEGA)))
; (IF (ENDP (REST (REST (REST X)))) NIL
; (CONS (FIRST (IF (ENDP (REST (REST (REST (REST X))))) X OMEGA))
; (IF (ENDP (REST (REST (REST (REST X))))) NIL OMEGA)))))))))
;Main Program: (IF (ENDP X)
; EMPTY-LIST
; (IF (ENDP (REST X))
; X
; (CONS (FIRST (Sub1 X))
; (Sub2 X))))
;Subprograms: (Sub1 x1) = (IF (ENDP (REST (REST x1)))
; (REST x1)
; (Sub1 (REST x1)))
; (Sub2 x1) = (CONS (FIRST (Sub3 x1
; X))
; (IF (ENDP (REST (REST x1)))
; EMPTY-LIST
; (Sub2 (REST x1))))
; (Sub3 x1 x2) = (IF (ENDP (REST (REST x1)))
; x2
; (Sub3 (REST x1)
; (REST x2)))
;*******************************
; Weave
;*******************************
; I/O examples:
(setf weave-test
(list
(cons '( () () ) '())
(cons '( (a) () ) '(a))
(cons '( () (a) ) '(a))
(cons '( (a) (b) ) '(a b))
(cons '( (a b) () ) '(a b))
(cons '( () (a b) ) '(a b))
(cons '( (a b) (c) ) '(a c b))
(cons '( (a) (b c) ) '(a b c))
(cons '( (a b) (c d) ) '(a c b d))
)
)
; Initial Term : OMEGA (fail)
; Main Program:
;*******************************
; SHIFTL
;*******************************
; I/O examples:
(setf shiftl-test
(list
(cons '() '())
(cons '(a) '(a))
(cons '(a b) '(b a))
(cons '(a b c) '(b c a))
(cons '(a b c d) '(b c d a))
(cons '(a b c d e) '(b c d e a))
(cons '(a b c d e f) '(b c d e f a))
)
)
; Initial Term:
;(IF (ENDP X) NIL
; (IF (ENDP (REST X)) X
; (CONS (FIRST (REST X))
; (CONS
; (FIRST
; (IF (ENDP (REST (REST X))) X
; (IF (ENDP (REST (REST (REST X)))) (REST (REST X))
; (IF (ENDP (REST (REST (REST (REST X))))) (REST (REST X)) (IF (ENDP (REST (REST (REST (REST (REST X)))))) (REST (REST X)) OMEGA)))))
; (IF (ENDP (REST (REST X))) NIL
; (CONS
; (FIRST
; (IF (ENDP (REST (REST (REST X)))) X
; (IF (ENDP (REST (REST (REST (REST X))))) (REST (REST (REST X)))
; (IF (ENDP (REST (REST (REST (REST (REST X)))))) (REST (REST (REST X))) OMEGA))))
; (IF (ENDP (REST (REST (REST X)))) NIL
; (CONS (FIRST (IF (ENDP (REST (REST (REST (REST X))))) X (IF (ENDP (REST (REST (REST (REST (REST X)))))) (REST (REST (REST (REST X)))) OMEGA)))
; (IF (ENDP (REST (REST (REST (REST X))))) NIL
; (CONS (FIRST (IF (ENDP (REST (REST (REST (REST (REST X)))))) X OMEGA)) (IF (ENDP (REST (REST (REST (REST (REST X)))))) NIL OMEGA)))))))))
;Main Program: (IF (ENDP X)
; EMPTY-LIST
; (IF (ENDP (REST X))
; X
; (CONS (FIRST (REST X))
; (Sub1 X))))
;Subprograms: (Sub1 x1) = (CONS (FIRST (Sub2 x1
; X
; x1))
; (IF (ENDP (REST (REST x1)))
; EMPTY-LIST
; (Sub1 (REST x1))))
; (Sub2 x1 x2 x3) = (IF (ENDP (REST (REST x1)))
; x2
; (Sub2 (REST x1)
; (REST (REST x3))
; x3))
;*******************************
; ShiftR
;*******************************
; I/O examples:
(setf shiftr-test
(list
(cons '() '())
(cons '(a) '(a))
(cons '(a b) '(b a))
(cons '(a b c) '(c a b))
(cons '(a b c d) '(d a b c))
(cons '(a b c d e) '(e a b c d))
)
)
; Initial Term:
;(IF (ENDP X) NIL
; (IF (ENDP (REST X)) X
; (CONS
; (FIRST
; (IF (ENDP (REST (REST X))) (REST X)
; (IF (ENDP (REST (REST (REST X)))) (REST (REST X))
; (IF (ENDP (REST (REST (REST (REST X))))) (REST (REST (REST X))) OMEGA))))
; (CONS (FIRST X)
; (IF (ENDP (REST (REST X))) NIL
; (CONS (FIRST (REST X))
; (IF (ENDP (REST (REST (REST X)))) NIL
; (CONS (FIRST (REST (REST X)))
; (IF (ENDP (REST (REST (REST (REST X))))) NIL OMEGA)))))))))
;Main Program: (IF (ENDP X)
; EMPTY-LIST
; (IF (ENDP (REST X))
; X
; (CONS (FIRST (Sub1 X))
; (Sub2 X))))
;Subprograms: (Sub1 x1) = (IF (ENDP (REST (REST x1)))
; (REST x1)
; (Sub1 (REST x1)))
; (Sub2 x1) = (CONS (FIRST x1)
; (IF (ENDP (REST (REST x1)))
; EMPTY-LIST
; (Sub2 (REST x1))))
;*******************************
; SWAP
;*******************************
; I/O examples:
(setf swap-test
(list
(cons '() '())
(cons '(a) '(a))
(cons '(a b) '(b a))
(cons '(a b c) '(c b a))
(cons '(a b c d) '(d b c d))
(cons '(a b c d e) '(e b c d a))
(cons '(a b c d e f) '(f b c d e a))
(cons '(a b c d e f g) '(g b c d e f a))
(cons '(a b c d e f g h) '(h b c d e f g a))
)
)
; Initial Term:
;(IF (ENDP X) NIL
; (IF (ENDP (REST X)) X
; (CONS
; (FIRST
; (IF (ENDP (REST (REST X))) (REST X)
; (IF (ENDP (REST (REST (REST X)))) (REST (REST X))
; (IF (ENDP (REST (REST (REST (REST X))))) (REST (REST (REST X)))
; (IF (ENDP (REST (REST (REST (REST (REST X)))))) (REST (REST (REST (REST X))))
; (IF (ENDP (REST (REST (REST (REST (REST (REST X))))))) (REST (REST (REST (REST (REST X)))))
; (IF (ENDP (REST (REST (REST (REST (REST (REST (REST X)))))))) (REST (REST (REST (REST (REST (REST X)))))) OMEGA)))))))
; (IF (ENDP (REST (REST X))) (CONS (FIRST X) NIL)
; (IF (ENDP (REST (REST (REST X)))) (CONS (FIRST (REST X)) (CONS (FIRST X) NIL))
; (IF (ENDP (REST (REST (REST (REST X))))) (REST X)
; (CONS (FIRST (REST X))
; (CONS (FIRST (REST (REST X)))
; (CONS (FIRST (REST (REST (REST X))))
; (CONS
; (FIRST
; (IF (ENDP (REST (REST (REST (REST (REST X)))))) X
; (IF (ENDP (REST (REST (REST (REST (REST (REST X))))))) (REST (REST (REST (REST X))))
; (IF (ENDP (REST (REST (REST (REST (REST (REST (REST X)))))))) (REST (REST (REST (REST X)))) OMEGA))))
; (IF (ENDP (REST (REST (REST (REST (REST X)))))) NIL
; (CONS
; (FIRST
; (IF (ENDP (REST (REST (REST (REST (REST (REST X))))))) X
; (IF (ENDP (REST (REST (REST (REST (REST (REST (REST X)))))))) (REST (REST (REST (REST (REST X))))) OMEGA)))
; (IF (ENDP (REST (REST (REST (REST (REST (REST X))))))) NIL
; (CONS (FIRST (IF (ENDP (REST (REST (REST (REST (REST (REST (REST X)))))))) X OMEGA))
; (IF (ENDP (REST (REST (REST (REST (REST (REST (REST X)))))))) NIL OMEGA)))))))))))))))
;Main Program: (FIRST (Sub1 #( ( (0))
; (X))#
; #( ( (0))
; (X))#))
;Subprograms: (Sub1 x1 x2) = (IF (ENDP (REST (REST (REST (REST (REST x1))))))
; x2
; (Sub1 (REST x1)
; (REST (REST (REST (REST X))))))
;*******************************
; SWITCH
;*******************************
; I/O examples:
(setf switch-test
(list
(cons '() '())
(cons '(a) '(a))
(cons '(a b) '(b a))
(cons '(a b c) '(b a c))
(cons '(a b c d) '(b a d c))
(cons '(a b c d e) '(b a d c e))
)
)
; Initial Term:
;(IF (ENDP X) NIL
; (IF (ENDP (REST X)) X
; (CONS (FIRST (REST X))
; (CONS (FIRST X)
; (IF (ENDP (REST (REST X))) NIL
; (IF (ENDP (REST (REST (REST X)))) (REST (REST X))
; (CONS (FIRST (REST (REST (REST X)))) (CONS (FIRST (REST (REST X))) (IF (ENDP (REST (REST (REST (REST X))))) NIL OMEGA)))))))))
;Main Program: (Sub1 X)
;Subprograms: (Sub1 x1) = (IF (ENDP x1)
; EMPTY-LIST
; (IF (ENDP (REST x1))
; x1
; (CONS (FIRST (REST x1))
; (CONS (FIRST x1)
; (Sub1 (REST (REST x1)))))))
;*******************************
; ZIP
;*******************************
; I/O examples:
(setf zip-test
(list
(cons '(() ()) '())
(cons '(() (a)) '(a))
(cons '(() (b)) '(b))
(cons '(() (a b)) '(a b))
(cons '(() (b a)) '(b a))
(cons '((c) ()) '(c))
(cons '((c) (d)) '(c d))
(cons '((c) (b)) '(c b))
(cons '((c) (a b)) '(c a b))
(cons '((c) (b a)) '(c b a))
(cons '((e) ()) '(e))
(cons '((e) (b)) '(e b))
(cons '((e) (a)) '(e a))
(cons '((e) (a b)) '(e a b))
(cons '((e) (b a)) '(e b a))
(cons '((a) ()) '(a))
(cons '((a) (b)) '(a b))
(cons '((a) (c)) '(a c))
(cons '((a) (b c)) '(a b c))
(cons '((a) (c b)) '(a c b))
(cons '((e f) ()) '(e f))
(cons '((e f) (a)) '(e a f))
(cons '((e f) (b)) '(e b f))
(cons '((e f) (a b)) '(e a f b))
(cons '((e f) (b a)) '(e b f a))
(cons '((e a) ()) '(e a))
(cons '((e a) (b)) '(e b a))
(cons '((e a) (c)) '(e c a))
(cons '((e f) (b c)) '(e b f c))
(cons '((e f) (c b)) '(e c f b))
)
)
; Initial Term: OMEGA
; Main Program: