package jasymca; /* Jasymca - - Symbolic Calculator for Mobile Devices This version is written for J2ME, CLDC 1.1, MIDP 2, JSR 75 or J2SE Copyright (C) 2006 - Helmut Dersch der@hs-furtwangen.de 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 the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /*------------------------------------------------------------*/ import java.util.Vector; public abstract class Algebraic{ public abstract Algebraic add (Algebraic x) throws JasymcaException; public abstract Algebraic mult(Algebraic x) throws JasymcaException; public abstract Algebraic div (Algebraic x) throws JasymcaException; public abstract Algebraic deriv( Variable var ) throws JasymcaException; public abstract Algebraic integrate( Variable var ) throws JasymcaException; public abstract double norm(); public Algebraic rat() throws JasymcaException{ return new LambdaRAT().f_exakt(this); } public Algebraic map( LambdaAlgebraic f ) throws JasymcaException{ throw new JasymcaException("Map not implemented for "+this); } // Divide 2 Polynomials with rest, overwritten in Polynomial && Zahl public Algebraic[] div( Algebraic q1, Algebraic[] result) throws JasymcaException{ return result; } public Algebraic divrest(Algebraic q) throws JasymcaException{ return div(q,null)[1]; } public boolean depends(Variable var) { return false; } // Loke depends, but does not recurse into functions public boolean depdir(Variable var){ return false; } // Build polynomial expression using Horner's method public static Algebraic horner(Variable x, Algebraic[] c, int n) throws JasymcaException{ if(n==0) return Zahl.ZERO; Polynomial X = new Polynomial(x); Algebraic p = c[n-1]; for(int i=n-2; i>=0; i--){ p = p.mult(X).add(c[i]); } return p; } // Build polynomial expression using Horner's method public static Algebraic horner(Variable x, Algebraic[] c) throws JasymcaException{ return horner(x,c,c.length); } public Algebraic sub (Algebraic x) throws JasymcaException{ return add(x.mult(Zahl.MINUS)); } public Algebraic reduce() throws JasymcaException{ return this; } public abstract boolean equals(Object x); public Object toPrefix(){ return this; }; public Algebraic pow_n(int n) throws JasymcaException{ if(n==0) return Zahl.ONE; if(n<0) return Zahl.ONE.div(pow_n(-n)); Algebraic result = this; for(int i=1; i=0; i--,k--){ cdiv[i] = nom[k].polydiv( den); nom[k] = Zahl.ZERO; for(int j=k-1,l=q.coef.length-2; j>k-q.coef.length; j--,l--) nom[j] = nom[j].sub( cdiv[i].mult(q.coef[l])); } return horner(p.var,cdiv); }else{ Algebraic[] cn = new Algebraic[p.coef.length]; for(int i=0; i=0; i--,k--){ cdiv[i] = nom[k].polydiv( den); nom[k] = Zahl.ZERO; for(int j=k-1,l=(q.degree(r)+1)-2; j>k- (q.degree(r)+1); j--,l--) nom[j] = nom[j].sub( cdiv[i].mult(q.coefficient(r,l))); } return horner(r,nom,nom.length-1 -len); } public Algebraic euclid( Algebraic q, Variable r) throws JasymcaException{ // p,q are numbers or polynomials // Alles bezogen auf Variable r ! int dp = degree(r); int dq = q.degree(r); Algebraic a = dp