source: git/Singular/LIB/factor.lib @ de9f10

spielwiese
Last change on this file since de9f10 was 82716e, checked in by Hans Schönemann <hannes@…>, 26 years ago
*hannes: typos in the info-help-string git-svn-id: file:///usr/local/Singular/svn/trunk@1773 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 2.7 KB
Line 
1// $Id: factor.lib,v 1.6 1998-05-14 18:44:59 Singular Exp $
2//(RS)
3///////////////////////////////////////////////////////////////////////////////
4
5version="$Id: factor.lib,v 1.6 1998-05-14 18:44:59 Singular Exp $";
6info="
7LIBRARY:  factor.lib    PROCEDURES FOR CALLING THE REDUCE FACTORIZER
8
9 delete_dollar(s)       return the string s with '$' deleted
10 reduce_factor(f)       list of factors of f, calling REDUCE (UNIX only)
11";
12
13///////////////////////////////////////////////////////////////////////////////
14
15proc delete_dollar ( string s )
16"USAGE:   delete_dollar(s);  s = string
17RETURN:  string, with '$' replaced by ' '
18EXAMPLE: example delete_dollar; shows an example
19"
20{
21   while( s[size(s)]=="$" and size(s)!=1 ) { s=s[1,size(s)-1]; }
22   while( s[1]=="$" and size(s)!=1 )       { s=s[2,size(s)-1]; }
23   if( size(s)==1 and s[1]=="$" )          { return(""); }
24   int i=find(s,"$");
25   while( i!=0 )
26   {
27     s=s[1,i-1]+s[i+1,size(s)-i];
28     i=find(s,"$");
29   }
30   return(s);
31}
32example
33{ "EXAMPLE:"; echo = 2;
34  string s = "123$456$";
35  delete_dollar(s);
36  delete_dollar(s)+"789";
37}
38///////////////////////////////////////////////////////////////////////////////
39
40proc reduce_factor ( poly f )
41"USAGE:   reduce_factor(f);  f = poly
42RETURN:  list, the factors of f
43NOTE:    due to a limitation of REDUCE, multivariate polynomials can only
44         be factorized in characteristic 0
45         This proc runs under UNIX only
46EXAMPLE: example reduce_factor; shows an example
47"
48{
49  string pid = string( system( "pid" ) );
50  string outname = "/tmp/singred." + pid + ".out";
51  string scriptname = "/tmp/singred." + pid + ".sh";
52  int n = char( basering );
53  int shortOutput = short;
54  short = 0;
55  write (scriptname,"#!/bin/sh
56                    $reduce/reduce >/dev/null <<EOF
57                    off nat$ off echo$ setmod " + string( n ) + "$
58                    erg:=factorize(",f,")$
59                    out \"" + outname + "\"$
60                    write(\"list result;\")$
61                    counter:=1$
62                    for each a in erg do begin
63                        write(\"result[\",counter,\"]=\",a,\";\");
64                        counter:=counter+1;
65                    end;
66                    shut \"" + outname + "\";
67                    quit$
68               EOF");
69  system( "sh", "chmod 700 " + scriptname );
70  system( "sh", scriptname );
71  string resultstring = read( outname );
72  if ( resultstring <> "" )
73  {
74    resultstring = delete_dollar( resultstring );
75    execute resultstring;
76  }
77  // remove tmp-files after usage */
78  system( "sh", "/bin/rm " + outname );
79  system( "sh", "/bin/rm " + scriptname );
80  short = shortOutput;
81  return( result );
82}
83example
84{ "EXAMPLE:"; echo = 2;
85  ring r=0,(x,y,z),lp;
86  poly f=(x+y)*(y+z)^2*(z+x);
87  f;
88  list L=reduce_factor(f);
89  L;
90}
Note: See TracBrowser for help on using the repository browser.