OKlibrary  0.2.1.6
CalkinWilf.mac
Go to the documentation of this file.
00001 /* Oliver Kullmann, 5.9.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/MaximaInternals/Auxiliary.mac")$
00024 oklib_include("OKlib/ComputerAlgebra/NumberTheory/Lisp/CalkinWilf.mac")$
00025 oklib_include("OKlib/ComputerAlgebra/Trees/Lisp/Basics.mac")$
00026 
00027 kill(f)$
00028 
00029 
00030 /* **********
00031    * Basics *
00032    **********
00033 */
00034 
00035 okltest_calkinwilf_expand(f) := block([p,q,res],
00036   res : f(p/q),
00037   assert(simplify_t(res = [p/(q+p), (q+p)/q]) = true),
00038   assert(simplify_t(res[2] = (q+p)/q) = true),
00039   true)$
00040 
00041 okltest_calkinwilf_reduce(f) := (
00042   for p : 1 thru cokltl(8,12) do
00043    for q : 1 thru cokltl(8,12) do block([e : calkinwilf_expand(p/q)],
00044     assert(f(first(e)) = p/q),
00045     assert(f(second(e)) = p/q)
00046   ),
00047   true)$
00048 
00049 okltest_calkinwilfg_lrt(f) := (
00050   /* XXX */
00051   true)$
00052 
00053 okltest_calkinwilf_lrt(f) := (
00054   for l : 0 thru cokltl(5,10) do
00055     assert(lll_lrt(f(l)) = calkinwilf_levels(l)),
00056   true)$
00057 
00058 okltest_calkinwilf_path(f) := block([T],
00059   T : calkinwilf_lrt(cokltl(8,10)),
00060   for r in l_lrt(T) do
00061     assert(ndrep2l_lrt(f(r), T) = r),
00062   true)$
00063 
00064 okltest_calkinwilf_levels(f) := (
00065   assert(f(0) = [1]),
00066   assert(f(1) = [1/2,2/1]),
00067   assert(f(2) = [1/3,3/2,2/3,3/1]),
00068   assert(f(3) = [1/4,4/3,3/5,5/2,2/5,5/3,3/4,4/1]),
00069   assert(f(4) = [1/5,5/4,4/7,7/3,3/8,8/5,5/7,7/2,2/7,7/5,5/8,8/3,3/7,7/4,4/5,5/1]),
00070   true)$
00071 
00072 okltest_calkinwilf_recursion(f) := (
00073   for l : 0 thru cokltl(5,8) do
00074     assert(create_list(f(n), n, 2^l-1, 2^(l+1)-2) = calkinwilf_levels(l)),
00075   true)$
00076