def i4vec_descends_test(): #*****************************************************************************80 # ## I4VEC_DESCENDS_TEST tests I4VEC_DESCENDS. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 07 May 2015 # # Author: # # John Burkardt # import numpy as np from i4vec_transpose_print import i4vec_transpose_print n = 4 test_num = 6 x_test = np.array ( [ \ [ 1, 3, 2, 4 ], \ [ 2, 2, 2, 2 ], \ [ 1, 2, 2, 4 ], \ [ 1, 2, 3, 4 ], \ [ 4, 4, 3, 1 ], \ [ 9, 7, 3, 0 ] ] ) print '' print 'I4VEC_DESCENDS_TEST' print ' I4VEC_DESCENDS determines if an I4VEC descends.' for i in range(0, test_num): x = np.zeros(n) for j in range(0, n): x[j] = x_test[i, j] i4vec_transpose_print(n, x, ' Test vector:') value = i4vec_descends(n, x) print ' I4VEC_DESCENDS = %s' % (value) # # Terminate. # print '' print 'I4VEC_DESCENDS_TEST' print ' Normal end of execution.' return
def catalan_row_next_test(): #*****************************************************************************80 # ## CATALAN_ROW_NEXT_TEST tests CATALAN_ROW_NEXT. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 08 May 2015 # # Author: # # John Burkardt # import numpy as np from i4vec_transpose_print import i4vec_transpose_print print '' print 'CATALAN_ROW_NEXT_TEST' print ' CATALAN_ROW_NEXT computes a row of Catalan\'s triangle.' print '' print ' First, compute row 7 from scratch.' ido = 0 i = 7 c = np.zeros(0) c = catalan_row_next(ido, i, c) i4vec_transpose_print(i + 1, c, ' Row 7:') print '' print ' Now compute rows one at a time:' print '' n = 10 ido = 0 c = np.zeros(0) for i in range(0, n + 1): c = catalan_row_next(ido, i, c) i4vec_transpose_print(i + 1, c, '') ido = 1 # # Terminate. # print '' print 'CATALAN_ROW_NEXT_TEST' print ' Normal end of execution.' return
def i4vec_descends_test ( ): #*****************************************************************************80 # ## I4VEC_DESCENDS_TEST tests I4VEC_DESCENDS. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 07 May 2015 # # Author: # # John Burkardt # import numpy as np from i4vec_transpose_print import i4vec_transpose_print n = 4 test_num = 6 x_test = np.array ( [ \ [ 1, 3, 2, 4 ], \ [ 2, 2, 2, 2 ], \ [ 1, 2, 2, 4 ], \ [ 1, 2, 3, 4 ], \ [ 4, 4, 3, 1 ], \ [ 9, 7, 3, 0 ] ] ) print '' print 'I4VEC_DESCENDS_TEST' print ' I4VEC_DESCENDS determines if an I4VEC descends.' for i in range ( 0, test_num ): x = np.zeros ( n ) for j in range ( 0, n ): x[j] = x_test[i,j] i4vec_transpose_print ( n, x, ' Test vector:' ) value = i4vec_descends ( n, x ) print ' I4VEC_DESCENDS = %s' % ( value ) # # Terminate. # print '' print 'I4VEC_DESCENDS_TEST' print ' Normal end of execution.' return
def catalan_row_next_test ( ): #*****************************************************************************80 # ## CATALAN_ROW_NEXT_TEST tests CATALAN_ROW_NEXT. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 08 May 2015 # # Author: # # John Burkardt # import numpy as np from i4vec_transpose_print import i4vec_transpose_print print '' print 'CATALAN_ROW_NEXT_TEST' print ' CATALAN_ROW_NEXT computes a row of Catalan\'s triangle.' print '' print ' First, compute row 7 from scratch.' ido = 0 i = 7 c = np.zeros ( 0 ) c = catalan_row_next ( ido, i, c ) i4vec_transpose_print ( i + 1, c, ' Row 7:' ) print '' print ' Now compute rows one at a time:' print '' n = 10 ido = 0 c = np.zeros ( 0 ) for i in range ( 0, n + 1 ): c = catalan_row_next ( ido, i, c ) i4vec_transpose_print ( i + 1, c, '' ) ido = 1 # # Terminate. # print '' print 'CATALAN_ROW_NEXT_TEST' print ' Normal end of execution.' return
def vec_lex_next_test(): #*****************************************************************************80 # ## VEC_LEX_NEXT_TEST tests VEC_LEX_NEXT. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 19 May 2015 # # Author: # # John Burkardt # import numpy as np from i4vec_transpose_print import i4vec_transpose_print print '' print 'VEC_LEX_NEXT_TEST' print ' VEC_LEX_NEXT generates all DIM_NUM-vectors' print ' in lex order in a given base BASE.' dim_num = 3 base = 3 a = np.zeros(dim_num) more = False print '' print ' The spatial dimension DIM_NUM = %d' % (dim_num) print ' The base BASE = %d' % (base) print '' while (True): a, more = vec_lex_next(dim_num, base, a, more) if (not more): break i4vec_transpose_print(dim_num, a, '') # # Terminate. # print '' print 'VEC_LEX_NEXT_TEST:' print ' Normal end of execution.' return
def comb_next_test ( ): #*****************************************************************************80 # ## COMB_NEXT_TEST tests COMB_NEXT. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 08 May 2015 # # Author: # # John Burkardt # import numpy as np from i4vec_transpose_print import i4vec_transpose_print n = 5 print '' print 'COMB_NEXT_TEST' print ' COMB_NEXT produces combinations.' print ' We are selecting from a set of size %d' % ( n ) for k in range ( 1, n + 1 ): print '' print ' Combinations of size %d:' % ( k ) print '' a = np.zeros ( k ) done = True while ( True ): a, done = comb_next ( n, k, a, done ) if ( done ): break i4vec_transpose_print ( k, a, '' ) # # Terminate. # print '' print 'COMB_NEXT_TEST' print ' Normal end of execution.' return
def vec_lex_next_test ( ): #*****************************************************************************80 # ## VEC_LEX_NEXT_TEST tests VEC_LEX_NEXT. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 19 May 2015 # # Author: # # John Burkardt # import numpy as np from i4vec_transpose_print import i4vec_transpose_print print '' print 'VEC_LEX_NEXT_TEST' print ' VEC_LEX_NEXT generates all DIM_NUM-vectors' print ' in lex order in a given base BASE.' dim_num = 3 base = 3 a = np.zeros ( dim_num ) more = False print '' print ' The spatial dimension DIM_NUM = %d' % ( dim_num ) print ' The base BASE = %d' % ( base ) print '' while ( True ): a, more = vec_lex_next ( dim_num, base, a, more ) if ( not more ): break i4vec_transpose_print ( dim_num, a, '' ) # # Terminate. # print '' print 'VEC_LEX_NEXT_TEST:' print ' Normal end of execution.' return
def thue_ternary_next_test(): #*****************************************************************************80 # ## THUE_TERNARY_NEXT_TEST tests THUE_TERNARY_NEXT. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 22 May 2015 # # Author: # # John Burkardt # import numpy as np from i4vec_transpose_print import i4vec_transpose_print print '' print 'THUE_TERNARY_NEXT_TEST' print ' THUE_TERNARY_NEXT returns the next' print ' Thue ternary sequence.' print '' thue = np.zeros(1) n = 1 thue[0] = 1 i4vec_transpose_print(n, thue, str(0)) for i in range(1, 6): [n, thue] = thue_ternary_next(n, thue) i4vec_transpose_print(n, thue, str(i)) # # Terminate. # print '' print 'THUE_TERNARY_NEXT_TEST:' print ' Normal end of execution.' return
def i4vec_sort_bubble_a_test ( ): #*****************************************************************************80 # ## I4VEC_SORT_BUBBLE_A_TEST tests I4VEC_SORT_BUBBLE_A. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 07 May 2015 # # Author: # # John Burkardt # from i4vec_transpose_print import i4vec_transpose_print from i4vec_uniform_ab import i4vec_uniform_ab print '' print 'I4VEC_SORT_BUBBLE_A_TEST' print ' I4VEC_SORT_BUBBLE_A ascending sorts an I4VEC.' n = 20 i4_lo = 0 i4_hi = 3 * n seed = 123456789 a, seed = i4vec_uniform_ab ( n, i4_lo, i4_hi, seed ) i4vec_transpose_print ( n, a, ' Unsorted:' ) a = i4vec_sort_bubble_a ( n, a ) i4vec_transpose_print ( n, a, ' Ascending sorted:' ) # # Terminate. # print '' print 'I4VEC_SORT_BUBBLE_A_TEST:' print ' Normal end of execution.' return
def i4vec_sort_bubble_a_test(): #*****************************************************************************80 # ## I4VEC_SORT_BUBBLE_A_TEST tests I4VEC_SORT_BUBBLE_A. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 07 May 2015 # # Author: # # John Burkardt # from i4vec_transpose_print import i4vec_transpose_print from i4vec_uniform_ab import i4vec_uniform_ab print '' print 'I4VEC_SORT_BUBBLE_A_TEST' print ' I4VEC_SORT_BUBBLE_A ascending sorts an I4VEC.' n = 20 i4_lo = 0 i4_hi = 3 * n seed = 123456789 a, seed = i4vec_uniform_ab(n, i4_lo, i4_hi, seed) i4vec_transpose_print(n, a, ' Unsorted:') a = i4vec_sort_bubble_a(n, a) i4vec_transpose_print(n, a, ' Ascending sorted:') # # Terminate. # print '' print 'I4VEC_SORT_BUBBLE_A_TEST:' print ' Normal end of execution.' return
def thue_ternary_next_test ( ): #*****************************************************************************80 # ## THUE_TERNARY_NEXT_TEST tests THUE_TERNARY_NEXT. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 22 May 2015 # # Author: # # John Burkardt # import numpy as np from i4vec_transpose_print import i4vec_transpose_print print '' print 'THUE_TERNARY_NEXT_TEST' print ' THUE_TERNARY_NEXT returns the next' print ' Thue ternary sequence.' print '' thue = np.zeros ( 1 ) n = 1 thue[0] = 1 i4vec_transpose_print ( n, thue, str ( 0 ) ) for i in range ( 1, 6 ): [ n, thue ] = thue_ternary_next ( n, thue ) i4vec_transpose_print ( n, thue, str ( i ) ) # # Terminate. # print '' print 'THUE_TERNARY_NEXT_TEST:' print ' Normal end of execution.' return
def perm0_check_test ( ): #*****************************************************************************80 # ## PERM0_CHECK_TEST tests PERM0_CHECK. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 24 May 2015 # # Author: # # John Burkardt # import numpy as np from i4vec_transpose_print import i4vec_transpose_print n = 5 p1 = np.array ( [ 5, 2, 3, 4, 1 ] ) p2 = np.array ( [ 4, 1, 3, 0, 2 ] ) p3 = np.array ( [ 0, 2, 1, 3, 2 ] ) print '' print 'PERM0_CHECK_TEST' print ' PERM0_CHECK checks a permutation of 0,...,N-1.' i4vec_transpose_print ( n, p1, ' Permutation 1:' ) check = perm0_check ( n, p1 ) i4vec_transpose_print ( n, p2, ' Permutation 2:' ) check = perm0_check ( n, p2 ) i4vec_transpose_print ( n, p3, ' Permutation 3:' ) check = perm0_check ( n, p3 ) # # Terminate. # print '' print 'PERM0_CHECK_TEST:' print ' Normal end of execution.' return
def vector_constrained_next3_test(): #*****************************************************************************80 # ## VECTOR_CONSTRAINED_NEXT3_TEST tests VECTOR_CONSTRAINED_NEXT3. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 31 May 2015 # # Author: # # John Burkardt # import numpy as np from i4vec_transpose_print import i4vec_transpose_print n_max = 3 print '' print 'VECTOR_CONSTRAINED_NEXT3_TEST' print ' VECTOR_CONSTRAINED_NEXT3:' print ' Consider vectors:' print ' X_MIN(1:N) <= X(1:N) <= X_MAX(1:N),' print ' Set' print ' CONSTRAINT = sum ( X(1:N) / X_MAX(1:N) )' print ' Accept only vectors for which:' print ' CONSTRAINT <= 1' x_min = np.array([1, 1, 1]) x_max = np.array([5, 6, 4]) for n in range(2, n_max + 1): more = False i4vec_transpose_print(n, x_min, ' XMIN:') i4vec_transpose_print(n, x_max, ' XMAX:') i = 0 x_prod = np.prod(x_max) print '' print ' Maximum allowed CONSTRAINT = P = %d' % (x_prod) print '' x = np.zeros(n) while (True): x, constraint, more = vector_constrained_next3 ( n, x_min, x_max, x, \ more ) if (not more): break i = i + 1 print ' %8d' % (i), for j in range(0, n): print ' %8d' % (x[j]), print ' %12g' % (constraint) # # Terminate. # print '' print 'VECTOR_CONSTRAINED_NEXT3_TEST' print ' Normal end of execution.' return
def monomial_value_test(): #*****************************************************************************80 # ## MONOMIAL_VALUE_TEST tests MONOMIAL_VALUE on sets of data in various dimensions. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 07 April 2015 # # Author: # # John Burkardt # from i4vec_transpose_print import i4vec_transpose_print from i4vec_uniform_ab import i4vec_uniform_ab from monomial_value import monomial_value from r8mat_nint import r8mat_nint from r8mat_uniform_ab import r8mat_uniform_ab print '' print 'MONOMIAL_VALUE_TEST' print ' Use monomial_value() to evaluate some monomials' print ' in dimensions 1 through 3.' e_min = -3 e_max = 6 n = 5 seed = 123456789 x_min = -2.0 x_max = +10.0 for m in range(1, 4): print '' print ' Spatial dimension M = %d' % (m) e, seed = i4vec_uniform_ab(m, e_min, e_max, seed) i4vec_transpose_print(m, e, ' Exponents:') x, seed = r8mat_uniform_ab(m, n, x_min, x_max, seed) # # To make checking easier, make the X values integers. # x = r8mat_nint(m, n, x) v = monomial_value(m, n, e, x) print '' print ' V(X) ', for i in range(0, m): print ' X(%d)' % (i), print '' print '' for j in range(0, n): print '%14.6g ' % (v[j]), for i in range(0, m): print '%10.4f' % (x[i, j]), print '' print '' print 'MONOMIAL_VALUE_TEST' print ' Normal end of execution.' return
def vector_constrained_next_test ( ): #*****************************************************************************80 # ## VECTOR_CONSTRAINED_NEXT_TEST tests VECTOR_CONSTRAINED_NEXT # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 29 May 2015 # # Author: # # John Burkardt # import numpy as np from i4vec_transpose_print import i4vec_transpose_print n = 3 print '' print 'VECTOR_CONSTRAINED_NEXT_TEST' print ' VECTOR_CONSTRAINED_NEXT:' print ' Consider vectors:' print ' X_MIN(1:N) <= X(1:N) <= X_MAX(1:N),' print ' Set' print ' P = Product X_MAX(1:N)' print ' Accept only vectors for which:' print ' sum ( (X(1:N)-1) * P / X_MAX(1:N) ) <= P' more = False x_min = np.array ( [ 2, 2, 1 ] ) x_max = np.array ( [ 4, 5, 3 ] ) i4vec_transpose_print ( n, x_min, ' XMIN:' ) i4vec_transpose_print ( n, x_max, ' XMAX:' ) i = 0 x_prod = np.prod ( x_max ) print '' print ' Maximum allowed CONSTRAINT = P = %d' % ( x_prod ) print '' x = np.zeros ( n ) while ( True ): x, constraint, more = vector_constrained_next ( n, x_min, x_max, x, more ) if ( not more ): break i = i + 1 print ' %8d: %8d %8d %8d %12d' % ( i, x[0], x[1], x[2], constraint ) # # Terminate. # print '' print 'VECTOR_CONSTRAINED_NEXT_TEST' print ' Normal end of execution.' return
def vector_constrained_next_test(): #*****************************************************************************80 # ## VECTOR_CONSTRAINED_NEXT_TEST tests VECTOR_CONSTRAINED_NEXT # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 29 May 2015 # # Author: # # John Burkardt # import numpy as np from i4vec_transpose_print import i4vec_transpose_print n = 3 print '' print 'VECTOR_CONSTRAINED_NEXT_TEST' print ' VECTOR_CONSTRAINED_NEXT:' print ' Consider vectors:' print ' X_MIN(1:N) <= X(1:N) <= X_MAX(1:N),' print ' Set' print ' P = Product X_MAX(1:N)' print ' Accept only vectors for which:' print ' sum ( (X(1:N)-1) * P / X_MAX(1:N) ) <= P' more = False x_min = np.array([2, 2, 1]) x_max = np.array([4, 5, 3]) i4vec_transpose_print(n, x_min, ' XMIN:') i4vec_transpose_print(n, x_max, ' XMAX:') i = 0 x_prod = np.prod(x_max) print '' print ' Maximum allowed CONSTRAINT = P = %d' % (x_prod) print '' x = np.zeros(n) while (True): x, constraint, more = vector_constrained_next(n, x_min, x_max, x, more) if (not more): break i = i + 1 print ' %8d: %8d %8d %8d %12d' % (i, x[0], x[1], x[2], constraint) # # Terminate. # print '' print 'VECTOR_CONSTRAINED_NEXT_TEST' print ' Normal end of execution.' return
def vector_constrained_next3_test ( ): #*****************************************************************************80 # ## VECTOR_CONSTRAINED_NEXT3_TEST tests VECTOR_CONSTRAINED_NEXT3. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 31 May 2015 # # Author: # # John Burkardt # import numpy as np from i4vec_transpose_print import i4vec_transpose_print n_max = 3 print '' print 'VECTOR_CONSTRAINED_NEXT3_TEST' print ' VECTOR_CONSTRAINED_NEXT3:' print ' Consider vectors:' print ' X_MIN(1:N) <= X(1:N) <= X_MAX(1:N),' print ' Set' print ' CONSTRAINT = sum ( X(1:N) / X_MAX(1:N) )' print ' Accept only vectors for which:' print ' CONSTRAINT <= 1' x_min = np.array ( [ 1, 1, 1 ] ) x_max = np.array ( [ 5, 6, 4 ] ) for n in range ( 2, n_max + 1 ): more = False i4vec_transpose_print ( n, x_min, ' XMIN:' ) i4vec_transpose_print ( n, x_max, ' XMAX:' ) i = 0 x_prod = np.prod ( x_max ) print '' print ' Maximum allowed CONSTRAINT = P = %d' % ( x_prod ) print '' x = np.zeros ( n ) while ( True ): x, constraint, more = vector_constrained_next3 ( n, x_min, x_max, x, \ more ) if ( not more ): break i = i + 1 print ' %8d' % ( i ), for j in range ( 0, n ): print ' %8d' % ( x[j] ), print ' %12g' % ( constraint ) # # Terminate. # print '' print 'VECTOR_CONSTRAINED_NEXT3_TEST' print ' Normal end of execution.' return
def monomial_value_test ( ): #*****************************************************************************80 # ## MONOMIAL_VALUE_TEST tests MONOMIAL_VALUE on sets of data in various dimensions. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 07 April 2015 # # Author: # # John Burkardt # from i4vec_transpose_print import i4vec_transpose_print from i4vec_uniform_ab import i4vec_uniform_ab from monomial_value import monomial_value from r8mat_nint import r8mat_nint from r8mat_uniform_ab import r8mat_uniform_ab print '' print 'MONOMIAL_VALUE_TEST' print ' Use monomial_value() to evaluate some monomials' print ' in dimensions 1 through 3.' e_min = -3 e_max = 6 n = 5 seed = 123456789 x_min = -2.0 x_max = +10.0 for m in range ( 1, 4 ): print '' print ' Spatial dimension M = %d' % ( m ) e, seed = i4vec_uniform_ab ( m, e_min, e_max, seed ) i4vec_transpose_print ( m, e, ' Exponents:' ) x, seed = r8mat_uniform_ab ( m, n, x_min, x_max, seed ) # # To make checking easier, make the X values integers. # x = r8mat_nint ( m, n, x ) v = monomial_value ( m, n, e, x ) print '' print ' V(X) ', for i in range ( 0, m ): print ' X(%d)' % ( i ), print '' print '' for j in range ( 0, n ): print '%14.6g ' % ( v[j] ), for i in range ( 0, m ): print '%10.4f' % ( x[i,j] ), print '' print '' print 'MONOMIAL_VALUE_TEST' print ' Normal end of execution.' return