# This Perl script runs in Windows OS, Unix, and OS X, though one may # need to edit $mylisp, the command used to launch the Lisp interpreter. # This version will create temporary files. # This version expects INPUTFILE OUTPUTAPPENDFILE # INPUTFILE format must be gensym[idnum] = {genus, genus-symbol-compact} # separated by blank lines # ########################################################################### # $mylisp is the name of the command used to launch the Common Lisp interpreter; # change as needed. Specify the full path here if the interpreter is not # in the path environment variable. If any flags are needed, e.g. for command # "/path/to/lisp -M /path/to/lispinit.mem", include these in $mylisp $mylisp = "clisp"; if((scalar @ARGV)<2){ print "Usage: perl makeFpPolys.pl inputfile outputAppendFile\n"; print "format must be gensym[idnum] = {dimension, list of nontrivial constituents}\nwith separating blank lines.\n"; exit; } $file = $ARGV[0]; $outfile="$file.in.tmp"; $mafile= $ARGV[1]; $maxcounter=-1; #set to -1 to get out of test mode. $message=""; if($maxcounter>0){$message="RUNNING IN TEST MODE with maxcounter=$maxcounter"}; print qq^This program uses input file: $file output file: $outfile $message ^; # Uncomment the following for more interactivity. # print "Enter Y if OK, or enter A to abort: "; #$ans=<>; #if($ans!~/y/i){ # print "Aborted. HIT ENTER to finish.\n"; # <>; #exit; #} if(!open(FIN, "<$file")) { print "FILE $file OPEN FAILURE\n"; # print "HIT ENTER TO FINISH\n"; # <>; exit; } if(!open(FOUT, ">$outfile")) { print "FILE $outfile WRITE FAILURE\n"; # print "HIT ENTER TO FINISH\n"; # <>; exit; } print FOUT qq^;;; This Lisp program uses functions in katsurada.cl ;;; to compute Fp polynomials. ;;; The output file will have format ;;; gensym[actual genus symbol] ;;; prime \#(c0 c1 c2 ...) ;;; prime \#(c0 c1 c2 ...) ;;; which will require postprocessing (load 'katsurada) ; omit cl extension so compiled version is used, if present ^; $counter = 0; $break=0; while(!$break){ $line=""; $okgenusDetected=0; $continue=1; while($continue){ $in=; if($in eq ""){$continue=0;$break=1;} chomp $in; if($in=~/gensym/){$okgenusDetected=1;} $line .= $in; if($okgenusDetected && ($in!~/\S/)){$continue=0;} } #print "$line\n"; if($line=~/gensym/){ if($line =~ /gensym\[(.*?)\]\s*=\s*\{(\d+)\s*,\s*(.*)\}\s*$/){ ($gid,$genus,$rest)=($1,$2,$3); $gs="{$genus,$rest}"; print FOUT qq^(list "gensym [$gs]")\n^; $rest=~s/\{/\(/g; $rest=~s/\}/\)/g; $rest=~s/,/ /g; print FOUT qq^(fppolys \#(2 $genus 0 $rest) t)\n(list "endgenus")\n^; }else{ print "ERROR parsing line $line\n"; print "Aborted. HIT ENTER to finish.\n"; #<>; exit; } } $counter++; if(($maxcounter>0)&&($counter>=$maxcounter)){$break=1;} } close(FOUT); close(FIN); $lispoutput = "$file.out.tmp"; print qq^==== Creation of LISP input file done ==== This program will run LISP on the file $outfile with output file $lispoutput. ^; #print "Enter Y if OK, or enter A to skip this step: "; #$ans=<>; #if($ans!~/y/i){ # print "Aborted. HIT ENTER to finish.\n"; # <>; #exit; #} print "Running lisp program.\n"; ################################# LISP SYSTEM CALL ######################### ## The following system call supposes that the lisp interpreter called $mylisp ## (defined at the top of this file) is in the path, or specifies the full path. ## It also supposes that the user has write permissions for the current directory. system(qq^$mylisp -q < $outfile > $lispoutput^); print "Done running lisp program.\n"; $file = $lispoutput; ##$outfile = $mafile; print qq^We now convert the output to Mathematica format and append results. lisp output file: $file to Mathematica file: $mafile ^; #print "Enter Y if OK, or enter A to abort: "; #$ans=<>; #if($ans!~/y/i){ # print "Aborted. HIT ENTER to finish.\n"; # <>; #exit; #} if(!open(FIN, "<$file")) { print "FILE $file OPEN FAILURE\n"; print "HIT ENTER TO FINISH\n"; # <>; exit; } if(!open(FOUT, ">>$mafile")) { print "FILE $mafile WRITE FAILURE\n"; print "HIT ENTER TO FINISH\n"; # <>; exit; } $break=0; $begin=1; ####print FOUT "kingList={"; while(!$break){ $line=""; $okgenusDetected=0; $continue=1; while($continue){ $in=; if($in eq ""){$continue=0;$break=1;} chomp $in; if($in=~/gensym/){$okgenusDetected=1;} $line .= $in; if($okgenusDetected && ($in=~/endgenus/)){$continue=0;} } #print "$line\n"; if($line=~/gensym/){ if($line =~ /gensym\s*\[(.*?)\]\"\)\s*(.*)\(\"endgenus\"\)\s*$/){ ($gid,$rest)=($1,$2); # print "$gid $rest\n"; if($rest=~/incom/){print "WARNING/ERROR: Incompatible numbers in\n", "$gid $rest\n"; } @xxx = $rest=~/(\d+\s*\#\([\d\-\ ]*\))/g; @poly=(); foreach $x (@xxx){ $x =~ /(\d+)\s*\#(.*)/; ($pr, $coef)=($1,$2); @yyy = $coef=~/(\-?\d+)/g; push @poly, "{".$pr.",".coefToPoly(@yyy)."}"; } #####if($begin){print FOUT "\n";$begin=0;}else{print FOUT ",\n";} #####print FOUT "{".$gid.",{".join(",",@poly)."}}"; print FOUT "FpData[".$gid."]={".join(",",@poly)."};\n"; }else{ print "ERROR parsing line $line\n"; print "Aborted. HIT ENTER to finish.\n"; <>; exit; } } } ###print FOUT "\n};\n"; close(FOUT); close(FIN); ## delete temporary files; comment out next two lines to keep them, for debugging unlink $outfile; unlink $lispoutput; #print "HIT ENTER TO FINISH\n"; #<>; sub coefToPoly{ my @x = @_; my $ans=$x[0]; my $n=0; my $c; for($n=1;$n<=$#x;$n++){ $c = $x[$n]; if($c ne "0"){$ans .= "+$c*x^$n";} } return $ans; }