001/* 002 * $Id$ 003 */ 004 005package edu.jas.ufd; 006 007 008import java.util.List; 009 010import edu.jas.poly.ExpVector; 011import edu.jas.ps.TaylorFunction; 012import edu.jas.structure.GcdRingElem; 013 014 015/** 016 * Polynomial quotient functions capable for Taylor series expansion. 017 * @param <C> ring element type 018 * @author Heinz Kredel 019 */ 020 021public class QuotientTaylorFunction<C extends GcdRingElem<C>> implements TaylorFunction<C> { 022 023 024 final Quotient<C> quo; 025 026 027 final long facul; 028 029 030 public QuotientTaylorFunction(Quotient<C> q) { 031 this(q, 1L); 032 } 033 034 035 public QuotientTaylorFunction(Quotient<C> q, long f) { 036 quo = q; 037 facul = f; 038 } 039 040 041 /** 042 * To String. 043 * @return string representation of this. 044 */ 045 @Override 046 public String toString() { 047 return quo.toString(); 048 } 049 050 051 /** 052 * Get the factorial coefficient. 053 * @return factorial coefficient. 054 */ 055 @Override 056 public long getFacul() { 057 return facul; 058 } 059 060 061 /** 062 * Test if this is zero. 063 * @return true if this is 0, else false. 064 */ 065 public boolean isZERO() { 066 return quo.isZERO(); 067 } 068 069 070 /** 071 * Derivative. 072 * @return derivative of this. 073 */ 074 @Override 075 public TaylorFunction<C> derivative() { 076 return new QuotientTaylorFunction<C>(PolyUfdUtil.<C> derivative(quo)); 077 } 078 079 080 /** 081 * Partial derivative. 082 * @param r index of the variable. 083 * @return partial derivative of this with respect to variable r. 084 */ 085 public TaylorFunction<C> derivative(int r) { 086 return new QuotientTaylorFunction<C>(PolyUfdUtil.<C> derivative(quo, r)); 087 } 088 089 090 /** 091 * Multi-partial derivative. 092 * @param i exponent vector. 093 * @return partial derivative of this with respect to all variables. 094 */ 095 public TaylorFunction<C> derivative(ExpVector i) { 096 Quotient<C> q = quo; 097 long f = 1L; 098 if (i.signum() == 0 || quo.isZERO()) { 099 return new QuotientTaylorFunction<C>(q, f); 100 } 101 for (int j = 0; j < i.length(); j++) { 102 long e = i.getVal(j); 103 if (e == 0) { 104 continue; 105 } 106 int jl = i.length() - 1 - j; 107 for (long k = 0; k < e; k++) { 108 q = PolyUfdUtil.<C> derivative(q, jl); 109 f *= (k + 1); 110 if (q.isZERO()) { 111 return new QuotientTaylorFunction<C>(q, f); 112 } 113 } 114 } 115 //System.out.println("i = " + i + ", f = " + f + ", der = " + q); 116 return new QuotientTaylorFunction<C>(q, f); 117 } 118 119 120 /** 121 * Evaluate. 122 * @param a element. 123 * @return this(a). 124 */ 125 @Override 126 public C evaluate(C a) { 127 C e = PolyUfdUtil.<C> evaluateMain(quo.ring.ring.coFac, quo, a); 128 return e; 129 } 130 131 132 /** 133 * Evaluate at a tuple of elements. 134 * @param a tuple of elements. 135 * @return this(a). 136 */ 137 public C evaluate(List<C> a) { 138 return PolyUfdUtil.<C> evaluateAll(quo.ring.ring.coFac, quo, a); 139 } 140 141}