This is a companion to the Beauregard and Suryanarayan treatment of Pythagorean Triples in The College Mathematics Journal:
  ```Beauregard, R.A., and E.R. Suryanarayan, Pythagorean```
  ```Triples: the Hyperbolic View```
  ```The College Mathematics Journal, Vol 27, No. 3, May 1996```
A vector such as 3 4 5, whose last element is the hypotenuse of the right-triangle with a pair specified by the first two, is called a pythagorean triple (PT) if the hypotenuse is an integer. We may define and use a hypotenuse function c as follows:
In [ ]:
    
c=: %: @: (+/) @: *:
    
In [ ]:
    
c 3 4
    
In [ ]:
    
c 5 12
    
In [ ]:
    
pt=: ],c  NB. Pythagorean triple
    
In [ ]:
    
pt 3 4
    
In [ ]:
    
on=: @:
    
In [ ]:
    
c=: sqrt on sum on sqr
    
In [ ]:
    
pt=: (right,c) "1
    
In [ ]:
    
sqrt=: %:
    
In [ ]:
    
sqr=: *:
    
In [ ]:
    
sum=: +/
    
In [ ]:
    
l=:  left=: [
    
In [ ]:
    
r=: right=: ]
    
In [ ]:
    
a=: first=: {.
    
In [ ]:
    
b=:  last=: {:
    
In [ ]:
    
v=: 3 4
    
In [ ]:
    
c v
    
In [ ]:
    
pt v
    
In the section of this title, B&S, i.e. Beauregard and Suryanarayan, define a function of two arguments that they denote by *. Applied to the pairs of two PTs it can be shown to produce the pair of a new PT. We will denote the function by p, and define it as specified in B&S:
In [ ]:
    
p=:(a on l*a on r) , (b on l*c on r)+(b on r*c on l)
    
In [ ]:
    
3 4 p  3 4
    
In [ ]:
    
pt 3 4 p 3 4
    
In [ ]:
    
3 4 p 5 12
    
In [ ]:
    
pt 3 4 p 5 12
    
In [ ]:
    
3 4 p 3 4 p 3 4
    
In [ ]:
    
pt 3 4 p 3 4 p 3 4
    
In [ ]:
    
M=: _3&(]\)@(c,b,0:,b,c,0:,0:,0:,a)
    
In [ ]:
    
F=: _1 1&{@,
    
In [ ]:
    
m=: M 3 4
    
In [ ]:
    
m
    
In [ ]:
    
F m
    
In [ ]:
    
X=: +/ . *  NB. Matrix product
    
In [ ]:
    
m X m
    
In [ ]:
    
F m X m
    
In [ ]:
    
pt F m X m
    
In [ ]:
    
qi=: 1 _1&*
    
In [ ]:
    
A=: 4 3
    
In [ ]:
    
B=: 3 4
    
In [ ]:
    
qi A p B
    
In [ ]:
    
(qi A) p (qi B)
    
In [ ]:
    
qi qi A
    
In [ ]:
    
A
    
In [ ]:
    
A p qi A
    
In [ ]:
    
a A
    
In [ ]:
    
(*: a A), 0
    
In [ ]:
    
E=: 1 0  NB. The identity of p
    
In [ ]:
    
E p A
    
In [ ]:
    
A p E
    
In [ ]:
    
D=: 5 0
    
In [ ]:
    
D p D
    
In [ ]:
    
(*:@a D) * E
    
An integer scalar multiple of a pair is itself a pair, and to provide a single representative of the entire class a primitive pair is defined as one whose elements are "in lowest terms", and contain no common factors. We also define a normalization function N that produces the primitive representative of any pair:
In [ ]:
    
D=: 3 * A
    
In [ ]:
    
D
    
In [ ]:
    
pt D
    
In [ ]:
    
+./D  NB. The GCD of the elements of D
    
In [ ]:
    
D % +./D
    
In [ ]:
    
N=: ] % +./
    
In [ ]:
    
N D
    
In [ ]:
    
mn=: N@(a , b + c)
    
In [ ]:
    
ab=: N on (*/ , half on diff on flip on sqr)
    
In [ ]:
    
half=: -:
    
In [ ]:
    
diff=: -/
    
In [ ]:
    
flip=: |.
    
In [ ]:
    
v=: 5 12
    
In [ ]:
    
w=: flip v
    
In [ ]:
    
w
    
In [ ]:
    
mn v
    
In [ ]:
    
ab mn v
    
In [ ]:
    
mn w
    
In [ ]:
    
ab mn w
    
In [ ]:
    
x=: v p w
    
In [ ]:
    
x
    
In [ ]:
    
pt x
    
In [ ]:
    
mn x
    
In [ ]:
    
ab mn x
    
Note that the two case of Proposition 2 (for even and odd) are combined in mn by the use of normalization.
An integer scalar multiple of a pair is itself a pair, and to provide a single representative of the entire class a primitive pair is defined as one whose elements are "in lowest terms", and contain no common factors. We also define a normalization function N that produces the primitive representative of any pair:
In [ ]:
    
D=: 3 * A
    
In [ ]:
    
D
    
In [ ]:
    
pt D
    
In [ ]:
    
+./D  NB. The GCD of the elements of D
    
In [ ]:
    
D % +./D
    
In [ ]:
    
N=: ] % +./
    
