[034ce1] | 1 | // $Id: factor.lib,v 1.7 2000-05-12 12:25:43 Singular Exp $ |
---|
[3d124a7] | 2 | //(RS) |
---|
| 3 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 4 | |
---|
[034ce1] | 5 | version="$Id: factor.lib,v 1.7 2000-05-12 12:25:43 Singular Exp $"; |
---|
[5480da] | 6 | info=" |
---|
[d6db1f2] | 7 | LIBRARY: factor.lib PROCEDURES FOR CALLING THE REDUCE FACTORIZER |
---|
[3d124a7] | 8 | |
---|
| 9 | delete_dollar(s) return the string s with '$' deleted |
---|
| 10 | reduce_factor(f) list of factors of f, calling REDUCE (UNIX only) |
---|
[5480da] | 11 | "; |
---|
[3d124a7] | 12 | |
---|
| 13 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 14 | |
---|
| 15 | proc delete_dollar ( string s ) |
---|
[d2b2a7] | 16 | "USAGE: delete_dollar(s); s = string |
---|
[3d124a7] | 17 | RETURN: string, with '$' replaced by ' ' |
---|
[82716e] | 18 | EXAMPLE: example delete_dollar; shows an example |
---|
[d2b2a7] | 19 | " |
---|
[3d124a7] | 20 | { |
---|
| 21 | while( s[size(s)]=="$" and size(s)!=1 ) { s=s[1,size(s)-1]; } |
---|
| 22 | while( s[1]=="$" and size(s)!=1 ) { s=s[2,size(s)-1]; } |
---|
| 23 | if( size(s)==1 and s[1]=="$" ) { return(""); } |
---|
| 24 | int i=find(s,"$"); |
---|
| 25 | while( i!=0 ) |
---|
| 26 | { |
---|
| 27 | s=s[1,i-1]+s[i+1,size(s)-i]; |
---|
| 28 | i=find(s,"$"); |
---|
| 29 | } |
---|
| 30 | return(s); |
---|
| 31 | } |
---|
| 32 | example |
---|
| 33 | { "EXAMPLE:"; echo = 2; |
---|
| 34 | string s = "123$456$"; |
---|
| 35 | delete_dollar(s); |
---|
| 36 | delete_dollar(s)+"789"; |
---|
| 37 | } |
---|
| 38 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 39 | |
---|
| 40 | proc reduce_factor ( poly f ) |
---|
[d2b2a7] | 41 | "USAGE: reduce_factor(f); f = poly |
---|
[3d124a7] | 42 | RETURN: list, the factors of f |
---|
| 43 | NOTE: due to a limitation of REDUCE, multivariate polynomials can only |
---|
| 44 | be factorized in characteristic 0 |
---|
[82716e] | 45 | This proc runs under UNIX only |
---|
[3d124a7] | 46 | EXAMPLE: example reduce_factor; shows an example |
---|
[d2b2a7] | 47 | " |
---|
[3d124a7] | 48 | { |
---|
| 49 | string pid = string( system( "pid" ) ); |
---|
| 50 | string outname = "/tmp/singred." + pid + ".out"; |
---|
| 51 | string scriptname = "/tmp/singred." + pid + ".sh"; |
---|
| 52 | int n = char( basering ); |
---|
| 53 | int shortOutput = short; |
---|
| 54 | short = 0; |
---|
[d6db1f2] | 55 | write (scriptname,"#!/bin/sh |
---|
[3d124a7] | 56 | $reduce/reduce >/dev/null <<EOF |
---|
| 57 | off nat$ off echo$ setmod " + string( n ) + "$ |
---|
| 58 | erg:=factorize(",f,")$ |
---|
| 59 | out \"" + outname + "\"$ |
---|
| 60 | write(\"list result;\")$ |
---|
| 61 | counter:=1$ |
---|
| 62 | for each a in erg do begin |
---|
| 63 | write(\"result[\",counter,\"]=\",a,\";\"); |
---|
| 64 | counter:=counter+1; |
---|
| 65 | end; |
---|
| 66 | shut \"" + outname + "\"; |
---|
| 67 | quit$ |
---|
[d6db1f2] | 68 | EOF"); |
---|
[3d124a7] | 69 | system( "sh", "chmod 700 " + scriptname ); |
---|
| 70 | system( "sh", scriptname ); |
---|
[82716e] | 71 | string resultstring = read( outname ); |
---|
[3d124a7] | 72 | if ( resultstring <> "" ) |
---|
| 73 | { |
---|
| 74 | resultstring = delete_dollar( resultstring ); |
---|
[034ce1] | 75 | execute(resultstring); |
---|
[3d124a7] | 76 | } |
---|
| 77 | // remove tmp-files after usage */ |
---|
| 78 | system( "sh", "/bin/rm " + outname ); |
---|
| 79 | system( "sh", "/bin/rm " + scriptname ); |
---|
| 80 | short = shortOutput; |
---|
| 81 | return( result ); |
---|
| 82 | } |
---|
| 83 | example |
---|
| 84 | { "EXAMPLE:"; echo = 2; |
---|
| 85 | ring r=0,(x,y,z),lp; |
---|
| 86 | poly f=(x+y)*(y+z)^2*(z+x); |
---|
| 87 | f; |
---|
| 88 | list L=reduce_factor(f); |
---|
| 89 | L; |
---|
| 90 | } |
---|