scope.rlg 17 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048
  1. Tue Apr 15 00:34:42 2008 run on win32
  2. % Test SCOPE Package.
  3. % ==================
  4. % NOTE: The SCOPE, GHORNER, GSTRUCTR and GENTRAN packages must be loaded
  5. % to run these tests.
  6. % Further reading: SCOPE 1.5 manual Section 3, example 1;
  7. scope_switches$
  8. ON : evallhseqp exp ftch nat period
  9. OFF : acinfo again double fort gentranopt inputc intern prefix
  10. priall primat roundbf rounded sidrel vectorc
  11. % Further reading: SCOPE 1.5 manual Section 3.1, examples 2,3,4 and 5.
  12. on priall$
  13. optimize z:=a^2*b^2+10*a^2*m^6+a^2*m^2+2*a*b*m^4+2*b^2*m^6+b^2*m^2
  14. iname s;
  15. 2 2 2 6 2 2 4 2 6 2 2
  16. z := a *b + 10*a *m + a *m + 2*a*b*m + 2*b *m + b *m
  17. Sumscheme :
  18. || EC|Far
  19. ------------
  20. 0|| 1| z
  21. ------------
  22. Productscheme :
  23. | 0 1 2| EC|Far
  24. ---------------------
  25. 1| 2 2| 1| 0
  26. 2| 6 2| 10| 0
  27. 3| 2 2| 1| 0
  28. 4| 4 1 1| 2| 0
  29. 5| 6 2 | 2| 0
  30. 6| 2 2 | 1| 0
  31. ---------------------
  32. 0 : m
  33. 1 : b
  34. 2 : a
  35. Number of operations in the input is:
  36. Number of (+/-) operations : 5
  37. Number of unary - operations : 0
  38. Number of * operations : 10
  39. Number of integer ^ operations : 11
  40. Number of / operations : 0
  41. Number of function applications : 0
  42. s0 := b*a
  43. s4 := m*m
  44. s1 := s4*b*b
  45. s2 := s4*a*a
  46. s3 := s4*s4
  47. z := s1 + s2 + s0*(2*s3 + s0) + s3*(2*s1 + 10*s2)
  48. Number of operations after optimization is:
  49. Number of (+/-) operations : 5
  50. Number of unary - operations : 0
  51. Number of * operations : 12
  52. Number of integer ^ operations : 0
  53. Number of / operations : 0
  54. Number of function applications : 0
  55. Sumscheme :
  56. | 0 3 4 5| EC|Far
  57. ------------------------
  58. 0| 1 1| 1| z
  59. 15| 2 10| 1| 14
  60. 17| 2 1 | 1| 16
  61. ------------------------
  62. 0 : s3
  63. 3 : s0
  64. 4 : s1
  65. 5 : s2
  66. Productscheme :
  67. | 8 9 10 11 17 18 19 20| EC|Far
  68. ------------------------------------
  69. 7| 1 1| 1| s0
  70. 8| 1 2 | 1| s1
  71. 9| 1 2| 1| s2
  72. 10| 2 | 1| s3
  73. 11| 2 | 1| s4
  74. 14| 1 | 1| 0
  75. 16| 1 | 1| 0
  76. ------------------------------------
  77. 8 : s4
  78. 9 : s3
  79. 10 : s2
  80. 11 : s1
  81. 17 : s0
  82. 18 : m
  83. 19 : b
  84. 20 : a
  85. off priall$
  86. on primat,acinfo$
  87. optimize
  88. ghorner <<z:=a^2*b^2+10*a^2*m^6+a^2*m^2+2*a*b*m^4+2*b^2*m^6+b^2*m^2>>
  89. vorder m
  90. iname s;
  91. Sumscheme :
  92. || EC|Far
  93. ------------
  94. 0|| 1| z
  95. 3|| 1| 2
  96. 7|| 1| 6
  97. 10|| 1| 9
  98. ------------
  99. Productscheme :
  100. | 0 1 2| EC|Far
  101. ---------------------
  102. 1| 2 2| 1| 0
  103. 2| 2 | 1| 0
  104. 4| 2| 1| 3
  105. 5| 2 | 1| 3
  106. 6| 2 | 1| 3
  107. 8| 1 1| 2| 7
  108. 9| 2 | 1| 7
  109. 11| 2| 10| 10
  110. 12| 2 | 2| 10
  111. ---------------------
  112. 0 : m
  113. 1 : b
  114. 2 : a
  115. Number of operations in the input is:
  116. Number of (+/-) operations : 5
  117. Number of unary - operations : 0
  118. Number of * operations : 8
  119. Number of integer ^ operations : 9
  120. Number of / operations : 0
  121. Number of function applications : 0
  122. s0 := b*a
  123. s1 := b*b
  124. s2 := a*a
  125. s3 := m*m
  126. z := s0*s0 + s3*(s1 + s2 + s3*(2*s0 + s3*(2*s1 + 10*s2)))
  127. Number of operations after optimization is:
  128. Number of (+/-) operations : 5
  129. Number of unary - operations : 0
  130. Number of * operations : 11
  131. Number of integer ^ operations : 0
  132. Number of / operations : 0
  133. Number of function applications : 0
  134. Sumscheme :
  135. | 0 1 2| EC|Far
  136. ---------------------
  137. 0| | 1| z
  138. 3| 1 1| 1| 2
  139. 7| 2 | 1| 6
  140. 10| 2 10| 1| 9
  141. ---------------------
  142. 0 : s0
  143. 1 : s1
  144. 2 : s2
  145. Productscheme :
  146. | 3 4 5 9 10 11 12| EC|Far
  147. ---------------------------------
  148. 1| 2 | 1| 0
  149. 2| 1 | 1| 0
  150. 6| 1 | 1| 3
  151. 9| 1 | 1| 7
  152. 13| 1 1| 1| s0
  153. 14| 2 | 1| s1
  154. 15| 2| 1| s2
  155. 16| 2 | 1| s3
  156. ---------------------------------
  157. 3 : s3
  158. 4 : s2
  159. 5 : s1
  160. 9 : s0
  161. 10 : m
  162. 11 : b
  163. 12 : a
  164. off exp,primat,acinfo$
  165. q:=a+b$
  166. r:=q+a+b$
  167. optimize x:=a+b,q:=:q^2,p(q)::=:r iname s;
  168. x := a + b
  169. q := x*x
  170. p(x) := 2*x
  171. on exp$
  172. clear q,r$
  173. % A similar example follows.
  174. % operator a$% Not necessary. Some differences between REDUCE 3.5 and REDUCE 3.6
  175. % when dealing with indices.
  176. on inputc$
  177. k:=j:=1$
  178. u:=c*x+d$
  179. v:=sin(u)$
  180. optimize {a(k,j):=v*(v^2*cos(u)^2+u),
  181. a(k,j)::=:v*(v^2*cos(u)^2+u)} iname s;
  182. 2 2
  183. a(1,1) := v*(v *cos(u) + u)
  184. 2 3
  185. a(1,1) := cos(c*x + d) *sin(c*x + d) + sin(c*x + d)*c*x + sin(c*x + d)*d
  186. s9 := cos(u)*v
  187. a(1,1) := v*(u + s9*s9)
  188. s6 := x*c + d
  189. s5 := sin(s6)
  190. s10 := s5*cos(s6)
  191. a(1,1) := s5*(s6 + s10*s10)
  192. off exp$
  193. optimize {a(k,j):=v*(v^2*cos(u)^2+u),
  194. a(k,j)::=:v*(v^2*cos(u)^2+u)} iname s;
  195. 2 2
  196. a(1,1) := v*(v *cos(u) + u)
  197. 2 2
  198. a(1,1) := (c*x + d + cos(c*x + d) *sin(c*x + d) )*sin(c*x + d)
  199. s9 := cos(u)*v
  200. a(1,1) := v*(u + s9*s9)
  201. s6 := x*c + d
  202. s5 := sin(s6)
  203. s10 := s5*cos(s6)
  204. a(1,1) := s5*(s6 + s10*s10)
  205. off inputc,period$
  206. optlang fortran$
  207. optimize z:=(6*a+18*b+9*c+3*d+6*j+18*f+6*g+5*h+5*k+3)^13 iname s;
  208. s0=5*(h+k)+3*(3*c+d+1+6*(b+f)+2*(a+j+g))
  209. s3=s0*s0*s0
  210. s2=s3*s3
  211. z=s0*s2*s2
  212. off ftch$
  213. optimize z:=(6*a+18*b+9*c+3*d+6*j+18*f+6*g+5*h+5*k+3)^13 iname s;
  214. z=(5*(h+k)+3*(3*c+d+1+6*(b+f)+2*(a+j+g)))**13
  215. optlang c$
  216. optimize z:=(6*a+18*b+9*c+3*d+6*j+18*f+6*g+5*h+5*k+3)^13 iname s;
  217. {
  218. s0=5*(h+k)+3*(3*c+d+1+6*(b+f)+2*(a+j+g));
  219. s3=s0*s0*s0;
  220. s2=s3*s3;
  221. z=s0*s2*s2;
  222. }
  223. % Note: C code never contains exponentiations.
  224. on ftch$
  225. optimize {x:=3*a*p,y:=3*a*q,z:=6*a*r+2*b*p,u:=6*a*d+2*b*q,
  226. v:=9*a*c+4*b*d,w:=4*b} iname s;
  227. {
  228. s2=3*a;
  229. x=s2*p;
  230. y=s2*q;
  231. s0=2*b;
  232. s3=6*a;
  233. z=s0*p+s3*r;
  234. u=s0*q+s3*d;
  235. w=4*b;
  236. v=w*d+9*c*a;
  237. }
  238. off ftch$
  239. optlang fortran$
  240. optimize {x:=3*a*p,y:=3*a*q,z:=6*a*r+2*b*p,u:=6*a*d+2*b*q,
  241. v:=9*a*c+4*b*d,w:=4*b} iname s;
  242. x=3*p*a
  243. y=3*q*a
  244. z=2*b*p+6*r*a
  245. u=2*b*q+6*d*a
  246. v=4*d*b+9*c*a
  247. w=4*b
  248. on ftch$
  249. setlength 2$
  250. optimize {x:=3*a*p,y:=3*a*q,z:=6*a*r+2*b*p,u:=6*a*d+2*b*q,
  251. v:=9*a*c+4*b*d,w:=4*b} iname s;
  252. x=3*p*a
  253. y=3*q*a
  254. z=2*b*p+6*r*a
  255. u=2*b*q+6*d*a
  256. v=4*d*b+9*c*a
  257. w=4*b
  258. resetlength$
  259. optlang nil$
  260. % Further reading: SCOPE 1.5 manual section 3.1, example 9 and section 3.2.
  261. u:=a*x+2*b$
  262. v:=sin(u)$
  263. w:=cos(u)$
  264. f:=v^2*w;
  265. 2
  266. f := cos(a*x + 2*b)*sin(a*x + 2*b)
  267. off exp$
  268. optimize f:=:f,g:=:f^2+f iname s$
  269. s3 := x*a + 2*b
  270. s2 := sin(s3)
  271. f := s2*s2*cos(s3)
  272. g := f*(f + 1)
  273. alst:=aresults;
  274. alst := {s3=a*x + 2*b,
  275. s2=sin(s3),
  276. 2
  277. f=cos(s3)*s2 ,
  278. g=(f + 1)*f}
  279. restorables;
  280. {f}
  281. f;
  282. f
  283. arestore f;
  284. f;
  285. 2
  286. cos(a*x + 2*b)*sin(a*x + 2*b)
  287. alst;
  288. {s3=a*x + 2*b,
  289. s2=sin(s3),
  290. 2 2
  291. cos(a*x + 2*b)*sin(a*x + 2*b) =cos(s3)*s2 ,
  292. 2 2
  293. g=(cos(a*x + 2*b)*sin(a*x + 2*b) + 1)*cos(a*x + 2*b)*sin(a*x + 2*b) }
  294. optimize f:=:f,g:=:f^2+f iname s$
  295. s3 := x*a + 2*b
  296. s2 := sin(s3)
  297. f := s2*s2*cos(s3)
  298. g := f*(f + 1)
  299. alst:=aresults$
  300. optimize f:=:f,g:=:f^2+f iname s$
  301. g := f*(f + 1)
  302. restoreall$
  303. f;
  304. f
  305. % Further reading: SCOPE 1.5 manual section 3.1, example 8.
  306. % See also section 5.
  307. % Also recommended: section 9.
  308. clear a$
  309. matrix a(2,2)$
  310. a(1,1):=x+y+z$
  311. a(1,2):=x*y$
  312. a(2,1):=(x+y)*x*y$
  313. a(2,2):=(x+2*y+3)^3-x$
  314. on exp$
  315. off fort,nat$
  316. optimize detexp:=:det(a) out "expfile" iname s$
  317. off exp$
  318. optimize detnexp:=:det(a) out "nexpfile" iname t$
  319. in expfile$
  320. in nexpfile$
  321. on nat$
  322. detexp-detnexp;
  323. 0
  324. system "rm expfile nexpfile"$
  325. % Further reading: SCOPE 1.5 manual section 4.2, example 15.
  326. % Although the output is similar, it is in general equivalent and
  327. % not identical when using REDUCE 3.6 in stead of REDUCE 3.5. This
  328. % is due to improvements in the simplification strategy.
  329. on acinfo$
  330. optimize
  331. gstructr<<a;aa:=(x+y)^2;b:=(x+y)*(y+z);c:=(x+2*y)*(y+z)*(z+x)^2>>
  332. name v iname s;
  333. Number of operations in the input is:
  334. Number of (+/-) operations : 8
  335. Number of unary - operations : 0
  336. Number of * operations : 8
  337. Number of integer ^ operations : 3
  338. Number of / operations : 0
  339. Number of function applications : 0
  340. v1 := y + z
  341. a(1,1) := v1 + x
  342. a(1,2) := y*x
  343. v3 := y + x
  344. a(2,1) := a(1,2)*v3
  345. s6 := 2*y + x
  346. s4 := s6 + 3
  347. a(2,2) := s4*s4*s4 - x
  348. aa := v3*v3
  349. b := v1*v3
  350. s5 := z + x
  351. c := s6*s5*s5*v1
  352. Number of operations after optimization is:
  353. Number of (+/-) operations : 7
  354. Number of unary - operations : 0
  355. Number of * operations : 10
  356. Number of integer ^ operations : 0
  357. Number of / operations : 0
  358. Number of function applications : 5
  359. alst:=
  360. algopt(algstructr({a,b=(x+y)^2,c=(x+y)*(y+z),d=(x+2*y)*(y+z)*(z+x)^2},v),s);
  361. Number of operations in the input is:
  362. Number of (+/-) operations : 8
  363. Number of unary - operations : 0
  364. Number of * operations : 8
  365. Number of integer ^ operations : 3
  366. Number of / operations : 0
  367. Number of function applications : 0
  368. Number of operations after optimization is:
  369. Number of (+/-) operations : 7
  370. Number of unary - operations : 0
  371. Number of * operations : 10
  372. Number of integer ^ operations : 0
  373. Number of / operations : 0
  374. Number of function applications : 5
  375. *** a declared operator
  376. alst := {v1=y + z,
  377. a(1,1)=v1 + x,
  378. a(1,2)=x*y,
  379. v3=x + y,
  380. a(2,1)=a(1,2)*v3,
  381. s6=x + 2*y,
  382. s4=s6 + 3,
  383. 3
  384. a(2,2)=s4 - x,
  385. 2
  386. b=v3 ,
  387. c=v1*v3,
  388. s5=x + z,
  389. 2
  390. d=s5 *s6*v1}
  391. off acinfo$
  392. % Further reading: SCOPE 1.5 manual section 4.3, example 16.
  393. clear a$
  394. procedure taylor(fx,x,x0,n);
  395. sub(x=x0,fx)+(for k:=1:n sum(sub(x=x0,df(fx,x,k))*(x-x0)^k/factorial(k)))$
  396. hlst:={f1=taylor(e^x,x,0,4),f2=taylor(cos x,x,0,6)}$
  397. on rounded$
  398. hlst:=hlst;
  399. 3 2
  400. hlst := {f1=0.0416666666667*(x + 4*x + 12*x + 24)*x + 1,
  401. 4 2 2
  402. f2= - 0.00138888888889*(x - 30*x + 360)*x + 1}
  403. optimize alghorner(hlst,{x}) iname g$
  404. g1 := x*x
  405. g0 := g1*x
  406. f1 := 1 + x*(0.166666666667*g1 + 0.0416666666667*g0 + 1 + 0.5*x)
  407. f2 := 1 + g1*(0.0416666666667*g1 - 0.5 - 0.00138888888889*g0*x)
  408. off rounded$
  409. % Further reading: SCOPE 1.5 manual section 3.1, examples 6 and 7.
  410. optimize z:=:for j:=2:6 sum a^(1/j) iname s$
  411. 1/60
  412. s0 := a
  413. s8 := s0*s0
  414. s7 := s8*s0
  415. s5 := s8*s7
  416. s3 := s5*s5
  417. s2 := s8*s3
  418. s1 := s7*s2
  419. s4 := s5*s1
  420. z := s3 + s2 + s1 + s4 + s4*s3
  421. optimize z1:=a+sqrt(sin(a^2+b^2)), z2:=b+sqrt(sin(a^2+b^2)),
  422. z3:=a+b+(a^2+b^2)^(1/2), z4:=sqroot(a^2+b^2)+(a^2+b^2)^3,
  423. z5:=a^2+b^2+cos(a^2+b^2), z6:=(a^2+b^2)^(1/3)+(a^2+b^2)^(1/6)
  424. iname s;
  425. s6 := b*b + a*a
  426. s8 := sqrt(sin(s6))
  427. z1 := s8 + a
  428. z2 := s8 + b
  429. 1/6
  430. s7 := s6
  431. s9 := s7*s7
  432. z3 := a + b + s9*s7
  433. z4 := sqroot(s6) + s6*s6*s6
  434. z5 := s6 + cos(s6)
  435. z6 := s7 + s9
  436. % Further reading: SCOPE 1.5 manual section 6, examples 18 and 19.
  437. optlang fortran$
  438. optimize {x(i+1,i-1):=a(i+1,i-1)+b(i),y(i-1):=a(i-1,i+1)-b(i)} iname s
  439. declare <<x(4),a(4,4),y(5):real;b(5):integer>>;
  440. integer b(5),i,s10,s9
  441. real a(4,4),x(4),y(5)
  442. s10=i+1
  443. s9=i-1
  444. x(s10,s9)=a(s10,s9)+b(i)
  445. y(s9)=a(s9,s10)-b(i)
  446. optlang c$
  447. optimize {x(i+1,i-1):=a(i+1,i-1)+b(i),y(i-1):=a(i-1,i+1)-b(i)} iname s
  448. declare <<x(4),a(4,4),y(5):real;b(5):integer>>;
  449. int b[6],i,s10,s9;
  450. float a[5][5],x[5],y[6];
  451. {
  452. s10=i+1;
  453. s9=i-1;
  454. x[s10][s9]=a[s10][s9]+b[i];
  455. y[s9]=a[s9][s10]-b[i];
  456. }
  457. optlang pascal$
  458. optimize {x(i+1,i-1):=a(i+1,i-1)+b(i),y(i-1):=a(i-1,i+1)-b(i)} iname s
  459. declare <<x(4),a(4,4),y(5):real;b(5):integer>>;
  460. var
  461. s9,s10,i: integer;
  462. b: array[0..5] of integer;
  463. y: array[0..5] of real;
  464. x: array[0..4] of real;
  465. a: array[0..4,0..4] of real;
  466. begin
  467. s10:=i+1;
  468. s9:=i-1;
  469. x[s10,s9]:=a[s10,s9]+b[i];
  470. y[s9]:=a[s9,s10]-b[i]
  471. end;
  472. optlang ratfor$
  473. optimize {x(i+1,i-1):=a(i+1,i-1)+b(i),y(i-1):=a(i-1,i+1)-b(i)} iname s
  474. declare <<x(4),a(4,4),y(5):real;b(5):integer>>;
  475. integer b(5),i,s10,s9
  476. real a(4,4),x(4),y(5)
  477. {
  478. s10=i+1
  479. s9=i-1
  480. x(s10,s9)=a(s10,s9)+b(i)
  481. y(s9)=a(s9,s10)-b(i)
  482. }
  483. precision 7$
  484. on rounded, double$
  485. optlang fortran$
  486. optimize x1:=2 *a + 10 *b,
  487. x2:=2.00001 *a + 10 *b,
  488. x3:=2 *a + 10.00001 *b,
  489. x4:=6 *a + 10 *b,
  490. x5:=2.0000001 *a + 10.000001 *b
  491. iname s
  492. declare << x1,x2,x3,x4,x5,a,b:real>>$
  493. double precision a,b,s1,s2,x1,x2,x3,x4,x5
  494. s1=2*a
  495. s2=10*b
  496. x1=s2+s1
  497. x2=s2+2.00001d0*a
  498. x3=s1+1.000001d1*b
  499. x4=s2+6*a
  500. x5=x1
  501. % Further reading: SCOPE 1.5 manual section 7, example 20.
  502. % Notice the double role of e: In the lhs as identifier. In the rhs as
  503. % exponential function.
  504. % Further notice that a is expected to be declared operator. This is
  505. % due to lower level scope activities.
  506. optimize a(1,x+1) := g + h*r^f,
  507. b(y+1) := a(1,2*x+1)*(g+h*r^f),
  508. c1 := (h*r)/g*a(2,1+x),
  509. c2 := c1*a(1,x+1) + sin(d),
  510. a(1,x+1) := c1^(5/2),
  511. d := b(y+1)*a(1,x+1),
  512. a(1,1+2*x):= (a(1,x+1)*b(y+1)*c)/(d*g^2),
  513. b(y+1) := a(1,1+x)+b(y+1) + sin(d),
  514. a(1,x+1) := b(y+1)*c + h/(g + sin(d)),
  515. d := k*e + d*(a(1,1+x) + 3),
  516. e := d*(a(1,1+x) + 3) + sin(d),
  517. f := d*(3 + a(1,1+x)) + sin(d),
  518. g := d*(3 + a(1,1+x)) + f
  519. iname s
  520. declare << a(5,5),b(7),c,c1,d,e,f,g,h,r:real*8; x,y:integer>>$
  521. *** a declared operator
  522. integer x,y,s0,s2,s6
  523. double precision c,h,r,s34,s3,c1,c2,s4,s24,b(7),a(5,5),s29,k,d,s33
  524. . ,e,f,g
  525. s0=x+1
  526. s34=r**f*h+g
  527. s2=1+y
  528. s6=2*x+1
  529. s3=s34*a(1,s6)
  530. c1=a(2,s0)*((r*h)/g)
  531. c2=dsin(d)+s34*c1
  532. s4=dsqrt(c1)*c1*c1
  533. d=s4*s3
  534. a(1,s6)=(d*c)/(g*g*d)
  535. s24=dsin(d)
  536. b(s2)=s4+s3+s24
  537. a(1,s0)=h/(g+s24)+b(s2)*c
  538. s29=3+a(1,s0)
  539. d=s29*d+dexp(1.0d0)*k
  540. s33=s29*d
  541. e=s33+dsin(d)
  542. f=dexp(1.0d0)
  543. g=s33+f
  544. % Further reading: SCOPE 1.5 manual section 8, examples 21 and 22.
  545. % Also recommended: section 9.
  546. optlang nil$
  547. delaydecs$
  548. gentran declare <<a,b,c,d,q,w: real>>$
  549. gentran a:=b+c$
  550. gentran d:=b+c$
  551. gentran <<q:=b+c;w:=b+c>>$
  552. makedecs$
  553. double precision a,b,c,d,q,w
  554. a=b+c
  555. d=b+c
  556. q=b+c
  557. w=b+c
  558. on gentranopt$
  559. delaydecs$
  560. gentran declare <<a,b,c,d,q,w: real>>$
  561. gentran a:=b+c$
  562. gentran d:=b+c$
  563. gentran <<q:=b+c;w:=b+c>>$
  564. makedecs$
  565. double precision b,c,a,d,q,w
  566. a=b+c
  567. d=b+c
  568. q=b+c
  569. w=q
  570. off gentranopt$
  571. delayopts$
  572. gentran declare <<a,b,c,d,q,w: real>>$
  573. gentran a:=b+c$
  574. gentran d:=b+c$
  575. gentran <<q:=b+c;w:=b+c>>$
  576. makeopts$
  577. a=b+c
  578. d=a
  579. q=a
  580. w=a
  581. delaydecs$
  582. gentran declare <<a,b,c,d,q,w: real>>$
  583. delayopts$
  584. gentran a:=b+c$
  585. gentran d:=b+c$
  586. gentran <<q:=b+c;w:=b+c>>$
  587. makeopts$
  588. makedecs$
  589. double precision b,c,a,d,q,w
  590. a=b+c
  591. d=a
  592. q=a
  593. w=a
  594. clear a,b,c,d,q,w$
  595. matrix a(2,2)$
  596. a:=mat(((b+c)*(c+d),(b+c+2)*(c+d-3)),((c+b-3)*(d+b),(c+b)*(d+b+4)));
  597. [ (b + c)*(c + d) (c + 2 + b)*(d - 3 + c)]
  598. a := [ ]
  599. [(c - 3 + b)*(b + d) (d + 4 + b)*(b + c) ]
  600. gentranlang!*:='c$
  601. delayopts$
  602. gentran aa:=:a$
  603. makeopts$
  604. {
  605. {
  606. g17=b+c;
  607. g18=c+d;
  608. aa[1][1]=g18*g17;
  609. aa[1][2]=(g18-3)*(g17+2);
  610. g16=b+d;
  611. aa[2][1]=g16*(g17-3);
  612. aa[2][2]=g17*(g16+4);
  613. }
  614. }
  615. end;
  616. Time for test: 295 ms, plus GC time: 7 ms