cantens.tst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. % Test of CANTENS.RED
  2. %
  3. % Authors: H. Caprasse <hubert.caprasse@ulg.ac.be>
  4. %
  5. % Version and Date: Version 1.1, 15 September 1998.
  6. %----------------------------------------------------------------
  7. off errcont;
  8. % Default :
  9. onespace ?;
  10. wholespace_dim ?;
  11. global_sign ? ;
  12. signature ?;
  13. % answers to the 4 previous commands: yes, dim, 1, 0
  14. wholespace_dim 4;
  15. signature 1;
  16. global_sign(-1);
  17. % answers to the three previous commands: 4, 1, (-1)
  18. % answer to the command below: {}
  19. show_spaces();
  20. % Several spaces:
  21. off onespace;
  22. onespace ?;
  23. % answer: no
  24. show_spaces();
  25. define_spaces wholespace={6,signature=1,indexrange=0 .. 5};
  26. % indexrange command is superfluous since 'wholespace':
  27. show_spaces();
  28. rem_spaces wholespace;
  29. define_spaces wholespace={11,signature=1};
  30. define_spaces mink={4,signature=1,indexrange=0 .. 3};
  31. define_spaces eucl={6,euclidian,indexrange=4 .. 9};
  32. show_spaces();
  33. %
  34. % if input error or modifications necessary:
  35. %
  36. define_spaces eucl={7,euclidian,indexrange=4 .. 10};
  37. %
  38. % do:
  39. %
  40. rem_spaces eucl;
  41. define_spaces eucl={7,euclidian,indexrange=4 .. 10};
  42. show_spaces();
  43. % done
  44. %
  45. define_spaces eucl1={1,euclidian,indexrange=11 .. 11};
  46. show_spaces();
  47. rem_spaces wholespace,mink,eucl,eucl1;
  48. show_spaces();
  49. %
  50. % Indices can be made to belong to a subspace or replaced
  51. % in the whole space:
  52. define_spaces eucl={3,euclidean};
  53. show_spaces();
  54. mk_ids_belong_space({a1,a2},eucl);
  55. % a1,a2 belong to the subspace eucl.
  56. mk_ids_belong_anyspace a1,a2;
  57. % replaced in the whole space.
  58. rem_spaces eucl;
  59. %%
  60. %% GENERIC TENSORS:
  61. on onespace;
  62. wholespace_dim dim;
  63. tensor te;
  64. te(3,a,-4,b,-c,7);
  65. te(3,a,{x,y},-4,b,-c,7);
  66. te(3,a,-4,b,{u,v},-c,7);
  67. te({x,y});
  68. make_variables x,y;
  69. te(x,y);
  70. te(x,y,a);
  71. remove_variables x;
  72. te(x,y,a);
  73. remove_variables y;
  74. %
  75. % implicit dependence:
  76. %
  77. operator op2;
  78. depend op1,op2(x);
  79. df(op1,op2(x));
  80. % the next response is 0:
  81. df(op1,op2(y));
  82. clear op2;
  83. % case of a tensor:
  84. operator op1;
  85. depend te,op1(x);
  86. df(te(a,-b),op1(x));
  87. % next the outcome is 0:
  88. df(te(a,-b),op1(y));
  89. %
  90. tensor x;
  91. depend te,x;
  92. % outcome is NOT 0:
  93. df(te(a,-b),x(c));
  94. %
  95. % Substitutions:
  96. sub(a=-c,te(a,b));
  97. sub(a=-1,te(a,b));
  98. % the following operation is wrong:
  99. sub(a=-0,te(a,b));
  100. % should be made as following to be correct:
  101. sub(a=-!0,te(a,b));
  102. % dummy indices recognition
  103. dummy_indices();
  104. te(a,b,-c,-a);
  105. dummy_indices();
  106. te(a,b,-c,-a);
  107. dummy_indices();
  108. % hereunder an error message correctly occurs:
  109. on errcont;
  110. te(a,b,-c,a);
  111. off errcont;
  112. sub(c=b,te(a,b,-c,-a));
  113. dummy_indices();
  114. % dummy indices suppression:
  115. on errcont;
  116. te(d,-d,d);
  117. off errcont;
  118. dummy_indices();
  119. rem_dummy_indices d;
  120. te(d,d);
  121. dummy_indices();
  122. rem_dummy_indices a,b;
  123. onespace ?;
  124. % case of space of integer dimension:
  125. wholespace_dim 4;
  126. signature 0;
  127. % 7 out of range
  128. on errcont;
  129. te(3,a,-b,7);
  130. off errcont;
  131. te(3,a,-b,3);
  132. te(4,a,-b,4);
  133. % an 'out-of-range' error is issued:
  134. on errcont;
  135. sub(a=5,te(3,a,-b,3));
  136. off errcont;
  137. signature 1;
  138. % now indices should run from 0 to 3 => error:
  139. on errcont;
  140. te(4,a,-b,4);
  141. off errcont;
  142. % correct:
  143. te(0,a,-b,3);
  144. %
  145. off onespace;
  146. define_spaces wholespace={4,euclidean};
  147. % We MUST say that te BELONG TO A SPACE, here to wholespace:
  148. make_tensor_belong_space(te,wholespace);
  149. on errcont;
  150. te(a,5,-b);
  151. off errcont;
  152. te(a,4,-b);
  153. rem_spaces wholespace;
  154. define_spaces wholespace={5,signature=1};
  155. define_spaces eucl={1,signature=0};
  156. show_spaces();
  157. make_tensor_belong_space(te,eucl);
  158. te(1);
  159. % hereunder, an error message is issued:
  160. on errcont;
  161. te(2);
  162. off errcont;
  163. % hereunder, an error message should be issued, it is not
  164. % because no indexrange has been declared:
  165. te(0);
  166. rem_spaces eucl;
  167. define_spaces eucl={1,signature=0,indexrange=1 .. 1};
  168. % NOW an error message is issued:
  169. on errcont;
  170. te(0);
  171. off errcont;
  172. te(1);
  173. % again an error message:
  174. on errcont;
  175. te(2);
  176. off errcont;
  177. %
  178. rem_dummy_indices a,b,c,d;
  179. % symmetry properties:
  180. %
  181. symmetric te;
  182. te(a,-b,c,d);
  183. remsym te;
  184. antisymmetric te;
  185. te(a,b,-c,d);
  186. remsym te;
  187. % mixed symmetries:
  188. tensor r;
  189. %
  190. symtree(r,{!+,{!-,1,2},{!-,3,4}});
  191. ra:=r(b,a,c,d)$
  192. canonical ra;
  193. ra:=r(c,d,a,b)$
  194. canonical ra;
  195. % here canonical is short-cutted
  196. ra:=r(b,b,c,a);
  197. %
  198. % symmetrization:
  199. on onespace;
  200. symmetrize(r(a,b,c,d),r,permutations,perm_sign);
  201. canonical ws;
  202. off onespace;
  203. symmetrize({a,b,c,d},r,cyclicpermlist);
  204. canonical ws;
  205. rem_tensor r;
  206. % Declared bloc-diagonal tensor:
  207. rem_spaces wholespace,eucl;
  208. define_spaces wholespace={7,signature=1};
  209. define_spaces mink={4,signature=1,indexrange=0 .. 3};
  210. define_spaces eucl={3,euclidian,indexrange=4 .. 6};
  211. show_spaces();
  212. make_tensor_belong_space(te,eucl);
  213. make_bloc_diagonal te;
  214. mk_ids_belong_space({a,b,c},eucl);
  215. te(a,b,z);
  216. mk_ids_belong_space({m1,m2},mink);
  217. te(a,b,m1);
  218. te(a,b,m2);
  219. mk_ids_belong_anyspace a,b,c,m1,m2;
  220. te(a,b,m2);
  221. % how to ASSIGN a particular component ?
  222. % take the simplest context:
  223. rem_spaces wholespace,mink,eucl;
  224. on onespace;
  225. te({x,y},a,-0)==x*y*te(a,-0);
  226. te({x,y},a,-0);
  227. te({x,y},a,0);
  228. % hereunder an error message is issued because already assigned:
  229. on errcont;
  230. te({x,y},a,-0)==x*y*te(a,-0);
  231. off errcont;
  232. % clear value:
  233. rem_value_tens te({x,y},a,-0);
  234. te({x,y},a,-0);
  235. te({x,y},a,-0)==(x+y)*te(a,-0);
  236. % A small illustration
  237. te(1)==sin th * cos phi;
  238. te(-1)==sin th * cos phi;
  239. te(2)==sin th * sin phi;
  240. te(-2)==sin th * sin phi;
  241. te(3)==cos th ;
  242. te(-3)==cos th ;
  243. for i:=1:3 sum te(i)*te(-i);
  244. rem_value_tens te;
  245. te(2);
  246. let te({x,y},-0)=x*y;
  247. te({x,y},-0);
  248. te({x,y},0);
  249. te({x,u},-0);
  250. for all x,a let te({x},a,-b)=x*te(a,-b);
  251. te({u},1,-b);
  252. te({u},c,-b);
  253. te({u},b,-b);
  254. te({u},a,-a);
  255. for all x,a clear te({x},a,-b);
  256. te({u},c,-b);
  257. % rule for indices only
  258. for all a,b let te({x},a,-b)=x*te(a,-b);
  259. te({x},c,-b);
  260. te({x},a,-a);
  261. % A BUG still exists for -0 i.e. rule does NOT apply:
  262. te({x},a,-0);
  263. % the cure is to use -!0 in this case
  264. te({x},0,-!0);
  265. %
  266. % local rules:
  267. %
  268. rul:={te(~a) => sin a};
  269. te(1) where rul;
  270. %
  271. rul1:={te(~a,{~x,~y}) => x*y*sin(a)};
  272. %
  273. te(a,{x,y}) where rul1;
  274. te({x,y},a) where rul1;
  275. %
  276. rul2:={te(-~a,{~x,~y}) => x*y*sin(-a)};
  277. %
  278. te(-a,{x,y}) where rul2;
  279. te({x,y},-a) where rul2;
  280. %% CANONICAL
  281. %
  282. % 1. Coherence of tensorial indices.
  283. %
  284. tensor te,tf;
  285. dummy_indices();
  286. make_tensor_belong_anyspace te;
  287. on errcont;
  288. bb:=te(a,b)*te(-b)*te(b);
  289. % hereunder an error message is issued:
  290. canonical bb;
  291. off errcont;
  292. bb:=te(a,b)*te(-b);
  293. % notice how it is rewritten by canonical:
  294. canonical bb;
  295. %
  296. dummy_indices();
  297. aa:=te(d,-c)*tf(d,-c);
  298. % if a and c are FREE no error message:
  299. canonical aa;
  300. % do NOT introduce powers for NON-INVARIANT tensors:
  301. aa:=te(d,-c)*te(d,-c);
  302. % Powers are taken away
  303. canonical aa;
  304. % A trace CANNOT be squared because powers are removed by 'canonical':
  305. cc:=te(a,-a)^2$
  306. canonical cc;
  307. %
  308. % Correct writing of the previous squared:
  309. cc:=te(a,-a)*te(b,-b)$
  310. canonical cc;
  311. % all terms must have the same variance:
  312. on errcont;
  313. aa:=te(a,c)+x^2;
  314. canonical aa;
  315. aa:=te(a,b)+tf(a,c);
  316. canonical aa;
  317. off errcont;
  318. dummy_indices();
  319. rem_dummy_indices a,b,c;
  320. dummy_indices();
  321. % a dummy VARIABLE is NOT a dummy INDEX
  322. dummy_names b;
  323. dummy_indices();
  324. % so, no error message in the following:
  325. canonical(te(b,c)*tf(b,c));
  326. % it is an incorrect input for a variable.
  327. % correct input is:
  328. canonical(te({b},c)*tf({b},c));
  329. clear_dummy_names;
  330. % contravariant indices are placed before covariant ones if possible.
  331. % i.e. Riemanian spaces by default:
  332. pp:=te(a,-a)+te(-a,a)+1;
  333. canonical pp;
  334. pp:=te(a,-c)+te(-b,b,a,-c);
  335. canonical pp;
  336. pp:=te(r,a,-f,d,-a,f)+te(r,-b,-c,d,b,c);
  337. canonical pp;
  338. % here, a case where a normal form cannot be obtained:
  339. tensor nt;
  340. a1:=nt(-a,d)*nt(-c,a);
  341. a2:=nt(-c,-a)*nt(a,d);
  342. % obviously, a1-a2 =0, but ....
  343. canonical(a1-a2);
  344. % does give the same expression with the sign changed.
  345. % zero is either:
  346. canonical a1 -a2;
  347. % or
  348. a1 -canonical a2;
  349. % below the result is a2:
  350. canonical a1;
  351. % below result is a1 again:
  352. canonical ws;
  353. % the above manipulations are NOT DONE if space is AFFINE
  354. off onespace;
  355. define_spaces aff={dd,affine};
  356. make_tensor_belong_space(te,aff);
  357. % dummy indices MUST be declared to belong
  358. % to a well defined space. here to 'aff':
  359. mk_ids_belong_space({a,b},aff);
  360. canonical(te(-a,a));
  361. canonical(te(-a,a)+te(b,-b));
  362. canonical(te(-a,c));
  363. % put back the system in the previous status:
  364. make_tensor_belong_anyspace te;
  365. mk_ids_belong_anyspace a,b;
  366. rem_spaces aff;
  367. on onespace;
  368. %
  369. % 2. Summations with DELTA tensor.
  370. %
  371. make_partic_tens(delta,delta);
  372. aa:=delta(a,-b)*delta(b,-c)*delta(c,-a) + 1;
  373. % below, answer is dim+1:
  374. canonical aa;
  375. aa:=delta(a,-b)*delta(b,-c)*delta(c,-d)*te(d,e)$
  376. canonical aa;
  377. % 3. Summations with DELTA and ETA tensors.
  378. make_partic_tens(eta,eta);
  379. signature 1;
  380. aa:=eta(a,b)*eta(-b,-c);
  381. canonical aa;
  382. aa:=eta(a,b)*eta(-b,-c)*eta(c,d);
  383. canonical aa;
  384. aa:=eta(a,b)*eta(-b,-c)*eta(d,c)*te(d,-a) +te(d,d);
  385. canonical aa;
  386. aa:=delta(a,-b)*eta(b,c);
  387. canonical aa;
  388. aa:=delta(a,-b)*delta(d,-a)*eta(-c,-d)*eta(b,c);
  389. % below the answer is dim:
  390. canonical aa;
  391. aa:=delta(a,-b)*delta(d,-a)*eta(-d,-e)*te(f,g,e);
  392. canonical aa;
  393. % Summations with the addition of the METRIC tensor:
  394. make_partic_tens(g,metric);
  395. g(1,2,{x})==1/4*sin x;
  396. g({x},1,2);
  397. aa:=g(a,b)*g(-a,-c);
  398. canonical aa;
  399. aa:=g(a,b)*g(c,d)*eta(-c,-b);
  400. % answer is g(a,d):
  401. canonical aa;
  402. tensor te;
  403. aa:=g(a,b)*g(c,d)*eta(-c,-e)*eta(e,f)*te(-f,g);
  404. canonical aa;
  405. % Summations with the addition of the EPSILON tensor.
  406. dummy_indices();
  407. rem_dummy_indices a,b,c,f;
  408. dummy_indices();
  409. wholespace_dim ?;
  410. signature ?;
  411. % define the generalized delta function:
  412. make_partic_tens(gd,del);
  413. make_partic_tens(epsilon,epsilon);
  414. aa:=epsilon(a,b)*epsilon(-c,-d);
  415. % Minus sign reflects the chosen signature.
  416. canonical aa;
  417. aa:=epsilon(a,b)*epsilon(-a,-b);
  418. canonical aa;
  419. aa:=epsilon(a,b,c,d)*epsilon(-a,-b,-c,-e);
  420. canonical aa;
  421. on exdelt;
  422. % extract delta function down to the bottom:
  423. aa:=epsilon(a,b,c)*epsilon(-b,-d,-e);
  424. canonical aa;
  425. off exdelt;
  426. % below expressed in terms of 'gd' tensor.
  427. canonical aa;
  428. rem_dummy_indices a;
  429. aa:=epsilon(- b,-c)*eta(a,b)*eta(a,c);
  430. % answer below is zero:
  431. canonical aa;
  432. aa:=epsilon(a,b,c)*te(-a)*te(-b);
  433. % below the result is again zero.
  434. canonical aa;
  435. %
  436. tensor tf,tg;
  437. aa:=epsilon(a,b,c)*te(-a)*tf(-b)*tg(-c)+epsilon(d,e,f)*te(-d)*tf(-e)*tg(-f);
  438. % below the result is twice the first term.
  439. canonical aa;
  440. aa:=epsilon(a,b,c)*te(-a)*tf(-c)*tg(-b)+epsilon(d,e,f)*te(-d)*tf(-e)*tg(-f);
  441. % below the result is zero.
  442. canonical aa;
  443. % An illustration when working inside several spaces.
  444. rem_dummy_indices a,b,c,d,e,f;
  445. off onespace;
  446. define_spaces wholespace={dim,signature=1};
  447. define_spaces sub4={4,signature=1};
  448. define_spaces subd={dim-4,signature=0};
  449. show_spaces();
  450. make_partic_tens(epsilon,epsilon);
  451. make_tensor_belong_space(epsilon,sub4);
  452. make_partic_tens(kappa,epsilon);
  453. make_tensor_belong_space(kappa,subd);
  454. show_epsilons();
  455. mk_ids_belong_space({i,j,k,l,m,n,r,s},sub4);
  456. mk_ids_belong_space({a,b,c,d,e,f},subd);
  457. off exdelt;
  458. aa:=kappa(a,b,c)*kappa(-d,-e,-f)*epsilon(i,j,k,l)*epsilon(-k,-l,-i,-j);
  459. canonical aa;
  460. aa:=kappa(a,b,c)*kappa(-d,-e,-f)*epsilon(i,j,k,l)*epsilon(-m,-n,-r,-s);
  461. canonical aa;
  462. end;