In [ ]:
    
N D
    
In [ ]:
    
on=: @:
    
In [ ]:
    
c=: sqrt on sum on sqr
    
In [ ]:
    
pt=: (right,c) "1
    
In [ ]:
    
sqrt=: %:
    
In [ ]:
    
sqr=: *:
    
In [ ]:
    
sum=: +/
    
In [ ]:
    
l=:  left=: [
    
In [ ]:
    
r=: right=: ]
    
In [ ]:
    
a=: first=: {.
    
In [ ]:
    
b=:  last=: {:
    
In [ ]:
    
p=: (a on l*a on r) , (b on l*c on r)+(b on r*c on l)
    
In [ ]:
    
M=: _3&(]\)@(c,b,0:,b,c,0:,0:,0:,a)
    
In [ ]:
    
F=: _1 1&{@,
    
In [ ]:
    
X=: +/ . *  NB. Matrix product
    
In [ ]:
    
qi=: 1 _1&*
    
In [ ]:
    
E=: 1 0  NB. The identity of p
    
In [ ]:
    
N=: ] % +./
    
In [ ]:
    
mn=: N@(a , b + c)
    
In [ ]:
    
ab=: N on (*/ , half on diff on flip on sqr)
    
In [ ]:
    
half=: -:
    
In [ ]:
    
diff=: -/
    
In [ ]:
    
flip=: |.
    
In [ ]:
    
] T=: 3 4,:4 3      NB. Table of basis elements
    
In [ ]:
    
T p"1/ T            NB. Table of p applied between each pair
    
In [ ]:
    
,/ T p"1/ T         NB. Table "ravelled" to a list of pairs
    
In [ ]:
    
N"1 ,/ T p"1/ T     NB. Normalized table
    
In [ ]:
    
~. N"1 ,/ T p"1/ T  NB. Nub (~.) suppresses duplicate items
    
In [ ]:
    
pt"1~. N"1 ,/ T p"1/ T
    
In [ ]:
    
g=: ~. on (,/ on (N"1 on (p"1/~))) NB. Generating function
    
In [ ]:
    
g T                    NB. Compare with earlier result
    
In [ ]:
    
sort=: /:~             NB. Define sort function
    
In [ ]:
    
sort g T               NB. Sort result
    
In [ ]:
    
] T1=: 1 0,T
    
In [ ]:
    
/:~ g T1
    
In [ ]:
    
]T2=: T1, qi"1 T  NB. Append quasi-inverses
    
In [ ]:
    
/:~ g T2
    
In [ ]:
    
/:~ g^:2 T2
    
In [ ]:
    
/:~ g^:3 T2
    
In [ ]:
    
x: T2
    
In [ ]:
    
/:~ pt"1 g^:3 x: T2
    
In [ ]:
    
tri=: pt sort ~. sort"1 | g^:3 x: T2
    
In [ ]:
    
tri
    
In [ ]:
    
<@q: }. tri
    
In [ ]: