OKlibrary  0.2.1.6
Basic.mac
Go to the documentation of this file.
00001 /* Oliver Kullmann, 20.8.2009 (Swansea) */
00002 /* Copyright 2009, 2011 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 /* ************************
00027    * Elementary functions *
00028    ************************
00029 */
00030 
00031 okltest_bt_apply_permutation(f) := block([x,y],
00032   assert(f([],[]) = []),
00033   assert(f([1],[x]) = [x]),
00034   assert(f([1,2],[x,y]) = [x,y]),
00035   assert(f([2,1],[x,y]) = [y,x]),
00036   assert(f([3,2,1],[x,y,10]) = [10,y,x]),
00037   true)$
00038 
00039 okltest_int_seq_bt(f) := block([s],
00040   s : f([5]),
00041   for n : 0 thru 10 do
00042     assert(s(n) = create_list(1,i,1,n)),
00043   s : f([1,2]),
00044   for n : 0 thru 6 do
00045     assert(s(n) = create_list(fib(i+1),i,0,n-1)),
00046   s : f([1,3]),
00047   assert(s(8) = [1,1,1,2,3,4,6,9]),
00048   s : f([2,4,3]),
00049   true)$
00050 
00051 
00052 /* ***************
00053    * Power means *
00054    ***************
00055 */
00056 
00057 okltest_meann(f) := block([x,y,z],
00058   assert(f(x) = x),
00059   assert(f(x,y) = (x+y)/2),
00060   assert(f(x,y,z) = (x+y+z)/3),
00061   true)$
00062 
00063 okltest_gmean(f) := block([x,y,z],
00064   assert(f([x]) = x),
00065   assert(f([x,y]) = sqrt(x*y)),
00066   assert(f([x,y,z]) = (x*y*z)^(1/3)),
00067   assert(f([0,x,y,z]) = 0),
00068   true)$
00069 
00070 okltest_gmeann(f) := block([x,y,z],
00071   assert(f(x) = x),
00072   assert(f(x,y) = sqrt(x*y)),
00073   assert(f(x,y,z) = (x*y*z)^(1/3)),
00074   assert(f(0,x,y,z) = 0),
00075   true)$
00076 
00077 okltest_hmean(f) := block([x,y,z],
00078   assert(f([x]) = x),
00079   assert(f([x,y]) = 2/(1/x+1/y)),
00080   assert(f([x,y,z]) = 3/(1/x+1/y+1/z)),
00081   true)$
00082 
00083 okltest_hmeann(f) := block([x,y,z],
00084   assert(f(x) = x),
00085   assert(f(x,y) = 2/(1/x+1/y)),
00086   assert(f(x,y,z) = 3/(1/x+1/y+1/z)),
00087   true)$
00088 
00089 
00090 /* ***********************************************
00091    * Lower and upper bounds for the tau-function *
00092    ***********************************************
00093 */
00094 
00095 /* ****************************
00096    * Comparison of tau-values *
00097    ****************************
00098 */
00099 
00100 /* ********************************
00101    *   Computing the tau-function *
00102    ********************************
00103 */
00104 
00105 /* ********************
00106    * Higher precision *
00107    ********************
00108 */
00109 
00110 /* ************************
00111    * Symbolic computation *
00112    ************************
00113 */
00114 
00115 /* ************************************
00116    * Derivatives of the tau-function *
00117    ************************************
00118 */
00119 
00120 
00121 /* ****************************************
00122    * The induced probability distribution *
00123    ****************************************
00124 */
00125 
00126 okltest_tauprob(f) := block([x,res].
00127   assert(f([0]) = [1]),
00128   assert(f([x]) = [1]),
00129   res : f([1,2]),
00130   assert_float_equal(res[1], 0.6180339887498948),
00131   assert_float_equal(res[2], 0.3819660112501052),
00132   assert(f([1,1]) = [0.5, 0.5]),
00133   assert(f([2,2]) = [0.5, 0.5]),
00134   assert(f([3,3]) = [0.5, 0.5]),
00135   for l : 3 thru 4 do
00136    for v : 1 thru 3 do block([t : create_list(v,i,1,l)],
00137     res : f(t),
00138     for r in res do
00139       assert_float_equal(r, 1/l)
00140   ),
00141   true)$
00142 
00143 okltest_tauprob_hp(f) := block([x,res,d:30].
00144   assert(f([0],d) = [1]),
00145   assert(f([x],d) = [1]),
00146   res : f([1,2],d),
00147   assert_bfloat_equal(res[1], 6.18033988749894848204586834366b-1, d),
00148   assert_bfloat_equal(res[2], 3.81966011250105151795413165634b-1, d),
00149   for l : 2 thru 4 do
00150    for v : 1 thru 3 do block([t : create_list(v,i,1,l)],
00151     res : f(t,d),
00152     for r in res do
00153       assert_bfloat_equal(r, 1/l, d)
00154   ),
00155   true)$
00156 
00157 okltest_tauprob_symbolical(f) := block([x],
00158   assert(f([0]) = [1]),
00159   assert(f([x]) = [1]),
00160   for l : 2 thru 4 do
00161    for v : 1 thru 3 do 
00162     assert(f(create_list(v,i,1,l)) = create_list(1/l,i,1,l)),
00163   assert(f([1,2]) = [2/(sqrt(5)+1),4/(sqrt(5)+1)^2]),
00164   true)$
00165 
00166 
00167 /* ****************
00168    * The tau-mean *
00169    ****************
00170 */
00171 
00172 okltest_taumean(f) := (
00173   assert(f([]) = inf),
00174   assert(f([1]) = inf),
00175   assert(f([0]) = inf),
00176   assert(f([2,0]) = 0),
00177   assert(f([2,0,2]) = 0),
00178   /* XXX */
00179   true)$
00180 
00181 okltest_taumean_inf(f) := (
00182   assert(f([inf]) = inf),
00183   assert(f([inf,inf]) = inf),
00184   assert(f([0,inf]) = unknown),
00185   assert(f([0,0,inf]) = 0),
00186   assert(okltest_taumean(f) = true),
00187   /* XXX */
00188   true)$
00189 
00190 
00191 /* *********************************************
00192    *   Convexity considerations: line versions *
00193    *********************************************
00194 */
00195 
00196 /* ************************************
00197    * Investigations on approximations *
00198    ************************************
00199 */
00200 
00201