def mono_rank_grlex_test ( ):

#******************************************************************************/
#
## MONO_RANK_GRLEX_TEST tests MONO_RANK_GRLEX.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    25 October 2014
#
#  Author:
#
#    John Burkardt
#
  from mono_upto_next_grlex import mono_upto_next_grlex
  import numpy as np

  m = 3
  test_num = 8
  x_test = np.array (  [ \
    0, 0, 0, \
    1, 0, 0, \
    0, 0, 1, \
    0, 2, 0, \
    1, 0, 2, \
    0, 3, 1, \
    3, 2, 1, \
    5, 2, 1 ], dtype = np.int32 )

  print ''
  print 'MONO_RANK_GRLEX_TEST'
  print '  MONO_RANK_GRLEX returns the rank of a monomial in the sequence'
  print '  of all monomials in M dimensions, in grlex order.'

  print ''
  print '  Print a monomial sequence with ranks assigned.'

  n = 4

  print ''
  print '  Let M = %d' % ( m )
  print '      N = %d' % ( n )
  print ''

  x = np.zeros ( m, dtype = np.int32 )

  x[0] = 0
  x[1] = 0
  x[2] = 0

  i = 1

  while ( True ):
    print '  %2d    ' % ( i ),
    for j in range ( 0, m ):
      print '%2d' % ( x[j] ),
    print ''

    if ( x[0] == n ):
      break

    mono_upto_next_grlex ( m, n, x )
    i = i + 1

  print ''
  print '  Now, given a monomial, retrieve its rank in the sequence:'
  print ''

  for test in range ( 0, test_num ):
    for j in range ( 0, m ):
      x[j] = x_test[j+test*m]
    rank = mono_rank_grlex ( m, x )

    print '  %3d    ' % ( rank ),
    for j in range ( 0, m ):
      print '%2d' % ( x[j] ),
    print ''

  print ''
  print 'MONO_RANK_GRLEX_TEST'
  print '  Normal end of execution.'

  return
def mono_unrank_grlex_test():

    #******************************************************************************/
    #
    ## MONO_UNRANK_GRLEX_TEST tests MONO_UNRANK_GRLEX.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    25 October 2014
    #
    #  Author:
    #
    #    John Burkardt
    #
    from i4_uniform_ab import i4_uniform_ab
    from mono_upto_enum import mono_upto_enum
    from mono_upto_next_grlex import mono_upto_next_grlex
    import numpy as np

    m = 3
    print ''
    print 'MONO_UNRANK_GRLEX'
    print '  MONO_UNRANK_GRLEX is given a rank, and returns the corresponding'
    print '  monomial in the sequence of all monomials in M dimensions'
    print '  in grlex order.'

    print ''
    print '  For reference, print a monomial sequence with ranks.'

    n = 4
    rank_max = mono_upto_enum(m, n)

    print ''
    print '  Let M = %d' % (m)
    print '      N = %d' % (n)
    print ''

    x = np.zeros(m, dtype=np.int32)

    i = 1

    while (True):
        print '  %2d    ' % (i),
        for j in range(0, m):
            print '%2d' % (x[j]),
        print ''

        if (x[0] == n):
            break

        mono_upto_next_grlex(m, n, x)
        i = i + 1

    print ''
    print '  Now choose random ranks between 1 and %d' % (rank_max)
    print ''

    seed = 123456789
    test_num = 5

    for test in range(0, test_num):
        rank, seed = i4_uniform_ab(1, rank_max, seed)
        x = mono_unrank_grlex(m, rank)
        print '  %2d    ' % (rank),
        for j in range(0, m):
            print '%2d' % (x[j]),
        print ''

    print ''
    print 'MONO_UNRANK_GRLEX_TEST'
    print '  Normal end of execution.'

    return
Example #3
0
def mono_rank_grlex_test():

    #******************************************************************************/
    #
    ## MONO_RANK_GRLEX_TEST tests MONO_RANK_GRLEX.
    #
    #  Licensing:
    #
    #    This code is distributed under the GNU LGPL license.
    #
    #  Modified:
    #
    #    25 October 2014
    #
    #  Author:
    #
    #    John Burkardt
    #
    from mono_upto_next_grlex import mono_upto_next_grlex
    import numpy as np

    m = 3
    test_num = 8
    x_test = np.array (  [ \
      0, 0, 0, \
      1, 0, 0, \
      0, 0, 1, \
      0, 2, 0, \
      1, 0, 2, \
      0, 3, 1, \
      3, 2, 1, \
      5, 2, 1 ], dtype = np.int32 )

    print ''
    print 'MONO_RANK_GRLEX_TEST'
    print '  MONO_RANK_GRLEX returns the rank of a monomial in the sequence'
    print '  of all monomials in M dimensions, in grlex order.'

    print ''
    print '  Print a monomial sequence with ranks assigned.'

    n = 4

    print ''
    print '  Let M = %d' % (m)
    print '      N = %d' % (n)
    print ''

    x = np.zeros(m, dtype=np.int32)

    x[0] = 0
    x[1] = 0
    x[2] = 0

    i = 1

    while (True):
        print '  %2d    ' % (i),
        for j in range(0, m):
            print '%2d' % (x[j]),
        print ''

        if (x[0] == n):
            break

        mono_upto_next_grlex(m, n, x)
        i = i + 1

    print ''
    print '  Now, given a monomial, retrieve its rank in the sequence:'
    print ''

    for test in range(0, test_num):
        for j in range(0, m):
            x[j] = x_test[j + test * m]
        rank = mono_rank_grlex(m, x)

        print '  %3d    ' % (rank),
        for j in range(0, m):
            print '%2d' % (x[j]),
        print ''

    print ''
    print 'MONO_RANK_GRLEX_TEST'
    print '  Normal end of execution.'

    return
def mono_unrank_grlex_test ( ):

#******************************************************************************/
#
## MONO_UNRANK_GRLEX_TEST tests MONO_UNRANK_GRLEX.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    25 October 2014
#
#  Author:
#
#    John Burkardt
#
  from i4_uniform_ab import i4_uniform_ab
  from mono_upto_enum import mono_upto_enum
  from mono_upto_next_grlex import mono_upto_next_grlex
  import numpy as np

  m = 3
  print ''
  print 'MONO_UNRANK_GRLEX'
  print '  MONO_UNRANK_GRLEX is given a rank, and returns the corresponding'
  print '  monomial in the sequence of all monomials in M dimensions'
  print '  in grlex order.'

  print ''
  print '  For reference, print a monomial sequence with ranks.'

  n = 4
  rank_max = mono_upto_enum ( m, n )

  print ''
  print '  Let M = %d' % ( m )
  print '      N = %d' % ( n )
  print ''

  x = np.zeros ( m, dtype = np.int32 )

  i = 1

  while ( True ):
    print '  %2d    ' % ( i ),
    for j in range ( 0, m ):
      print '%2d' % ( x[j] ),
    print ''

    if ( x[0] == n ):
      break

    mono_upto_next_grlex ( m, n, x )
    i = i + 1

  print ''
  print '  Now choose random ranks between 1 and %d' % ( rank_max )
  print ''

  seed = 123456789
  test_num = 5

  for test in range ( 0, test_num ):
    rank, seed = i4_uniform_ab ( 1, rank_max, seed )
    x = mono_unrank_grlex ( m, rank )
    print '  %2d    ' % ( rank ),
    for j in range ( 0, m ):
      print '%2d' % ( x[j] ),
    print ''

  print ''
  print 'MONO_UNRANK_GRLEX_TEST'
  print '  Normal end of execution.'

  return