source: git/Singular/LIB/factor.lib @ 90df7c

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