source: git/Singular/LIB/factor.lib @ 5480da

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