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 * Add the elements. 027 * 028 * @param a Field element. 029 * @param b Field element. 030 * @return {@code a + b}. 031 */ 032 T add(T a, T b); 033 034 /** 035 * Subtract the element {@code b} from {@code a}. 036 * 037 * @param a Field element. 038 * @param b Field element. 039 * @return {@code a - b}. 040 */ 041 T subtract(T a, T b); 042 043 /** 044 * Negate the element. 045 * 046 * @param a Field element. 047 * @return {@code -a}. 048 */ 049 T negate(T a); 050 051 /** 052 * Multiply the element {@code a} by a specified number of times {@code n}. 053 * 054 * @param a Field element. 055 * @param n Number of times {@code a} must be added to itself. 056 * @return {@code n a}. 057 */ 058 T multiply(int n, T a); 059 060 /** 061 * Multiply the elements. 062 * 063 * @param a Field element. 064 * @param b Field element. 065 * @return {@code a * b}. 066 */ 067 T multiply(T a, T b); 068 069 /** 070 * Divide the element {@code a} by {@code b}. 071 * 072 * @param a Field element. 073 * @param b Field element. 074 * @return <code>a * b<sup>-1</sup></code>. 075 */ 076 T divide(T a, T b); 077 078 /** 079 * Return the reciprocal (multiplicative inverse). 080 * 081 * @param a Field element. 082 * @return <code>a<sup>-1</sup></code>. 083 */ 084 T reciprocal(T a); 085 086 /** 087 * Return the value of one. 088 * 089 * @return the field element {@code 1} such that for all {@code a}, 090 * {@code 1 * a == a}. 091 */ 092 T one(); 093 094 /** 095 * Return the value of zero. 096 * 097 * @return the field element {@code 0} such that for all {@code a}, 098 * {@code 0 + a == a}. 099 */ 100 T zero(); 101}