logo

Given a function T : (n, k) → T(n, k)
Triangle := proc(T, len) local k, n;
seq(print(seq(T(n,k), k=0..n)), n = 0..len) end;

Note in particular that the offset is (0,0) for all triangles!

T formatted as a triangle:
T(0,0)  
T(1,0) T(1,1)  
T(2,0) T(2,1) T(2,2)  
T(3,0) T(3,1) T(3,2) T(3,3)  
T(4,0) T(4,1) T(4,2) T(4,3) T(4,4)  
T(5,0) T(5,1) T(5,2) T(5,3) T(5,4) T(5,5)  
T(6,0) T(6,1) T(6,2) T(6,3) T(6,4) T(6,5) T(6,6)

FlippedTriangle := proc(T, len) local k, n;
seq(print(seq(T(n,n-k), k=0..n)), n = 0..len) end;

T formatted as a flipped triangle:
T(0,0)  
T(1,1) T(1,0)  
T(2,2) T(2,1) T(2,0)  
T(3,3) T(3,2) T(3,1) T(3,0)  
T(4,4) T(4,3) T(4,2) T(4,1) T(4,0)  
T(5,5) T(5,4) T(5,3) T(5,2) T(5,1) T(5,0)  
T(6,6) T(6,5) T(6,4) T(6,3) T(6,2) T(6,1) T(6,0)

T formatted as a rectangle:
n \ k 0 1 2 3 4
0 T(0,0) T(1,0) T(2,0) T(3,0) T(4,0)
1 T(1,1) T(2,1) T(3,1) T(4,1) T(5,1)
2 T(2,2) T(3,2) T(4,2) T(5,2) T(6,2)
3 T(3,3) T(4,3) T(5,3) T(6,3) T(7,3)
4 T(4,4) T(5,4) T(6,4) T(7,4) T(8,4)

The definitions of the subsequences.

Row(T, m) → seq(T(k + m, m), k = 0 .. len),
starts at T(m,m) for some m.

Row(T, 0) → T(0, 0) T(1, 0) T(2, 0) T(3, 0) T(4, 0)
Row(T, 1) → T(1, 1) T(2, 1) T(3, 1) T(4, 1) T(5, 1)
Row(T, 2) → T(2, 2) T(3, 2) T(4, 2) T(5, 2) T(6, 2)
Row(T, 3) → T(3, 3) T(4, 3) T(5, 3) T(6, 3) T(7, 3)
Row(T, 4) → T(4, 4) T(5, 4) T(6, 4) T(7, 4) T(8, 4)

Col(T, m) → seq(T(k + m , k), k = 0 .. len),
starts at T(m,0) for some m.

Col(T, 0) → T(0, 0) T(1, 1) T(2, 2) T(3, 3) T(4, 4)
Col(T, 1) → T(1, 0) T(2, 1) T(3, 2) T(4, 3) T(5, 4)
Col(T, 2) → T(2, 0) T(3, 1) T(4, 2) T(5, 3) T(6, 4)
Col(T, 3) → T(3, 0) T(4, 1) T(5, 2) T(6, 3) T(7, 4)
Col(T, 4) → T(4, 0) T(5, 1) T(6, 2) T(7, 3) T(8, 4)

RowDiag(T, m) → seq(T(2*k + m, m + k), k = 0 .. len),
starts at T(m,m) for some m.

RowDiag(T, 0) → T(0, 0) T(2, 1) T(4, 2) T(6, 3) T(8, 4)
RowDiag(T, 1) → T(1, 1) T(3, 2) T(5, 3) T(7, 4) T(9, 5)
RowDiag(T, 2) → T(2, 2) T(4, 3) T(6, 4) T(8, 5) T(10, 6)
RowDiag(T, 3) → T(3, 3) T(5, 4) T(7, 5) T(9, 6) T(11, 7)
RowDiag(T, 4) → T(4, 4) T(6, 5) T(8, 6) T(10,7) T(12, 8)

ColDiag(T, m), → seq(T(2*k + m, k), k = 0 .. len),
starts at T(m,0) for some m.

ColDiag(T, 0) → T(0, 0) T(2, 1) T(4, 2) T(6, 3) T(8, 4)
ColDiag(T, 1) → T(1, 0) T(3, 1) T(5, 2) T(7, 3) T(9, 4)
ColDiag(T, 2) → T(2, 0) T(4, 1) T(6, 2) T(8, 3) T(10, 4)
ColDiag(T, 3) → T(3, 0) T(5, 1) T(7, 2) T(9, 3) T(11, 4)
ColDiag(T, 4) → T(4, 0) T(6, 1) T(8, 2) T(10,3) T(12, 4)

The definitions of some characteristics.

Note that we take the absolute values of the members of the triangle.

SUM(T, n) → add(abs(T(n, k)),k=0..n);
ALS(T, n) → abs(add((-1)^k*abs(T(n, k)),k=0..n));

Calculating the lcm and the gcd of the rows of the triangle we want to exclude 0 and 1 most of the time. Therefore we use the following algorithm.

  • Z = Z setminus {-1,0,1}.
  • If Z = {} (empty set) then Z = {1}.
  • Now compute lcm Z and gcd Z as usual.

In some cases other algorithms might be better suited.

LCMGCD := proc(T, len, U) local n,k,L,S,R,Z,C;
  S:= []; 
  for n from 0 to len do
     Z := {seq(T(n,k),k=0..n)};
     Z := Z minus {-1,0,1};
     if Z = {} then Z := {1} fi;
     L := `if`(U=0,ilcm(op(Z)),igcd(op(Z)));
     S := [op(S), L];
  od; S end:

LCM := (T,len) -> LCMGCD(T,len,0):
GCD := (T,len) -> LCMGCD(T,len,1):