OKlibrary  0.2.1.6
Permutations.mac
Go to the documentation of this file.
```00001 /* Oliver Kullmann, 22.8.2012 (Swansea) */
00002 /* Copyright 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/Hypergraphs/Lisp/SetSystems.mac")\$
00024 oklib_include("OKlib/ComputerAlgebra/Combinatorics/Lisp/Enumeration/Permutations.mac")\$
00025
00026 kill(f)\$
00027
00028
00029 /* ************
00030    * Counting *
00031    ************
00032 */
00033
00034 /* ****************************
00035    * Lexicographical ordering *
00036    ****************************
00037 */
00038
00039 okltest_lex_permutations_l(f) := (
00040   assert(f({}) = [[]]),
00041   assert(f({1}) = [[1]]),
00042   assert(f({-1,2}) = [[-1,2],[2,-1]]),
00043   assert(f({1,3,5}) = [[1,3,5],[1,5,3],[3,1,5],[3,5,1],[5,1,3],[5,3,1]]),
00044   true)\$
00045
00046 okltest_rank_lex_permutations(f) := (
00047   for n : 0 thru cokltl(5,7) do
00048     assert(map(f,lex_permutations_l(setn(n))) = create_list(i,i,1,n!)),
00049   true)\$
00050
00051 okltest_unrank_lex_permutations(f) := (
00052   for n : 0 thru cokltl(5,7) do
00053     assert(map(lambda([x],f(x,n)),create_list(i,i,1,n!)) = lex_permutations_l(setn(n))),
00054   true)\$
00055
00056
```