[BACK]Return to factor-a.sm1 CVS log [TXT][DIR] Up to [local] / OpenXM / src / kan96xx / Doc

File: [local] / OpenXM / src / kan96xx / Doc / factor-a.sm1 (download)

Revision 1.1.1.1 (vendor branch), Fri Oct 8 02:12:02 1999 UTC (24 years, 8 months ago) by maekawa
Branch: OpenXM, MAIN
CVS Tags: maekawa-ipv6, R_1_3_1-2, RELEASE_20000124, RELEASE_1_3_1_13b, RELEASE_1_2_3_12, RELEASE_1_2_3, RELEASE_1_2_2_KNOPPIX_b, RELEASE_1_2_2_KNOPPIX, RELEASE_1_2_2, RELEASE_1_2_1, RELEASE_1_1_3, RELEASE_1_1_2, KNOPPIX_2006, HEAD, DEB_REL_1_2_3-9, ALPHA
Changes since 1.1: +0 -0 lines

o import OpenXM sources

%% This package requires kan/sm1 version 2.981101 or later.

/factor-a.version (2.981101) def
(factor-a.sm1 : kan/sm1 package to factor polynomials by calling risa/asir.)
message
(             : kan/sm1 package to simplify rationals by calling risa/asir.)
message
(               Version : ) messagen  factor-a.version message

factor-a.version [(Version)] system_variable gt
{ (This package requires the latest version of kan/sm1) message
  (Please get it from http://www.math.kobe-u.ac.jp/KAN) message
  error
} { } ifelse


[(factor)
 [(polynomial factor list_of_strings)
  (Example: (x^2-1). factor :: ---> [[$1$ $1$] [$x-1$ $1$] [$x+1$ $1$]])
  (cf.:     data_conversion, map, get, pushfile)
  (Note:    The function call creates work files asir-tmp.t, asir-tmp.tt,)
  (          asir-tmp-out.t, asri-tmp-log.t and asir-tmp-out.tt )
  (          in the current directory.)
 ]
] putUsages

%% /f (Dx^10*d*a-d*a) def

/factor-asir-1 {
 /arg1 set
 [/f /fd /fnewline] pushVariables
 [
  arg1 /f set
  %% (factor-asir-1 is tested with Asir version 950831 on Linux.) message
  (asir-tmp.t) (w) file /fd set
  /fnewline { fd 10 (string) data_conversion writestring } def
  fd $output("asir-tmp-out.t");$ writestring fnewline
  fd $fctr($ writestring 
  fd  f writestring
  fd $); output(); quit(); $ writestring fnewline
  fd closefile
  (/bin/rm -f asir-tmp.tt) system
  (sed "s/D/kanD/g" asir-tmp.t | sed "s/E/kanE/g" | sed "s/Q/kanQ/g" >asir-tmp.tt) system
  (/bin/rm -f asir-tmp-out.t asir-tmp-out.tt asir-tmp-log.t) system
  (asir <asir-tmp.tt >asir-tmp-log.t) system
  (sed "s/\[1\]/ /g" asir-tmp-out.t | sed "s/\[2\]/ /g" | sed "1s/1/ /g"| sed "s/\[/{/g" | sed "s/\]/}/g" | sed "s/kanD/D/g" | sed "s/kanE/E/g" | sed "s/kanQ/Q/g" >asir-tmp-out.tt) system
 ] pop
 popVariables
} def

/clean-workfiles {
 (/bin/rm -f asir-tmp-out.t asir-tmp-out.tt asir-tmp.t asir-tmp.tt sm0-tmp.t sm0-tmp-out.t asir-tmp-log.t) system
} def


%% comment: there is not data conversion function from string --> array
%%                           e.g. (abc) ---> [0x61, 0x62, 0x63]
%%          We can do (abc) 1 10 put, but "get" does not work for strings.

%% f factor-asir-1

%%/aaa 
%% ({{1,1},{x-1,1},{x+1,1},{x^4+x^3+x^2+x+1,1},{x^4-x^3+x^2-x+1,1}})
%%def

/asir-list-to-kan {
  /arg1 set
  [/aaa /ftmp /ftmp2] pushVariables
  [
    /aaa arg1 def
    [ aaa to_records pop ] /ftmp set
    ftmp { to_records pop [ 3 1 roll ] } map /ftmp2 set
    /arg1 ftmp2 def
  ] pop
  popVariables
  arg1
} def

/foo {
  (input string is in f) message
  f ::
  f factor-asir-1
  %% (asir-tmp-out.tt) run 
  %% (answer in @asir.out) message
  %% bug of run.
  (asir-tmp-out.tt) pushfile /@asir.out set
  @asir.out asir-list-to-kan /ff2 set
  (answer in ff2) message
} def

/factor {
  (string) data_conversion
  factor-asir-1
  (asir-tmp-out.tt) pushfile asir-list-to-kan
} def

%%%%%%%%%%%%%%%%% macros for simplification (reduction, cancel)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[(cancel)
 [(polynomial cancel list_of_strings)
  (This function simplifies rationals.)
  (Example: $x^2-1$. $x+1$. div cancel :: ---> [[$x-1$ , $1$]])
  (Note:    The function call creates work files asir-tmp.t, asir-tmp.tt,)
  (          asir-tmp-out.t, asri-tmp-log.t and asir-tmp-out.tt )
  (          in the current directory.)
 ]
] putUsages

/reduce-asir-1 {
 /arg1 set
 [/f /fd /fnewline] pushVariables
 [
  arg1 /f set
  %% (reduce-asir-1 is tested with Asir version 950831 on Linux.) message
  (asir-tmp.t) (w) file /fd set
  /fnewline { fd 10 (string) data_conversion writestring } def
  fd $output("asir-tmp-out.t");$ writestring fnewline
  fd $AsirTmp012=red($ writestring 
  fd  f writestring
  fd $)$ writestring 
  fd ($ )  writestring fnewline
  fd $AsirTmp013=ptozp(nm(AsirTmp012))$ writestring
  fd ($ )  writestring fnewline
  fd $AsirTmp014=red(nm(AsirTmp012)/AsirTmp013)$ writestring
  fd ($ )  writestring fnewline
  fd $[[nm(AsirTmp014)*AsirTmp013,dn(AsirTmp014)*dn(AsirTmp012)]];output();quit(); $ writestring fnewline
  fd closefile
  (/bin/rm -f asir-tmp.tt) system
  (sed "s/D/kanD/g" asir-tmp.t | sed "s/E/kanE/g" | sed "s/Q/kanQ/g" >asir-tmp.tt) system
  (/bin/rm -f asir-tmp-out.t asir-tmp-out.tt asir-tmp-log.t) system
  (asir <asir-tmp.tt >asir-tmp-log.t) system
  (sed "s/\[1\]/ /g" asir-tmp-out.t | sed "s/\[2\]/ /g" |sed "s/\[3\]/ /g" |sed "s/\[4\]/ /g" |sed "s/\[5\]/ /g" | sed "1s/1/ /g"| sed "s/\[/{/g" | sed "s/\]/}/g" | sed "s/kanD/D/g" | sed "s/kanE/E/g" | sed "s/kanQ/Q/g" | sed "s/kanLeftBrace/\[/g" | sed "s/kanRightBrace/\]/g" | sed "s/kanComma/\,/g" >asir-tmp-out.tt) system


 ] pop
 popVariables
} def

/cancel {
  (string) data_conversion
  reduce-asir-1
  (asir-tmp-out.tt) pushfile asir-list-to-kan
} def


(Loaded macros "factor", "cancel") message