OKlibrary  0.2.1.6
Conversions.mac
Go to the documentation of this file.
```00001 /* Oliver Kullmann, 21.7.2008 (Swansea) */
00002 /* Copyright 2008, 2009 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 /* ********************
00023    * Handling symbols *
00024    ********************
00025 */
00026
00027 /* When translating positions into variables, then the base
00028    name of the formal variable is given by the following variable:
00029 */
00030 special_symbol : "x"\$
00031
00032 /* Appending a distinguishing "index" to the special symbol: */
00033 indexed_symbol(i) :=  parse_string(sconcat(special_symbol,i))\$
00034
00035
00036 /* ********************************************
00037    * Auxiliary functions handling "equations" *
00038    ********************************************
00039 */
00040
00041 /* Translating a vector into a linear combination, based on
00042    the special symbol.
00043    If special_symbol = x and a = [1,4,7], then
00044    is(translate_vector_lincomb(a) = 1 * x1 + 4 * x2 + 7 * x3)
00045    is true.
00046 */
00047 translate_vector_lincomb_n(a,n) :=
00048   sum(a[i] * indexed_symbol(i), i,1,n)\$
00049 translate_vector_lincomb(a) :=
00050   translate_vector_lincomb_n(a,length(a))\$
00051
00052 /* Treating a matrix row-wise, translate "A x >= 0" into a list
00053    of inequalities:
00054 */
00055 translate_matrix_ineq(A) := block([m,n],
00056   [m,n] : matrix_size(A),
00057   block([eqslhs : create_list(translate_vector_lincomb_n(A[i],n),i,1,m)],
00058     create_list(eqslhs[i] >= 0,i,1,m)))\$
00059
00060 /* Creating inequalities x_i >= 1, x_i <= -1, and x_i = 0,
00061    specifying the index i (while "x" is special_symbol): */
00062 interprete_poscond(i) := indexed_symbol(i) >= 1\$
00063 interprete_negcond(i) := indexed_symbol(i) <= -1\$
00064 interprete_zerocond(i) := indexed_symbol(i) = 0\$
00065
00066
```