init.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 "init.hpp"
  20. Gomu::Type* type_ZPoly;
  21. Gomu::Type* type_ZPolyFact;
  22. Gomu::Type* type_ZRatFrac;
  23. Gomu::Type* type_ZMatrix;
  24. Gomu::Type* type_ZPolyMat;
  25. extern "C"{
  26. Gomu::Module::Type types[]={
  27. {"ZPoly",dispPoly,delPoly,copyPoly,cmpPoly,&type_ZPoly},
  28. {"ZPolyFact",dispPolyFact,delPolyFact,copyPolyFact,cmpPolyFact,&type_ZPolyFact},
  29. {"ZRatFrac",dispRat,delRat,copyRat,cmpRat,&type_ZRatFrac},
  30. {"ZMatrix",dispMatrix,delMatrix,copyMatrix,cmpMatrix,&type_ZMatrix},
  31. {"ZPolyMat",dispPolyMatrix,delPolyMatrix,copyPolyMatrix,cmpPolyMatrix,&type_ZPolyMat},
  32. TYPE_SENTINEL
  33. };
  34. Gomu::Module::Function memberFunctions[]={
  35. //ZMatrix
  36. {"ZPoly","charpoly",{"ZMatrix"},FUNC(charpoly)},
  37. {"String","toSage",{"ZMatrix"},FUNC(toSage)},
  38. {"ZPolyMat","toZPolyMat",{"ZMatrix"},FUNC(toPolyMatrix)},
  39. //ZPoly
  40. {"ZPolyFact","factorize",{"ZPoly"},FUNC(factorize)},
  41. FUNC_SENTINEL
  42. };
  43. }
  44. //**************
  45. //* Polynomial *
  46. //**************
  47. void*
  48. copyPoly(void* v){
  49. fmpz_poly_struct* res=new fmpz_poly_struct;
  50. fmpz_poly_init(res);
  51. fmpz_poly_set(res,(fmpz_poly_struct*)v);
  52. return res;
  53. }
  54. //*********************
  55. //* Polynomial factor *
  56. //*********************
  57. void*
  58. copyPolyFact(void* v){
  59. fmpz_poly_factor_struct* res=new fmpz_poly_factor_struct;
  60. fmpz_poly_factor_init(res);
  61. fmpz_poly_factor_set(res,(fmpz_poly_factor_struct*)v);
  62. return res;
  63. }
  64. //*************
  65. //* Rationnal *
  66. //*************
  67. void*
  68. copyRat(void* v){
  69. fmpz_poly_q_struct* res=new fmpz_poly_q_struct;
  70. fmpz_poly_q_init(res);
  71. fmpz_poly_q_set(res,(fmpz_poly_q_struct*)v);
  72. return res;
  73. }
  74. //**********
  75. //* Matrix *
  76. //**********
  77. void* copyMatrix(void* v){
  78. fmpz_mat_struct* res=new fmpz_mat_struct;
  79. fmpz_mat_init_set(res,(fmpz_mat_struct*)v);
  80. return res;
  81. }
  82. //*********************
  83. //* Polynomial Matrix *
  84. //*********************
  85. void* copyPolyMatrix(void* v){
  86. fmpz_poly_mat_struct* res=new fmpz_poly_mat_struct;
  87. fmpz_poly_mat_init_set(res,(fmpz_poly_mat_struct*)v);
  88. return res;
  89. }
  90. //***************************
  91. //* Matrix member functions *
  92. //***************************
  93. void* charpoly(void* v){
  94. fmpz_poly_struct* res=new fmpz_poly_struct;
  95. fmpz_poly_init(res);
  96. fmpz_mat_charpoly(res,(fmpz_mat_struct*)v);
  97. return res;
  98. }
  99. void* toSage(void* v){
  100. ostringstream os;
  101. dispSage(os,(fmpz_mat_struct*)v);
  102. return new string(os.str());
  103. }
  104. void* toPolyMatrix(void* v){
  105. fmpz_poly_mat_struct* res=new fmpz_poly_mat_struct;
  106. fmpz_poly_mat_init_set(res,(fmpz_mat_struct*) v);
  107. return res;
  108. };
  109. //*******************************
  110. //* Polynomial member functions *
  111. //*******************************
  112. void* factorize(void* v){
  113. fmpz_poly_factor_struct* res=new fmpz_poly_factor_struct;
  114. fmpz_poly_factor_init(res);
  115. fmpz_poly_factor_zassenhaus(res,(fmpz_poly_struct*)v);
  116. return res;
  117. }