Skip to content

Commit

Permalink
A Ring is a MultiplicativeMonoid
Browse files Browse the repository at this point in the history
  • Loading branch information
mihxil committed Oct 22, 2024
1 parent 96b498a commit 3e57fc5
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public class DihedralGroup implements Group<DihedralSymmetry>, Streamable<Dihedr
private DihedralGroup(int n) {
this.n = n;
}

public static DihedralGroup of(int n) {
return CACHE.computeIfAbsent(n, DihedralGroup::new);
}


public DihedralSymmetry r(int k) {
return DihedralSymmetry.r(k, this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ public class DihedralSymmetry implements GroupElement<DihedralSymmetry>, UnaryOp

private final DihedralGroup group;

static DihedralSymmetry r(int k, DihedralGroup diHedralGroup) {
return new DihedralSymmetry(r, k, diHedralGroup);
static DihedralSymmetry r(int k, DihedralGroup dihedralGroup) {
return new DihedralSymmetry(r, k, dihedralGroup);
}
static DihedralSymmetry s(int k, DihedralGroup diHedralGroup) {
return new DihedralSymmetry(s, k, diHedralGroup);

static DihedralSymmetry s(int k, DihedralGroup dihedralGroup) {
return new DihedralSymmetry(s, k, dihedralGroup);
}

public static DihedralSymmetry r(int k, int n) {
Expand All @@ -41,17 +42,17 @@ public static DihedralSymmetry s(int k, int n) {
}


private DihedralSymmetry(Symmetry symmetry, int k, DihedralGroup diHedralGroup) {
private DihedralSymmetry(Symmetry symmetry, int k, DihedralGroup dihedralGroup) {
this.symmetry = symmetry;
if (k < 0) {
throw new InvalidElementCreationException(symmetry.name() + k + " is impossible");
}
this.k = k;
if (k >= diHedralGroup.n) {
throw new InvalidElementCreationException(symmetry.name() + k + " is impossible for " + diHedralGroup);
if (k >= dihedralGroup.n) {
throw new InvalidElementCreationException(symmetry.name() + k + " is impossible for " + dihedralGroup);

}
this.group = diHedralGroup;
this.group = dihedralGroup;
}

private DihedralSymmetry(Symmetry symmetry, int k, int n) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import jakarta.validation.constraints.Min;

import org.meeuw.math.exceptions.ReciprocalException;
import org.meeuw.math.exceptions.IllegalPowerException;

/**
* An element of the {@link MultiplicativeMonoid} structure.
Expand All @@ -39,7 +39,7 @@ public interface MultiplicativeMonoidElement<E extends MultiplicativeMonoidEleme
@Override
default E pow(@Min(0) int n) {
if (n < 0) {
throw new ReciprocalException("");
throw new IllegalPowerException("");
}
if (n == 0) {
return getStructure().one();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
*/
package org.meeuw.math.abstractalgebra;

import java.util.NavigableSet;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.meeuw.math.ArrayUtils;
import org.meeuw.math.operators.AlgebraicBinaryOperator;
import org.meeuw.math.operators.AlgebraicUnaryOperator;
import org.meeuw.math.validation.Square;

import static org.meeuw.math.ArrayUtils.minor;
Expand All @@ -28,9 +32,12 @@
* @since 0.4
* @param <E>
*/
public interface Ring<E extends RingElement<E>> extends Rng<E> {
public interface Ring<E extends RingElement<E>> extends Rng<E>, MultiplicativeMonoid<E> {


NavigableSet<AlgebraicBinaryOperator> OPERATORS = Rng.OPERATORS;
NavigableSet<AlgebraicUnaryOperator> UNARY_OPERATORS = Rng.UNARY_OPERATORS;

E one();

/**
* Given a (square) matrix of elements of this Ring, calculate its determinant.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @author Michiel Meeuwissen
* @since 0.4
*/
public interface RingElement<E extends RingElement<E>> extends RngElement<E> {
public interface RingElement<E extends RingElement<E>> extends RngElement<E>, MultiplicativeMonoidElement<E> {

@Override
Ring<E> getStructure();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* @since 0.4
*/
public interface DivisionRingTheory<E extends DivisionRingElement<E>> extends
RingTheory<E>,
MultiplicativeGroupTheory<E>,
AdditiveGroupTheory<E> {

Expand All @@ -54,15 +55,4 @@ default void operatorEnums(
.isEqualTo((e1.plus(e2).sqr()).negation());
}

@Property
default void distributivity (
@ForAll(ELEMENTS) E v1,
@ForAll(ELEMENTS) E v2,
@ForAll(ELEMENTS) E v3
) {
assertThat(v1.times(v2.plus(v3)))
.usingComparator(eqComparator())
.isEqualTo(v1.times(v2).plus(v1.times(v3)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,28 @@
import org.meeuw.math.abstractalgebra.RingElement;

import static org.assertj.core.api.Assertions.assertThat;
import static org.meeuw.math.abstractalgebra.AlgebraicElement.eqComparator;

/**
* @author Michiel Meeuwissen
* @since 0.4
*/
public interface RingTheory<E extends RingElement<E>> extends AdditiveGroupTheory<E>, RngTheory<E> {
public interface RingTheory<E extends RingElement<E>> extends AdditiveGroupTheory<E>, RngTheory<E> , MultiplicativeMonoidTheory<E> {

@Property
default void one(
@ForAll(ELEMENTS) E v) {
assertThat(v.times(v.getStructure().one())).isEqualTo(v);
}

@Property
default void distributivity (
@ForAll(ELEMENTS) E v1,
@ForAll(ELEMENTS) E v2,
@ForAll(ELEMENTS) E v3
) {
assertThat(v1.times(v2.plus(v3)))
.usingComparator(eqComparator())
.isEqualTo(v1.times(v2).plus(v1.times(v3)));
}
}

0 comments on commit 3e57fc5

Please sign in to comment.