All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.tensorics.core.fields.doubles.DoubleField Maven / Gradle / Ivy

Go to download

Tensorics is a java framework which uses a tensor as a central object. A tensor represents a set of values placed in an N-dimensional space. Wherever you are tempted to use maps of maps, a tensor might be a good choice ;-) Tensorics provides methods to create, transform and performing calculations with those tensors.

There is a newer version: 0.0.81
Show newest version
// @formatter:off
 /*******************************************************************************
 *
 * This file is part of tensorics.
 * 
 * Copyright (c) 2008-2011, CERN. All rights reserved.
 *
 * Licensed 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.
 * 
 ******************************************************************************/
// @formatter:on

package org.tensorics.core.fields.doubles;

import org.tensorics.core.math.operations.CommutativeAssociativeOperation;
import org.tensorics.core.math.operations.UnaryOperation;
import org.tensorics.core.math.predicates.BinaryPredicate;
import org.tensorics.core.math.structures.grouplike.AbelianGroup;
import org.tensorics.core.math.structures.ringlike.OrderedField;

/**
 * Provides mathematical structures for double values (which form a field). Usually, users will not construct instances
 * of this class manually, but use the convenience methods from the {@link Structures} class. The reason is that
 * instances of this class are per se of limited use. They only become useful, if they are extended by additional
 * functionality.
 * 
 * @author kfuchsbe
 * @see Structures
 */
@SuppressWarnings("PMD.TooManyMethods")
public final class DoubleField implements OrderedField {

    private static final double ZERO = 0.0;
    private static final double ONE = 1.0;

    private final CommutativeAssociativeOperation additionOperation //
    = new CommutativeAssociativeOperation() {
        @Override
        public Double perform(Double left, Double right) {
            return left + right;
        }
    };

    private final CommutativeAssociativeOperation multiplicationOperation //
    = new CommutativeAssociativeOperation() {
        @Override
        public Double perform(Double left, Double right) {
            return left * right;
        }
    };

    private final UnaryOperation additiveInverseOperation = new UnaryOperation() {
        @Override
        public Double perform(Double value) {
            return -value;
        }
    };

    private final UnaryOperation multiplicativeInverseOperation = new UnaryOperation() {
        @Override
        public Double perform(Double value) {
            return 1 / value;
        }
    };

    private final AbelianGroup additionGroup = new AbelianGroup() {
        @Override
        public CommutativeAssociativeOperation operation() {
            return additionOperation;
        }

        @Override
        public Double identity() {
            return ZERO;
        }

        @Override
        public UnaryOperation inversion() {
            return additiveInverseOperation;
        }
    };

    private final AbelianGroup multiplicationGroup = new AbelianGroup() {

        @Override
        public CommutativeAssociativeOperation operation() {
            return multiplicationOperation;
        }

        @Override
        public Double identity() {
            return ONE;
        }

        @Override
        public UnaryOperation inversion() {
            return multiplicativeInverseOperation;
        }
    };

    private final BinaryPredicate lessOrEqual = new BinaryPredicate() {

        @Override
        public boolean test(Double left, Double right) {
            return left <= right;
        }
    };

    /**
     * Package visible constructor to allow the structures class to instantiate the class. Use the lookup methods in the
     * {@link Structures} class to retrieve an instance of the field.
     */
    DoubleField() {
        /* Use Factory methods */
    }

    @Override
    public AbelianGroup additionStructure() {
        return additionGroup;
    }

    @Override
    public AbelianGroup multiplicationStructure() {
        return multiplicationGroup;
    }

    @Override
    public BinaryPredicate lessOrEqualPredicate() {
        return lessOrEqual;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy