1 | // $Id: redfac.lib,v 1.2 1997-04-28 19:27:24 obachman Exp $ |
---|
2 | //(RS) |
---|
3 | /////////////////////////////////////////////////////////////////////////////// |
---|
4 | |
---|
5 | LIBRARY: 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 | |
---|
12 | proc replace_dollar ( string s ) |
---|
13 | USAGE: replace_dollar(s); s = string |
---|
14 | RETURN: string, with '$' replaced by ' ' |
---|
15 | EXAMPLE: 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 | } |
---|
27 | example |
---|
28 | { "EXAMPLE:"; echo = 2; |
---|
29 | string s = "123$456$"; |
---|
30 | replace_dollar( s ); |
---|
31 | replace_dollar( s )+"789"; |
---|
32 | } |
---|
33 | |
---|
34 | proc factor ( poly f ) |
---|
35 | USAGE: factor(f); f = poly |
---|
36 | RETURN: list, the factors of f |
---|
37 | NOTE: due to a limitation of reduce, multivariate polynomials can only |
---|
38 | be factorized in characteristic 0 |
---|
39 | This proc runs under UNIX only |
---|
40 | EXAMPLE: 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 | } |
---|
76 | example |
---|
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 | } |
---|