OKlibrary  0.2.1.6
BasicNotions.mac
Go to the documentation of this file.
00001 /* Oliver Kullmann, 6.7.2008 (Swansea) */
00002 /* Copyright 2008, 2009, 2012 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 oklib_include("OKlib/ComputerAlgebra/Algebra/Lisp/Groupoids/Semigroups/BasicExamples.mac");
00024 oklib_include("OKlib/ComputerAlgebra/CombinatorialMatrices/Lisp/LatinSquares/tests/BasicNotions.mac")$
00025 oklib_include("OKlib/ComputerAlgebra/Algebra/Lisp/Groupoids/BasicNotions.mac")$
00026 
00027 
00028 kill(f)$
00029 
00030 /* ************************************
00031    * Checking the defining properties *
00032    ************************************
00033 */
00034 
00035 okltest_compo_p(f) := (
00036   assert(f(identity,{}) = true),
00037   assert(f("+",{0}) = true),
00038   assert(f("+",{0,1}) = false),
00039   assert(f("*",{0,1,-1}) = true),
00040   assert(f("*",{0,1,-1,x}) = false),
00041   assert(f(0,{1}) = false),
00042   assert(f({},{1}) = false),
00043   assert(f(lambda([x,y],[1]),{[1]}) = true),
00044   true)$
00045 
00046 
00047 okltest_grd_p(f) := (
00048   assert(f(0) = false),
00049   assert(f({}) = false),
00050   assert(f([]) = false),
00051   assert(f([{}]) = false),
00052   assert(f([{},{}]) = true),
00053   assert(f([{1},{}]) = false),
00054   assert(f(empty_sgr) = true),
00055   assert(f(singleton_sgr) = true),
00056   assert(f(non_assoc_2_grd) = true),
00057   true)$
00058 
00059 okltest_ugrd_p(f) := (
00060   /* XXX */
00061   true)$
00062 
00063 okltest_cgrd_p(f) := (
00064   /* XXX */
00065   true)$
00066 
00067 okltest_cugrd_p(f) := (
00068   /* XXX */
00069   true)$
00070 
00071 okltest_ogrd_p(f) := (
00072   assert(f(0) = false),
00073   assert(f({}) = false),
00074   assert(f([]) = false),
00075   assert(f([{}]) = false),
00076   assert(f([{},{}]) = false),
00077   assert(f([[],[]]) = true),
00078   assert(f([{1},{}]) = false),
00079   assert(f([[1],[]]) = false),
00080   assert(f([[1],lambda([x,y],1)]) = true),
00081   assert(f([[1,1],lambda([x,y],1)]) = false),
00082   assert(f([[1],lambda([x,y],2)]) = false),
00083   assert(f(empty_sgr) = false),
00084   assert(f(grd2ogrd(empty_sgr)) = true),
00085   assert(f(grd2ogrd(singleton_sgr)) = true),
00086   assert(f(grd2ogrd(non_assoc_2_grd)) = true),
00087   true)$
00088 
00089 okltest_ougrd_p(f) := (
00090   assert(f(0) = false),
00091   assert(f({}) = false),
00092   assert(f([]) = false),
00093   assert(f([{}]) = false),
00094   assert(f([{},{}]) = false),
00095   assert(f([[],[]]) = false),
00096   assert(f([[1],[],2]) = false),
00097   assert(f([[1],lambda([x,y],1),1]) = true),
00098   assert(f([{1},{}]) = false),
00099   assert(f([[1],[]]) = false),
00100   assert(f([[1],lambda([x,y],1),2]) = false),
00101   assert(f([[1,1],lambda([x,y],1)]) = false),
00102   assert(f([[2,1],lambda([x,y],1),1]) = false),
00103   assert(f([[1,2],lambda([x,y],1),1]) = false),
00104   assert(f([[1,2],lambda([x,y], if x=1 and y=1 then 1 else 2),1]) = true),
00105   assert(f(empty_sgr) = false),
00106   assert(f(grd2ogrd(empty_sgr)) = false),
00107   assert(f(grd2ogrd(singleton_sgr)) = false),
00108   assert(f(grd2ogrd(non_assoc_2_grd)) = false),
00109   /* XXX */
00110   true)$
00111 
00112 
00113 okltest_sgr_p(f) := (
00114   assert(f(0) = false),
00115   assert(f({}) = false),
00116   assert(f([]) = false),
00117   assert(f([{}]) = false),
00118   assert(f([{},{}]) = true),
00119   assert(f([{1},{}]) = false),
00120   assert(f(empty_sgr) = true),
00121   assert(f(singleton_sgr) = true),
00122   assert(f(non_assoc_2_grd) = false),
00123   assert(f(null_sgr({1,2},1)) = true),
00124   assert(f(leftnull_sgr({1,2,3})) = true),
00125   assert(f(rightnull_sgr({-1,2,-3})) = true),
00126   true)$
00127 
00128 okltest_csgr_p(f) := (
00129   /* XXX */
00130   true)$
00131 
00132 okltest_mon_p(f) := (
00133   /* XXX */
00134   true)$
00135 
00136 okltest_cmon_p(f) := (
00137   /* XXX */
00138   true)$
00139 
00140 
00141 /* Remark: The semantics of okltest_qgrp_p is identical with that of
00142    okltest_ls_p. Currently all tests are handled by okltest_ls_p.
00143 */
00144 okltest_qgrp_p(f) := (
00145   assert(okltest_ls_p(f)),
00146   true)$
00147 
00148 okltest_cqgrp_p(f) := (
00149   /* XXX */
00150   true)$
00151 
00152 okltest_uqgrp_p(f) := (
00153   assert(f(endcons(1,m2grd(matrix([1,2,3],[2,3,1],[3,1,2])))) = true),
00154   assert(f(endcons(1,m2grd(matrix([1,2,3],[2,1,2],[3,2,1])))) = false),
00155   /* XXX */
00156   true)$
00157 
00158 okltest_cuqgrp_p(f) := (
00159   /* XXX */
00160   true)$
00161 
00162 okltest_oqgrp_p(f) := (
00163   assert(f(m2grd(matrix([1,2,3],[2,3,1],[3,1,2]))) = false),
00164   assert(f(grd2ogrd(m2grd(matrix([1,2,3],[2,3,1],[3,1,2])))) = true),
00165   /* XXX */
00166   true)$
00167 
00168 okltest_ouqgrp_p(f) := (
00169   assert(f(m2grd(matrix([1,2,3],[2,3,1],[3,1,2]))) = false),
00170   assert(f(grd2ogrd(m2grd(matrix([1,2,3],[2,3,1],[3,1,2])))) = false),
00171   assert(f(endcons(1,m2grd(matrix([1,2,3],[2,3,1],[3,1,2])))) = false),
00172   assert(f(ugrd2ougrd(endcons(1,m2grd(matrix([1,2,3],[2,3,1],[3,1,2]))))) = true),
00173   /* XXX */
00174   true)$
00175 
00176 okltest_grp_p(f) := (
00177   assert(f(singleton_sgr) = true),
00178   /* XXX */
00179   true)$
00180 
00181 okltest_cgrp_p(f) := (
00182   /* XXX */
00183   true)$
00184 
00185 okltest_ugrp_p(f) := (
00186   /* XXX */
00187   true)$
00188 
00189 okltest_cugrp_p(f) := (
00190   /* XXX */
00191   true)$
00192 
00193 okltest_ugrpi_p(f) := (
00194   assert(f([{1},lambda([x,y],1),1,identity]) = true),
00195   assert(f([{1},lambda([x,y],1),2,identity]) = false),
00196   /* XXX */
00197   true)$
00198 
00199 okltest_cugrpi_p(f) := (
00200   /* XXX */
00201   true)$
00202 
00203 okltest_ogrp_p(f) := (
00204   assert(f(singleton_sgr) = false),
00205   assert(f(grd2ogrd(singleton_sgr)) = true),
00206   /* XXX */
00207   true)$
00208 
00209 okltest_ougrp_p(f) := (
00210   assert(f(grd2ogrd(singleton_sgr)) = false),
00211   assert(f(endcons(1,grd2ogrd(singleton_sgr))) = true),
00212   /* XXX */
00213   true)$
00214 
00215 okltest_ougrpi_p(f) := (
00216   assert(f(endcons(1,grd2ogrd(singleton_sgr))) = false),
00217   assert(f(append(grd2ogrd(singleton_sgr),[1,identity])) = true),
00218   /* XXX */
00219   true)$
00220 
00221 
00222 /* *********************
00223    * Checking equality *
00224    *********************
00225 */
00226 
00227 okltest_grd_equalp(f) := (
00228   assert(f(empty_sgr,empty_sgr) = true),
00229   assert(f(empty_sgr,singleton_sgr) = false),
00230   assert(f(singleton_sgr,empty_sgr) = false),
00231   assert(f(singleton_sgr,singleton_sgr) = true),
00232   assert(f(null_sgr({1},1),null_sgr({1},1)) = true),
00233   assert(f(null_sgr({1},1),null_sgr({2},2)) = false),
00234   assert(f(null_sgr({1,2},2),null_sgr({2},2)) = false),
00235   assert(f(leftnull_sgr({1}),rightnull_sgr({1})) = true),
00236   assert(f(leftnull_sgr({1}),rightnull_sgr({2})) = false),
00237   assert(f(leftnull_sgr({1,2}),rightnull_sgr({1,2})) = false),
00238   true)$
00239 
00240 okltest_ugrd_equalp(f) := (
00241   /* XXX */
00242   true)$
00243 
00244 
00245 /* *************
00246    * Downcasts *
00247    *************
00248 */
00249 
00250 okltest_ugrd2grd(f) := block([V,C,e],
00251   assert(f([V,C,e]) = [V,C]),
00252   /* XXX */
00253   true)$
00254 
00255 okltest_ogrd2grd(f) := block([C],
00256   assert(f([[],C]) = [{},C]),
00257   assert(f([[1],C]) = [{1},C]),
00258   assert(f([[2,1],C]) = [{1,2},C]),
00259   /* XXX */
00260   true)$
00261 
00262 okltest_ugrpi2ugrp(f) := block([V,C,e,i],
00263   assert(f([V,C,e,i]) = [V,C,e]),
00264   /* XXX */
00265   true)$
00266 
00267 okltest_ugrpi2grp(f) := block([V,C,e,i],
00268   assert(f([V,C,e,i]) = [V,C]),
00269   /* XXX */
00270   true)$
00271 
00272 okltest_ugrp2grp(f) := block([V,C,e],
00273   assert(f([V,C,e]) = [V,C]),
00274   /* XXX */
00275   true)$
00276 
00277 okltest_ougrp2ugrp(f) := block([C,e],
00278   assert(f([[],C,e]) = [{},C,e]),
00279   assert(f([[1],C,e]) = [{1},C,e]),
00280   assert(f([[2,1],C,e]) = [{1,2},C,e]),
00281   /* XXX */
00282   true)$
00283 
00284 okltest_ougrpi2ugrpi(f) :=  block([C,e,i],
00285   assert(f([[],C,e,i]) = [{},C,e,i]),
00286   assert(f([[1],C,e,i]) = [{1},C,e,i]),
00287   assert(f([[2,1],C,e,i]) = [{1,2},C,e,i]),
00288   /* XXX */
00289   true)$
00290 
00291 
00292 /* **************
00293    * Promotions *
00294    **************
00295 */
00296 
00297 okltest_grd2ogrd(f) := block([C],
00298   assert(f([{},C]) = [[],C]),
00299   assert(f([{1},C]) = [[1],C]),
00300   assert(f([{2,4},C]) = [[2,4],C]),
00301   true)$
00302 
00303 okltest_ugrd2ougrd(f) := block([C,e],
00304   assert(f([{e},C,e]) = [[e],C,e]),
00305   assert(f([{1,e},C,e]) = [[e,1],C,e]),
00306   assert(f([{e,2,4},C,e]) = [[e,2,4],C,e]),
00307   true)$
00308 
00309 okltest_ugrp2ougrp(f) := block([C,e],
00310   assert(f([{e},C,e]) = [[e],C,e]),
00311   assert(f([{1,e},C,e]) = [[e,1],C,e]),
00312   assert(f([{e,2,4},C,e]) = [[e,2,4],C,e]),
00313   true)$
00314 
00315 okltest_ugrpi2ougrpi(f) := block([C,e,i],
00316   assert(f([{e},C,e,i]) = [[e],C,e,i]),
00317   assert(f([{1,e},C,e,i]) = [[e,1],C,e,i]),
00318   assert(f([{e,2,4},C,e,i]) = [[e,2,4],C,e,i]),
00319   true)$
00320 
00321 
00322 /* ***************
00323    * Conversions *
00324    ***************
00325 */
00326 
00327 okltest_scom2grd(f) := block([M],
00328   assert(f(M) = M),
00329   true)$
00330 
00331 okltest_grd2scom(f) := block([V],
00332   assert(f(V) = V),
00333   true)$
00334 
00335 okltest_m2grd(f) := (
00336   assert(grd_equalp(f(matrix()), empty_sgr) = true),
00337   assert(grd_equalp(f(matrix([1])), singleton_sgr) = true),
00338   assert(grd_equalp(f(matrix([1,1],[2,2])), leftnull_sgr({1,2})) = true),
00339   assert(grd_equalp(f(matrix([1,2],[1,2])), rightnull_sgr({1,2})) = true),
00340   true)$
00341 
00342 okltest_grd2m(f) := (
00343   assert(f(empty_sgr) = matrix()),
00344   assert(f(singleton_sgr) = matrix([1])),
00345   assert(f(null_sgr({[],{}},{})) = matrix([{},{}],[{},{}])),
00346   true)$
00347 
00348 okltest_grd2stdgrd(f) := (
00349   assert(grd_equalp(f(empty_sgr), empty_sgr) = true),
00350   assert(grd_equalp(f(singleton_sgr), singleton_sgr) = true),
00351   assert(grd_equalp(f(leftnull_sgr({2,3,4})), leftnull_sgr({1,2,3})) = true),
00352   assert(grd_equalp(f(rightnull_sgr({[],[1],[2]})), rightnull_sgr({1,2,3})) = true),
00353   true)$
00354 
00355 okltest_grd2m_std(f) := (
00356   assert(f(empty_sgr) = matrix()),
00357   assert(f(singleton_sgr) = matrix([1])),
00358   assert(f(leftnull_sgr({[],[1],[2]})) = matrix([1,1,1],[2,2,2],[3,3,3])),
00359   true)$
00360 
00361