Macaulay2 Engine
Loading...
Searching...
No Matches

◆ weyl_diff() [2/3]

Nterm * WeylAlgebra::weyl_diff ( const ring_elem c,
const_exponents expf,
const int * derivatives,
const Nterm * g ) const
protected

Definition at line 339 of file weylalg.cpp.

343{
344 // This isn't really differentiation, but it is close.
345 // It is the inner loop of the multiplication routine for the Weyl algebra.
346 // Returns: sum of d*[n,derivative]*c*n*m/(derivative,derivatives) e_i, for
347 // each
348 // term d*n*e_i of v which satisfies: x part of n is >= derivatives,
349 // and where the multiplication and division of monomials is in the
350 // commutative
351 // monoid.
352
353 Nterm head;
354 head.next = nullptr;
355 Nterm *result = &head;
356
357 int i;
359 exponents_t deriv_exp = newarray_atomic(int, nvars_);
360 exponents_t result_exp = newarray_atomic(int, nvars_);
361 for (i = 0; i < nvars_; i++) deriv_exp[i] = 0;
363 {
364 int sum = 0;
365 for (i = 0; i < _nderivatives; i++)
366 {
367 sum += 2 * derivatives[i];
368 deriv_exp[_derivative[i]] = derivatives[i];
369 deriv_exp[_commutative[i]] = derivatives[i];
370 }
371 deriv_exp[_homog_var] = -sum;
372 }
373 else
374 for (i = 0; i < _nderivatives; i++)
375 {
376 deriv_exp[_derivative[i]] = derivatives[i];
377 deriv_exp[_commutative[i]] = derivatives[i];
378 }
379
380 for (Nterm& t : ring_elem(g))
381 {
382 // This first part checks whether the x-part of t->monom is divisible by
383 // 'derivatives'. If so, true is returned, and the resulting monomial is
384 // set.
385 M_->to_expvector(t.monom, result_exp);
386 extractCommutativePart(result_exp, exp);
387 if (divides(derivatives, exp))
388 {
389 ring_elem a = diff_coefficients(c, derivatives, exp);
390 if (K_->is_zero(a))
391 {
392 K_->remove(a);
393 continue;
394 }
395 ring_elem b = K_->mult(a, t.coeff);
396 K_->remove(a);
397 if (K_->is_zero(b))
398 {
399 K_->remove(b);
400 continue;
401 }
402 // Now compute the new monomial:
403 Nterm *tm = new_term();
404 tm->coeff = b;
405 for (int i2 = 0; i2 < nvars_; i2++)
406 result_exp[i2] += expf[i2] - deriv_exp[i2];
407 M_->from_expvector(result_exp, tm->monom);
408
409 // Append to the result
410 result->next = tm;
411 result = tm;
412 }
413 }
414 freemem(exp);
415 freemem(result_exp);
416 result->next = nullptr;
417 return head.next;
418}
exponents::Exponents exponents_t
Nterm * new_term() const
Definition poly.cpp:146
const Ring * K_
Definition polyring.hpp:123
const Monoid * M_
Definition polyring.hpp:124
ring_elem diff_coefficients(const ring_elem c, const int *derivatives, const_exponents exp) const
Definition weylalg.cpp:307
void extractCommutativePart(const_exponents exp, int *result) const
Definition weylalg.cpp:298
int * _derivative
Definition weylalg.hpp:65
int _homog_var
Definition weylalg.hpp:64
int _nderivatives
Definition weylalg.hpp:62
bool _homogeneous_weyl_algebra
Definition weylalg.hpp:63
int * _commutative
Definition weylalg.hpp:67
bool divides(const_exponents expbottom, const_exponents exptop) const
Definition weylalg.cpp:266
void freemem(void *s)
Definition m2-mem.cpp:103
VALGRIND_MAKE_MEM_DEFINED & result(result)
const mpreal exp(const mpreal &x, mp_rnd_t r=mpreal::get_default_rnd())
Definition mpreal.h:2298
const mpreal sum(const mpreal tab[], const unsigned long int n, int &status, mp_rnd_t mode=mpreal::get_default_rnd())
Definition mpreal.h:2600
#define newarray_atomic(T, len)
Definition newdelete.hpp:91
Nterm * next
Definition ringelem.hpp:157
ring_elem coeff
Definition ringelem.hpp:158
int monom[1]
Definition ringelem.hpp:160

References _commutative, _derivative, _homog_var, _homogeneous_weyl_algebra, _nderivatives, Nterm::coeff, diff_coefficients(), divides(), extractCommutativePart(), freemem(), PolynomialRing::K_, PolynomialRing::M_, Nterm::monom, PolyRing::new_term(), newarray_atomic, Nterm::next, PolynomialRing::nvars_, and result().

Referenced by mult_by_term().