OKlibrary  0.2.1.6
Basics.mac
Go to the documentation of this file.
00001 /* Oliver Kullmann, 16.3.2008 (Swansea) */
00002 /* Copyright 2008, 2009, 2010, 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 oklib_include("OKlib/ComputerAlgebra/Hypergraphs/Lisp/Basics.mac")$
00024 oklib_include("OKlib/ComputerAlgebra/Hypergraphs/Lisp/SetSystems.mac")$
00025 oklib_include("OKlib/ComputerAlgebra/CombinatorialMatrices/Lisp/Basics.mac")$
00026 oklib_include("OKlib/ComputerAlgebra/Cryptology/Lisp/CryptoSystems/Rijndael/SmallScaleWordFields.mac")$
00027 
00028 
00029 kill(f)$
00030 
00031 /* *****************
00032    * Basic notions *
00033    *****************
00034 */
00035 
00036 okltest_binfam_p(f) := (
00037 
00038   true)$
00039 
00040 okltest_com_p(f) := block([fun],
00041   assert(f(0,{}) = false),
00042   assert(f([],{}) = false),
00043   assert(f([0,0],{}) = false),
00044   assert(f([0,0,0],{}) = false),
00045   assert(f([[],[],[]],{}) = false),
00046   assert(f([{},{},fun],{}) = true),
00047   assert(f([{1},{},fun],{}) = true),
00048   assert(f([{},{1},fun],{}) = true),
00049   assert(f([{1},{1},fun],{}) = false),
00050   assert(f([{1},{1},lambda([i,j],2)],{}) = false),
00051   assert(f([{1},{1},lambda([i,j],2)],{1}) = false),
00052   assert(f([{1},{1},lambda([i,j],2)],{2}) = true),
00053   true)$
00054 
00055 okltest_ocom_p(f) := block(
00056   /* XXX */
00057   true)$
00058 
00059 okltest_scom_p(f) := block([fun],
00060   assert(f(0,{}) = false),
00061   assert(f([],{}) = false),
00062   assert(f([0,0],{}) = false),
00063   assert(f([[],fun],{}) = false),
00064   assert(f([{},fun],{}) = true),
00065   assert(f([{1},fun],{}) = false),
00066   assert(f([{1},lambda([i,j],0)],{}) = false),
00067   assert(f([{1},lambda([i,j],0)],{0}) = true),
00068   assert(f([{1,2},lambda([i,j],i+j)],{2,3,4}) = true),
00069   true)$
00070 
00071 okltest_sqscom_p(f) := (
00072   /* XXX */
00073   true)$
00074 
00075 okltest_osqcom_p(f) := (
00076   /* XXX */
00077   true)$
00078 
00079 
00080 
00081 /* *********************
00082    * Checking equality *
00083    *********************
00084 */
00085 
00086 okltest_com_equalp(f) := (
00087   assert(f(emptycom,emptycom) = true),
00088   assert(f(emptycom,zerocom({},{1})) = false),
00089   assert(f(constantcom({1,2},{1,3},2), constantcom({1,2},{1,3},2)) = true),
00090   assert(f(constantcom({1,2},{1,3},1), constantcom({1,2},{1,3},2)) = false),
00091   assert(f(trans(trans(constantcom({1,2},{1,3},1))), constantcom({1,2},{1,3},1)) = true),
00092   true)$
00093 
00094 okltest_scom_equalp(f) := (
00095   assert(f(emptyscom,emptyscom) = true),
00096   assert(f(emptyscom,zeroscom({1})) = false),
00097   assert(f(constantscom({1,2},2), constantscom({1,2},2)) = true),
00098   assert(f(constantscom({1,2},1), constantscom({1,2},2)) = false),
00099   assert(f(strans(constantscom({1,2},1)), constantscom({1,2},1)) = true),
00100   assert(f(strans(idscom({1,2})), idscom({1,2})) = true),
00101   true)$
00102 
00103 
00104 /* ***************
00105    * Conversions *
00106    ***************
00107 */
00108 
00109 okltest_scom2com(f) := block([I,fun],
00110   assert(f([I,fun]) = [I,I,fun]),
00111   true)$
00112 
00113 okltest_oscom2ocom(f) := block([I,fun],
00114   assert(f([I,fun]) = [I,I,fun]),
00115   true)$
00116 
00117 okltest_com2scom(f) := block([I,fun],
00118   assert(f([I,I,fun]) = [I,fun]),
00119   true)$
00120 
00121 okltest_ocom2oscom(f) := block([I,fun],
00122   assert(f([I,I,fun]) = [I,fun]),
00123   true)$
00124 
00125 okltest_ocom2com(f) := block(
00126   /* XXX */
00127   true)$
00128 
00129 okltest_oscom2scom(f) := block(
00130   /* XXX */
00131   true)$
00132 
00133 
00134 okltest_com2ocom(f) := block(
00135   /* XXX */
00136   true)$
00137 
00138 okltest_scom2oscom(f) := block(
00139   /* XXX */
00140   true)$
00141 
00142 
00143 okltest_com2m(f) := (
00144   assert(f([{},{},identity]) = matrix()),
00145   assert(f([{1},{},identity]) = matrix([])),
00146   assert(f([{-1,1},{},identity]) = matrix([],[])),
00147   assert(f([{},{1},identity]) = matrix()),
00148   assert(f([{1,2},{1,2},lambda([i,j],i+j)]) = matrix([2,3],[3,4])),
00149   assert(f([{-1,0},{-4,3},lambda([i,j],i+j)]) = matrix([-5,2],[-4,3])),
00150   true)$
00151 
00152 okltest_ocom2m(f) := ([a,b,c],
00153   assert(f([[a,b],[a,-1,c],lambda([i,j],i+j)]) = matrix([2*a,a-1,a+c],[b+a,b-1,b+c])),
00154   assert(okltest_com2m(buildq([f],lambda([M],f([listify(M[1]),listify(M[2]),M[3]]))))),
00155   true)$
00156 
00157 okltest_scom2m(f) := ([fun],
00158   assert(f([{},fun]) = matrix()),
00159   assert(f([{1,2},lambda([i,j],i*j)]) = matrix([1,2],[2,4])),
00160   true)$
00161 
00162 okltest_oscom2m(f) := ([fun],
00163   assert(f([[],fun]) = matrix()),
00164   assert(f([[1,2],lambda([i,j],i*j)]) = matrix([1,2],[2,4])),
00165   assert(f([[4,3],lambda([i,j],i*j)]) = matrix([16,12],[12,9])),
00166   true)$
00167 
00168 okltest_m2com(f) := block([fun],
00169   assert(com_equalp(f(matrix()), [{},{},fun]) = true),
00170   assert(com_equalp(f(matrix([])), [{1},{},fun]) = true),
00171   assert(com_equalp(f(matrix([],[])), [{1,2},{},fun]) = true),
00172   assert(okltest_m2scom(buildq([f],lambda([M],com2scom(f(M)))))),
00173   true)$
00174 
00175 okltest_m2ocom(f) := block([fun],
00176   assert(com_equalp(f(matrix()), [[],[],fun]) = true),
00177   assert(com_equalp(f(matrix([])), [[1],[],fun]) = true),
00178   assert(com_equalp(f(matrix([],[])), [[1,2],[],fun]) = true),
00179   assert(okltest_m2oscom(buildq([f],lambda([M],ocom2oscom(f(M)))))),
00180   true)$
00181 
00182 okltest_m2scom(f) := block(
00183   assert(scom_equalp(f(matrix()),[{},identity]) = true),
00184   assert(scom_equalp(f(matrix([1])),[{1},lambda([i,j],1)]) = true),
00185   assert(scom_equalp(f(matrix([1,1],[1,1])),[{1,2},lambda([i,j],1)]) = true),
00186   assert(scom_equalp(f(matrix([2,3],[3,4])),[{1,2},lambda([i,j],i+j)]) = true),
00187   true)$
00188 
00189 okltest_m2oscom(f) := block(
00190   assert(scom_equalp(f(matrix()),[[],identity]) = true),
00191   assert(scom_equalp(f(matrix([1])),[[1],lambda([i,j],1)]) = true),
00192   assert(scom_equalp(f(matrix([1,1],[1,1])),[[1,2],lambda([i,j],1)]) = true),
00193   assert(scom_equalp(f(matrix([2,3],[3,4])),[[1,2],lambda([i,j],i+j)]) = true),
00194   true)$
00195 
00196 
00197 okltest_com_l(f) := (
00198   /* XXX */
00199   true)$
00200 
00201 okltest_scom_l(f) := (
00202   /* XXX */
00203   true)$
00204 
00205 okltest_mrc2ocom(f) := block([M,m,x],
00206   m : matrix([1,2],[3,4]),
00207   M : f(m,["a",88],[x,"jkl"]),
00208   assert(M[1] = ["a",88]),
00209   assert(M[2] = [x,"jkl"]),
00210   assert(M[3]("a",x) = 1),
00211   assert(M[3]("a","jkl") = 2),
00212   assert(M[3](88,x) = 3),
00213   assert(M[3](88,"jkl") = 4),
00214   /* XXX */
00215   true)$
00216 
00217 
00218 /* ***********************
00219    * Basic constructions *
00220    ***********************
00221 */
00222 
00223 okltest_emptycom(f) := (
00224   assert(com_p(f,{}) = true),
00225   assert(dim_com(f) = [0,0]),
00226   true)$
00227 
00228 okltest_emptycom_r(f) := (
00229 
00230   true)$
00231 
00232 okltest_emptycom_c(f) := (
00233 
00234   true)$
00235 
00236 okltest_emptyscom(f) := (
00237   assert(scom_p(f,{}) = true),
00238   assert(order_scom(f) = 0),
00239   true)$
00240 
00241 okltest_zerocom(f) := (
00242 
00243   true)$
00244 
00245 okltest_zeroscom(f) := (
00246 
00247   true)$
00248 
00249 okltest_constantcom(f) := (
00250 
00251   true)$
00252 
00253 okltest_constantscom(f) := (
00254 
00255   true)$
00256 
00257 okltest_idscom(f) := (
00258 
00259   true)$
00260 
00261 okltest_cdiagscom(f) := (
00262 
00263   true)$
00264 
00265 okltest_all_m(f) := (
00266   assert(f(0,0,[]) = [matrix()]),
00267   assert(f(0,0,[1]) = [matrix()]),
00268   assert(f(1,0,[]) = [matrix([])]),
00269   assert(f(2,0,[]) = [matrix([],[])]),
00270   assert(f(2,0,[1]) = [matrix([],[])]),
00271   assert(f(1,1,[-1,3,-2]) = [matrix([-1]),matrix([3]),matrix([-2])]),
00272   assert(length(f(2,2,[-3,0,3])) = 3^4),
00273   true)$
00274 
00275 okltest_genmatrix_m(f) := (
00276 
00277   true)$
00278 
00279 okltest_genmatrix_sm(f) := (
00280 
00281   true)$
00282 
00283 
00284 /* *******************
00285    * Random matrices *
00286    *******************
00287 */
00288 
00289 okltest_random_m(f) := block([x],
00290   assert(f(0,0,x) = matrix()),
00291   assert(f(1,0,x) = matrix([])),
00292   assert(f(1,1,1) = matrix([0])),
00293   set_random_state(make_random_state(0)),
00294   assert(f(2,2,100) = matrix([44,39],[33,60])),
00295   true)$
00296 
00297 okltest_random_intiv_m(f) := block([a,b],
00298   assert(f(0,0,a,b) = matrix()),
00299   assert(f(1,0,a,b) = matrix([])),
00300   assert(f(1,1,0,0) = matrix([0])),
00301   set_random_state(make_random_state(0)),
00302   assert(f(4,2,-200,500) = matrix([211,131],[29,16],[384,320],[375,-36])),
00303   true)$
00304 
00305 okltest_random_fpiv_m(f) := block([a,b,M],
00306   assert(f(0,0,a,b) = matrix()),
00307   assert(f(1,0,a,b) = matrix([])),
00308   set_random_state(make_random_state(0)),
00309   M : f(2,2,-200,500),
00310   assert_float_equal(M[1,1], 4.084476632548927),
00311   assert_float_equal(M[1,2], -121.2580674814649),
00312   assert_float_equal(M[2,1], -98.31836515964578),
00313   assert_float_equal(M[2,2], 40.18142835447708),
00314   true)$
00315 
00316 okltest_random_sm(f) := block([x],
00317   assert(f(0,x) = matrix()),
00318   assert(f(2,1) = matrix([0,0],[0,0])),
00319   set_random_state(make_random_state(0)),
00320   assert(f(2,100) = matrix([44,39],[39,33])),
00321   thru 5 do block(
00322    [N : setmn(0,99), M : f(3,100)],
00323     assert(symmetric_m_p(M)),
00324     assert(every_scom_p(lambda([x],elementp(x,N)), m2scom(M)))),
00325   true)$
00326 
00327 okltest_random_permutation_m(f) := (
00328   assert(f(matrix()) = matrix()),
00329   assert(f(matrix([])) = matrix([])),
00330   assert(f(matrix([],[])) = matrix([],[])),
00331   assert(f(matrix([0])) = matrix([0])),
00332   assert(f(matrix([0,0])) = matrix([0,0])),
00333   set_random(1),
00334   assert(f(matrix([1,2],[3,4])) = matrix([4,3],[2,1])),
00335   assert(f(matrix([1,2,3],[4,5,6])) = matrix([3,1,2],[6,4,5])),
00336   assert(f(matrix([1,2],[3,4],[5,6])) = matrix([6,5],[2,1],[4,3])),
00337   true)$
00338 
00339 okltest_random_rpermutation_m(f) := (
00340   assert(f(matrix()) = matrix()),
00341   assert(f(matrix([])) = matrix([])),
00342   assert(f(matrix([],[])) = matrix([],[])),
00343   assert(f(matrix([0])) = matrix([0])),
00344   assert(f(matrix([0,0])) = matrix([0,0])),
00345   set_random(1),
00346   assert(f(matrix([1,2],[3,4],[5,6])) = matrix([5,6],[1,2],[3,4])),
00347   assert(f(matrix([1,2,3,4,5,6])) = matrix([1,2,3,4,5,6])),
00348   true)$
00349 
00350 okltest_random_cpermutation_m(f) := (
00351   assert(f(matrix()) = matrix()),
00352   assert(f(matrix([])) = matrix([])),
00353   assert(f(matrix([],[])) = matrix([],[])),
00354   assert(f(matrix([0])) = matrix([0])),
00355   assert(f(matrix([0,0])) = matrix([0,0])),
00356   assert(f(matrix([1,2,3],[4,5,6],[7,8,9])) = matrix([3,1,2],[6,4,5],[9,7,8])),
00357   assert(f(matrix([1],[2],[3],[4],[5],[6])) = matrix([1],[2],[3],[4],[5],[6])),
00358   true)$
00359 
00360 okltest_random_spolar_m(f) := (
00361 
00362   true)$
00363 
00364 okltest_extend_linear_hull(f) := block([H],
00365   H : {},
00366   H : f([1,0,0],H,{0,1},
00367       lambda([a,b],ss_add(a,b,2,x)), lambda([a,b],ss_mul(a,b,2,x))),
00368   assert(H = {[1,0,0]}),
00369   H : f([1,0,0],H,{0,1},
00370     lambda([a,b],ss_add(a,b,2,x)), lambda([a,b],ss_mul(a,b,2,x))),
00371   assert(H = {[1,0,0]}),
00372   H : f([0,1,0],H,{0,1},
00373       lambda([a,b],ss_add(a,b,2,x)), lambda([a,b],ss_mul(a,b,2,x))),
00374   assert(H = {[0,1,0],[1,0,0],[1,1,0]}),
00375   H : f([0,0,1],H,{0,1},
00376     lambda([a,b],ss_add(a,b,2,x)), lambda([a,b],ss_mul(a,b,2,x))),
00377   assert(H = {[0,0,1],[0,1,0],[0,1,1],[1,0,0],[1,0,1],[1,1,0],[1,1,1]}),
00378   true)$
00379 
00380 okltest_linear_hull(f) := (
00381   assert(f({},{0,1}, 'f, 'g) = {}),
00382   assert(f({[0,0,1]},{0,1},
00383       lambda([a,b],ss_add(a,b,2,x)), lambda([a,b],ss_mul(a,b,2,x))) =
00384     {[0,0,1]}),
00385   assert(f({[1,0,0],[0,0,1]},{0,1},
00386       lambda([a,b],ss_add(a,b,2,x)), lambda([a,b],ss_mul(a,b,2,x))) =
00387     {[0,0,1],[1,0,0],[1,0,1]}),
00388   assert(f({[0,1,0],[1,0,0],[0,0,1]},{0,1}, lambda([a,b],ss_add(a,b,2,x)),
00389       lambda([a,b],ss_mul(a,b,2,x))) =
00390     {[0,0,1],[0,1,0],[0,1,1],[1,0,0],[1,0,1],[1,1,0],[1,1,1]}),
00391   true)$
00392 
00393 okltest_random_inv_m(f) := (
00394   set_random(1),
00395   assert(f(2,2,{0,1},
00396       lambda([a,b],ss_add(a,b,2,x)), lambda([a,b],ss_mul(a,b,2,x))) =
00397     matrix([1,1],[1,0])),
00398   assert(f(2,2,{0,1},
00399       lambda([a,b],ss_add(a,b,2,x)), lambda([a,b],ss_mul(a,b,2,x))) =
00400     matrix([1,0],[0,1])),
00401   true)$
00402 
00403 
00404 /* ****************************
00405    * Rows, columns, diagonals *
00406    ****************************
00407 */
00408 
00409 okltest_com2l_r(f) := (
00410   assert(f(emptycom) = []),
00411   assert(f(zerocom({1,2},{3,4})) = [0,0,0,0]),
00412   assert(f([{1,2},{7,10},lambda([i,j],i+j)]) = [8,11,9,12]),
00413   true)$
00414 okltest_com2ll_r(f) := (
00415   assert(f(emptycom) = []),
00416   assert(f(zerocom({1,2,3},{4,5})) = [[0,0],[0,0],[0,0]]),
00417   assert(okltest_com2l_r(buildq([f],lambda([M],lappend(f(M)))))),
00418   true)$
00419 okltest_scom2ll_r(f) := (
00420   /* XXX */
00421   true)$
00422 
00423 okltest_com2l_c(f) := (
00424   assert(f(emptycom) = []),
00425   assert(f(zerocom({1,2},{3,4})) = [0,0,0,0]),
00426   assert(f([{1,2},{7,10},lambda([i,j],i+j)]) = [8,9,11,12]),
00427   true)$
00428 okltest_com2ll_c(f) := (
00429   assert(f(emptycom) = []),
00430   assert(f(zerocom({1,2,3},{4,5})) = [[0,0,0],[0,0,0]]),
00431   assert(okltest_com2l_c(buildq([f],lambda([M],lappend(f(M)))))),
00432   true)$
00433 okltest_scom2ll_c(f) := (
00434   /* XXX */
00435   true)$
00436 
00437 okltest_row_m(f) := (
00438   assert(f(matrix([]),1) = []),
00439   assert(f(matrix([],[]),2) = []),
00440   assert(f(matrix([1]),1) = [1]),
00441   assert(f(matrix([1,2],[3,4]),2) = [3,4]),
00442   true)$
00443 
00444 okltest_column_m(f) := (
00445   assert(f(matrix([1]),1) = [1]),
00446   assert(f(matrix([1,2],[3,4]),2) = [2,4]),
00447   true)$
00448 
00449 okltest_com2omsoms_r(f) := (
00450   assert(f(emptycom) = []),
00451   assert(f(zerocom({1,2,3},{1,2})) = [[[[0,2]],3]]),
00452   assert(f(m2com(matrix([1,2,1],[2,3,3],[1,3,4],[2,1,1]))) = [ [[[1,1],[3,1],[4,1]],1], [[[1,2],[2,1]],2],  [[[2,1],[3,2]],1]  ]),
00453   true)$
00454 
00455 okltest_com2omsoms_c(f) := (
00456   assert(f(emptycom) = []),
00457   assert(f(zerocom({1,2,3},{1,2})) = [[[[0,3]],2]]),
00458   assert(f(m2com(matrix([1,2,1],[2,3,3],[1,3,4],[2,1,1]))) = [ [[[1,1],[2,1],[3,2]],1], [[[1,2],[2,2]],1], [[[1,2],[3,1],[4,1]],1] ]),
00459   true)$
00460 
00461 okltest_maindiag_scom(f) := (
00462   assert(f(emptyscom) = []),
00463   assert(f(zeroscom({2,3,4})) = [0,0,0]),
00464   assert(f(m2scom(matrix([1,2,3],[2,3,4],[3,4,5]))) = [1,3,5]),
00465   true)$
00466 
00467 okltest_maindiagoms_scom(f) := (
00468   assert(f(emptyscom) = []),
00469   assert(f(zeroscom({2,3,4})) = [[0,3]]),
00470   assert(f(m2scom(matrix([1,2,3],[2,3,4],[3,4,5]))) = [[1,1],[3,1],[5,1]]),
00471   assert(f(m2scom(matrix([1,2,3],[2,1,4],[3,4,5]))) = [[1,2],[5,1]]),
00472   true)$
00473 
00474 
00475 /* *******************
00476    * Transformations *
00477    *******************
00478 */
00479 
00480 okltest_scom2g(f) := (
00481 
00482   true)$
00483 
00484 okltest_scom2gl(f) := (
00485 
00486   true)$
00487 
00488 okltest_scom2dg(f) := (
00489 
00490   true)$
00491 
00492 okltest_scom2dgl(f) := (
00493 
00494   true)$
00495 
00496 okltest_com2ghg(f) := (
00497   assert(ghg_equalp(f(emptycom), [{},{}, identity]) = true),
00498   assert(ghg_equalp(f(zerocom({1,2},{1,2})), [{1,2},{1,2}, lambda([e],{})]) = true),
00499   assert(ghg_equalp(f(constantcom({1,2},{3,4},2)), [{1,2},{3,4}, lambda([e],{1,2})]) = true),
00500   true)$
00501 
00502 okltest_trans_l2scom(f) := (
00503 
00504   true)$
00505 
00506 
00507 /* ********************
00508    * Basic operations *
00509    ********************
00510 */
00511 
00512 okltest_dim_com(f) := (
00513   assert(f(emptycom) = [0,0]),
00514   assert(f(zerocom({},{1,2})) = [0,2]),
00515   assert(f(zerocom({1,2},{3})) = [2,1]),
00516   assert(okltest_order_scom(buildq([f],lambda([M],f(scom2com(M))[1])))),
00517   true)$
00518 
00519 okltest_order_scom(f) := (
00520   assert(f(emptyscom) = 0),
00521   assert(f(zeroscom({1,2})) = 2),
00522   true)$
00523 
00524 okltest_trans_com(f) := (
00525   assert(com_equalp(f(emptycom), emptycom) = true),
00526   assert(com_equalp(f(zerocom({1,3},{-3,4})), zerocom({-3,4},{1,3}))),
00527   assert(okltest_trans_scom(buildq([f],lambda([M],com2scom(f(scom2com(M))))))),
00528   true)$
00529 
00530 okltest_trans_scom(f) := (
00531   assert(scom_equalp(f(emptyscom), emptyscom)),
00532   assert(scom_equalp(f(zeroscom({-3,4})), zeroscom({-3,4}))),
00533   true)$
00534 
00535 
00536 /* ************************
00537    * Algebraic operations *
00538    ************************
00539 */
00540 
00541 okltest_add_scom(f) := (
00542 
00543   true)$
00544 
00545 okltest_diff_scom(f) := (
00546 
00547   true)$
00548 
00549 okltest_scprod_scom(f) := (
00550 
00551   true)$
00552 
00553 okltest_prod_com(f) := block([fun],
00554   assert(com_equalp(f([{},{},fun],[{},{},fun]), [{},{},fun]) = true),
00555   assert(com_equalp(f([{1,2},{},fun],[{},{3,4},fun]), zerocom({1,2},{3,4})) = true),
00556   assert(com_equalp(f(constantcom({1,2},{1,3},2),constantcom({1,2},{1,3},3)), constantcom({1,2},{1,3},12)) = true),
00557   true)$
00558 
00559 
00560 /* ********************
00561    * Entry statistics *
00562    ********************
00563 */
00564 
00565 okltest_min_com(f) := (
00566   assert(f(zerocom({1,2},{3,4})) = 0),
00567   assert(f(m2com(matrix([1,2],[-1,0]))) = -1),
00568   true)$
00569 
00570 okltest_max_com(f) := (
00571   assert(f(zerocom({1,2},{3,4})) = 0),
00572   assert(f(m2com(matrix([1,2],[-1,0]))) = 2),
00573   true)$
00574 
00575 okltest_sum_com(f) := (
00576   assert(f(emptycom) = 0),
00577   assert(f(emptycom_r({1,2})) = 0),
00578   assert(f(emptycom_c({3,4})) = 0),
00579   assert(f(conststdcom(3,4,-1)) = 3*4 * -1),
00580   assert(okltest_sum_scom(buildq([f],lambda([M],f(scom2com(M)))))),
00581   true)$
00582 
00583 okltest_sum_scom(f) := (
00584   assert(f(emptyscom) = 0),
00585   assert(f(constantscom(setn(3),2)) = 18),
00586   true)$
00587 
00588 okltest_sum_m(f) := block([a,b,c,d],
00589   assert(f(matrix(),[]) = 0),
00590   assert(f(matrix([5]),[]) = 0),
00591   assert(f(matrix([5]),[[1,1]]) = 5),
00592   assert(f(matrix([a,b],[c,d]), [[1,2]]) = b),
00593   assert(f(matrix([a,b],[c,d]), [[1,2],[2,2]]) = b+d),
00594   true)$
00595 
00596 okltest_abs_com(f) := (
00597   assert(com_equalp(f(emptycom), emptycom) = true),
00598   assert(com_equalp(f(zerocom({1},{2})), zerocom({1},{2})) = true),
00599   assert(com_equalp(f(constantcom({1,2},{3,4},-1)), constantcom({1,2},{3,4},1)) = true),
00600   true)$
00601 
00602 okltest_abs_scom(f) := (
00603   assert(scom_equalp(f(emptyscom), emptyscom) = true),
00604   assert(scom_equalp(f(zeroscom({1})), zeroscom({1})) = true),
00605   assert(scom_equalp(f(constantscom({1,2},-1)), constantscom({1,2},1)) = true),
00606   assert(scom_equalp(f(idscom({1,2})), idscom({1,2})) = true),
00607   assert(scom_equalp(f(cdiagscom({1,2},-2)), cdiagscom({1,2},2)) = true),
00608   true)$
00609 
00610 
00611 okltest_rowsums_list_com(f) := block([u],
00612   assert(f([{},{},u]) = []),
00613   assert(f([{},{1},u]) = []),
00614   for n : 0 thru 4 do
00615     assert(f([setn(n),{},u]) = if n=0 then [] else [[0,n]]),
00616   for n : 0 thru 3 do
00617     for m : 0 thru 3 do
00618       for k : 0 thru 2 do
00619         assert(f([setn(n),setn(m),lambda([i,j],k)]) = if n=0 then [] else [[m*k,n]]),
00620   true)$
00621 
00622 okltest_columnsums_list_com(f) := block(
00623   okltest_rowsums_list_com(buildq([f],lambda([M],f(trans(M))))),
00624   true)$
00625 
00626 okltest_com_distribution(f) := (
00627   assert(f(emptycom) = []),
00628   assert(f(emptycom_r({1,2})) = []),
00629   assert(f(emptycom_c({3,4})) = []),
00630   assert(f(m2com(matrix([1,2,3],[2,3,4],[1,4,5]))) = [[1,2],[2,2],[3,2],[4,2],[5,1]]),
00631   assert(f(m2com(matrix([{},{1},{-1}],[{1,2},{},{-1}]))) = [[{},2],[{-1},2],[{1},1],[{1,2},1]]),
00632   true)$
00633 
00634 
00635 /* ***************
00636    * Basic tests *
00637    ***************
00638 */
00639 
00640 okltest_empty_com_p(f) := block([fun],
00641   assert(f([{},{},fun]) = true),
00642   assert(f([{},{1},fun]) = true),
00643   assert(f([{1},{},fun]) = true),
00644   assert(f([{1},{1},fun]) = false),
00645   true)$
00646 
00647 okltest_every_com_p(f) := block([fun],
00648   assert(f(fun,emptycom) = true),
00649   assert(f(lambda([x],is(x=0)),zerocom({1,2},{-3,3})) = true),
00650   assert(f(lambda([x],is(x=0)),scom2com(idscom({1,2}))) = false),
00651   assert(okltest_every_scom_p(buildq([f],lambda([pred,M],f(pred,scom2com(M)))))),
00652   true)$
00653 
00654 okltest_every_scom_p(f) := block([fun],
00655   assert(f(fun,emptyscom) = true),
00656   assert(f(identity,constantscom({1,2},true)) = true),
00657   assert(f(identity,constantscom({1,2},false)) = false),
00658   true)$
00659 
00660 okltest_some_com_p(f) :=  block([fun],
00661   assert(f(fun,emptycom) = false),
00662   assert(f(lambda([x],is(x=0)),zerocom({1},{-3,3})) = true),
00663   assert(f(lambda([x],is(x=1)),zerocom({1},{-3,3})) = false),
00664   assert(f(lambda([x],is(x=0)),scom2com(idscom({1,2}))) = true),
00665   assert(f(lambda([x],is(x=1)),scom2com(idscom({1,2}))) = true),
00666   assert(okltest_some_scom_p(buildq([f],lambda([pred,M],f(pred,scom2com(M)))))),
00667   assert(okltest_every_com_p(buildq([f],lambda([pred,M],
00668     not f(lambda([x], not pred(x)), M))))),
00669   true)$
00670 
00671 okltest_some_scom_p(f) :=  block([fun],
00672   assert(f(fun,emptyscom) = false),
00673   assert(f(lambda([x],is(x=0)),zeroscom({-3,3})) = true),
00674   assert(f(lambda([x],is(x=1)),zeroscom({-3,3})) = false),
00675   assert(f(lambda([x],is(x=0)),idscom({0,1})) = true),
00676   assert(f(lambda([x],is(x=1)),idscom({0,1})) = true),
00677   true)$
00678 
00679 okltest_every_diagc_scom_p(f) :=  block(
00680   assert(f(emptyscom,1) = true),
00681   assert(f(zeroscom({1}),1) = false),
00682   assert(f(zeroscom({1}),0) = true),
00683   assert(f(zeroscom({1,3}),1) = false),
00684   assert(f(zeroscom({1,3}),0) = true),
00685   assert(f(idscom({0,1}),1) = true),
00686   assert(f(idscom({0,1}),0) = false),
00687   true)$
00688 
00689 okltest_every_diag_scom_p(f) := block([fun],
00690   assert(f(fun,emptyscom) = true),
00691   assert(okltest_every_diagc_scom_p(buildq([f], lambda([M,c],
00692     f(lambda([x],is(x=c)), M))))),
00693   true)$
00694 
00695 okltest_every_ndiagc_scom_p(f) := block(
00696   assert(f(emptyscom,1) = true),
00697   assert(f(zeroscom({1}),1) = true),
00698   assert(f(zeroscom({1}),0) = true),
00699   assert(f(zeroscom({1,3}),1) = false),
00700   assert(f(zeroscom({1,3}),0) = true),
00701   assert(f(idscom({0,1}),1) = false),
00702   assert(f(idscom({0,1}),0) = true),
00703   true)$
00704 
00705 okltest_every_ndiag_scom_p(f) := block([fun],
00706   assert(f(fun,emptyscom) = true),
00707   assert(okltest_every_ndiagc_scom_p(buildq([f], lambda([M,c],
00708     f(lambda([x],is(x=c)), M))))),
00709   true)$
00710 
00711 okltest_some_ndiag_scom_p(f) := block([fun],
00712   assert(f(fun,emptyscom) = false),
00713   assert(f(identity, m2scom(matrix([false,true],[false,false]))) = true),
00714   assert(f(identity, m2scom(matrix([false,false],[false,false]))) = false),
00715   assert(okltest_every_ndiag_scom_p(buildq([f], lambda([npred,M],
00716     not f(lambda([x], not npred(x)), M))))),
00717   true)$
00718 
00719 okltest_extscom_com_p(f) := (
00720   assert(f(emptycom) = true),
00721   assert(f(emptycom_r({1})) = false),
00722   assert(f(emptycom_c({2})) = false),
00723   assert(f(zerocom({1,2},{3,4})) = true),
00724   assert(f(zerocom({1,2},{3})) = false),
00725   true)$
00726 
00727 okltest_obsscom_com_p(f) := (
00728   assert(f(emptycom) = true),
00729   assert(f(emptycom_r({1})) = false),
00730   assert(f(emptycom_c({2})) = false),
00731   assert(f(zerocom({1,2},{3,4})) = false),
00732   assert(f(zerocom({1,2},{3})) = false),
00733   assert(f(zerocom({1,2},{1,2})) = true),
00734   true)$
00735 
00736 okltest_symmetric_scom_p(f) := (
00737   assert(f(emptyscom) = true),
00738   assert(f(zeroscom({0,2})) = true),
00739   assert(f(idscom({0,2})) = true),
00740   assert(f(m2scom(matrix([1,2],[1,2]))) = false),
00741   true)$
00742 
00743 okltest_symmetric_m_p(f) := (
00744   assert(f(matrix()) = true),
00745   assert(f(matrix([1])) = true),
00746   assert(f(zeromatrix(3,3)) = true),
00747   assert(f(zeromatrix(2,3)) = false),
00748   true)$
00749 
00750 okltest_alldifferent_m_p(f) := (
00751   assert(f(matrix(),[]) = true),
00752   assert(f(matrix([1]),[]) = true),
00753   assert(f(matrix([1]),[[1,1]]) = true),
00754   assert(f(matrix([1,1]),[[1,1]]) = true),
00755   assert(f(matrix([1,1]),[[1,1],[1,2]]) = false),
00756   assert(f(matrix([1,2],[2,3]),[[1,1],[1,2],[2,2]]) = true),
00757   assert(f(matrix([1,2],[2,3]),[[1,2],[2,1]]) = false),
00758   true)$
00759 
00760 
00761 /* ***************
00762    * Polynomials *
00763    ***************
00764 */
00765 
00766 okltest_charpoly_m(f) := block([x],
00767   assert(f(matrix()) = 1),
00768   assert(f(matrix([0])) = x),
00769   assert(f(matrix([1])) = x-1),
00770   assert(f(matrix([2,0],[0,0])) = x^2 - 2 * x),
00771   assert(f(matrix([1,1],[1,1])) = x^2 - 2 * x),
00772   true)$
00773 
00774 okltest_charpoly_scom(f) := block([fun],
00775   assert(f([{},fun]) = 1),
00776   assert(okltest_charpoly_m(buildq([f],lambda([M],f(m2scom(M)))))),
00777   true)$
00778 
00779