crlinalg.red 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. %********************************************************************
  2. module linalgsys$
  3. %********************************************************************
  4. % Routines for the memory efficient solution of linear algebraic systems
  5. % Author: Thomas Wolf
  6. % December 1998
  7. symbolic fluid '(count_tries tr_subsys max_losof matrix_849)$
  8. lisp(tr_subsys:=nil)$
  9. symbolic procedure trian_lin_alg(arglist)$
  10. if not lin_problem then nil else
  11. begin scalar h1,h2,h3,h4,f,fl,newfl,tr_opt,remain_pdes,remain_fl,li,
  12. total_terms;
  13. tr_opt:=t;
  14. % get a list h1 of purely algebraic equation by disregarding the
  15. % non-algebraic equations
  16. h2:=car arglist;
  17. while h2 do <<
  18. if is_algebraic(car h2) then h1:=cons(car h2,h1);
  19. h2:=cdr h2
  20. >>;
  21. % Just for testing spot_over_det():
  22. spot_over_det(h1,nil,nil,nil)$
  23. write "count_tries=",count_tries; terpri()$
  24. return nil;
  25. % start with reducing the length of all equations as much as possible
  26. repeat <<
  27. h2:=alg_length_reduction({h1,nil,vl_,h1});
  28. % nil for forg which is not used in alg_length_reduction()
  29. if h2 then h1:=car h2
  30. >> until contradiction_ or null h2;
  31. remain_pdes:=h1;
  32. total_terms:=0;
  33. for each h2 in remain_pdes do total_terms:=total_terms+get(h2,'terms);
  34. % fl now becomes a list of lists: ((n1,f1,d11,d12,d13,..),
  35. % (n2,f2,d21,d22,d23,...),...) where fi are the functions,
  36. % dij are equation names in which fi occurs and ni is the number of dij
  37. for each h2 in h1 do fl:=add_equ_to_fl(h2,fl)$
  38. % newfl is the final newly ordered list of functions
  39. while fl and null contradiction_ do <<
  40. % re-order all functions, those occuring in the fewest equations
  41. % come first
  42. fl:=idx_sort fl;
  43. if tr_opt then <<terpri()$write"fl2="$prettyprint fl>>$
  44. if caar fl = 1 then << % the first function occurs in only one eqn.
  45. % If a function occurs in only one equation then drop the function
  46. % and the equation from all functions in fl
  47. while caar fl leq 1 do <<
  48. if tr_opt and (caar fl = 1) then <<
  49. write"equation ",caddar fl," determines ",cadar fl$terpri()
  50. >>$
  51. newfl:=cons(cadar fl,newfl);
  52. fl:=if caar fl = 0 then cdr fl
  53. else <<remain_pdes:=delete(caddar fl,remain_pdes);
  54. total_terms:=total_terms-get(caddar fl,'terms);
  55. fl:=del_equ_from_fl(caddar fl,cdr fl)>>
  56. >>;
  57. >> else << % all remaining functions occur in at least 2 eqn.
  58. % Find a subsystem of equations that has less or equally many
  59. % functions as equations
  60. % ...
  61. % Find a function which is easiest decoupled/substituted
  62. % (e.g. use min-growth-substitution for that)
  63. remain_fl:=for each h3 in fl collect cadr h3;
  64. % update 'fcteval_lin for all equations. This is a preparation to
  65. % find the cheapest substitution
  66. for each h1 in remain_pdes do <<
  67. h2:=get(h1,'fcteval_lin)$
  68. li:=nil;
  69. if null h2 then << % assign all allowed subst.
  70. for each f in remain_fl do
  71. if not freeof(get(h1,'rational),f) then
  72. li:=cons(cons(reval coeffn(get(h1,'val),f,1),f),li);
  73. >> else << % keep only substitutions related to fl-functions
  74. while h2 do <<
  75. if not freeof(cdar h2,remain_fl) then li:=cons(car h2,li);
  76. h2:=cdr h2
  77. >>
  78. >>;
  79. if li then put(h1,'fcteval_lin,reverse li);
  80. >>;
  81. % Do the substitution with the lowest upper bound of increase in complexity
  82. % make_subst(pdes,forg,vl,l1,length_limit,pdelimit,less_vars,no_df,no_cases,
  83. % lin_subst,min_growth,cost_limit,keep_eqn)$
  84. h1:=make_subst(remain_pdes,remain_fl,vl_,remain_pdes,
  85. nil,nil,nil,nil,t,t,t,nil,t,nil)$
  86. if null contradiction_ and h1 then << % update all data
  87. h2:=caddr h1; % h2 was used for substitution
  88. h3:=total_terms-get(h2,'terms)$
  89. remain_pdes:=delete(h2,car h1);
  90. total_terms:=0;
  91. for each h4 in remain_pdes do total_terms:=total_terms+get(h4,'terms);
  92. if tr_opt then <<
  93. write"equation ",h2," now disregarded"$ terpri()$
  94. write"growth: ",total_terms-h3," terms"$terpri()$
  95. write length remain_pdes," remaining PDEs: ",remain_pdes$ terpri()$
  96. >>$
  97. fl:=del_equ_from_fl(h2,fl);
  98. h2:=cadr h1;
  99. while (not pairp car h2) or (caar h2 neq 'EQUAL) do h2:=cdr h2;
  100. f:=cadar h2$
  101. remain_fl:=delete(f,remain_fl);
  102. if tr_opt then <<
  103. write length remain_fl," remaining functions: ",remain_fl$ terpri()$
  104. >>$
  105. % Drop the entry for function f from fl. h4 is the list of
  106. % equations with f
  107. if cadar fl = f then <<h4:=cddar fl;fl:=cdr fl>>
  108. else <<
  109. h3:=fl;
  110. while cadadr h3 neq f do h3:=cdr h3;
  111. h4:=cddadr h3;
  112. rplacd(h3,cddr h3);
  113. >>;
  114. % update the appearance of equations in fl in which f was substituted
  115. for each h3 in h4 do <<
  116. fl:=del_equ_from_fl(h3,fl);
  117. if not freeof(remain_pdes,h3) then fl:=add_equ_to_fl(h3,fl)
  118. >>$
  119. % Have length reductions become possible through substitution?
  120. repeat <<
  121. h2:=alg_length_reduction({remain_pdes,nil,vl_,remain_pdes});
  122. % nil for forg which is not used in alg_length_reduction()
  123. if h2 then <<
  124. % update fl:
  125. % at first deleting dropped redundand equations from fl
  126. h3:=setdiff(remain_pdes,car h2);
  127. for each h4 in h3 do fl:=del_equ_from_fl(h4,fl);
  128. remain_pdes:=car h2;
  129. % now updating the entry for the changed equations
  130. for each h3 in caddr h2 do <<
  131. fl:=del_equ_from_fl(h3,fl);
  132. if not freeof(remain_pdes,h3) then fl:=add_equ_to_fl(h3,fl)
  133. >>
  134. >>
  135. >> until contradiction_ or null h2;
  136. >> else rederr("make_subst=nil, what now???");
  137. >>
  138. >>$
  139. if newfl neq ftem_ then
  140. change_fcts_ordering(newfl,car arglist,vl_)
  141. % clear dec_with????
  142. end$
  143. endmodule$
  144. end$