grgproc.sl 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891
  1. %==========================================================================%
  2. % GRGproc.sl Forms and Vectors Processor %
  3. %==========================================================================%
  4. % GRG 3.2 Standard Lisp Source Code (C) 1988-96 Vadim V. Zhytnikov %
  5. %==========================================================================%
  6. % This file is distributed without any warranty. You may modify it but you %
  7. % are not allowed to remove author's name and/or distribute modified file. %
  8. %==========================================================================%
  9. %---- Main algebraic simplification functionS -----------------------------
  10. (de eval!> (w)
  11. (cond (!*aeval (reval (aeval w)) )
  12. (t (reval w) ) ))
  13. (de raeval!> (w) (reval (aeval w)))
  14. %---------- Algebraic Simplification --------------------------------------
  15. % Algebraic simplification with NIL return ...
  16. (de evalalg!> (w)
  17. (cond ((or (null w) (eqn w 0)) nil)
  18. (t (zn!>(eval!> w)))))
  19. % Alg or Alg Equation simplification ...
  20. (de evalalgx!> (w)
  21. (cond ((and (pairp w) (eq (car w) 'equal))
  22. (equationa!> (cadr w) (caddr w)))
  23. (t (evalalg!> w))))
  24. %---------- Form Simplification -------------------------------------------
  25. % Form simplification ...
  26. (de evalform!> (lst)
  27. (cond ((null lst) nil)
  28. (t (proc (wa wb wc)
  29. (while!> lst
  30. (setq wa (eval!> (caar lst)))
  31. (cond ((not(or (eqn wa 0) (null wa)))
  32. (setq wc (cons (cons wa (cdar lst)) wc)) ))
  33. (setq lst (cdr lst)))
  34. (return (reversip wc))))))
  35. % Alg or Alg Equation simplification ...
  36. (de evalformx!> (w)
  37. (cond ((and (pairp w) (eq (car w) 'equal))
  38. (equationf!> (cadr w) (caddr w)))
  39. (t (evalform!> w))))
  40. % Form simplification with AEVAL ...
  41. (de aevalform!> (lst)
  42. (cond((null lst)nil)
  43. (t(proc(wa wb wc)
  44. (while!> lst
  45. (setq wa(aeval(caar lst)))
  46. (cond((not(or(eqn wa 0)(null wa)))
  47. (setq wc(cons(cons wa(cdar lst))wc)) ))
  48. (setq lst(cdr lst)))
  49. (return(reversip wc))))))
  50. %---------- 0 <-> nil -----------------------------------------------------
  51. (de nz!> (w) (cond (w w) (t 0))) % alg -> alg0
  52. (de zn!> (w) (cond ((eqn w 0) nil)(t w))) % alg0 -> alg
  53. %-------- Multiplication ------------------------------------------------
  54. % Times W * Alg ...
  55. (de multa!> (w wa)
  56. (cond ((or (null w) (null wa)) nil)
  57. ((eqn w 1) wa )
  58. (t (list 'times w wa))))
  59. % Times W * Alg or Alg Equation ...
  60. (de multax!> (w wa)
  61. (cond ((and (pairp wa) (eq (car wa) 'equal))
  62. (equation!> (multa!> w (cadr wa)) (multa!> w (caddr wa))))
  63. (t (multa!> w wa))))
  64. % Times W * Form ...
  65. (de multf!> (w wa)
  66. (cond ((or (null w) (null wa)) nil)
  67. ((eqn w 1) wa )
  68. (t (fndfpr!> w wa))))
  69. % Times W * Form or Form Equation ...
  70. (de multfx!> (w wa)
  71. (cond ((and (pairp wa) (eq (car wa) 'equal))
  72. (equation!> (multf!> w (cadr wa)) (multf!> w (caddr wa))))
  73. (t (multf!> w wa))))
  74. %-------- Summatuon --------------------------------------------------------
  75. % Sum list of Alg ...
  76. (de summa!> (w)
  77. (cond ((null w) nil)
  78. (t (evalalg!> (cons 'plus w)))))
  79. % Sum list of Alg or Alg Equations ...
  80. (de summax!> (w)
  81. (cond ((not(equationp!> w)) (summa!> w))
  82. (t (equation!> (summa!> (mapcar w 'eqleft!>))
  83. (summa!> (mapcar w 'eqright!>))))))
  84. % Sum list of Forms ...
  85. (de summf!> (w)
  86. (cond ((null w) nil)
  87. (t (evalform!> (dfsum!> w)))))
  88. % Sum list of Forms or Forms Equations ...
  89. (de summfx!> (w)
  90. (cond ((not(equationp!> w)) (summf!> w))
  91. (t (equation!> (summf!> (mapcar w 'eqleft!>))
  92. (summf!> (mapcar w 'eqright!>))))))
  93. (de eqleft!> (w) (cond ((pairp w) (cadr w)) (t nil)))
  94. (de eqright!> (w) (cond ((pairp w) (caddr w)) (t nil)))
  95. (de equationp!> (w)
  96. (cond ((null w) nil)
  97. ((null(car w)) (equationp!>(cdr w)))
  98. ((pairp(car w)) (eq (caar w) 'equal))
  99. (t nil)))
  100. % Summation ...
  101. (de algsum!> (w)
  102. (progn
  103. (setq w (algsum1!> w))
  104. (cond ((null w) w)
  105. ((null(cdr w)) (car w))
  106. (t (cons 'plus w)))))
  107. (de algsum1!> (w)
  108. (cond ((null w) nil)
  109. ((null(car w)) (algsum1!>(cdr w)))
  110. (t (cons (car w) (algsum1!>(cdr w))))))
  111. %-------- Equations building functions -------------------------------------
  112. (de equation!> (wl wr) % makes (equal wl wr) or nil if both null ...
  113. (cond ((and (null wl) (null wr)) nil)
  114. (t (list 'equal wl wr))))
  115. (de equationf!> (w1 w2) % form=form with eval ...
  116. (cond((and(null(setq w1(evalform!> w1)))
  117. (null(setq w2(evalform!> w2)))) nil)
  118. (t(list3 'equal w1 w2))))
  119. (de equationf1!> (w1 w2) % form=form -> form-form=0 with eval ...
  120. (cond((null(setq w1
  121. (evalform!>(dfsum!>(list w1 (chsign!> t w2))))))
  122. nil)
  123. (t(list3 'equal w1 nil))))
  124. (de equationa!> (w1 w2) % alg=alg with eval ...
  125. (cond((and(or(null(setq w1(eval!> w1)))(eqn w1 0))
  126. (or(null(setq w2(eval!> w2)))(eqn w2 0)) ) nil)
  127. (t(list3 'equal (zn!> w1) (zn!> w2)))))
  128. (de equationa1!> (w1 w2) % alg=alg -> alg-alg=0 with eval ...
  129. (cond((or(null(setq w1(eval!>(list3 'difference w1 w2))))(eqn w1 0))
  130. nil)
  131. (t(list3 'equal (zn!> w1) nil))))
  132. %------ Forms <-> Reduce matrix conversion support -------------------------
  133. % (LIST of 1-forms) -> Reduce matrix ... 05.96
  134. (de mkmtetr!> (lst)
  135. (cons 'mat
  136. (foreach!> a in (dimlist!> 0) collect
  137. (foreach!> b in (dimlist!> 0) collect
  138. (getfdx!> (getel1!> lst a) b)))))
  139. % Reduce matrix -> tetrad (LIST of 1-forms) ... 05.96
  140. (de mktetrm!> (w ww)
  141. (prog(wa wb wc) (setq wa 0)
  142. (foreach!> x in w do (progn
  143. (setq wa(add1 wa))
  144. (setq wc nil) (setq wb -1)
  145. (foreach!> y in x do (progn (setq wb(add1 wb))
  146. (setq wc(dfsum!>(list2 wc(fndfpr!>(zn!>(eval!> y))(mkdx!> wb)))))))
  147. (putel1!> (evalform!> wc) ww (sub1 wa))))
  148. (return t)))
  149. %----- Matrix Reduce <-> GRG conversion support ----------------------------
  150. (de mat!> (lst) % 05.96 GRG -> Reduce
  151. (cons 'mat
  152. (foreach!> i in (dimlist!> 0) collect
  153. (foreach!> j in (dimlist!> 0) collect
  154. (getel!> lst (list2 i j))))))
  155. (de mats!> (lst) % 05.96 GRG -> Reduce
  156. (cons 'mat
  157. (foreach!> i in (dimlist!> 0) collect
  158. (foreach!> j in (dimlist!> 0) collect
  159. (getel2s!> lst i j)))))
  160. (de matsf!> (fun) % 05.96 GRG -> Reduce
  161. (cons 'mat
  162. (foreach!> i in (dimlist!> 0) collect
  163. (foreach!> j in (dimlist!> 0) collect
  164. (eval (list fun i j))))))
  165. (de rmat!> (lst wm) % 05.96 Reduce -> GRG
  166. (prog (w)
  167. (fordim!> i do (progn
  168. (setq wm (cdr wm))
  169. (setq w (car wm))
  170. (fordim!> j do (progn
  171. (putel!> (zn!>(eval!>(car w))) lst (list2 i j))
  172. (setq w (cdr w))))))))
  173. (de rmats!> (lst wm) % 05.96 Reduce -> GRG
  174. (prog (w)
  175. (fordim!> i do (progn
  176. (setq wm (cdr wm))
  177. (setq w (car wm))
  178. (fordim!> j do (progn
  179. (cond((leq i j)
  180. (putel!> (zn!>(eval!>(car w))) lst (list2 i j))))
  181. (setq w (cdr w))))))))
  182. %---------- Sign Changing --------------------------------------------------
  183. (de chsignf!> (w) (chsign!> t w)) % form
  184. (de chsigna!> (w) (chsign!> nil w)) % alg expression
  185. % Sign changing ... BOOL=T - Form, BOOL=NIL - Alg
  186. (de chsign!> (bool lst)
  187. (cond((null lst) nil)
  188. (bool(mapcar lst 'chsign1!>))
  189. (t(chsign2!> lst))))
  190. (de chsignx!> (wt w)
  191. (cond ((and (pairp w) (eq (car w) 'equal))
  192. (equation!> (chsign!> wt (cadr w)) (chsign!> wt (caddr w))))
  193. (t (chsign!> wt w))))
  194. (de chsign1!> (w)
  195. (cond((and(pairp(car w))(eq(caar w) 'minus))
  196. (cons (cadar w) (cdr w)))
  197. ((numberp(car w))
  198. (cons (minus(car w)) (cdr w)))
  199. (t(cons (list2 'minus(car w)) (cdr w)))))
  200. (de chsign2!> (w)
  201. (cond((and(pairp w)(eq(car w) 'minus)) (cadr w))
  202. ((numberp w) (minus w))
  203. (t (list2 'minus w))))
  204. %---------- Exterior Forms Processor. 10.01.91 ---------------------------
  205. % Exterior forms summation ...
  206. (de dfsum!> (lst)
  207. (cond
  208. ((null lst)nil)
  209. ((null(cdr lst))(car lst))
  210. (t(proc (w ww wt wn wr wx)
  211. (setq w (flcopy!> lst))
  212. (setq ww w)
  213. (loop!>
  214. (setq wn nil)
  215. (setq w ww)
  216. (while!> w
  217. (cond((car w)
  218. (cond((null wn) (setq wn (cadaar w)))
  219. ((lessp(cadaar w)wn) (setq wn (cadaar w))))))
  220. (setq w (cdr w)))
  221. (exitif(null wn))
  222. (setq w ww)
  223. (setq wt nil)
  224. (while!> w
  225. (cond((car w)
  226. (cond((eqn wn (cadaar w))
  227. (progn
  228. (setq wx (cdaar w))
  229. (setq wt (cons (caaar w) wt))
  230. (rplaca w (cdar w)) )))))
  231. (setq w (cdr w)))
  232. (cond((cdr wt)(setq wt (cons (cons 'plus wt) wx)))
  233. (t (setq wt (cons (car wt) wx))))
  234. (setq wr (cons wt wr)) )
  235. (return(reversip wr)) ))))
  236. (de flcopy!> (w)
  237. (cond((null w) nil)
  238. (t(cons (car w) (flcopy!> (cdr w))))))
  239. % alg * form or vector multiplication ...
  240. (de fndfpr!> (alg form)
  241. (cond((or(null form)(zerop alg)(null alg))nil)
  242. ((eqn alg 1) form)
  243. ((eqn alg -1) (chsign!> t form))
  244. (t(proc(wa)
  245. (while!> form
  246. (setq wa
  247. (cons (cons (list 'times alg (caar form)) (cdar form))
  248. wa))
  249. (setq form(cdr form)))
  250. (return(reversip wa))))))
  251. % Exterior product ...
  252. (de dfprod!> (lst)
  253. (cond ((memq nil lst) nil)
  254. ((null(cdr lst)) (car lst))
  255. (t (dfprod2!> (car lst) (dfprod!>(cdr lst))))))
  256. % Exterior product form1/\form2 ...
  257. (de dfprod2!> (frm1 frm2)
  258. (cond((null(and frm1 frm2))nil)
  259. (t(proc (x y wa wb wc w res sgn)
  260. (setq w t)
  261. (while!> frm1
  262. (setq wa frm2)
  263. (while!> frm2
  264. (setq sgn t)
  265. (setq x(cddar frm1))
  266. (setq y(cddar frm2))
  267. (while!> (and x y (null(and(caar x)(caar y)))
  268. (prog2 (and (null(cdr y)) (setq w(not(cdar y))))
  269. t))
  270. (setq wb(cons(cons(or(caar x)(caar y))
  271. (eq(cdar x)(cdar y)))
  272. wb))
  273. (cond((and(caar x)(not(cdar y)))
  274. (setq sgn(not sgn)) ))
  275. (setq x(cdr x))
  276. (setq y(cdr y)) )
  277. (tohead (and x y (caar x) (caar y)
  278. (progn (setq wb nil) (setq frm2(cdr frm2)) t)))
  279. (while!> x
  280. (setq wb(cons(cons(caar x)
  281. (cond((caar wb)(not(cdar wb)))
  282. (t(cdar wb))))
  283. wb))
  284. (cond((and(caar wb)(null w))
  285. (setq sgn(not sgn))))
  286. (setq x(cdr x)))
  287. (while!> y
  288. (setq wb(cons(cons(caar y)
  289. (cond((caar wb)(not(cdar wb)))
  290. (t(cdar wb))))
  291. wb))
  292. (setq y(cdr y)))
  293. (setq x(list3(quote times)(caar frm1)(caar frm2)))
  294. (cond((null sgn)(setq x(list2(quote minus)x))))
  295. (setq y(cons x(cons
  296. (plus(cadar frm1)(cadar frm2))
  297. (reversip wb))))
  298. (setq wc(cons y wc))
  299. (setq wb nil)
  300. (setq frm2(cdr frm2)))
  301. (setq frm1(cdr frm1))
  302. (setq frm2 wa)
  303. (cond(wc(prog2(setq res(cons(reversip wc)res))
  304. (setq wc nil)))) )
  305. (return(dfsum!> res)) )) ))
  306. (de dfsum2!> (wa wb) (dfsum!> (list2 wa wb)))
  307. % Exterior differential d form ...
  308. (de dex!> (frm) (dex1!> frm ![umod!]))
  309. (de dex1!> (frm wm)
  310. (cond ((null frm) nil) (t
  311. (prog(w)
  312. (foreach!> x in frm do (prog2
  313. (setq w (cons (dfprod2!> (dfun1!> (car x) wm)
  314. (ncons (cons 1 (cdr x))) )
  315. w))
  316. (cond (wm (setq w (cons (fndfpr!> (car x) (dexxb!>(cdr x)))
  317. w))))
  318. ))
  319. (return (dfsum!> w))))))
  320. (de dexxb!> (w) % with d(b/\...) accumulation
  321. (proc (wc wr ww)
  322. (setq ww (car w))
  323. (cond ((setq wc (assoc (car w) ![dbas!])) (return(cdr wc)))
  324. (t (setq w (cdr w))))
  325. (setq wc -1)
  326. (while!> w
  327. (setq wc (add1 wc))
  328. (cond ((caar w) (setq wr (cons (getel1!> !#!b wc) wr))))
  329. (setq w (cdr w)))
  330. (setq wr (evalform!>(nbform!>(dex1!>(dfprod!>(reversip wr))nil))))
  331. (setq ![dbas!] (cons (cons ww wr) ![dbas!]))
  332. (return wr)))
  333. %(de dexxb!> (w) % without d(b/\...) accumulation
  334. % (proc (wc wr)
  335. % (setq w (cdr w))
  336. % (setq wc -1)
  337. % (while!> w
  338. % (setq wc (add1 wc))
  339. % (cond((caar w)(setq wr(cons(getel1!> !#!b wc)wr))))
  340. % (setq w (cdr w)))
  341. % (return(nbform!>(dex1!>(dfprod!>(reversip wr))nil)))))
  342. % Exterior differential d Alg ...
  343. (de dfun!> (lst) (dfun1!> lst ![umod!]))
  344. (de dfun1!> (lst wm)
  345. (cond((null lst) nil) (t
  346. (proc (wb wc wd)
  347. (foreach!> x in ![cord!] do (prog2
  348. (setq wd (mkdf!> lst x wm))
  349. (cond (wd
  350. (setq wb
  351. (cons (cons wd (cdar (mkdx!> (get x '!=cord))))
  352. wb))))))
  353. (return(reversip wb)))) ))
  354. (de mkdf!> (lst id wm)
  355. (evalalg!> (cond (wm (bfun!> (getel1!> !#!e (get id '!=cord)) lst))
  356. (t (list3 'df lst id)))))
  357. (de bfun!> (wb lst)
  358. (cond((null lst) nil)
  359. (t(proc (w wn wc)
  360. (while!> wb
  361. (setq wn (cadar wb))
  362. (setq wc -1)
  363. (while!> (not(eqn wn 1))
  364. (setq wn (quotient wn 2))
  365. (setq wc (add1 wc)) )
  366. (setq w(cons(list 'times (caar wb)
  367. (list 'df lst (getel1!> ![cord!] wc)))
  368. w))
  369. (setq wb(cdr wb)))
  370. (return(cond((null w) nil)
  371. ((null(cdr w)) (car w))
  372. (t(cons 'plus w))))))))
  373. %---------- Vectors processor. 08.01.91 ---------------------------------
  374. % Vec _| 1-form ...
  375. (de vform1!> (wv wf)
  376. (cond((or (null wv)(null wf)) nil)
  377. (t(proc (w wa)
  378. (setq wa wf)
  379. (while!> wv
  380. (setq wf wa)(setq wa nil)
  381. (while!> wf
  382. (cond((eqn(cadar wf)(cadar wv))
  383. (setq w(cons(list 'times(caar wf)(caar wv))w)))
  384. (t(setq wa(cons(car wf)wa))))
  385. (setq wf(cdr wf)))
  386. (setq wv(cdr wv)))
  387. (return(cond((null w) nil)
  388. ((null(cdr w)) (car w))
  389. (t(cons 'plus w))))))))
  390. % Vec | Alg ...
  391. (de vfun!> (wv wf)
  392. (cond ((or (null wv) (null wf)) nil)
  393. (t (vfun1!> wv wf ![umod!]))))
  394. %(de vfun0!> (wv wf)
  395. % (cond((or(null wv)(null wf)) nil)
  396. % (t(vfun1!> wv wf nil))))
  397. (de vfun1!> (wv wf wm)
  398. (proc (wb wa x cord)
  399. (setq cord ![cord!])
  400. (while!> (and cord wv)
  401. (setq x (car cord))
  402. (setq cord (cdr cord))
  403. (cond
  404. ((eqn (expt 2 (add1(get x '!=cord))) (cadar wv))
  405. (progn
  406. (setq wa (mkdf!> wf x wm))
  407. (cond(wa
  408. (setq wb
  409. (cons (list 'times (caar wv) wa)
  410. wb))))
  411. (setq wv (cdr wv)) ))))
  412. (return (cond ((null wb) nil)
  413. ((null (cdr wb)) (car wb))
  414. (t (cons 'plus wb))) )))
  415. % Vecr _| n-form for n>1 ...
  416. (de vform!> (wv wf)
  417. (cond((or(null wv)(null wf)) nil)
  418. (t(proc(w wl wa wb wc wss)
  419. (while!> wv
  420. (setq wl wf)
  421. (while!> wl
  422. (setq wa(cddar wv))
  423. (setq wb(cddar wl))
  424. (setq wc nil)
  425. (while!> (and wa wb)
  426. (exitif (and(caar wa)(caar wb)))
  427. (setq wc(cons(car wb)wc))
  428. (setq wa(cdr wa))
  429. (setq wb(cdr wb)))
  430. (cond((and wa wb) (progn
  431. (setq wss(cdar wb))
  432. (setq wc(cons(cons nil(cdar wb))wc))
  433. (setq wb(cdr wb))
  434. (while!> wb
  435. (setq wc(cons(cons(caar wb)(not(cdar wb)))wc))
  436. (setq wb(cdr wb)))
  437. (setq w (cons(ncons(append(list
  438. (list 'times(caar wv)
  439. (cond(wss(caar wl))
  440. (t(list 'minus(caar wl)))))
  441. (difference(cadar wl)(cadar wv)) )
  442. (rever!> wc))) w)) )))
  443. (setq wl(cdr wl)))
  444. (setq wv(cdr wv)))
  445. (return(cond(w(dfsum!> w))
  446. (t nil)))))))
  447. (de rever!>(wc)
  448. (proc(w wss)
  449. (while!> wc
  450. (cond((and(null wss)(null(caar wc))) nil)
  451. (t(prog2(setq wss t)(setq w(cons(car wc)w)))))
  452. (setq wc(cdr wc)))
  453. (return w)))
  454. % [ vec1 , vec2 ] ...
  455. (de vbrack!> (w1 w2)
  456. (cond((and w1 w2)
  457. (dfsum!> (list2 (vcvc!> w1 w2 ![umod!])
  458. (chsign!> t (vcvc!> w2 w1 ![umod!])))))
  459. (t nil)))
  460. (de vcvc!> (w1 w2 wm)
  461. (proc (w wc ww wa)
  462. (while!> w2
  463. (setq wc (vfun1!> w1 (caar w2) wm))
  464. (cond (wc (setq w (cons (cons wc (cdar w2)) w))))
  465. (cond (wm
  466. (cond ((setq wa (vcb!> w1 (sub1(log2!>(cadar w2)))))
  467. (setq ww (cons (fndfpr!> (caar w2) wa) ww))))))
  468. (setq w2 (cdr w2)))
  469. (return (cond ((and wm ww) (dfsum!> (cons (reversip w) ww)))
  470. (t (reversip w))))))
  471. (de vcb!> (w1 we)
  472. (cond ((null w1) nil)
  473. (t(proc (wa w)
  474. (setq we (getel1!> !#!e we))
  475. (while!> w1
  476. (setq wa (vcvc!> (getel1!> !#!e (sub1(log2!>(cadar w1))))
  477. we nil))
  478. (cond (wa
  479. (setq w (cons (fndfpr!> (caar w1) (nbvec!> wa)) w))))
  480. (setq w1 (cdr w1)))
  481. (return (cond (w (dfsum!> w))
  482. (t nil)))))))
  483. %---------- Complex conjugation. 25.12.90 --------------------------------
  484. (de coexpr!> (wt w) % wt - type, 0 alg, n form, -1 vector
  485. (cond ((eqn wt 0) (coalg!> w))
  486. ((eqn wt -1) (covec!> w))
  487. (t (coform!> w))))
  488. (de coexprx!> (wt w)
  489. (cond ((and (pairp w) (eq (car w) 'equal))
  490. (equation!> (coexpr!> wt (cadr w))
  491. (coexpr!> wt (caddr w))))
  492. (t (coexpr!> wt w))))
  493. % Conjugation of Alg ...
  494. (de coalg!> (w)
  495. (cond ((atom w)
  496. (cond ((or (eq w '!*sq) (eq w 'taylor!*))
  497. (err!> 9999)) % *sq form !!!
  498. ((eq w 'i) '(minus i)) % i -> -i
  499. ((get w '!=conj) (get w '!=conj)) % x~ -> x, x -> x~
  500. (t w))) % y -> y
  501. (t (mapcar w 'coalg!>))))
  502. % Conjugation of Form ...
  503. (de coform!> (wf) (cofv!> wf ![ccb!]))
  504. % Conjugation of Vector ...
  505. (de covec!> (wf) (cofv!> wf ![ccbi!]))
  506. (de cofv!> (wf wb)
  507. (cond ((null wf) nil)
  508. (t(proc (w wa wp wx wn)
  509. (while!> wf
  510. (setq wa (coalg!>(caar wf)))
  511. (setq wx (cddar wf)) % wx = d x/\d y ...
  512. (setq wp nil)
  513. (setq wn -1)
  514. (while!> wx
  515. (setq wn (add1 wn))
  516. (cond((caar wx)
  517. (setq wp (cons
  518. (cond (![umod!] (getel1!> wb wn))
  519. (t (mkdx!>
  520. (get (coalg!>(getel1!> ![cord!] wn)) '!=cord))))
  521. wp))))
  522. (setq wx (cdr wx)))
  523. (setq wp (dfprod!>(reversip wp))) % wp = (d x/\d y ...)~
  524. (setq w (cons (fndfpr!> wa wp) w))
  525. (setq wf (cdr wf)))
  526. (return(evalform!>(dfsum!> w)))))))
  527. %---------- Vector Product 09.96 -------------------------------------------
  528. % vec.vec Need !#G !#T
  529. (de vprod!> (wa wb)
  530. (prog (w wx wy)
  531. (fordim!> m do (progn
  532. (setq wx (vform1!> wa (getframe!> m)))
  533. (setq wy (vform1!> wb (getlo!> !#!T m)))
  534. (cond ((and wx wy) (setq w (cons (list 'times wx wy) w))))))
  535. (return (cond (w (cons 'plus w)) (t nil)))))
  536. % frm1.frm1 Need !#D !#GI
  537. (de fprod!> (wa wb)
  538. (prog (w wx wy)
  539. (fordim!> m do (progn
  540. (setq wx (vform1!> (getiframe!> m) wa))
  541. (setq wy (vform1!> (getup!> !#!D m) wb))
  542. (cond ((and wx wy) (setq w (cons (list 'times wx wy) w))))))
  543. (return (cond (w (cons 'plus w)) (t nil)))))
  544. %---------- Dualisation 05.96 ----------------------------------------------
  545. % Dualisation #(alg) -> dim-form ...
  546. % Use: !#VOL
  547. (de dual0!> (w)
  548. (cond ((null w) nil)
  549. (t (fndfpr!> w (car !#!V!O!L)))))
  550. % Dualisation #(dim-form) -> alg ...
  551. % Use: !#VOL
  552. (de duald!> (w)
  553. (cond ((null w) nil)
  554. (t (list 'times (invsvol!>) (caar w)))))
  555. % version for spinorial regime only = - i #
  556. (de dualdi!> (w)
  557. (cond ((null w) nil)
  558. (t (list 'times (invsvoli!>) (caar w)))))
  559. (de invsvol!> nil
  560. (cond ((null(car !#!V!O!L)) 0)
  561. (t (list 'quotient ![sigprod!] (caaar !#!V!O!L)))))
  562. (de invsvoli!> nil
  563. (cond ((null(car !#!V!O!L)) 0)
  564. (t (list 'quotient 'i (caaar !#!V!O!L)))))
  565. % Defines P of the P-form ...
  566. (de pformq!> (w)
  567. (proc (wp)
  568. (cond ((null w) (return 0)))
  569. (setq wp 0)
  570. (setq w (cddar w))
  571. (while!> w
  572. (cond ((caar w) (setq wp (add1 wp))))
  573. (setq w (cdr w)))
  574. (return wp)))
  575. % Dualisation #(p-form) -> (dim-p)-form ...
  576. % Use: !#sdetG !#G !#T !#VOL
  577. (de dual!> (w)
  578. (cond ((null w) nil)
  579. (t(proc (wp wdp wr wl wf wc)
  580. (setq wp (pformq!> w)) % We are dualizing p-form=wp
  581. (cond ((eqn wp ![dim!]) (return (duald!> w))))
  582. (setq wdp (difference ![dim!] wp)) % to (dim-p)-form
  583. (setq ![tlow!] % List of T_a (lower index a)
  584. (foreach!> x in (dimlist!> 0) collect (getlo!> !#!T x)))
  585. (setq wl (mklambda!> wdp ![dim!])) % All T_a/\... (dim-p)-forms
  586. (setq wf (invsvol!>)) % The coefficient
  587. (while!> wl
  588. (setq wc (dfprod2!> (cdar wl) w))
  589. (cond (wc (setq wr (cons (fndfpr!> (list 'times wf (caar wc))
  590. (tprod!> (caar wl)))
  591. wr))))
  592. (setq wl (cdr wl)))
  593. (return (dfsum!> wr)) ))))
  594. (de mklambda!> (wp wd)
  595. (proc (wr ww wc wn wi wa)
  596. (setq wr (mklist!> (sub1 wp) (sub1 wd)))
  597. (setq wr (mapcar wr 'lform1!>))
  598. (setq wi (sub1 wp))
  599. (while!> (greaterp wi 0)
  600. (setq ww nil)
  601. (while!> wr
  602. (setq wc (car wr))
  603. (setq wn (mklist!> (sub1 wi) (sub1(caar wc))))
  604. (while!> wn
  605. (setq wa (car wn))
  606. (setq ww (cons (cons (cons wa (car wc))
  607. (dfprod2!> (getel1!> ![tlow!] wa)
  608. (cdr wc)))
  609. ww))
  610. (setq wn (cdr wn)))
  611. (setq wr (cdr wr)))
  612. (setq wr (reversip ww))
  613. (setq wi (sub1 wi)))
  614. (return wr)))
  615. (de lform1!> (w) (cons (ncons w) (getel1!> ![tlow!] w)))
  616. (de tprod!> (w)
  617. (cond ((null(cdr w)) (getframe!> (car w)))
  618. (t (dfprod2!> (getframe!> (car w))
  619. (tprod!> (cdr w))))))
  620. (de mklist!> (wa wb)
  621. (cond ((greaterp wa wb) nil)
  622. (t (cons wa (mklist!> (add1 wa) wb)))))
  623. %---------- Limits ---------------------------------------------------------
  624. % Limits 6.03.94 ...
  625. %(de lima!> (wx wl wt lst)
  626. % (cond((null lst) nil)
  627. % ((eq wt 'p) (list 'limit!+ lst wx wl))
  628. % ((eq wt 'm) (list 'limit!- lst wx wl))
  629. % (t (list 'limit lst wx wl))))
  630. %
  631. %(de limf!> (wx wl wt lst)
  632. % (cond((null lst) nil)
  633. % (t(proc (wr)
  634. % (while!> lst
  635. % (setq wr (cons (cons (lima!> wx wl wt (caar lst))
  636. % (cdar lst)) wr))
  637. % (setq lst (cdr lst)))
  638. % (return(reversip wr))))))
  639. %---------- SUBstitutions 7.03.94 -----------------------------------------
  640. (de subalg!> (wl lst)
  641. (cond((null lst) nil)
  642. (t(cons 'sub (append wl (ncons lst))))))
  643. (de subdf!> (wl lst)
  644. (cond((null lst) nil)
  645. (t(proc (wr)
  646. (while!> lst
  647. (setq wr (cons (cons (subalg!> wl(caar lst))
  648. (cdar lst)) wr))
  649. (setq lst (cdr lst)))
  650. (return(reversip wr))))))
  651. %-------- Anholonomic Mode 04.03.91, 05.96 --------------------------------
  652. % Anholonomic/Holonomic command ...
  653. (de turnbg!> (wm)
  654. (prog2
  655. (setq wm (errorset!> (list 'turnbg0!> wm) ![erst1!] ![erst2!]))
  656. (cond ((atom wm) (erm!> wm) (erm!> 8803) (msg!> 88033) !!er!!)
  657. (t (car wm))) ))
  658. (de turnbg0!> (wm)
  659. (proc (w)
  660. (cond((eq wm ![umod!]) (progn % current mode ?
  661. (prin2 "Current Basis is ")
  662. (cond(![umod!](prin2 "an")))
  663. (prin2 "holonomic already.")(terpri)
  664. (return t))))
  665. (setq ![chain!] nil)
  666. (setq w (request!> '!#!b)) % basis ?
  667. (cond((eq w !!er!!) (return w))
  668. ((null w) (trsf!> '!#!b)(setq ![er!] 6046)(return !!er!!)))
  669. (setq ![chain!] nil)
  670. (setq w (request!> '!#!e)) % inverse basis ?
  671. (cond((eq w !!er!!) (return w))
  672. ((null w) (trsf!> '!#!b)(setq ![er!] 6046)(return !!er!!)))
  673. (setq w (evalform!>(dfprod!> !#!b))) % singular basis ?
  674. (cond ((null w) (prog2 (setq ![er!] 8400) (return !!er!!))))
  675. (setq w (evalform!>(dfprod!> !#!e))) % singilar inverse basis ?
  676. (cond ((null w) (prog2 (setq ![er!] 8401) (return !!er!!))))
  677. (cond (wm (mktables!>))
  678. (t (prog2 (setq ![xf!] !#!b) % b = d x
  679. (setq ![xv!] !#!e)))) % e = @ x
  680. (setq ![xb!] nil)
  681. (setq w (altdata!>(alldata!>)))
  682. (while!> w % converting all data to new basis ...
  683. (cond ((or (memq (car w) '( ![cord!] ![const!] ![fun!] ![apar!]
  684. !#!b !#!e))
  685. (zerop (gettype!> (car w)))) nil)
  686. (t (set (car w)
  687. (allcoll!> (eval(car w)) (car w) nil
  688. (cond((get (car w) '!=idxl)(get (car w) '!=idxl))
  689. (t '(0)))
  690. (function nbel!>))) ))
  691. (setq w (cdr w)))
  692. (setq ![umod!] wm)
  693. (cond ((null wm) (progn
  694. (setq ![ccb!] nil)
  695. (setq ![ccbi!] nil)
  696. (setq ![xv!] nil)
  697. (setq ![xf!] nil))))
  698. (ftype!>)
  699. (fitype!>)
  700. (done!>)
  701. (return t)))
  702. % New basis for element ...
  703. (de nbel!> (lst wi wn)
  704. (cond ((null lst) nil)
  705. ((and (eqn (gettype!> wn) -1) (not (flagp wn '!+equ))) % vec
  706. (nbvec!> lst))
  707. ((not (flagp wn '!+equ)) % form
  708. (nbform!> lst))
  709. ((eqn (gettype!> wn) -1) % eq vec
  710. (equation!> (nbvec!>(cadr lst)) (nbvec!>(caddr lst))))
  711. (t % eq form
  712. (equation!> (nbform!>(cadr lst)) (nbform!>(caddr lst))))
  713. ))
  714. % New basis for form ...
  715. (de nbform!> (w)
  716. (cond ((null w) w)
  717. (t (evalform!> (dfsum!> (mapcar w (function nbform1!>)))))))
  718. (de nbform1!> (w)
  719. (fndfpr!> (car w)
  720. (nbxb!> (cdr w))))
  721. % New basis for d X/\d Y/\...
  722. (de nbxb!> (w)
  723. (cond
  724. ((assoc (car w) ![xb!]) (cadr (assoc (car w) ![xb!])))
  725. (t (progn
  726. (setq ![xb!] (cons (list2 (car w) (evalform!> (mkbxb!>(cdr w) )))
  727. ![xb!]))
  728. (cadar ![xb!])))))
  729. (de mkbxb!> (w)
  730. (proc (wa wn)
  731. (setq wn 0)
  732. (while!> w
  733. (cond ((caar w)
  734. (setq wa (cons (getel1!> ![xf!] wn) wa))))
  735. (setq wn (add1 wn))
  736. (setq w (cdr w)))
  737. (return (evalform!> (dfprod!>(reverse wa))))))
  738. (de mktables!> nil
  739. (prog (w)
  740. (setq ![xf!] (mkt!> 1))
  741. (setq w (aeval (list 'quotient 1 (mkmtetr!> !#!b))))
  742. (mktetrm!> (cdr w) ![xf!]) % d x = b
  743. (setq ![xv!] (mkt!> 1))
  744. (setq w (aeval (list 'tp (mkmtetr!> !#!b))))
  745. (mktetrm!> (cdr w) ![xv!]) % @ x = e
  746. (setq ![ccb!] % ~ b
  747. (mapcar (mapcar !#!b 'coform!>) (function nbform!>)))
  748. (setq ![ccbi!] % ~ e
  749. (mapcar (mapcar !#!e 'coform!>) (function nbvec!>)))
  750. ))
  751. % New basis for vector ...
  752. (de nbvec!> (w)
  753. (cond ((null w) w)
  754. (t (evalform!> (dfsum!> (mapcar w (function nbvec1!>)))))))
  755. (de nbvec1!> (w)
  756. (fndfpr!> (car w)
  757. (nbxv!> (cadr w))))
  758. (de nbxv!> (w)
  759. (proc (wc)
  760. (setq wc -1)
  761. (while!> (not (eqn w 1))
  762. (setq w (quotient w 2))
  763. (setq wc (add1 wc)) )
  764. (return (getel1!> ![xv!] wc)) ))
  765. %========= End of GRGproc.sl ==============================================%