[seqfan] Re: More rows of triangle in A271100?

Marc LeBrun mlb at well.com
Sat May 7 18:34:59 CEST 2016


>="Felix Fröhlich" <felix.froe at gmail.com>
> One problem is that the code for the function for each
n gets longer and
> longer for increasing n. [...]
> Is there an easy way to compute further rows of the triangle
> without the
need to write a custom function for each n?

Felix, I'm not able to delve into the problem specifics, so my apologies if
this suggestion basic programming is off the mark, but:

Do you really need to have increasingly long expressions?  Or might you
instead use associativity and write a loop (or recursion)?

For example just as an expression like
  T = X1 + X2 + X3 + ...
can be "unrolled" into a sequence of steps
  T = 0
  T = T + X1
  T = T + X2
  T = T + X3
  ...
that can then be "rolled" up as a program loop like
  T = 0
  for n from 1 to ...
    T = T + Xn
  return T
so can logical expressions be computed, just by replacing + with AND or OR.

By nesting loops you can likewise accumulate or reduce subsub expressions
into sub expressions and so forth:
  for row = 1 to num_rows
    O = FALSE
    for or_index = 1 to num_ors_for_row(row)
      A = TRUE
      for and_index = 1 to num_ands_for_row(row)
        A = A AND subsubexpression(or_index, and_index)
      O = O OR A
  return O

Does this help?





More information about the SeqFan mailing list