You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ps...@apache.org on 2006/11/19 22:36:23 UTC
svn commit: r476930 [15/22] - in
/jakarta/commons/proper/math/trunk/src/mantissa: ./ src/ src/org/
src/org/spaceroots/ src/org/spaceroots/mantissa/
src/org/spaceroots/mantissa/algebra/
src/org/spaceroots/mantissa/estimation/ src/org/spaceroots/mantissa...
Added: jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/utilities/ArrayMapperEntry.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/utilities/ArrayMapperEntry.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/utilities/ArrayMapperEntry.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/utilities/ArrayMapperEntry.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,46 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.utilities;
+
+/**
+ * This class is a simple container for an offset and an
+ * {@link ArraySliceMappable} object.
+
+ * @version $Id: ArrayMapperEntry.java 1705 2006-09-17 19:57:39Z luc $
+ * @author L. Maisonobe
+
+ */
+
+class ArrayMapperEntry {
+
+ /** Mappable object. */
+ public final ArraySliceMappable object;
+
+ /** Offset from start of array. */
+ public final int offset;
+
+ /** Simple constructor.
+ * @param object mappable object
+ * @param offset offset from start of array
+ */
+ public ArrayMapperEntry(ArraySliceMappable object, int offset) {
+ this.object = object;
+ this.offset = offset;
+ }
+
+}
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/utilities/ArrayMapperEntry.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/utilities/ArraySliceMappable.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/utilities/ArraySliceMappable.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/utilities/ArraySliceMappable.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/utilities/ArraySliceMappable.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,81 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.utilities;
+
+/** This interface is used to map objects to and from simple arrays.
+ *
+ * <p> Lots of mathematical algorithms are generic ones which can
+ * process the data from domain objects despite they ignore what
+ * this data represent. As an example, the same algorithm can
+ * integrate either the orbit evolution of a spacecraft under a
+ * specified force model or the electrical characteristics of a
+ * circuit after a switch is opened. </p>
+
+ * <p> The approach of the Mantissa library is to define an interface
+ * for each such algorithm to represent the type of problem they can
+ * handle ({@link
+ * org.spaceroots.mantissa.ode.FirstOrderDifferentialEquations
+ * FirstOrderDifferentialEquations} for an ODE integrators, {@link
+ * org.spaceroots.mantissa.estimation.EstimationProblem
+ * EstimationProblem} for least squares estimators, ...). Furthermore,
+ * the state data that is handled by these algorithms is often a
+ * mixture of data coming from several domain objects (the orbit,
+ * plus the aerodynamical coefficients of the spacecraft, plus the
+ * characteristics of the thrusters, plus ...). Therefore, the user
+ * needs to gather and dispatch data between different objects
+ * representing different levels of abstraction. </p>
+
+ * <p> This interface is designed to copy data back and forth between
+ * existing objects during the iterative processing of these
+ * algorithms and avoid the cost of recreating the objects. </p>
+
+ * <p> The nominal way to use this interface is to have the domain
+ * objects implement it (either directly or using inheritance to add
+ * this feature to already existing objects) and to create one class
+ * that implements the problem interface (for example {@link
+ * org.spaceroots.mantissa.ode.FirstOrderDifferentialEquations}) and
+ * uses the {@link ArrayMapper} class to dispatch the data to and from
+ * the domain objects.</p>
+
+ * @see ArrayMapper
+ *
+ * @version $Id: ArraySliceMappable.java 1705 2006-09-17 19:57:39Z luc $
+ * @author L. Maisonobe
+ *
+ */
+
+public interface ArraySliceMappable {
+
+ /** Get the dimension of the object.
+ * @return dimension of the object
+ */
+ public int getStateDimension();
+
+ /** Reinitialize internal state from the specified array slice data.
+ * @param start start index in the array
+ * @param array array holding the data to extract
+ */
+ public void mapStateFromArray(int start, double[] array);
+
+ /** Store internal state data into the specified array slice.
+ * @param start start index in the array
+ * @param array array where data should be stored
+ */
+ public void mapStateToArray(int start, double[] array);
+
+}
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/utilities/ArraySliceMappable.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/utilities/Interval.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/utilities/Interval.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/utilities/Interval.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/utilities/Interval.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,166 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.utilities;
+
+/** This class represents an interval on the real line.
+
+ * <p>This class allows to perform simple interval operations like
+ * point inclusion tests and intersection operations.</p>
+
+ * <p>There is no distinction between open and closed intervals
+ * because real numbers cannot be represented exactly.</p>
+
+ * @see IntervalsList
+ * @author Luc Maisonobe
+ * @version $Id: Interval.java 1705 2006-09-17 19:57:39Z luc $
+ */
+public class Interval {
+
+ /** Build the [0, 0] interval.
+ */
+ public Interval() {
+ inf = 0;
+ sup = 0;
+ }
+
+ /** Build an interval with the given bounds.
+ * <p>The given bounds do not need to be ordered, they will be
+ * reordered by the constructor.</p>
+ * @param a first bound
+ * @param b second bound
+ */
+ public Interval(double a, double b) {
+ if (a <= b) {
+ inf = a;
+ sup = b;
+ } else {
+ inf = b;
+ sup = a;
+ }
+ }
+
+ /** Copy-constructor.
+ * @param i interval to copy
+ */
+ public Interval(Interval i) {
+ inf = i.inf;
+ sup = i.sup;
+ }
+
+ /** Get the lower bound of the interval.
+ * @return lower bound of the interval
+ */
+ public double getInf() {
+ return inf;
+ }
+
+ /** Get the upper bound of the interval.
+ * @return upper bound of the interval
+ */
+ public double getSup() {
+ return sup;
+ }
+
+ /** Get the length of the interval.
+ * @return length of the interval
+ */
+ public double getLength() {
+ return sup - inf;
+ }
+
+ /** Check if the interval contains a point.
+ * @param x point to check
+ * @return true if the interval contains x
+ */
+ public boolean contains(double x) {
+ return (inf <= x) && (x <= sup);
+ }
+
+ /** Check if the interval contains another interval.
+ * @param i interval to check
+ * @return true if i is completely included in the instance
+ */
+ public boolean contains(Interval i) {
+ return (inf <= i.inf) && (i.sup <= sup);
+ }
+
+ /** Check if an interval intersects the instance.
+ * @param i interval to check
+ * @return true if i intersects the instance
+ */
+ public boolean intersects(Interval i) {
+ return (inf <= i.sup) && (i.inf <= sup);
+ }
+
+ /** Add an interval to the instance.
+ * <p>This method expands the instance.</p>
+ * <p>This operation is <strong>not</strong> a union operation. If
+ * the instance and the interval are disjoints (i.e. if {@link
+ * #intersects intersects(i)} would return <code>false</code>), then
+ * the hole between the intervals is filled in.</p>
+ * @param i interval to add to the instance
+ */
+ public void addToSelf(Interval i) {
+ inf = Math.min(inf, i.inf);
+ sup = Math.max(sup, i.sup);
+ }
+
+ /** Add two intervals.
+ * <p>This operation is <strong>not</strong> a union operation. If
+ * the intervals are disjoints (i.e. if {@link
+ * #intersects i1.intersects(i2)} would return <code>false</code>), then
+ * the hole between the intervals is filled in.</p>
+ * @param i1 first interval
+ * @param i2 second interval
+ * @return a new interval
+ */
+ public static Interval add(Interval i1, Interval i2) {
+ Interval copy = new Interval(i1);
+ copy.addToSelf(i2);
+ return copy;
+ }
+
+ /** Intersects the instance with an interval.
+ * <p>This method reduces the instance, it could even become empty
+ * if the interval does not intersects the instance.</p>
+ * @param i interval with which the instance should be intersected
+ */
+ public void intersectSelf(Interval i) {
+ inf = Math.max(inf, i.inf);
+ sup = Math.max(Math.min(sup, i.sup), inf);
+ }
+
+ /** Intersect two intervals.
+ * @param i1 first interval
+ * @param i2 second interval
+ * @return a new interval which is the intersection of i1 with i2
+ */
+ public static Interval intersection(Interval i1, Interval i2) {
+ Interval copy = new Interval(i1);
+ copy.intersectSelf(i2);
+ return copy;
+ }
+
+ /** Lower bound of the interval. */
+ private double inf;
+
+ /** Upper bound of the interval. */
+ private double sup;
+
+}
+
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/utilities/Interval.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/utilities/IntervalsList.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/utilities/IntervalsList.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/utilities/IntervalsList.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/utilities/IntervalsList.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,362 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.utilities;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Iterator;
+
+/** This class represents an intervals list.
+ * <p>An interval list represent a list of contiguous regions on the
+ * real line. All intervals of the list are disjoints to each other,
+ * they are stored in ascending order.</p>
+ * <p>The class supports the main set operations like union and
+ * intersection.</p>
+ * @see Interval
+ * @author Luc Maisonobe
+ * @version $Id: IntervalsList.java 1705 2006-09-17 19:57:39Z luc $
+ */
+public class IntervalsList {
+
+ /** Build an empty intervals list.
+ */
+ public IntervalsList() {
+ intervals = new ArrayList();
+ }
+
+ /** Build an intervals list containing only one interval.
+ * @param a first bound of the interval
+ * @param b second bound of the interval
+ */
+ public IntervalsList(double a, double b) {
+ intervals = new ArrayList();
+ intervals.add(new Interval(a, b));
+ }
+
+ /** Build an intervals list containing only one interval.
+ * @param i interval
+ */
+ public IntervalsList(Interval i) {
+ intervals = new ArrayList();
+ intervals.add(i);
+ }
+
+ /** Build an intervals list containing two intervals.
+ * @param i1 first interval
+ * @param i2 second interval
+ */
+ public IntervalsList(Interval i1, Interval i2) {
+ intervals = new ArrayList();
+ if (i1.intersects(i2)) {
+ intervals.add(new Interval(Math.min(i1.getInf(), i2.getInf()),
+ Math.max(i1.getSup(), i2.getSup())));
+ } else if (i1.getSup () < i2.getInf()) {
+ intervals.add(i1);
+ intervals.add(i2);
+ } else {
+ intervals.add(i2);
+ intervals.add(i1);
+ }
+ }
+
+ /** Copy constructor.
+ * <p>The copy operation is a deep copy: the underlying intervals
+ * are independant of the instances of the copied list.</p>
+ * @param list intervals list to copy
+ */
+ public IntervalsList(IntervalsList list) {
+ intervals = new ArrayList(list.intervals.size());
+ for (Iterator iterator = list.intervals.iterator(); iterator.hasNext();) {
+ intervals.add(new Interval((Interval) iterator.next()));
+ }
+ }
+
+ /** Check if the instance is empty.
+ * @return true if the instance is empty
+ */
+ public boolean isEmpty() {
+ return intervals.isEmpty();
+ }
+
+ /** Check if the instance is connected.
+ * <p>An interval list is connected if it contains only one
+ * interval.</p>
+ * @return true is the instance is connected
+ */
+ public boolean isConnex() {
+ return intervals.size() == 1;
+ }
+
+ /** Get the lower bound of the list.
+ * @return lower bound of the list or Double.NaN if the list does
+ * not contain any interval
+ */
+ public double getInf() {
+ return intervals.isEmpty()
+ ? Double.NaN : ((Interval) intervals.get(0)).getInf();
+ }
+
+ /** Get the upper bound of the list.
+ * @return upper bound of the list or Double.NaN if the list does
+ * not contain any interval
+ */
+ public double getSup() {
+ return intervals.isEmpty()
+ ? Double.NaN : ((Interval) intervals.get(intervals.size() - 1)).getSup();
+ }
+
+ /** Get the number of intervals of the list.
+ * @return number of intervals in the list
+ */
+ public int getSize() {
+ return intervals.size();
+ }
+
+ /** Get an interval from the list.
+ * @param i index of the interval
+ * @return interval at index i
+ */
+ public Interval getInterval(int i) {
+ return (Interval) intervals.get(i);
+ }
+
+ /** Get the ordered list of disjoints intervals.
+ * @return list of disjoints intervals in ascending order
+ */
+ public List getIntervals() {
+ return intervals;
+ }
+
+ /** Check if the list contains a point.
+ * @param x point to check
+ * @return true if the list contains x
+ */
+ public boolean contains(double x) {
+ for (Iterator iterator = intervals.iterator(); iterator.hasNext();) {
+ if (((Interval) iterator.next()).contains(x)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /** Check if the list contains an interval.
+ * @param i interval to check
+ * @return true if i is completely included in the instance
+ */
+ public boolean contains(Interval i) {
+ for (Iterator iterator = intervals.iterator(); iterator.hasNext();) {
+ if (((Interval) iterator.next()).contains(i)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /** Check if an interval intersects the instance.
+ * @param i interval to check
+ * @return true if i intersects the instance
+ */
+ public boolean intersects(Interval i) {
+ for (Iterator iterator = intervals.iterator(); iterator.hasNext();) {
+ if (((Interval) iterator.next()).intersects(i)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /** Add an interval to the instance.
+ * <p>This method expands the instance.</p>
+ * <p>This operation is a union operation. The number of intervals
+ * in the list can decrease if the interval fills some holes between
+ * existing intervals in the list.</p>
+ * @param i interval to add to the instance
+ */
+ public void addToSelf(Interval i) {
+
+ List newIntervals = new ArrayList();
+ double inf = Double.NaN;
+ double sup = Double.NaN;
+ boolean pending = false;
+ boolean processed = false;
+ for (Iterator iterator = intervals.iterator(); iterator.hasNext();) {
+ Interval local = (Interval) iterator.next();
+
+ if (local.getSup() < i.getInf()) {
+ newIntervals.add(local);
+ } else if (local.getInf() < i.getSup()) {
+ if (! pending) {
+ inf = Math.min(local.getInf(), i.getInf());
+ pending = true;
+ processed = true;
+ }
+ sup = Math.max(local.getSup(), i.getSup());
+ } else {
+ if (pending) {
+ newIntervals.add(new Interval(inf, sup));
+ pending = false;
+ } else if (! processed) {
+ newIntervals.add(i);
+ }
+ processed = true;
+ newIntervals.add(local);
+ }
+ }
+
+ if (pending) {
+ newIntervals.add(new Interval(inf, sup));
+ } else if (! processed) {
+ newIntervals.add(i);
+ }
+
+ intervals = newIntervals;
+
+ }
+
+ /** Add an intervals list and an interval.
+ * @param list intervals list
+ * @param i interval
+ * @return a new intervals list which is the union of list and i
+ */
+ public static IntervalsList add(IntervalsList list, Interval i) {
+ IntervalsList copy = new IntervalsList(list);
+ copy.addToSelf(i);
+ return copy;
+ }
+
+ /** Remove an interval from the list.
+ * <p>This method reduces the instance. This operation is defined in
+ * terms of points set operation. As an example, if the [2, 3]
+ * interval is subtracted from the list containing only the [0, 10]
+ * interval, the result will be the [0, 2] U [3, 10] intervals
+ * list.</p>
+ * @param i interval to remove
+ */
+ public void subtractFromSelf(Interval i) {
+ double a = Math.min(getInf(), i.getInf());
+ double b = Math.max(getSup(), i.getSup());
+ intersectSelf(new IntervalsList(new Interval(a - 1.0, i.getInf()),
+ new Interval(i.getSup(), b + 1.0)));
+ }
+
+ /** Remove an interval from a list.
+ * @param list intervals list
+ * @param i interval to remove
+ * @return a new intervals list
+ */
+ public static IntervalsList subtract(IntervalsList list, Interval i) {
+ IntervalsList copy = new IntervalsList(list);
+ copy.subtractFromSelf(i);
+ return copy;
+ }
+
+ /** Intersects the instance and an interval.
+ * @param i interval
+ */
+ public void intersectSelf(Interval i) {
+ List newIntervals = new ArrayList();
+ for (Iterator iterator = intervals.iterator(); iterator.hasNext();) {
+ Interval local = (Interval) iterator.next();
+ if (local.intersects(i)) {
+ newIntervals.add(Interval.intersection(local, i));
+ }
+ }
+ intervals = newIntervals;
+ }
+
+ /** Intersect a list and an interval.
+ * @param list intervals list
+ * @param i interval
+ * @return the intersection of list and i
+ */
+ public static IntervalsList intersection(IntervalsList list, Interval i) {
+ IntervalsList copy = new IntervalsList(list);
+ copy.intersectSelf(i);
+ return copy;
+ }
+
+ /** Add an intervals list to the instance.
+ * <p>This method expands the instance.</p>
+ * <p>This operation is a union operation. The number of intervals
+ * in the list can decrease if the list fills some holes between
+ * existing intervals in the instance.</p>
+ * @param list intervals list to add to the instance
+ */
+ public void addToSelf(IntervalsList list) {
+ for (Iterator iterator = list.intervals.iterator(); iterator.hasNext();) {
+ addToSelf((Interval) iterator.next());
+ }
+ }
+
+ /** Add two intervals lists.
+ * @param list1 first intervals list
+ * @param list2 second intervals list
+ * @return a new intervals list which is the union of list1 and list2
+ */
+ public static IntervalsList add(IntervalsList list1, IntervalsList list2) {
+ IntervalsList copy = new IntervalsList(list1);
+ copy.addToSelf(list2);
+ return copy;
+ }
+
+ /** Remove an intervals list from the instance.
+ * @param list intervals list to remove
+ */
+ public void subtractFromSelf(IntervalsList list) {
+ for (Iterator iterator = list.intervals.iterator(); iterator.hasNext();) {
+ subtractFromSelf((Interval) iterator.next());
+ }
+ }
+
+ /** Remove an intervals list from another one.
+ * @param list1 intervals list
+ * @param list2 intervals list to remove
+ * @return a new intervals list
+ */
+ public static IntervalsList subtract(IntervalsList list1, IntervalsList list2) {
+ IntervalsList copy = new IntervalsList(list1);
+ copy.subtractFromSelf(list2);
+ return copy;
+ }
+
+ /** Intersect the instance and another intervals list.
+ * @param list list to intersect with the instance
+ */
+ public void intersectSelf(IntervalsList list) {
+ intervals = intersection(this, list).intervals;
+ }
+
+ /** Intersect two intervals lists.
+ * @param list1 first intervals list
+ * @param list2 second intervals list
+ * @return a new list which is the intersection of list1 and list2
+ */
+ public static IntervalsList intersection(IntervalsList list1, IntervalsList list2) {
+ IntervalsList list = new IntervalsList();
+ for (Iterator iterator = list2.intervals.iterator(); iterator.hasNext();) {
+ list.addToSelf(intersection(list1, (Interval) iterator.next()));
+ }
+ return list;
+ }
+
+ /** The list of intervals. */
+ private List intervals;
+
+}
+
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/utilities/IntervalsList.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/utilities/MappableArray.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/utilities/MappableArray.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/utilities/MappableArray.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/utilities/MappableArray.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,93 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.utilities;
+
+/**
+ * Wrapper class around an array in order to have it implement the
+ * {@link ArraySliceMappable} interface.
+
+ * @version $Id: MappableArray.java 1705 2006-09-17 19:57:39Z luc $
+ * @author L. Maisonobe
+
+ */
+
+public class MappableArray
+ implements ArraySliceMappable {
+
+ /** Simple constructor.
+ * Build a mappable array from its dimension
+ * @param dimension dimension of the array
+ */
+ public MappableArray(int dimension) {
+ internalArray = new double[dimension];
+ for (int i = 0; i < dimension; ++i) {
+ internalArray[i] = 0;
+ }
+ }
+
+ /** Simple constructor.
+ * Build a mappable array from an existing array
+ * @param array array to use
+ * @param doReallocate true if a new array should be allocated and
+ * initialized using the other argument, false if the instance
+ * should reference the existing array throughout its lifetime
+ */
+ public MappableArray(double[] array, boolean doReallocate) {
+ if (doReallocate) {
+ internalArray = new double[array.length];
+ System.arraycopy(array, 0, internalArray, 0, array.length);
+ } else {
+ internalArray = array;
+ }
+ }
+
+ /** Get the array stored in the instance.
+ * @return array stored in the instance
+ */
+ public double[] getArray () {
+ return internalArray;
+ }
+
+ /** Get the dimension of the internal array.
+ * @return dimension of the array
+ */
+ public int getStateDimension() {
+ return internalArray.length;
+ }
+
+ /** Reinitialize internal state from the specified array slice data.
+ * @param start start index in the array
+ * @param array array holding the data to extract
+ */
+ public void mapStateFromArray(int start, double[] array) {
+ System.arraycopy(array, start, internalArray, 0, internalArray.length);
+ }
+
+ /** Store internal state data into the specified array slice.
+ * @param start start index in the array
+ * @param array array where data should be stored
+ */
+ public void mapStateToArray(int start, double[] array) {
+ System.arraycopy(internalArray, 0, array, start, internalArray.length);
+ }
+
+ /** Internal array holding all data.
+ */
+ double[] internalArray;
+
+}
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/utilities/MappableArray.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/utilities/MappableScalar.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/utilities/MappableScalar.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/utilities/MappableScalar.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/utilities/MappableScalar.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,88 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.utilities;
+
+/**
+ * Wrapper class around a scalar in order to have it implement the
+ * {@link ArraySliceMappable} interface.
+
+ * @version $Id: MappableScalar.java 1705 2006-09-17 19:57:39Z luc $
+ * @author L. Maisonobe
+
+ */
+
+public class MappableScalar
+ implements ArraySliceMappable {
+
+ /** Simple constructor.
+ * Build a mappable scalar
+ */
+ public MappableScalar() {
+ value = 0;
+ }
+
+ /** Simple constructor.
+ * Build a mappable scalar from its initial value
+ * @param value initial value of the scalar
+ */
+ public MappableScalar(double value) {
+ this.value = value;
+ }
+
+ /** Get the value stored in the instance.
+ * @return value stored in the instance
+ */
+ public double getValue () {
+ return value;
+ }
+
+ /** Set the value stored in the instance.
+ * @param value value to store in the instance
+ */
+ public void setValue (double value) {
+ this.value = value;
+ }
+
+ /** Get the dimension of the internal array.
+ * @return dimension of the array (always 1 for this class)
+ */
+ public int getStateDimension() {
+ return 1;
+ }
+
+ /** Reinitialize internal state from the specified array slice data.
+ * @param start start index in the array
+ * @param array array holding the data to extract
+ */
+ public void mapStateFromArray(int start, double[] array) {
+ value = array[start];
+ }
+
+ /** Store internal state data into the specified array slice.
+ * @param start start index in the array
+ * @param array array where data should be stored
+ */
+ public void mapStateToArray(int start, double[] array) {
+ array[start] = value;
+ }
+
+ /** Internal scalar.
+ */
+ double value;
+
+}
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/utilities/MappableScalar.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/AllTests.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/AllTests.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/AllTests.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/AllTests.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,45 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllTests {
+
+ public static Test suite() {
+
+ TestSuite suite= new TestSuite("org.spaceroots.mantissa");
+
+ suite.addTest(org.spaceroots.mantissa.linalg.AllTests.suite());
+ suite.addTest(org.spaceroots.mantissa.estimation.AllTests.suite());
+ suite.addTest(org.spaceroots.mantissa.functions.AllTests.suite());
+ suite.addTest(org.spaceroots.mantissa.roots.AllTests.suite());
+ suite.addTest(org.spaceroots.mantissa.fitting.AllTests.suite());
+ suite.addTest(org.spaceroots.mantissa.ode.AllTests.suite());
+ suite.addTest(org.spaceroots.mantissa.quadrature.AllTests.suite());
+ suite.addTest(org.spaceroots.mantissa.utilities.AllTests.suite());
+ suite.addTest(org.spaceroots.mantissa.geometry.AllTests.suite());
+ suite.addTest(org.spaceroots.mantissa.algebra.AllTests.suite());
+ suite.addTest(org.spaceroots.mantissa.optimization.AllTests.suite());
+
+ return suite;
+
+ }
+
+}
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/AllTests.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/AllTests.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/AllTests.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/AllTests.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/AllTests.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,40 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.algebra;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllTests {
+ public static Test suite() {
+
+ TestSuite suite = new TestSuite("org.spaceroots.mantissa.algebra");
+
+ suite.addTest(RationalNumberTest.suite());
+ suite.addTest(PolynomialRationalTest.suite());
+ suite.addTest(PolynomialDoubleTest.suite());
+ suite.addTest(ChebyshevTest.suite());
+ suite.addTest(HermiteTest.suite());
+ suite.addTest(LegendreTest.suite());
+ suite.addTest(LaguerreTest.suite());
+ suite.addTest(PolynomialFractionTest.suite());
+
+ return suite;
+
+ }
+}
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/AllTests.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/ChebyshevTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/ChebyshevTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/ChebyshevTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/ChebyshevTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,86 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.algebra;
+
+import junit.framework.*;
+
+public class ChebyshevTest
+ extends TestCase {
+
+ public ChebyshevTest(String name) {
+ super(name);
+ }
+
+ public void aatestOne() {
+ assertTrue(new Chebyshev().isOne());
+ }
+
+ public void testFirstPolynomials() {
+
+ checkPolynomial(new Chebyshev(3), "-3 x + 4 x^3");
+ checkPolynomial(new Chebyshev(2), "-1 + 2 x^2");
+ checkPolynomial(new Chebyshev(1), "x");
+ checkPolynomial(new Chebyshev(0), "1");
+
+ checkPolynomial(new Chebyshev(7), "-7 x + 56 x^3 - 112 x^5 + 64 x^7");
+ checkPolynomial(new Chebyshev(6), "-1 + 18 x^2 - 48 x^4 + 32 x^6");
+ checkPolynomial(new Chebyshev(5), "5 x - 20 x^3 + 16 x^5");
+ checkPolynomial(new Chebyshev(4), "1 - 8 x^2 + 8 x^4");
+
+ }
+
+ public void aatestBounds() {
+ for (int k = 0; k < 12; ++k) {
+ Chebyshev Tk = new Chebyshev(k);
+ for (double x = -1.0; x <= 1.0; x += 0.02) {
+ assertTrue(Math.abs(Tk.valueAt(x)) < (1.0 + 1.0e-12));
+ }
+ }
+ }
+
+ public void aatestDifferentials() {
+ for (int k = 0; k < 12; ++k) {
+
+ Polynomial.Rational Tk0 = new Chebyshev(k);
+ Polynomial.Rational Tk1 = (Polynomial.Rational) Tk0.getDerivative();
+ Polynomial.Rational Tk2 = (Polynomial.Rational) Tk1.getDerivative();
+
+ Polynomial.Rational g0 = new Polynomial.Rational(k * k);
+ Polynomial.Rational g1 = new Polynomial.Rational(-1l, 0l);
+ Polynomial.Rational g2 = new Polynomial.Rational(-1l, 0l, 1l);
+
+ Polynomial.Rational Tk0g0 = Polynomial.Rational.multiply(Tk0, g0);
+ Polynomial.Rational Tk1g1 = Polynomial.Rational.multiply(Tk1, g1);
+ Polynomial.Rational Tk2g2 = Polynomial.Rational.multiply(Tk2, g2);
+
+ Polynomial.Rational d =
+ Polynomial.Rational.add(Tk0g0, Polynomial.Rational.add(Tk1g1, Tk2g2));
+ assertTrue(d.isZero());
+
+ }
+ }
+
+ public void checkPolynomial(Polynomial.Rational p, String reference) {
+ assertTrue(p.toString().equals(reference));
+ }
+
+ public static Test suite() {
+ return new TestSuite(ChebyshevTest.class);
+ }
+
+}
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/ChebyshevTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/ChebyshevTest.java
------------------------------------------------------------------------------
svn:executable = *
Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/HermiteTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/HermiteTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/HermiteTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/HermiteTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,77 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.algebra;
+
+import junit.framework.*;
+
+public class HermiteTest
+ extends TestCase {
+
+ public HermiteTest(String name) {
+ super(name);
+ }
+
+ public void testOne() {
+ assertTrue(new Hermite().isOne());
+ }
+
+ public void testFirstPolynomials() {
+
+ checkPolynomial(new Hermite(3), "-12 x + 8 x^3");
+ checkPolynomial(new Hermite(2), "-2 + 4 x^2");
+ checkPolynomial(new Hermite(1), "2 x");
+ checkPolynomial(new Hermite(0), "1");
+
+ checkPolynomial(new Hermite(7), "-1680 x + 3360 x^3 - 1344 x^5 + 128 x^7");
+ checkPolynomial(new Hermite(6), "-120 + 720 x^2 - 480 x^4 + 64 x^6");
+ checkPolynomial(new Hermite(5), "120 x - 160 x^3 + 32 x^5");
+ checkPolynomial(new Hermite(4), "12 - 48 x^2 + 16 x^4");
+
+ }
+
+ public void testDifferentials() {
+ for (int k = 0; k < 12; ++k) {
+
+ Polynomial.Rational Hk0 = new Hermite(k);
+ Polynomial.Rational Hk1 = (Polynomial.Rational) Hk0.getDerivative();
+ Polynomial.Rational Hk2 = (Polynomial.Rational) Hk1.getDerivative();
+
+ Polynomial.Rational g0 = new Polynomial.Rational(2l * k);
+ Polynomial.Rational g1 = new Polynomial.Rational(-2l, 0l);
+ Polynomial.Rational g2 = new Polynomial.Rational(1l);
+
+ Polynomial.Rational Hk0g0 = Polynomial.Rational.multiply(Hk0, g0);
+ Polynomial.Rational Hk1g1 = Polynomial.Rational.multiply(Hk1, g1);
+ Polynomial.Rational Hk2g2 = Polynomial.Rational.multiply(Hk2, g2);
+
+ Polynomial.Rational d =
+ Polynomial.Rational.add(Hk0g0, Polynomial.Rational.add(Hk1g1, Hk2g2));
+ assertTrue(d.isZero());
+
+ }
+ }
+
+ public void checkPolynomial(Polynomial.Rational p, String reference) {
+ assertTrue(p.toString().equals(reference));
+ }
+
+ public static Test suite() {
+ return new TestSuite(HermiteTest.class);
+ }
+
+}
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/HermiteTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/HermiteTest.java
------------------------------------------------------------------------------
svn:executable = *
Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/LaguerreTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/LaguerreTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/LaguerreTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/LaguerreTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,83 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.algebra;
+
+import junit.framework.*;
+
+public class LaguerreTest
+ extends TestCase {
+
+ public LaguerreTest(String name) {
+ super(name);
+ }
+
+ public void testOne() {
+ assertTrue(new Laguerre().isOne());
+ }
+
+ public void testFirstPolynomials() {
+
+ checkLaguerre(new Laguerre(3), 6l, "6 - 18 x + 9 x^2 - x^3");
+ checkLaguerre(new Laguerre(2), 2l, "2 - 4 x + x^2");
+ checkLaguerre(new Laguerre(1), 1l, "1 - x");
+ checkLaguerre(new Laguerre(0), 1l, "1");
+
+ checkLaguerre(new Laguerre(7), 5040l,
+ "5040 - 35280 x + 52920 x^2 - 29400 x^3"
+ + " + 7350 x^4 - 882 x^5 + 49 x^6 - x^7");
+ checkLaguerre(new Laguerre(6), 720l,
+ "720 - 4320 x + 5400 x^2 - 2400 x^3 + 450 x^4"
+ + " - 36 x^5 + x^6");
+ checkLaguerre(new Laguerre(5), 120l,
+ "120 - 600 x + 600 x^2 - 200 x^3 + 25 x^4 - x^5");
+ checkLaguerre(new Laguerre(4), 24l,
+ "24 - 96 x + 72 x^2 - 16 x^3 + x^4");
+
+ }
+
+ public void testDifferentials() {
+ for (int k = 0; k < 12; ++k) {
+
+ Polynomial.Rational Lk0 = new Laguerre(k);
+ Polynomial.Rational Lk1 = (Polynomial.Rational) Lk0.getDerivative();
+ Polynomial.Rational Lk2 = (Polynomial.Rational) Lk1.getDerivative();
+
+ Polynomial.Rational g0 = new Polynomial.Rational(k);
+ Polynomial.Rational g1 = new Polynomial.Rational(-1l, 1l);
+ Polynomial.Rational g2 = new Polynomial.Rational(1l, 0l);
+
+ Polynomial.Rational Lk0g0 = Polynomial.Rational.multiply(Lk0, g0);
+ Polynomial.Rational Lk1g1 = Polynomial.Rational.multiply(Lk1, g1);
+ Polynomial.Rational Lk2g2 = Polynomial.Rational.multiply(Lk2, g2);
+
+ Polynomial.Rational d =
+ Polynomial.Rational.add(Lk0g0, Polynomial.Rational.add(Lk1g1, Lk2g2));
+ assertTrue(d.isZero());
+
+ }
+ }
+
+ public void checkLaguerre(Laguerre p, long denominator, String reference) {
+ assertTrue(Laguerre.multiply(p, denominator).toString().equals(reference));
+ }
+
+ public static Test suite() {
+ return new TestSuite(LaguerreTest.class);
+ }
+
+}
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/LaguerreTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/LegendreTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/LegendreTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/LegendreTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/LegendreTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,102 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.algebra;
+
+import junit.framework.*;
+
+public class LegendreTest
+ extends TestCase {
+
+ public LegendreTest(String name) {
+ super(name);
+ }
+
+ public void testOne() {
+ assertTrue(new Legendre().isOne());
+ }
+
+ public void testFirstPolynomials() {
+
+ checkLegendre(new Legendre(3), 2l, "-3 x + 5 x^3");
+ checkLegendre(new Legendre(2), 2l, "-1 + 3 x^2");
+ checkLegendre(new Legendre(1), 1l, "x");
+ checkLegendre(new Legendre(0), 1l, "1");
+
+ checkLegendre(new Legendre(7), 16l, "-35 x + 315 x^3 - 693 x^5 + 429 x^7");
+ checkLegendre(new Legendre(6), 16l, "-5 + 105 x^2 - 315 x^4 + 231 x^6");
+ checkLegendre(new Legendre(5), 8l, "15 x - 70 x^3 + 63 x^5");
+ checkLegendre(new Legendre(4), 8l, "3 - 30 x^2 + 35 x^4");
+
+ }
+
+ public void testDifferentials() {
+ for (int k = 0; k < 12; ++k) {
+
+ Polynomial.Rational Pk0 = new Legendre(k);
+ Polynomial.Rational Pk1 = (Polynomial.Rational) Pk0.getDerivative();
+ Polynomial.Rational Pk2 = (Polynomial.Rational) Pk1.getDerivative();
+
+ Polynomial.Rational g0 = new Polynomial.Rational(k * (k + 1));
+ Polynomial.Rational g1 = new Polynomial.Rational(-2l, 0l);
+ Polynomial.Rational g2 = new Polynomial.Rational(-1l, 0l, 1l);
+
+ Polynomial.Rational Pk0g0 = Polynomial.Rational.multiply(Pk0, g0);
+ Polynomial.Rational Pk1g1 = Polynomial.Rational.multiply(Pk1, g1);
+ Polynomial.Rational Pk2g2 = Polynomial.Rational.multiply(Pk2, g2);
+
+ Polynomial.Rational d =
+ Polynomial.Rational.add(Pk0g0, Polynomial.Rational.add(Pk1g1, Pk2g2));
+ assertTrue(d.isZero());
+
+ }
+ }
+
+ public void testHighDegree() {
+ checkLegendre(new Legendre(40), 274877906944l,
+ "34461632205"
+ + " - 28258538408100 x^2"
+ + " + 3847870979902950 x^4"
+ + " - 207785032914759300 x^6"
+ + " + 5929294332103310025 x^8"
+ + " - 103301483474866556880 x^10"
+ + " + 1197358103913226000200 x^12"
+ + " - 9763073770369381232400 x^14"
+ + " + 58171647881784229843050 x^16"
+ + " - 260061484647976556945400 x^18"
+ + " + 888315281771246239250340 x^20"
+ + " - 2345767627188139419665400 x^22"
+ + " + 4819022625419112503443050 x^24"
+ + " - 7710436200670580005508880 x^26"
+ + " + 9566652323054238154983240 x^28"
+ + " - 9104813935044723209570256 x^30"
+ + " + 6516550296251767619752905 x^32"
+ + " - 3391858621221953912598660 x^34"
+ + " + 1211378079007840683070950 x^36"
+ + " - 265365894974690562152100 x^38"
+ + " + 26876802183334044115405 x^40");
+ }
+
+ public void checkLegendre(Legendre p, long denominator, String reference) {
+ assertTrue(Legendre.multiply(p, denominator).toString().equals(reference));
+ }
+
+ public static Test suite() {
+ return new TestSuite(LegendreTest.class);
+ }
+
+}
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/LegendreTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/LegendreTest.java
------------------------------------------------------------------------------
svn:executable = *
Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/PolynomialDoubleTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/PolynomialDoubleTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/PolynomialDoubleTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/PolynomialDoubleTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,139 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.algebra;
+
+import junit.framework.*;
+
+public class PolynomialDoubleTest
+ extends TestCase {
+
+ public PolynomialDoubleTest(String name) {
+ super(name);
+ }
+
+ public void testConstructors() {
+
+ Polynomial.Double p = new Polynomial.Double(1.0, 3.0, -5.0);
+ double[] a = p.getCoefficients();
+ assertEquals(a.length, 3);
+ assertEquals(-5.0, a[0], 1.0e-12);
+ assertEquals(3.0, a[1], 1.0e-12);
+ assertEquals(1.0, a[2], 1.0e-12);
+ assertEquals(p.getDegree(), 2);
+
+ assertEquals(1, new Polynomial.Double(0.0, 3.0, 5.0).getDegree());
+ assertEquals(0, new Polynomial.Double(0.0, 0.0, 5.0).getDegree());
+ assertEquals(0, new Polynomial.Double(0.0, 0.0, 0.0).getDegree());
+ assertEquals(1, new Polynomial.Double(3.0, 5.0).getDegree());
+ assertEquals(0, new Polynomial.Double(0.0, 5.0).getDegree());
+ assertEquals(0, new Polynomial.Double(0.0, 0.0).getDegree());
+ assertEquals(0, new Polynomial.Double(5.0).getDegree());
+ assertEquals(0, new Polynomial.Double(0.0).getDegree());
+
+ }
+
+ public void testConversion() {
+ Polynomial.Rational r = new Polynomial.Rational(1l, 3l, -5l);
+ r.multiplySelf(new RationalNumber(1l, 2l));
+ Polynomial.Double p = new Polynomial.Double(r);
+ checkPolynomial(p, "-2.5 + 1.5 x + 0.5 x^2");
+ }
+
+ public void testString() {
+
+ Polynomial.Double p = new Polynomial.Double(1.0, 3.0, -5.0);
+ checkPolynomial(p, "-5.0 + 3.0 x + x^2");
+ p.setUnknownName("alpha");
+ checkPolynomial(p, "-5.0 + 3.0 alpha + alpha^2");
+ p.setUnknownName(null);
+ checkPolynomial(p, "-5.0 + 3.0 x + x^2");
+
+ checkPolynomial(new Polynomial.Double(3.0, -2.0, 0.0),
+ "-2.0 x + 3.0 x^2");
+ checkPolynomial(new Polynomial.Double(3.0, -2.0, 1.0),
+ "1.0 - 2.0 x + 3.0 x^2");
+ checkPolynomial(new Polynomial.Double(3.0, 2.0, 0.0),
+ "2.0 x + 3.0 x^2");
+ checkPolynomial(new Polynomial.Double(3.0, 2.0, 1.0),
+ "1.0 + 2.0 x + 3.0 x^2");
+ checkPolynomial(new Polynomial.Double(3.0, 0.0, 1.0),
+ "1.0 + 3.0 x^2");
+ checkPolynomial(new Polynomial.Double(0.0),
+ "0");
+
+ }
+
+ public void testAddition() {
+
+ Polynomial.Double p1 = new Polynomial.Double(1.0, -2.0);
+ Polynomial.Double p2 = new Polynomial.Double(0.0, -1.0, 2.0);
+ assertTrue(Polynomial.Double.add(p1, p2).isZero());
+
+ p2 = new Polynomial.Double(p1);
+ p2.addToSelf(p2);
+ checkPolynomial(p2, "-4.0 + 2.0 x");
+
+ p1 = new Polynomial.Double(2.0, -4.0, 1.0);
+ p2 = new Polynomial.Double(-2.0, 3.0, -1.0);
+ p1.addToSelf(p2);
+ assertEquals(1, p1.getDegree());
+ checkPolynomial(p1, "-x");
+
+ }
+
+ public void testSubtraction() {
+
+ Polynomial.Double p1 = new Polynomial.Double(1.0, -2.0);
+ assertTrue(Polynomial.Double.subtract(p1, p1).isZero());
+
+ Polynomial.Double p2 = new Polynomial.Double(6.0, -2.0);
+ p2.subtractFromSelf(p1);
+ checkPolynomial(p2, "5.0 x");
+
+ p1 = new Polynomial.Double(2.0, -4.0, 1.0);
+ p2 = new Polynomial.Double(2.0, 3.0, -1.0);
+ p1.subtractFromSelf(p2);
+ assertEquals(1, p1.getDegree());
+ checkPolynomial(p1, "2.0 - 7.0 x");
+
+ }
+
+ public void testMultiplication() {
+
+ Polynomial.Double p1 = new Polynomial.Double(2.0, -3.0);
+ Polynomial.Double p2 = new Polynomial.Double(1.0, 2.0, 3.0);
+ checkPolynomial(Polynomial.Double.multiply(p1, p2), "-9.0 + x^2 + 2.0 x^3");
+
+ p1 = new Polynomial.Double(1.0, 0.0);
+ p2 = new Polynomial.Double(p1);
+ for (int i = 2; i < 10; ++i) {
+ p2.multiplySelf(p1);
+ checkPolynomial(p2, "x^" + i);
+ }
+
+ }
+
+ public void checkPolynomial(Polynomial.Double p, String reference) {
+ assertEquals(reference, p.toString());
+ }
+
+ public static Test suite() {
+ return new TestSuite(PolynomialDoubleTest.class);
+ }
+
+}
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/PolynomialDoubleTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/PolynomialDoubleTest.java
------------------------------------------------------------------------------
svn:executable = *
Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/PolynomialFractionTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/PolynomialFractionTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/PolynomialFractionTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/PolynomialFractionTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,223 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.algebra;
+
+import junit.framework.*;
+
+public class PolynomialFractionTest
+ extends TestCase {
+
+ public PolynomialFractionTest(String name) {
+ super(name);
+ }
+
+ public void testNullDenominator() {
+ try {
+ new PolynomialFraction(1l, 0l);
+ fail("an exception should have been thrown");
+ } catch (ArithmeticException e) {
+ } catch (Exception e) {
+ fail("wrong exception caught");
+ }
+ }
+
+ public void testToString() {
+ checkValue(new PolynomialFraction(1l, 2l), "1/2");
+ checkValue(new PolynomialFraction(-1l, 2l), "-1/2");
+ checkValue(new PolynomialFraction(1l, -2l), "-1/2");
+ checkValue(new PolynomialFraction(-1l, -2l), "1/2");
+ checkValue(new PolynomialFraction(0l, 500l), "0");
+ checkValue(new PolynomialFraction(-12l), "-12");
+ checkValue(new PolynomialFraction(12l), "12");
+ }
+
+ public void testSimplification() {
+ checkValue(new PolynomialFraction(2l, 4l), "1/2");
+ checkValue(new PolynomialFraction(307692l, 999999l), "4/13");
+ checkValue(new PolynomialFraction(999999l, 307692l), "13/4");
+ }
+
+ public void testInvert() {
+
+ PolynomialFraction f = new PolynomialFraction(2l, 4l);
+ f.invertSelf();
+ checkValue(f, "2");
+ f.invertSelf();
+ checkValue(f, "1/2");
+
+ f = new PolynomialFraction(120l);
+ f.invertSelf();
+ checkValue(f, "1/120");
+
+ f = new PolynomialFraction(0l, 4l);
+ try {
+ f.invertSelf();
+ fail("an exception should have been thrown");
+ } catch (ArithmeticException e) {
+ } catch (Exception e) {
+ fail("wrong exception caught");
+ }
+
+ f = new PolynomialFraction(307692l, 999999l);
+ PolynomialFraction fInverse = PolynomialFraction.invert(f);
+ checkValue(fInverse, "13/4");
+ checkValue(f, "4/13");
+
+ }
+
+ public void testAddition() {
+
+ PolynomialFraction f1 = new PolynomialFraction(4l, 6l);
+ f1.addToSelf(f1);
+ checkValue(f1, "4/3");
+
+ checkValue(PolynomialFraction.add(new PolynomialFraction(17l, 3l),
+ new PolynomialFraction(-17l, 3l)),
+ "0");
+ checkValue(PolynomialFraction.add(new PolynomialFraction(2l, 3l),
+ new PolynomialFraction(3l, 4l)),
+ "17/12");
+ checkValue(PolynomialFraction.add(new PolynomialFraction(1l, 6l),
+ new PolynomialFraction(2l, 6l)),
+ "1/2");
+ checkValue(PolynomialFraction.add(new PolynomialFraction(4l, 5l),
+ new PolynomialFraction(-3l, 4l)),
+ "1/20");
+ checkValue(PolynomialFraction.add(new PolynomialFraction(-3l, 4l),
+ new PolynomialFraction(4l, 5l)),
+ "1/20");
+
+ }
+
+ public void testSubtraction() {
+
+ PolynomialFraction f1 = new PolynomialFraction(4l, 6l);
+ f1.subtractFromSelf(f1);
+ checkValue(f1, "0");
+
+ checkValue(PolynomialFraction.subtract(new PolynomialFraction(7l, 3l),
+ new PolynomialFraction(-7l, 3l)),
+ "14/3");
+
+ checkValue(PolynomialFraction.subtract(new PolynomialFraction(3l, 4l),
+ new PolynomialFraction(2l, 3l)),
+ "1/12");
+ checkValue(PolynomialFraction.subtract(new PolynomialFraction(3l, 4l),
+ new PolynomialFraction(-2l, 3l)),
+ "17/12");
+ checkValue(PolynomialFraction.subtract(new PolynomialFraction(-3l, 4l),
+ new PolynomialFraction(2l, 3l)),
+ "-17/12");
+ checkValue(PolynomialFraction.subtract(new PolynomialFraction(-3l, 4l),
+ new PolynomialFraction(-2l, 3l)),
+ "-1/12");
+
+ checkValue(PolynomialFraction.subtract(new PolynomialFraction(2l, 3l),
+ new PolynomialFraction(3l, 4l)),
+ "-1/12");
+ checkValue(PolynomialFraction.subtract(new PolynomialFraction(-2l, 3l),
+ new PolynomialFraction(3l, 4l)),
+ "-17/12");
+ checkValue(PolynomialFraction.subtract(new PolynomialFraction(2l, 3l),
+ new PolynomialFraction(-3l, 4l)),
+ "17/12");
+ checkValue(PolynomialFraction.subtract(new PolynomialFraction(-2l, 3l),
+ new PolynomialFraction(-3l, 4l)),
+ "1/12");
+
+ checkValue(PolynomialFraction.subtract(new PolynomialFraction(1l, 6l),
+ new PolynomialFraction(2l, 6l)),
+ "-1/6");
+ checkValue(PolynomialFraction.subtract(new PolynomialFraction(1l, 2l),
+ new PolynomialFraction(1l, 6l)),
+ "1/3");
+
+ }
+
+ public void testMultiplication() {
+
+ PolynomialFraction f = new PolynomialFraction(2l, 3l);
+ f.multiplySelf(new PolynomialFraction(9l,4l));
+ checkValue(f, "3/2");
+
+ checkValue(PolynomialFraction.multiply(new PolynomialFraction(1l, 2l),
+ new PolynomialFraction(0l)),
+ "0");
+ checkValue(PolynomialFraction.multiply(new PolynomialFraction(4l, 15l),
+ new PolynomialFraction(-5l, 2l)),
+ "-2/3");
+ checkValue(PolynomialFraction.multiply(new PolynomialFraction(-4l, 15l),
+ new PolynomialFraction(5l, 2l)),
+ "-2/3");
+ checkValue(PolynomialFraction.multiply(new PolynomialFraction(4l, 15l),
+ new PolynomialFraction(5l, 2l)),
+ "2/3");
+ checkValue(PolynomialFraction.multiply(new PolynomialFraction(-4l, 15l),
+ new PolynomialFraction(-5l, 2l)),
+ "2/3");
+
+ }
+
+ public void testDivision() {
+
+ PolynomialFraction f = new PolynomialFraction(2l, 3l);
+ f.divideSelf(new PolynomialFraction(4l,9l));
+ checkValue(f, "3/2");
+
+ try {
+ PolynomialFraction.divide(new PolynomialFraction(1l, 2l),
+ new PolynomialFraction(0l));
+ fail("an exception should have been thrown");
+ } catch (ArithmeticException e) {
+ } catch (Exception e) {
+ fail("wrong exception caught");
+ }
+
+ checkValue(PolynomialFraction.divide(new PolynomialFraction(4l, 15l),
+ new PolynomialFraction(-2l, 5l)),
+ "-2/3");
+ checkValue(PolynomialFraction.divide(new PolynomialFraction(-4l, 15l),
+ new PolynomialFraction(2l, 5l)),
+ "-2/3");
+ checkValue(PolynomialFraction.divide(new PolynomialFraction(4l, 15l),
+ new PolynomialFraction(2l, 5l)),
+ "2/3");
+ checkValue(PolynomialFraction.divide(new PolynomialFraction(-4l, 15l),
+ new PolynomialFraction(-2l, 5l)),
+ "2/3");
+
+ }
+
+ public void testEuclidianDivision() {
+ checkValue(new PolynomialFraction(new Polynomial.Rational(1l, 0l, -1l),
+ new Polynomial.Rational(2l, 2l)),
+ "-1/2 + 1/2 x");
+ checkValue(new PolynomialFraction(new Polynomial.Rational(1l, 3l, 2l),
+ new Polynomial.Rational(2l, 10l, 12l)),
+ "(1 + x)/(6 + 2 x)");
+ }
+
+ private void checkValue(PolynomialFraction f, String reference) {
+ assertTrue(f.toString().equals(reference));
+ }
+
+ public static Test suite() {
+ return new TestSuite(PolynomialFractionTest.class);
+ }
+
+}
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/PolynomialFractionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/PolynomialFractionTest.java
------------------------------------------------------------------------------
svn:executable = *
Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/PolynomialRationalTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/PolynomialRationalTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/PolynomialRationalTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/PolynomialRationalTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,151 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.algebra;
+
+import java.math.BigInteger;
+
+import junit.framework.*;
+
+public class PolynomialRationalTest
+ extends TestCase {
+
+ public PolynomialRationalTest(String name) {
+ super(name);
+ }
+
+ public void testZero() {
+ assertTrue(new Polynomial.Rational().isZero());
+ }
+
+ public void testConstructors() {
+
+ Polynomial.Rational p = new Polynomial.Rational(1l, 3l, -5l);
+ RationalNumber[] a = p.getCoefficients();
+ assertEquals(a.length, 3);
+ assertEquals(new RationalNumber(-5l), a[0]);
+ assertEquals(new RationalNumber(3l), a[1]);
+ assertEquals(new RationalNumber(1l), a[2]);
+ assertEquals(2, p.getDegree());
+
+ assertEquals(1, new Polynomial.Rational(0l, 3l, 5l).getDegree());
+ assertEquals(0, new Polynomial.Rational(0l, 0l, 5l).getDegree());
+ assertEquals(0, new Polynomial.Rational(0l, 0l, 0l).getDegree());
+ assertEquals(1, new Polynomial.Rational(3l, 5l).getDegree());
+ assertEquals(0, new Polynomial.Rational(0l, 5l).getDegree());
+ assertEquals(0, new Polynomial.Rational(0l, 0l).getDegree());
+ assertEquals(0, new Polynomial.Rational(5l).getDegree());
+ assertEquals(0, new Polynomial.Rational(0l).getDegree());
+
+ }
+
+ public void testString() {
+
+ Polynomial.Rational p = new Polynomial.Rational(1l, 3l, -5l);
+ checkPolynomial(p, "-5 + 3 x + x^2");
+ p.setUnknownName("alpha");
+ checkPolynomial(p, "-5 + 3 alpha + alpha^2");
+ p.setUnknownName(null);
+ checkPolynomial(p, "-5 + 3 x + x^2");
+
+ checkPolynomial(new Polynomial.Rational(3l, -2l, 0l), "-2 x + 3 x^2");
+ checkPolynomial(new Polynomial.Rational(3l, -2l, 1l), "1 - 2 x + 3 x^2");
+ checkPolynomial(new Polynomial.Rational(3l, 2l, 0l), "2 x + 3 x^2");
+ checkPolynomial(new Polynomial.Rational(3l, 2l, 1l), "1 + 2 x + 3 x^2");
+ checkPolynomial(new Polynomial.Rational(3l, 0l, 1l), "1 + 3 x^2");
+ checkPolynomial(new Polynomial.Rational(0l), "0");
+
+ }
+
+ public void testAddition() {
+
+ Polynomial.Rational p1 = new Polynomial.Rational(1l, -2l);
+ Polynomial.Rational p2 = new Polynomial.Rational(0l, -1l, 2l);
+ assertTrue(Polynomial.Rational.add(p1, p2).isZero());
+
+ p2 = new Polynomial.Rational(p1);
+ p2.addToSelf(p2);
+ checkPolynomial(p2, "-4 + 2 x");
+
+ p1 = new Polynomial.Rational(2l, -4l, 1l);
+ p2 = new Polynomial.Rational(-2l, 3l, -1l);
+ p1.addToSelf(p2);
+ assertEquals(1, p1.getDegree());
+ checkPolynomial(p1, "-x");
+
+ }
+
+ public void testSubtraction() {
+
+ Polynomial.Rational p1 = new Polynomial.Rational(1l, -2l);
+ assertTrue(Polynomial.Rational.subtract(p1, p1).isZero());
+
+ Polynomial.Rational p2 = new Polynomial.Rational(6l, -2l);
+ p2.subtractFromSelf(p1);
+ checkPolynomial(p2, "5 x");
+
+ p1 = new Polynomial.Rational(2l, -4l, 1l);
+ p2 = new Polynomial.Rational(2l, 3l, -1l);
+ p1.subtractFromSelf(p2);
+ assertEquals(1, p1.getDegree());
+ checkPolynomial(p1, "2 - 7 x");
+
+ }
+
+ public void testMultiplication() {
+
+ Polynomial.Rational p1 = new Polynomial.Rational(2l, -3l);
+ Polynomial.Rational p2 = new Polynomial.Rational(1l, 2l, 3l);
+ checkPolynomial(Polynomial.Rational.multiply(p1, p2), "-9 + x^2 + 2 x^3");
+
+ p1 = new Polynomial.Rational(1l, 0l);
+ p2 = new Polynomial.Rational(p1);
+ for (int i = 2; i < 10; ++i) {
+ p2.multiplySelf(p1);
+ checkPolynomial(p2, "x^" + i);
+ }
+
+ }
+
+ public void testLCM() {
+ Polynomial.Rational p = new Polynomial.Rational(new RationalNumber(2l, 5l),
+ new RationalNumber(-1l, 6l),
+ new RationalNumber(3l, 4l));
+ checkPolynomial(p, "3/4 - 1/6 x + 2/5 x^2");
+ BigInteger lcm = p.getDenominatorsLCM();
+ assertEquals(BigInteger.valueOf(60l), lcm);
+ p.multiplySelf(lcm);
+ checkPolynomial(p, "45 - 10 x + 24 x^2");
+ }
+
+ public void testEuclidianDivision() {
+ Polynomial.Rational p = new Polynomial.Rational(4l, 6l, -3l);
+ Polynomial.Rational q = new Polynomial.Rational(3l, 2l);
+ Polynomial.DivisionResult res = Polynomial.Rational.euclidianDivision(p, q);
+ checkPolynomial(res.quotient, "10/9 + 4/3 x");
+ checkPolynomial(res.remainder, "-47/9");
+ }
+
+ public void checkPolynomial(Polynomial.Rational p, String reference) {
+ assertEquals(reference, p.toString());
+ }
+
+ public static Test suite() {
+ return new TestSuite(PolynomialRationalTest.class);
+ }
+
+}
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/PolynomialRationalTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/PolynomialRationalTest.java
------------------------------------------------------------------------------
svn:executable = *
Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/RationalNumberTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/RationalNumberTest.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/RationalNumberTest.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/RationalNumberTest.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,214 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.algebra;
+
+import junit.framework.*;
+
+public class RationalNumberTest
+ extends TestCase {
+
+ public RationalNumberTest(String name) {
+ super(name);
+ }
+
+ public void testNullDenominator() {
+ try {
+ new RationalNumber(1l, 0l);
+ fail("an exception should have been thrown");
+ } catch (ArithmeticException e) {
+ } catch (Exception e) {
+ fail("wrong exception caught");
+ }
+ }
+
+ public void testToString() {
+ checkValue(new RationalNumber(1l, 2l), "1/2");
+ checkValue(new RationalNumber(-1l, 2l), "-1/2");
+ checkValue(new RationalNumber(1l, -2l), "-1/2");
+ checkValue(new RationalNumber(-1l, -2l), "1/2");
+ checkValue(new RationalNumber(0l, 500l), "0");
+ checkValue(new RationalNumber(-12l), "-12");
+ checkValue(new RationalNumber(12l), "12");
+ }
+
+ public void testSimplification() {
+ checkValue(new RationalNumber(2l, 4l), "1/2");
+ checkValue(new RationalNumber(307692l, 999999l), "4/13");
+ checkValue(new RationalNumber(999999l, 307692l), "13/4");
+ }
+
+ public void testInvert() {
+
+ RationalNumber f = new RationalNumber(2l, 4l);
+ f.invertSelf();
+ checkValue(f, "2");
+ f.invertSelf();
+ checkValue(f, "1/2");
+
+ f = new RationalNumber(120l);
+ f.invertSelf();
+ checkValue(f, "1/120");
+
+ f = new RationalNumber(0l, 4l);
+ try {
+ f.invertSelf();
+ fail("an exception should have been thrown");
+ } catch (ArithmeticException e) {
+ } catch (Exception e) {
+ fail("wrong exception caught");
+ }
+
+ f = new RationalNumber(307692l, 999999l);
+ RationalNumber fInverse = RationalNumber.invert(f);
+ checkValue(fInverse, "13/4");
+ checkValue(f, "4/13");
+
+ }
+
+ public void testAddition() {
+
+ RationalNumber f1 = new RationalNumber(4l, 6l);
+ f1.addToSelf(f1);
+ checkValue(f1, "4/3");
+
+ checkValue(RationalNumber.add(new RationalNumber(17l, 3l),
+ new RationalNumber(-17l, 3l)),
+ "0");
+ checkValue(RationalNumber.add(new RationalNumber(2l, 3l),
+ new RationalNumber(3l, 4l)),
+ "17/12");
+ checkValue(RationalNumber.add(new RationalNumber(1l, 6l),
+ new RationalNumber(2l, 6l)),
+ "1/2");
+ checkValue(RationalNumber.add(new RationalNumber(4l, 5l),
+ new RationalNumber(-3l, 4l)),
+ "1/20");
+ checkValue(RationalNumber.add(new RationalNumber(-3l, 4l),
+ new RationalNumber(4l, 5l)),
+ "1/20");
+
+ }
+
+ public void testSubtraction() {
+
+ RationalNumber f1 = new RationalNumber(4l, 6l);
+ f1.subtractFromSelf(f1);
+ checkValue(f1, "0");
+
+ checkValue(RationalNumber.subtract(new RationalNumber(7l, 3l),
+ new RationalNumber(-7l, 3l)),
+ "14/3");
+
+ checkValue(RationalNumber.subtract(new RationalNumber(3l, 4l),
+ new RationalNumber(2l, 3l)),
+ "1/12");
+ checkValue(RationalNumber.subtract(new RationalNumber(3l, 4l),
+ new RationalNumber(-2l, 3l)),
+ "17/12");
+ checkValue(RationalNumber.subtract(new RationalNumber(-3l, 4l),
+ new RationalNumber(2l, 3l)),
+ "-17/12");
+ checkValue(RationalNumber.subtract(new RationalNumber(-3l, 4l),
+ new RationalNumber(-2l, 3l)),
+ "-1/12");
+
+ checkValue(RationalNumber.subtract(new RationalNumber(2l, 3l),
+ new RationalNumber(3l, 4l)),
+ "-1/12");
+ checkValue(RationalNumber.subtract(new RationalNumber(-2l, 3l),
+ new RationalNumber(3l, 4l)),
+ "-17/12");
+ checkValue(RationalNumber.subtract(new RationalNumber(2l, 3l),
+ new RationalNumber(-3l, 4l)),
+ "17/12");
+ checkValue(RationalNumber.subtract(new RationalNumber(-2l, 3l),
+ new RationalNumber(-3l, 4l)),
+ "1/12");
+
+ checkValue(RationalNumber.subtract(new RationalNumber(1l, 6l),
+ new RationalNumber(2l, 6l)),
+ "-1/6");
+ checkValue(RationalNumber.subtract(new RationalNumber(1l, 2l),
+ new RationalNumber(1l, 6l)),
+ "1/3");
+
+ }
+
+ public void testMultiplication() {
+
+ RationalNumber f = new RationalNumber(2l, 3l);
+ f.multiplySelf(new RationalNumber(9l,4l));
+ checkValue(f, "3/2");
+
+ checkValue(RationalNumber.multiply(new RationalNumber(1l, 2l),
+ new RationalNumber(0l)),
+ "0");
+ checkValue(RationalNumber.multiply(new RationalNumber(4l, 15l),
+ new RationalNumber(-5l, 2l)),
+ "-2/3");
+ checkValue(RationalNumber.multiply(new RationalNumber(-4l, 15l),
+ new RationalNumber(5l, 2l)),
+ "-2/3");
+ checkValue(RationalNumber.multiply(new RationalNumber(4l, 15l),
+ new RationalNumber(5l, 2l)),
+ "2/3");
+ checkValue(RationalNumber.multiply(new RationalNumber(-4l, 15l),
+ new RationalNumber(-5l, 2l)),
+ "2/3");
+
+ }
+
+ public void testDivision() {
+
+ RationalNumber f = new RationalNumber(2l, 3l);
+ f.divideSelf(new RationalNumber(4l,9l));
+ checkValue(f, "3/2");
+
+ try {
+ RationalNumber.divide(new RationalNumber(1l, 2l),
+ new RationalNumber(0l));
+ fail("an exception should have been thrown");
+ } catch (ArithmeticException e) {
+ } catch (Exception e) {
+ fail("wrong exception caught");
+ }
+
+ checkValue(RationalNumber.divide(new RationalNumber(4l, 15l),
+ new RationalNumber(-2l, 5l)),
+ "-2/3");
+ checkValue(RationalNumber.divide(new RationalNumber(-4l, 15l),
+ new RationalNumber(2l, 5l)),
+ "-2/3");
+ checkValue(RationalNumber.divide(new RationalNumber(4l, 15l),
+ new RationalNumber(2l, 5l)),
+ "2/3");
+ checkValue(RationalNumber.divide(new RationalNumber(-4l, 15l),
+ new RationalNumber(-2l, 5l)),
+ "2/3");
+
+ }
+
+ private void checkValue(RationalNumber f, String reference) {
+ assertTrue(f.toString().equals(reference));
+ }
+
+ public static Test suite() {
+ return new TestSuite(RationalNumberTest.class);
+ }
+
+}
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/algebra/RationalNumberTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/estimation/AllTests.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/estimation/AllTests.java?view=auto&rev=476930
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/estimation/AllTests.java (added)
+++ jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/estimation/AllTests.java Sun Nov 19 13:36:15 2006
@@ -0,0 +1,38 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.spaceroots.mantissa.estimation;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllTests {
+
+ public static Test suite() {
+
+ TestSuite suite = new TestSuite("org.spaceroots.mantissa.estimation");
+
+ suite.addTest(EstimatedParameterTest.suite());
+ suite.addTest(WeightedMeasurementTest.suite());
+ suite.addTest(GaussNewtonEstimatorTest.suite());
+ suite.addTest(LevenbergMarquardtEstimatorTest.suite());
+
+ return suite;
+
+ }
+
+}
Propchange: jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/estimation/AllTests.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org