calimat.red 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. module calimat;
  2. Comment
  3. #######################
  4. # #
  5. # MATRIX SUPPLEMENT #
  6. # #
  7. #######################
  8. Supplement to the REDUCE matrix package.
  9. Matrices are transformed into nested lists of s.q.'s.
  10. end comment;
  11. % ------ The Jacobian matrix -------------
  12. symbolic operator matjac;
  13. symbolic procedure matjac(m,l);
  14. % Returns the Jacobian matrix from the ideal m in prefix form
  15. % (given as an algebraic mode list) with respect to the var. list l.
  16. if not eqcar(m,'list) then typerr(m,"ideal basis")
  17. else if not eqcar(l,'list) then typerr(l,"variable list")
  18. else 'mat . for each x in cdr l collect
  19. for each y in cdr m collect prepsq difff(numr simp reval y,x);
  20. % ---------- Random linear forms -------------
  21. symbolic operator random_linear_form;
  22. symbolic procedure random_linear_form(vars,bound);
  23. % Returns a random linear form in algebraic prefix form.
  24. if not eqcar(vars,'list) then typerr(vars,"variable list")
  25. else 'plus . for each x in cdr vars collect
  26. {'times,random(2*bound)-bound,x};
  27. % ----- Singular locus -----------
  28. symbolic operator singular_locus;
  29. symbolic procedure singular_locus(m,c);
  30. if !*mode='algebraic then
  31. (if not numberp c then
  32. rederr"Syntax : singular_locus(polynomial list, codimension)"
  33. else dpmat_2a singular_locus!*(m,c))
  34. else singular_locus!*(m,c);
  35. symbolic procedure singular_locus!*(m,c);
  36. % m must be a complete intersection of codimension c given as a list
  37. % of polynomials in prefix form. Returns the singular locus computing
  38. % the corresponding jacobian.
  39. matsum!* {dpmat_from_a m, mat2list!* dpmat_from_a
  40. minors(matjac(m,makelist ring_names cali!=basering),c)};
  41. % ------------- Minors --------------
  42. symbolic operator minors;
  43. symbolic procedure minors(m,k);
  44. % Returns the matrix of k-minors of the matrix m.
  45. if not eqcar(m,'mat) then typerr(m,"matrix")
  46. else begin scalar r,c;
  47. m:=for each x in cdr m collect for each y in x collect simp y;
  48. r:=cali_choose(for i:=1:length m collect i,k);
  49. c:=cali_choose(for i:=1:length car m collect i,k);
  50. return 'mat . for each x in r collect for each y in c collect
  51. mk!*sq detq calimat!=submat(m,x,y);
  52. end;
  53. symbolic operator ideal_of_minors;
  54. symbolic procedure ideal_of_minors(m,k);
  55. % The ideal of the k-minors of the matrix m.
  56. if !*mode='algebraic then dpmat_2a ideal_of_minors!*(m,k)
  57. else ideal_of_minors!*(m,k);
  58. symbolic procedure ideal_of_minors!*(m,k);
  59. if not eqcar(m,'mat) then typerr(m,"matrix") else
  60. interreduce!* mat2list!* dpmat_from_a minors(m,k);
  61. symbolic procedure calimat!=submat(m,x,y);
  62. for each a in x collect for each b in y collect nth(nth(m,a),b);
  63. symbolic procedure calimat!=sum(a,b);
  64. for each x in pair(a,b) collect
  65. for each y in pair(car x,cdr x) collect addsq(car y,cdr y);
  66. symbolic procedure calimat!=neg a;
  67. for each x in a collect for each y in x collect negsq y;
  68. symbolic procedure calimat!=tp a;
  69. tp1 append(a,nil); % since tp1 is destructive.
  70. symbolic procedure calimat!=zero!? a;
  71. begin scalar b; b:=t;
  72. for each x in a do for each y in x do b:=b and null car y;
  73. return b;
  74. end;
  75. % -------------- Pfaffians ---------------
  76. symbolic procedure calimat!=skewsymmetric!? m;
  77. calimat!=zero!? calimat!=sum(m,calimat!=tp m);
  78. symbolic operator pfaffian;
  79. symbolic procedure pfaffian m;
  80. % The pfaffian of a skewsymmetric matrix m.
  81. if not eqcar(m,'mat) then typerr(m,"matrix") else
  82. begin scalar m1;
  83. m1:=for each x in cdr m collect for each y in x collect simp y;
  84. if not calimat!=skewsymmetric!? m1
  85. then typerr(m,"skewsymmetic matrix");
  86. return mk!*sq calimat!=pfaff m1;
  87. end;
  88. symbolic procedure calimat!=pfaff m;
  89. if length m=1 then nil . 1
  90. else if length m=2 then cadar m
  91. else begin scalar a,b,p,c,d,ind,sgn;
  92. b:=for each x in cdr m collect cdr x;
  93. a:=cdar m; ind:=for i:=1:length a collect i;
  94. p:=nil . 1;
  95. for i:=1:length a do
  96. << c:=delete(i,ind); d:=calimat!=pfaff calimat!=submat(b,c,c);
  97. if sgn then d:=negsq d; sgn:=not sgn;
  98. p:=addsq(p,multsq(nth(a,i),d));
  99. >>;
  100. return p;
  101. end;
  102. symbolic operator ideal_of_pfaffians;
  103. symbolic procedure ideal_of_pfaffians(m,k);
  104. % The ideal of the 2k-pfaffians of the skewsymmetric matrix m.
  105. if !*mode='algebraic then dpmat_2a ideal_of_pfaffians!*(m,k)
  106. else ideal_of_pfaffians!*(m,k);
  107. symbolic procedure ideal_of_pfaffians!*(m,k);
  108. % The same, but for a dpmat m.
  109. if not eqcar(m,'mat) then typerr(m,"matrix") else
  110. begin scalar m1,u;
  111. m1:=for each x in cdr m collect for each y in x collect simp y;
  112. if not calimat!=skewsymmetric!? m1
  113. then typerr(m,"skewsymmetic matrix");
  114. u:=cali_choose(for i:=1:length m1 collect i,2*k);
  115. return interreduce!* dpmat_from_a makelist
  116. for each x in u collect
  117. prepsq calimat!=pfaff calimat!=submat(m1,x,x);
  118. end;
  119. endmodule; % calimat
  120. end;