Hipparchus-Math / hipparchus

An efficient, general-purpose mathematics components library in the Java programming language
Apache License 2.0
139 stars 41 forks source link

Optional test method / lambda expression for testing if a FieldElement is zero #110

Closed axkr closed 3 years ago

axkr commented 3 years ago

For FieldMatrix methods can we have an "extra" method or "lambda function" for the "zero" test of a FieldElement which is not the same as the default "zero" test?

Something similar to:

which will be called in matrix operations like:

maisonobe commented 3 years ago

The isZero() method already exists, it was added in version 1.8. I checked were it could be used anbd found only FieldQRDecomposition. Other algorithms like ComplexEigenDecomposition use a user-configurable epsilon to check zero.

axkr commented 3 years ago

Yes you call the FieldElement#isZero() method for FieldQRDecomposition.
In "standard/numeric" calculations this isZero() method often contains a "fast default check" for 0.

But for symbolic matrix "simplification" operations, it often make sense to use a more "expensive" test to check for 0. My proposal means that the zero test should be configurable with a "lambda function" and that the FieldElement#isZero() method should be used as the default operation for this lambda function.

For example you can use different symbolic simplifications to test if an expression is zero:

maisonobe commented 3 years ago

Could you suggest a list of algorithms where we could put this feature? I guess the lambda function would be an implementation of a new interface in the spirit of:

  public interface ZeroChecker<T extends FieldElement<T>> {
    /** Check if value is semantically zero.
      * @param value value to check
      * @return true if value is semantically zero
      */
  boolean isZero(T value);
  }
axkr commented 3 years ago

In the first moment FieldLUDecomposition and FieldQRDecomposition are the main candidates.

Not sure, but some of these "zero checks" may also be "hidden" in the methods of objects of type AbstractFieldMatrix ?

maisonobe commented 3 years ago

I checked AbstractFieldMatrix but found nothing. This class does not implement any solve operation, i basically just handles the basic operations as well as getter/setters for entries, rows and columns.

I'll do a quick commit, most probably incomplete and let you check of this suit your needs.

axkr commented 3 years ago

Do you provide a 1.9-SNAPSHOT somewhere?

maisonobe commented 3 years ago

I have pushed a basic implementation for testing. You can et the snapshot from the Orekit continuous integration server here: https://packages.orekit.org/#browse/browse:maven-snapshots

It should appear automatically if the tests pass.

axkr commented 3 years ago

For me this implementation seems to work.