OKlibrary  0.2.1.6
Collatz.mac
Go to the documentation of this file.
00001 /* Oliver Kullmann, 10.12.2012 (Swansea) */
00002 /* Copyright 2012, 2013 Oliver Kullmann
00003 This file is part of the OKlibrary. OKlibrary is free software; you can redistribute
00004 it and/or modify it under the terms of the GNU General Public License as published by
00005 the Free Software Foundation and included in this library; either version 3 of the
00006 License, or any later version. */
00007 
00022 oklib_include("OKlib/ComputerAlgebra/TestSystem/Lisp/Asserts.mac")$
00023 
00024 kill(f)$
00025 
00026 okltest_collatz_reduction(f) := (
00027   assert(f(2) = 1),
00028   assert(f(3) = 10),
00029   assert(f(4) = 2),
00030   assert(f(5) = 16),
00031   true)$
00032 
00033 okltest_collatz_redseq(f) := (
00034   assert(f(1) = [1]),
00035   assert(f(2) = [2,1]),
00036   assert(f(3) = [3,10,5,16,8,4,2,1]),
00037   assert(f(4) = [4,2,1]),
00038   assert(f(5) = [5,16,8,4,2,1]),
00039   assert(f(6) = [6,3,10,5,16,8,4,2,1]),
00040   assert(f(11) = [11,34,17,52,26,13,40,20,10,5,16,8,4,2,1]),
00041   assert(length(f(63728127)) = 950),
00042   true)$
00043 
00044 okltest_collatz_basics(f) := (
00045   assert(f(1) = [0,1]),
00046   assert(f(2) = [1,2]),
00047   assert(f(3) = [7,16]),
00048   assert(f(4) = [2,4]),
00049   assert(f(5) = [5,16]),
00050   assert(f(6) = [8,16]),
00051   assert(f(11) = [14,52]),
00052   assert(f(63728127) = [949,966616035460]),
00053   true)$
00054 
00055 okltest_collatz_switch_p(f) := (
00056   assert(f(1) = false),
00057   assert(f(2) = false),
00058   assert(f(3) = false),
00059   assert(f(4) = true),
00060   true)$
00061 
00062 okltest_collatz_prevswitch(f) := (
00063   assert(f(4) = [16]),
00064   assert(f(10) = [40]),
00065   assert(f(16) = [64,10]),
00066   assert(f(22) = [88, 28]),
00067   assert(f(28) = [112]),
00068   true)$
00069 
00070 okltest_collatz_prevswitch_lrt_g(f) := block([n],
00071   assert(f(0,n) = [n]),
00072   assert(f(1, 106) = [106, [424], [70]]),
00073   true)$
00074 
00075 okltest_collatz_prevswitch_lrt(f) := (
00076   assert(f(0) = [4]),
00077   assert(f(1) = [4, [16]]),
00078   assert(f(2) = [4, [16, [64], [10]]]),
00079   assert(f(3) = [4, [16, [64, [256]], [10, [40]]]]),
00080   assert(f(4) = [4, [16, [64, [256, [1024], [340]]], [10, [40, [160], [52]]]]]),
00081   true)$
00082 
00083 okltest_collatz_prevswitch_l(f) := (
00084   assert(f(0) = [4]),
00085   assert(f(1) = [4,16]),
00086   assert(f(2) = [4,16,64,10]),
00087   assert(f(3) = [4,16,64,10,256,40]),
00088   true)$
00089 
00090 okltest_collatz_redswitch(f) := (
00091   assert(f(4) = 1),
00092   assert(f(10) = 2),
00093   true)$
00094 
00095 okltest_collatz_prevswitchred_lrt(f) := (
00096   assert(f(0) = [1]),
00097   assert(f(1) = [1, [3]]),
00098   assert(f(2) = [1, [3, [11], [2]]]),
00099   assert(f(3) = [1, [3, [11, [43]], [2, [7]]]]),
00100   assert(f(4) = [1, [3, [11, [43, [171], [57]]], [2, [7, [27], [9]]]]]),
00101   true)$
00102 
00103 okltest_collatz_prevswitchred_l(f) := (
00104   assert(f(0) = [1]),
00105   assert(f(1) = [1,3]),
00106   assert(f(2) = [1,3,11,2]),
00107   assert(f(3) = [1,3,11,2,43,7]),
00108   true)$
00109 
00110 okltest_collatz_prevswitch_rm(f) := (
00111   assert(f(0) = [4]),
00112   assert(f(1) = [4,16]),
00113   assert(f(2) = [4,16,10]),
00114   assert(f(3) = [4,16,10,40]),
00115   assert(f(4) = [4,16,10,40,52]),
00116   true)$
00117 
00118 okltest_collatz_prevswitchred_rm(f) := (
00119   assert(f(0) = [1]),
00120   assert(f(1) = [1,3]),
00121   assert(f(2) = [1,3,2]),
00122   assert(f(3) = [1,3,2,7]),
00123   assert(f(4) = [1,3,2,7,9]),
00124   true)$
00125 
00126