diff --git a/src/java.base/share/classes/java/lang/MathAbelianGroup.java b/src/java.base/share/classes/java/lang/MathAbelianGroup.java new file mode 100644 index 00000000000..e61c4ae3fc2 --- /dev/null +++ b/src/java.base/share/classes/java/lang/MathAbelianGroup.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package java.lang; + +/** + * Indicates a type conforms to the requirements of the algebraic + * structure of an abelian group. Abelian groups are also know as + * commutative groups. + * + * @apiNote + * TODO: discuss properties of an abelian group. + * + * @param The type satisfying abelian group properties + */ +public interface MathAbelianGroup extends MathGroup { + + /** + * {@inheritDoc Numerical} + * + * This addition operation is associative and commutative. + * + * @param addend {@inheritDoc MathGroup} + * @param augend {@inheritDoc MathGroup} + * @return {@inheritDoc MathGroup} + */ + @Override + MAG add(MAG addend, MAG augend); +} diff --git a/src/java.base/share/classes/java/lang/MathField.java b/src/java.base/share/classes/java/lang/MathField.java new file mode 100644 index 00000000000..d29c620d235 --- /dev/null +++ b/src/java.base/share/classes/java/lang/MathField.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package java.lang; + +/** + * Indicates a type conforms to the requirements of the algebraic + * structure of a field. + * + * @apiNote + * TODO: discuss properties of a field, including distributivity. + * + * @param The type satisfying field properties + */ +public interface MathField extends MathRing { + + /** + * {@inheritDoc Numerical} + * + * This multiplication operation is associative and commutative. + * + * @param multiplier {@inheritDoc Numerical} + * @param multiplicand {@inheritDoc Numerical} + * @return {@inheritDoc Numerical} + */ + MF multiply(MF multiplier, MF multiplicand); + + + /** + * {@return the multiplicative inverse of the argument} + * + * @implSpec + * This method returns {@link #one() one} {@linkplain #divide(NT, NT) + * divided} by the operand. + * + * @param operand the operand + */ + default MF reciprocal(MF operand) { + return this.divide(one(), operand); + } +} diff --git a/src/java.base/share/classes/java/lang/MathGroup.java b/src/java.base/share/classes/java/lang/MathGroup.java new file mode 100644 index 00000000000..69818727d3f --- /dev/null +++ b/src/java.base/share/classes/java/lang/MathGroup.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package java.lang; + +/** + * Indicates a type conforms to the requirements of the algebraic + * structure of a group. + * + * @apiNote + * TODO: discuss properties of a group. + * + * @param The type satisfying group properties + */ +public interface MathGroup extends Numerical { + /** + * {@return the identity element for the group} + */ + MG zero(); + + /** + * {@inheritDoc Numerical} + * + * @implSpec + * The addition operation is associative for a group. + * + * @param addend {@inheritDoc Numerical} + * @param augend {@inheritDoc Numerical} + * @return {@inheritDoc Numerical} + */ + @Override + MG add(MG addend, MG augend); + + /** + * {@inheritDoc Numerical} + * + * @implSpec + * The negation of the operand is its inverse in the group. + * + * @param operand {@inheritDoc Numerical} + */ + @Override + MG negate(MG operand); +} diff --git a/src/java.base/share/classes/java/lang/MathRing.java b/src/java.base/share/classes/java/lang/MathRing.java new file mode 100644 index 00000000000..e6cf476370d --- /dev/null +++ b/src/java.base/share/classes/java/lang/MathRing.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package java.lang; + +/** + * Indicates a type conforms to the requirements of the algebraic + * structure of a ring. + * + * @apiNote + * TODO: discuss properties of a ring. + * + * @param The type satisfying ring properties + */ +public interface MathRing extends MathAbelianGroup { + /** + * {@return the multiplicative identity element} + */ + MR one(); + + /** + * {@inheritDoc Numerical} + * + * @implSpec + * This multiplication operation is associative. + * + * @param multiplier {@inheritDoc Numerical} + * @param multiplicand {@inheritDoc Numerical} + * @return {@inheritDoc Numerical} + */ + MR multiply(MR multiplier, MR multiplicand); + + /** + * {@inheritDoc Numerical} + * + * The negation of the operand is its additive inverse. + * + * @param operand {@inheritDoc Numerical} + */ + @Override + MR negate(MR operand); +}