Annotation of OpenXM/src/kan96xx/Doc/factor-a.sm1, Revision 1.1.1.1
1.1 maekawa 1: %% This package requires kan/sm1 version 2.981101 or later.
2:
3: /factor-a.version (2.981101) def
4: (factor-a.sm1 : kan/sm1 package to factor polynomials by calling risa/asir.)
5: message
6: ( : kan/sm1 package to simplify rationals by calling risa/asir.)
7: message
8: ( Version : ) messagen factor-a.version message
9:
10: factor-a.version [(Version)] system_variable gt
11: { (This package requires the latest version of kan/sm1) message
12: (Please get it from http://www.math.kobe-u.ac.jp/KAN) message
13: error
14: } { } ifelse
15:
16:
17: [(factor)
18: [(polynomial factor list_of_strings)
19: (Example: (x^2-1). factor :: ---> [[$1$ $1$] [$x-1$ $1$] [$x+1$ $1$]])
20: (cf.: data_conversion, map, get, pushfile)
21: (Note: The function call creates work files asir-tmp.t, asir-tmp.tt,)
22: ( asir-tmp-out.t, asri-tmp-log.t and asir-tmp-out.tt )
23: ( in the current directory.)
24: ]
25: ] putUsages
26:
27: %% /f (Dx^10*d*a-d*a) def
28:
29: /factor-asir-1 {
30: /arg1 set
31: [/f /fd /fnewline] pushVariables
32: [
33: arg1 /f set
34: %% (factor-asir-1 is tested with Asir version 950831 on Linux.) message
35: (asir-tmp.t) (w) file /fd set
36: /fnewline { fd 10 (string) data_conversion writestring } def
37: fd $output("asir-tmp-out.t");$ writestring fnewline
38: fd $fctr($ writestring
39: fd f writestring
40: fd $); output(); quit(); $ writestring fnewline
41: fd closefile
42: (/bin/rm -f asir-tmp.tt) system
43: (sed "s/D/kanD/g" asir-tmp.t | sed "s/E/kanE/g" | sed "s/Q/kanQ/g" >asir-tmp.tt) system
44: (/bin/rm -f asir-tmp-out.t asir-tmp-out.tt asir-tmp-log.t) system
45: (asir <asir-tmp.tt >asir-tmp-log.t) system
46: (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
47: ] pop
48: popVariables
49: } def
50:
51: /clean-workfiles {
52: (/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
53: } def
54:
55:
56: %% comment: there is not data conversion function from string --> array
57: %% e.g. (abc) ---> [0x61, 0x62, 0x63]
58: %% We can do (abc) 1 10 put, but "get" does not work for strings.
59:
60: %% f factor-asir-1
61:
62: %%/aaa
63: %% ({{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}})
64: %%def
65:
66: /asir-list-to-kan {
67: /arg1 set
68: [/aaa /ftmp /ftmp2] pushVariables
69: [
70: /aaa arg1 def
71: [ aaa to_records pop ] /ftmp set
72: ftmp { to_records pop [ 3 1 roll ] } map /ftmp2 set
73: /arg1 ftmp2 def
74: ] pop
75: popVariables
76: arg1
77: } def
78:
79: /foo {
80: (input string is in f) message
81: f ::
82: f factor-asir-1
83: %% (asir-tmp-out.tt) run
84: %% (answer in @asir.out) message
85: %% bug of run.
86: (asir-tmp-out.tt) pushfile /@asir.out set
87: @asir.out asir-list-to-kan /ff2 set
88: (answer in ff2) message
89: } def
90:
91: /factor {
92: (string) data_conversion
93: factor-asir-1
94: (asir-tmp-out.tt) pushfile asir-list-to-kan
95: } def
96:
97: %%%%%%%%%%%%%%%%% macros for simplification (reduction, cancel)
98: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99: [(cancel)
100: [(polynomial cancel list_of_strings)
101: (This function simplifies rationals.)
102: (Example: $x^2-1$. $x+1$. div cancel :: ---> [[$x-1$ , $1$]])
103: (Note: The function call creates work files asir-tmp.t, asir-tmp.tt,)
104: ( asir-tmp-out.t, asri-tmp-log.t and asir-tmp-out.tt )
105: ( in the current directory.)
106: ]
107: ] putUsages
108:
109: /reduce-asir-1 {
110: /arg1 set
111: [/f /fd /fnewline] pushVariables
112: [
113: arg1 /f set
114: %% (reduce-asir-1 is tested with Asir version 950831 on Linux.) message
115: (asir-tmp.t) (w) file /fd set
116: /fnewline { fd 10 (string) data_conversion writestring } def
117: fd $output("asir-tmp-out.t");$ writestring fnewline
118: fd $AsirTmp012=red($ writestring
119: fd f writestring
120: fd $)$ writestring
121: fd ($ ) writestring fnewline
122: fd $AsirTmp013=ptozp(nm(AsirTmp012))$ writestring
123: fd ($ ) writestring fnewline
124: fd $AsirTmp014=red(nm(AsirTmp012)/AsirTmp013)$ writestring
125: fd ($ ) writestring fnewline
126: fd $[[nm(AsirTmp014)*AsirTmp013,dn(AsirTmp014)*dn(AsirTmp012)]];output();quit(); $ writestring fnewline
127: fd closefile
128: (/bin/rm -f asir-tmp.tt) system
129: (sed "s/D/kanD/g" asir-tmp.t | sed "s/E/kanE/g" | sed "s/Q/kanQ/g" >asir-tmp.tt) system
130: (/bin/rm -f asir-tmp-out.t asir-tmp-out.tt asir-tmp-log.t) system
131: (asir <asir-tmp.tt >asir-tmp-log.t) system
132: (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
133:
134:
135: ] pop
136: popVariables
137: } def
138:
139: /cancel {
140: (string) data_conversion
141: reduce-asir-1
142: (asir-tmp-out.tt) pushfile asir-list-to-kan
143: } def
144:
145:
146: (Loaded macros "factor", "cancel") message
147:
148:
149:
150:
151:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>