// $Id: redfac.lib,v 1.2 1997-04-28 19:27:24 obachman Exp $ //(RS) /////////////////////////////////////////////////////////////////////////////// LIBRARY: redfac.lib PROCEDURES FOR CALLING THE REDUCE FACTORIZER replace_dollar(s) returns the string s with '$' replaced by ' ' factor(f) returns the list of factors of f /////////////////////////////////////////////////////////////////////////////// proc replace_dollar ( string s ) USAGE: replace_dollar(s); s = string RETURN: string, with '$' replaced by ' ' EXAMPLE: example replace_dollar; shows an example { int i,n; n = size( s ); for ( i=1; i <= n; i=i+1 ) { if ( s[i] == "$" ) { s[i] = " "; } } return( s ); } example { "EXAMPLE:"; echo = 2; string s = "123$456$"; replace_dollar( s ); replace_dollar( s )+"789"; } proc factor ( poly f ) USAGE: factor(f); f = poly RETURN: list, the factors of f NOTE: due to a limitation of reduce, multivariate polynomials can only be factorized in characteristic 0 This proc runs under UNIX only EXAMPLE: example factor; shows an example { string pid = string( system( "pid" ) ); string outname = "/tmp/singred." + pid + ".out"; string scriptname = "/tmp/singred." + pid + ".sh"; int n = char( basering ); int shortOutput = short; short = 0; write scriptname,"#!/bin/sh $reduce/reduce >/dev/null < "" ) { resultstring = replace_dollar( resultstring ); execute resultstring; } // remove tmp-files after usage */ system( "sh", "/bin/rm " + outname ); system( "sh", "/bin/rm " + scriptname ); short = shortOutput; return( result ); } example { "EXAMPLE:"; echo = 3; ring r=0,(x,y,z),lp; poly f=(x+y)*(y+z)^2*(z+x); list L=factor(f); L; }