#!/usr/bin/perl
#
# Usage: fn_det matrix size [offset [rootname]]
#
# Computes the determinant of a matrix written as a linear combination
# of __e[i,j] (the matrix with a 1 at line i, column j and 0 in all
# other positions). The offset indicates if lines/columns are numbered
# from 0 or 1 (or more); the default is offset=1. The rootname is __e
# by default.

if ($#ARGV < 1 || $#ARGV > 3)
	{ die "Usage: $0 matrix size [offset [rootname]]\n" }
$matrix = $ARGV[0];
$size = $ARGV[1];
if ($#ARGV >= 2) { $offset   = $ARGV[2] } else { $offset = 1 }
if ($#ARGV >= 3) { $rootname = $ARGV[3] } else { $rootname = "__e" }
$rootname =~ s/^\+//;

open(STDOUT, "|samuel -b");
$sep = "|";
print "E=$matrix;";
foreach $i ($offset .. $offset+$size-1) {
	print "\n";
	foreach $j ($offset .. $offset+$size-1) {
		print "$sep(?E:$rootname[$i,$j])";
		$sep = ","
	}
}
print "|;\n";
close STDOUT;	# Wait for samuel(1) to terminate
exit 0;
