source: git/Singular/LIB/redfac.lib @ 6f2edc

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