source: git/Singular/LIB/factor.lib @ 3d124a7

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