braids.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /**
  2. * This file is part of Gomu.
  3. *
  4. * Copyright 2016 by Jean Fromentin <jean.fromentin@math.cnrs.fr>
  5. *
  6. * Gomu is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Gomu is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Gomu. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "braids.hpp"
  20. #include "init.hpp"
  21. //******************
  22. //* Global objects *
  23. //******************
  24. MonoidFamily ArtinA_mf("Artin A-type",ArtinA_disp,ArtinA_gnum);
  25. MonoidFamily dualA_mf("Dual A-type",DualA_disp,DualA_gnum);
  26. //***********************
  27. //* Auxiliary functions *
  28. //***********************
  29. //---------------
  30. // braids_init()
  31. //---------------
  32. void braids_init(){
  33. ArtinA_mf.set_left_complement(&ArtinA_left_sc);
  34. ArtinA_mf.set_right_complement(&ArtinA_right_sc);
  35. ArtinA_mf.data=(void*)type_ArtinWordA;
  36. dualA_mf.set_left_complement(&DualA_left_sc);
  37. dualA_mf.set_right_complement(&DualA_right_sc);
  38. dualA_mf.data=(void*)type_DualWordA;
  39. }
  40. //------------------------------------------------
  41. // ArtinA_left_sc(Generator,Generator,Generator*)
  42. //------------------------------------------------
  43. int ArtinA_left_sc(const Generator& x,const Generator& y,Generator* comp){
  44. //Comp statisfy comp*x=...*y
  45. if(x==y) return 0;
  46. if(abs(x-y)==1){
  47. comp[0]=x;
  48. comp[1]=y;
  49. return 2;
  50. }
  51. else{
  52. comp[0]=y;
  53. return 1;
  54. }
  55. }
  56. //-------------------------------------------------
  57. // ArtinA_rigth_sc(Generator,Generator,Generator*)
  58. //-------------------------------------------------
  59. int ArtinA_right_sc(const Generator& x,const Generator& y,Generator* comp){
  60. //Comp satisfy x*comp=y*...
  61. if(x==y) return 0;
  62. if(abs(x-y)==1){
  63. comp[0]=y;
  64. comp[1]=x;
  65. return 2;
  66. }
  67. else{
  68. comp[0]=y;
  69. return 1;
  70. }
  71. }
  72. //--------------------
  73. // DualA_gnum(size_t)
  74. //--------------------
  75. inline size_t
  76. DualA_gnum(size_t n){
  77. size_t res=0;
  78. for(size_t i=1;i<n;++i){
  79. res+=i;
  80. }
  81. return res;
  82. }
  83. //-----------------------------------------------
  84. // DualA_left_sc(Generator,Generator,Generator*)
  85. //-----------------------------------------------
  86. int DualA_left_sc(const Generator& x,const Generator& y,Generator* comp){
  87. //Case 1
  88. if(x==y) return 0;
  89. uint p=get_i(x);
  90. uint q=get_j(x);
  91. uint r=get_i(y);
  92. uint s=get_j(y);
  93. //Case 5 and 6
  94. if(p==r){
  95. comp[0]=(q<s)?y:generator(s,q);
  96. return 1;
  97. }
  98. //Case 7 and 8
  99. if(q==s){
  100. comp[0]=(p<r)?y:generator(r,p);
  101. return 1;
  102. }
  103. //Case 3
  104. if(p==s){
  105. comp[0]=y;
  106. return 1;
  107. }
  108. //Case 5
  109. if(q==r){
  110. comp[0]=generator(p,s);
  111. return 1;
  112. }
  113. //Case 9
  114. if(p<r and r<q and q<s){
  115. comp[0]=generator(r,q);
  116. comp[1]=generator(p,s);
  117. return 2;
  118. }
  119. //Case 10
  120. if(r<p and p<s and s<q){
  121. comp[0]=generator(s,q);
  122. comp[1]=generator(r,p);
  123. return 2;
  124. }
  125. //Case 2
  126. comp[0]=y;
  127. return 1;
  128. }
  129. //------------------------------------------------
  130. // DualA_right_sc(Generator,Generator,Generator*)
  131. //------------------------------------------------
  132. int DualA_right_sc(const Generator& x,const Generator& y,Generator* comp){
  133. //Case 1
  134. if(x==y) return 0;
  135. uint p=get_i(x);
  136. uint q=get_j(x);
  137. uint r=get_i(y);
  138. uint s=get_j(y);
  139. //Case 5 and 6
  140. if(p==r){
  141. comp[0]=(q<s)?generator(q,s):y;
  142. return 1;
  143. }
  144. //Case 7 and 8
  145. if(q==s){
  146. comp[0]=(p<r)?generator(p,r):y;
  147. return 1;
  148. }
  149. //Case 3
  150. if(p==s){
  151. comp[0]=generator(r,q);
  152. return 1;
  153. }
  154. //Case 5
  155. if(q==r){
  156. comp[0]=y;
  157. return 1;
  158. }
  159. //Case 9
  160. if(p<r and r<q and q<s){
  161. comp[0]=generator(q,s);
  162. comp[1]=generator(p,r);
  163. return 2;
  164. }
  165. //Case 10
  166. if(r<p and p<s and s<q){
  167. comp[0]=generator(p,s);
  168. comp[1]=generator(r,q);
  169. return 2;
  170. }
  171. //Case 2
  172. comp[0]=y;
  173. return 1;
  174. }