checkind.red 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. module checkind;
  2. % This modules contains procedures to detect indices,
  3. % check the coherence (variance) of expressions (sum), (free indices)
  4. % declares repeated (1 cov and 1 cont) indices as dummy.
  5. global '(spaces!*);
  6. fluid('(dummy_id!* g_dvnames epsilon!*));
  7. symbolic procedure split_free_dum_ids(ltens);
  8. % ltens est la liste qui provient de sep_tens_from_other.
  9. % result of all_index_lst is the full set of indices.
  10. % verify the consistency of the list of dummy indices.
  11. % output the list (<ordered set of free indices>,<set of dummy indices>)
  12. begin scalar ind,dumlist,freelist;
  13. ind:=split_cov_cont_ids all_index_lst ltens;
  14. ind:=list(clean_numid car ind,clean_numid cadr ind);
  15. dumlist:=intersection(car ind,cadr ind);
  16. verify_tens_ids ind where dummy_id!*=dumlist;
  17. % construct the list of covariant FREE indices:
  18. freelist:=for each y in setdiff(car ind,dumlist)
  19. collect lowerind y;
  20. % add to it the list of contravariant FREE indices
  21. freelist:=append(freelist,setdiff(cadr ind,dumlist));
  22. return list(ordn freelist,dumlist);
  23. end;
  24. symbolic procedure check_ids(sf);
  25. % check the variance consistency of the input SF
  26. begin scalar dumlist, freelist, y;
  27. freelist:='undefined;
  28. while not domainp (sf) do
  29. <<
  30. y:=sep_tens_from_other (lt sf .+ nil);
  31. if length car y >=1
  32. then
  33. << % There are tensors, get dummy and free indices, compare
  34. y:= split_free_dum_ids car y;
  35. if freelist='undefined then freelist:=car y
  36. else
  37. if freelist neq car y then rerror(cantens,11,
  38. list("mismatch in free indices : ",
  39. list(car y, freelist)));
  40. dumlist:= union(dumlist, cadr y)
  41. >>
  42. else
  43. % no FREE indices
  44. if freelist then
  45. if freelist = 'undefined then freelist:=nil
  46. else rerror(cantens,11,"scalar added with tensor(s)");
  47. sf:=red sf
  48. >>;
  49. if freelist neq 'undefined then
  50. if (y:=repeats freelist) and extract_dummy_ids y then
  51. rerror(cantens,12,list("wrong use of indices",y));
  52. return
  53. if freelist='undefined or null freelist then list(nil,dumlist)
  54. else
  55. if sf then rerror(cantens,12,"scalar added with tensor(s)")
  56. else list(freelist,dumlist)
  57. end;
  58. endmodule;
  59. end;