map2strn.red 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. module map2strn;
  2. %************* TRANSFORMATION OF MAP TO STRAND **********************$
  3. % $
  4. % 25.11.87 $
  5. % $
  6. %********************************************************************$
  7. exports color!-strand,contract!-strand $
  8. imports nil$
  9. %---------------- utility added 09.06.90 ---------------------------
  10. symbolic procedure constimes u;
  11. % u=list of terms
  12. % inspect u, delete all 1's
  13. % and form smar product $
  14. cstimes(u,nil)$
  15. symbolic procedure cstimes(u,s);
  16. if null u then
  17. if null s then 1
  18. else if null cdr s then car s
  19. else 'times . s
  20. else if car u = 1 then cstimes(cdr u,s)
  21. else cstimes(cdr u,car u . s)$
  22. symbolic procedure consrecip u;
  23. % do same as consTimes
  24. if or(car u = 1,car u = -1) then car u
  25. else 'recip . u$
  26. symbolic procedure listquotient(u,v)$
  27. % the same !!!
  28. if v=1 then u
  29. else
  30. if v = u then 1
  31. else list('quotient,u,v)$
  32. symbolic procedure consplus u;
  33. % u=list of terms
  34. % inspect u, delete all 0's
  35. % and form smar sum $
  36. csplus(u,nil)$
  37. symbolic procedure csplus(u,s);
  38. if null u then
  39. if null s then 0
  40. else if null cdr s then car s
  41. else 'plus . s
  42. else if car u = 0 then csplus(cdr u,s)
  43. else csplus(cdr u,car u . s)$
  44. %--------------------------------------------------------------------
  45. %---------------- CONVERTING OF MAP TO STRAND DIAGRAM ---------------$
  46. symbolic procedure map_!-to!-strand(edges,map_)$
  47. %.....................................................................
  48. % ACTION: CONVERTS "MAP_" WITH "EDGES" INTO STRAND DIAGRAM.
  49. % STRAND ::= <LIST OF STRAND VERTICES>,
  50. % STRAND VERTEX ::= <SVERTEX NAME> . (<LIST1 OF ROADS> <LIST2 ...>),
  51. % ROAD ::= <ATOM> . <NUMBER>.
  52. % LIST1,2 CORRESPOND TO OPPOSITE SIDES OF STRAND VERTEX.
  53. % ROADS LISTED CLOCKWISE.
  54. %....................................................................$
  55. if null edges then nil
  56. else mk!-strand!-vertex(car edges,map_) .
  57. map_!-to!-strand(cdr edges,map_)$
  58. %YMBOLIC PROCEDURE MAP_!-TO!-STRAND(EDGES,MAP_)$
  59. %F NULL EDGES THEN NIL
  60. %LSE (LAMBDA SVERT$ IF SVERT THEN SVERT .
  61. % MAP_!-TO!-STRAND(CDR EDGES,MAP_)
  62. % ELSE MAP_!-TO!-STRAND(CDR EDGES,MAP_) )
  63. % MK!-STRAND!-VERTEX(CAR EDGES,MAP_)$
  64. symbolic procedure mk!-strand!-vertex(edge,map_)$
  65. begin
  66. scalar vert1,vert2,tail$
  67. tail:=incident(edge,map_,1)$
  68. vert1:=car tail$
  69. tail:=incident(edge,cdr tail,add1 cdar vert1)$
  70. vert2:= if null tail then mk!-external!-leg edge
  71. else car tail$
  72. return %F NULL VERT2 THEN NIL
  73. mk!-strand!-vertex2(edge,vert1,vert2)
  74. end$
  75. symbolic procedure incident(edge,map_,vertno)$
  76. if null map_ then nil
  77. else (lambda z$ if z then z . cdr map_
  78. else incident(edge,cdr map_,add1 vertno) )
  79. incident1( edge,car map_,vertno)$
  80. symbolic procedure incident1(edname,vertex,vertno)$
  81. if eq(edname,s!-edge!-name car vertex) then
  82. mk!-road!-name(cadr vertex,caddr vertex,vertno)
  83. else if eq(edname,s!-edge!-name cadr vertex) then
  84. mk!-road!-name(caddr vertex,car vertex,vertno)
  85. else if eq(edname,s!-edge!-name caddr vertex) then
  86. mk!-road!-name(car vertex,cadr vertex,vertno)
  87. else nil$
  88. symbolic procedure mk!-strand!-vertex2(edge,vert1,vert2)$
  89. list(edge, vert1, vert2)$
  90. %------------------ COLOURING OF ROADS IN STRAND --------------------$
  91. symbolic procedure color!-strand(alst,map_,count)$
  92. %.....................................................................
  93. % ACTION: GENERATE REC. ALIST COLORING STRAND, CORRESPONDING TO "MAP_".
  94. % COLORING OF STRAND INDUCED BY "MAP_" COLORING, DEFINED BY ALIST
  95. % "ALST". "COUNT" COUNTS MAP_ VERTICES. INITIALLY IS 1.
  96. % REC.ALIST::= ( ... <(ATOM1 . COL1 ATOM2 . COL2 ...) . NUMBER> ... )
  97. % WHERE COL1 IS COLOR OF ROAD=ATOM1 . NUMBER.
  98. %....................................................................$
  99. if null map_ then nil
  100. else (color!-roads(alst,car map_) . count) .
  101. color!-strand(alst,cdr map_,add1 count)$
  102. symbolic procedure color!-roads(alst,vertex)$
  103. begin
  104. scalar e1,e2,e3,lines$
  105. e1:=getedge(s!-edge!-name car vertex,alst)$
  106. e2:=getedge(s!-edge!-name cadr vertex,alst)$
  107. e3:=getedge(s!-edge!-name caddr vertex,alst)$
  108. lines:=(e1+e2+e3)/2$
  109. e1:=lines-e1$
  110. e2:=lines-e2$
  111. e3:=lines-e3$
  112. return list(
  113. s!-edge!-name car vertex . e1,
  114. s!-edge!-name cadr vertex . e2,
  115. s!-edge!-name caddr vertex . e3)
  116. end$
  117. symbolic procedure zero!-roads l$
  118. %---------------------------------------------------------------------
  119. % L IS OUTPUT OF COLOR!-STRAND
  120. %--------------------------------------------------------------------$
  121. if null l then nil
  122. else (lambda z$ if z then z . zero!-roads cdr l
  123. else zero!-roads cdr l)
  124. z!-roads car l$
  125. symbolic procedure z!-roads y$
  126. (lambda w$ w and (car w . cdr y))
  127. ( if (0=cdr caar y)then caar y
  128. else if (0=cdr cadar y) then cadar y
  129. else if (0=cdr caddar y) then caddar y
  130. else nil)$
  131. %------------------- CONTRACTION OF STRAND --------------------------$
  132. symbolic procedure deletez1(strand,alst)$
  133. %.....................................................................
  134. % ACTION: DELETES FROM "STRAND" VERTICES WITH NAMES HAVING 0-COLOR
  135. % VIA MAP_-COLORING ALIST "ALST".
  136. %....................................................................$
  137. if null strand then nil
  138. else if 0 = cdr assoc(caar strand,alst) then
  139. deletez1(cdr strand,alst)
  140. else car strand . deletez1(cdr strand,alst)$
  141. symbolic procedure contract!-strand(strand,slst)$
  142. %.....................................................................
  143. % ACTION: CONTRACTS "STRAND".
  144. % "SLST" IS REC. ALIST COLORING "STRAND"
  145. %....................................................................$
  146. contr!-strand(strand,zero!-roads slst)$
  147. symbolic procedure contr!-strand(strand,zlst)$
  148. if null zlst then strand
  149. else contr!-strand(contr1!-strand(strand,car zlst),cdr zlst)$
  150. symbolic procedure contr1!-strand(strand,rname)$
  151. contr2!-strand(strand,rname,nil,nil)$
  152. symbolic procedure contr2!-strand(st,rname,rand,flag_)$
  153. if null st then rand
  154. else (lambda z$
  155. if z then
  156. if member(car z,cdr z) then sappend(st,rand) % 16.12 ****$
  157. else
  158. if null flag_ then
  159. contr2!-strand(contr2(z,cdr st,rand),rname,nil,t)
  160. else contr2(z,cdr st,rand)
  161. else contr2!-strand(cdr st,rname,car st . rand,nil) )
  162. contrsp(car st,rname)$
  163. symbolic procedure contrsp(svertex,rname)$
  164. contrsp2(cadr svertex,caddr svertex,rname)
  165. or
  166. contrsp2(caddr svertex,cadr svertex,rname)$
  167. symbolic procedure contrsp2(l1,l2,rname)$
  168. if 2 = length l1 then
  169. if rname = car l1 then (cadr l1) . l2
  170. else if rname = cadr l1 then (car l1) . l2
  171. else nil$
  172. symbolic procedure contr2(single,st,rand)$
  173. if null st then contr(single,rand)
  174. else if null rand then contr(single,st)
  175. else split!-road(single,car st) . contr2(single,cdr st,rand)$
  176. symbolic procedure contr(single,strand)$
  177. if null strand then nil
  178. else split!-road(single,car strand) . contr(single,cdr strand)$
  179. symbolic procedure split!-road(single,svertex)$
  180. list(car svertex,
  181. sroad(car single,cdr single,cadr svertex),
  182. sroad(car single,cdr single,caddr svertex))$
  183. symbolic procedure sroad(line_,lines,lst)$
  184. if null lst then nil
  185. else if line_ = car lst then sappend(lines,cdr lst)
  186. else car lst . sroad(line_,lines,cdr lst)$
  187. endmodule;
  188. end;