stdtoPARI.txt
Perl script to convert from std format to PARI format
For information about the data base of lattices, see:
Index File and
Abbreviations.
We suggest that you:
o download this file
o copy it to a new file called stdtoPARI.perl,
o delete everything up to and including the line "cut 1 here",
o delete the line "cut 2 here" and everything after it,
o then make the file executable.
o To use it, type (for example) stdtoPARI.perl E8.std >out
then read "out" into gp.
------- cut 1 here -------
#!/usr/bin/perl
# stdtoPARI.perl Perl script to make PARI readable
# version of gram matrix from standard library file
# Last modified Feb 32 1997
if ( $#ARGV != 0 )
{ die "Useage: stdtoPARI.perl file.std >out then start gp, then
type \\r out " }
# check file name ends in .std
if ( ! $ARGV[0] =~ /\.std$/) { die "filename doesn't end with .std! "}
# check if file exists
if ( ! -f $ARGV[0] ) { die "$ARGV[0] does not exist! " }
# open lattice file ($1)
open(LATTICE,$ARGV[0]);
# states: 0 = neutral, 1 means have just read "^%GRAM",
# 2 means reading Gram matrix
$state = "0";
# set up empty list to hold Gram matrix
@gramlist = ();
# read all input lines
while () {
chop; # delete newline at end
$_ =~ s/^ *//; # delete leading blanks
@line = split; # break up into a list
if ( $#line < 0 ) {next } # skip if empty line
if ($line[0] =~ /^%/) { $state = "0" } #reset state to 0 if find %
if ($line[0] =~ /^%GRAM$/) { # look for line beginning %GRAM
$state = "1"; # sets state to 1, getting ready
# for reading dimensions on next line
next; }
if ($state =~ "1") { $d1 = $line[0]; # state = 1,
# so read dimensions of array
$d2 = $line[1];
$state = "2"; # and set state to 2
next;
}
if ($state =~ "2" && $line[0] !~ /^%/) { # reading Gram matrix
$t1 = $#line; # get no of entries on the current line
# add then to gram matrix
push( @gramlist, @line) }
}
# print in PARI format, calling the gram matrix "m"
# print LHS
print("m=[\\\n");
### case 1, Gram matrix given in square form:
if ( $d1 == $d2 ) # square Gram matrix
{ # start bracket 1
$at = 0;
# print row i (but not the last one)
for ($i = 0; $i < $d1 - 1; $i = $i + 1) {
# print element j (but not the last one)
for ($j = 0; $j < $d1 - 1; $j = $j + 1) {
print($gramlist[$at],",\\\n");
$at = $at + 1; };
# print last elt in row
print($gramlist[$at],";\\\n");
$at = $at + 1;
}
# print last row
$i = $d1 - 1;
# print element j (but not the last one)
for ($j = 0; $j < $d1 - 1; $j = $j + 1) {
print($gramlist[$at],",\\\n");
$at = $at + 1; };
# print last elt in row
print($gramlist[$at],"];\n");
} # end bracket 1
else
### case 2 , Gram matrix given in triangular form
{ # start bracket 2
# print row i
for ($i = 0; $i < $d1 ; $i = $i + 1) {
# print column j
# print elements j = 0 .. i
for ($j = 0; $j <= $i ; $j = $j + 1) {
$at = $i * ($i + 1)/2 + $j;
print($gramlist[$at],"\\\n");
# follow it by a comma unless at end of line
# if at end of row, print ";" or "];"
if ($j < $d1 - 1 ) {print(",\\\n"); } elsif ($i < $d1 - 1) {print(";\\\n");}
else {print("];\n");}
};
# print elements j = i+1 .. $d1-1
for ($j = $i + 1; $j < $d1 ; $j = $j + 1) {
$at = $j * ($j + 1)/2 + $i;
print($gramlist[$at],"\\\n");
# follow it by a comma unless at end of line
# if at end of row, print ";" or "];"
if ($j < $d1 - 1 ) {print(",\\\n"); } elsif ($i < $d1 - 1) {print(";\\\n");}
else {print("];\n");}
};
};
} # end bracket 2
# produce print statements for PARI to say what to do next
# template is:
# print("pprint(\"\\\\hi\")\n");
print("pprint(\"\\\\Now do:\")\n");
print("pprint(\"\\\\d=det2(m) to get det\")\n");
---------- cut 2 here -------