# Black box algorithm to find standard generators of S4(17)

	set F 0
	set G 0
	set V 0
lbl SEMISTD
	rand 1
	ord 1 A
	incr V
	if V gt 1000 then timeout
	if A notin 1 2 3 4 5 6 8 9 12 16 17 18 24 29 34 36 48 51 &
			68 72 102 136 144 145 153 272 306 then fail
	if F eq 0 then
		if A in 4 6 8 12 16 18 24 34 36 48 68 72 102 136 &
				144 272 306 then
			div A 2 B
			pwr B 1 2
			rand 3
			com 2 3 4
			ord 4 C
			if C gt 17 then set F 1
		endif
	endif
	if G eq 0 then
		if A eq 144 then
			pwr 24 1 5
			mu 5 5 6          # Hopefully a 3B element
			mu 5 6 7          # Hopefully a 2A element
			call 2A2BTEST
			if R eq 1 then set G 1
		endif
	endif

	if F eq 0 then jmp SEMISTD
	if G eq 0 then jmp SEMISTD


	# At this stage, we have:
	# g2 - a 2B element
	# g6 - an element of order 3, probably a 3B element
	# g7 - an element of order 2 (2A if and only if g6 is 3B)
	#
	# We now conjugate g6 until g2, g6 are standard generators.
	# If it seems to be taking too long, we re-check that
	# g7 is 2A again.

	set X 0
	set Y 0
lbl CONJUGATE
	incr X
	if X gt 5000 then timeout
	rand 8
	cjr 6 8
	mu 2 6 9
	ord 9 D

	if D noteq 145 then jmp CONJUGATE

	mu 9 6 10
	mu 9 10 11

	ord 11 E
	incr Y
	if E noteq 5 then
		if Y gt 100 then
			set Y 0
			call 2A2BTEST
			if R eq 0 then
				set G 0
				jmp SEMISTD
			endif
		endif
		jmp CONJUGATE
	endif

	oup 2 2 6

#######################################################################
# A subroutine to test whether the element g7 is a 2A element.
# R = 1 means the element is probably 2A
# R = 0 means the element is definitely 2B
# (N.B. This is a one-sided test.)
lbl 2A2BTEST
	set R 0		
	set T 0
lbl BEGIN2A2BTEST
	rand 3
	com 7 3 4
	ord 4 S
	if S gt 17 then return   # It's a 2B element
	incr T
	if T lt 3 then jmp BEGIN2A2BTEST
	set R 1                  # It's (probably) a 2A element
	return
