001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.numbers.field;
018
019/**
020 * Interface representing a <a href="http://mathworld.wolfram.com/Field.html">field</a>.
021 *
022 * @param <T> Type of the field elements.
023 */
024public interface Field<T> {
025    /**
026     * @param a Field element.
027     * @param b Field element.
028     * @return {@code a + b}.
029     */
030    T add(T a, T b);
031
032    /**
033     * @param a Field element.
034     * @param b Field element.
035     * @return {@code a - b}.
036     */
037    T subtract(T a, T b);
038
039    /**
040     * @param a Field element.
041     * @return {@code -a}.
042     */
043    T negate(T a);
044
045    /**
046     * @param a Field element.
047     * @param n Number of times {@code a} must be added to itself.
048     * @return {@code n a}.
049     */
050    T multiply(int n, T a);
051
052    /**
053     * @param a Field element.
054     * @param b Field element.
055     * @return {@code a * b}.
056     */
057    T multiply(T a, T b);
058
059    /**
060     * @param a Field element.
061     * @param b Field element.
062     * @return <code>a * b<sup>-1</sup></code>.
063     */
064    T divide(T a, T b);
065
066    /**
067     * @param a Field element.
068     * @return <code>a<sup>-1</sup></code>.
069     */
070    T reciprocal(T a);
071
072    /**
073     * @return the field element {@code 1} such that for all {@code a},
074     * {@code 1 * a == a}.
075     */
076    T one();
077
078    /**
079     * @return the field element {@code 0} such that for all {@code a},
080     * {@code 0 + a == a}.
081     */
082    T zero();
083}