]> www.ginac.de Git - ginac.git/blobdiff - ginac/normal.cpp
* Added resultant() function (by Ralf Stephan <ralf@ark.in-berlin.de>).
[ginac.git] / ginac / normal.cpp
index 15982a038ab5c0a2ef86183191d5049b995e2ef9..8ba5df0de4810f14485e588b306945381f2647cd 100644 (file)
@@ -6,7 +6,7 @@
  *  computation, square-free factorization and rational function normalization. */
 
 /*
- *  GiNaC Copyright (C) 1999-2003 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2004 Johannes Gutenberg University Mainz, Germany
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -300,7 +300,6 @@ static ex multiply_lcm(const ex &e, const numeric &lcm)
 /** Compute the integer content (= GCD of all numeric coefficients) of an
  *  expanded polynomial.
  *
- *  @param e  expanded polynomial
  *  @return integer content */
 numeric ex::integer_content() const
 {
@@ -1003,7 +1002,6 @@ static ex sr_gcd(const ex &a, const ex &b, sym_desc_vec::const_iterator var)
 /** Return maximum (absolute value) coefficient of a polynomial.
  *  This function is used internally by heur_gcd().
  *
- *  @param e  expanded multivariate polynomial
  *  @return maximum coefficient
  *  @see heur_gcd */
 numeric ex::max_coefficient() const
@@ -1220,6 +1218,8 @@ static ex heur_gcd(const ex &a, const ex &b, ex *ca, ex *cb, sym_desc_vec::const
  *
  *  @param a  first multivariate polynomial
  *  @param b  second multivariate polynomial
+ *  @param ca pointer to expression that will receive the cofactor of a, or NULL
+ *  @param cb pointer to expression that will receive the cofactor of b, or NULL
  *  @param check_args  check whether a and b are polynomials with rational
  *         coefficients (defaults to "true")
  *  @return the GCD as a new expression */
@@ -1498,7 +1498,7 @@ static exvector sqrfree_yun(const ex &a, const symbol &x)
 /** Compute a square-free factorization of a multivariate polynomial in Q[X].
  *
  *  @param a  multivariate polynomial over Q[X]
- *  @param x  lst of variables to factor in, may be left empty for autodetection
+ *  @param l  lst of variables to factor in, may be left empty for autodetection
  *  @return   a square-free factorization of \p a.
  *
  * \note
@@ -2375,4 +2375,33 @@ ex collect_common_factors(const ex & e)
 }
 
 
+/** Resultant of two expressions e1,e2 with respect to symbol s.
+ *  Method: Compute determinant of Sylvester matrix of e1,e2,s.  */
+ex resultant(const ex & e1, const ex & e2, const ex & s)
+{
+       const ex ee1 = e1.expand();
+       const ex ee2 = e2.expand();
+       const int h1 = ee1.degree(s);
+       const int l1 = ee1.ldegree(s);
+       const int h2 = ee2.degree(s);
+       const int l2 = ee2.ldegree(s);
+
+       const int msize = h1 + h2;
+       matrix m(msize, msize);
+
+       for (int l = h1; l >= l1; --l) {
+               const ex e = ee1.coeff(s, l);
+               for (int k = 0; k < h2; ++k)
+                       m(k, k+h1-l) = e;
+       }
+       for (int l = h2; l >= l2; --l) {
+               const ex e = ee2.coeff(s, l);
+               for (int k = 0; k < h1; ++k)
+                       m(k+h2, k+h2-l) = e;
+       }
+
+       return m.determinant();
+}
+
+
 } // namespace GiNaC