[3d124a7] | 1 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 2 | |
---|
[341696] | 3 | version="$Id$"; |
---|
[5480da] | 4 | info=" |
---|
[d6db1f2] | 5 | LIBRARY: factor.lib PROCEDURES FOR CALLING THE REDUCE FACTORIZER |
---|
[3d124a7] | 6 | |
---|
| 7 | delete_dollar(s) return the string s with '$' deleted |
---|
| 8 | reduce_factor(f) list of factors of f, calling REDUCE (UNIX only) |
---|
[5480da] | 9 | "; |
---|
[3d124a7] | 10 | |
---|
| 11 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 12 | |
---|
| 13 | proc delete_dollar ( string s ) |
---|
[d2b2a7] | 14 | "USAGE: delete_dollar(s); s = string |
---|
[3d124a7] | 15 | RETURN: string, with '$' replaced by ' ' |
---|
[82716e] | 16 | EXAMPLE: example delete_dollar; shows an example |
---|
[d2b2a7] | 17 | " |
---|
[3d124a7] | 18 | { |
---|
| 19 | while( s[size(s)]=="$" and size(s)!=1 ) { s=s[1,size(s)-1]; } |
---|
| 20 | while( s[1]=="$" and size(s)!=1 ) { s=s[2,size(s)-1]; } |
---|
| 21 | if( size(s)==1 and s[1]=="$" ) { return(""); } |
---|
| 22 | int i=find(s,"$"); |
---|
| 23 | while( i!=0 ) |
---|
| 24 | { |
---|
| 25 | s=s[1,i-1]+s[i+1,size(s)-i]; |
---|
| 26 | i=find(s,"$"); |
---|
| 27 | } |
---|
| 28 | return(s); |
---|
| 29 | } |
---|
| 30 | example |
---|
| 31 | { "EXAMPLE:"; echo = 2; |
---|
| 32 | string s = "123$456$"; |
---|
| 33 | delete_dollar(s); |
---|
| 34 | delete_dollar(s)+"789"; |
---|
| 35 | } |
---|
| 36 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 37 | |
---|
| 38 | proc reduce_factor ( poly f ) |
---|
[d2b2a7] | 39 | "USAGE: reduce_factor(f); f = poly |
---|
[3d124a7] | 40 | RETURN: list, the factors of f |
---|
| 41 | NOTE: due to a limitation of REDUCE, multivariate polynomials can only |
---|
| 42 | be factorized in characteristic 0 |
---|
[82716e] | 43 | This proc runs under UNIX only |
---|
[3d124a7] | 44 | EXAMPLE: example reduce_factor; shows an example |
---|
[d2b2a7] | 45 | " |
---|
[3d124a7] | 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; |
---|
[d6db1f2] | 53 | write (scriptname,"#!/bin/sh |
---|
[3d124a7] | 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$ |
---|
[d6db1f2] | 66 | EOF"); |
---|
[3d124a7] | 67 | system( "sh", "chmod 700 " + scriptname ); |
---|
| 68 | system( "sh", scriptname ); |
---|
[82716e] | 69 | string resultstring = read( outname ); |
---|
[3d124a7] | 70 | if ( resultstring <> "" ) |
---|
| 71 | { |
---|
| 72 | resultstring = delete_dollar( resultstring ); |
---|
[034ce1] | 73 | execute(resultstring); |
---|
[3d124a7] | 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 | } |
---|
| 81 | example |
---|
| 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 | } |
---|