Skip to content

Commit

Permalink
adic integers would support 'shift' operators e.g.
Browse files Browse the repository at this point in the history
  • Loading branch information
mihxil committed Dec 20, 2024
1 parent dd45dee commit 7851e18
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.meeuw.math.exceptions.*;

import static org.meeuw.math.DigitUtils.AdicDigits.NOT_REPETITIVE;
import static org.meeuw.math.DigitUtils.adicToString;
import static org.meeuw.math.DigitUtils.multiplyAdicDigits;
/**
* WIP
*/
Expand Down Expand Up @@ -59,7 +61,7 @@ public PAdicInteger dividedBy(long divisor) {
@Override
public PAdicInteger times(long multiplier) {
AdicDigits mult = new AdicDigits(DigitUtils.toBase(structure.base, multiplier), new byte[0]);
return new PAdicInteger(structure, DigitUtils.multiplyPAdicDigits((byte) structure.base, this.digits, mult));
return new PAdicInteger(structure, multiplyAdicDigits((byte) structure.base, this.digits, mult));
}

@Override
Expand All @@ -69,7 +71,7 @@ public PAdicInteger reciprocal() throws ReciprocalException {

@Override
public PAdicInteger times(PAdicInteger multiplier) {
return new PAdicInteger(structure, DigitUtils.multiplyPAdicDigits(structure.base, this.digits, multiplier.digits));
return new PAdicInteger(structure, multiplyAdicDigits(structure.base, this.digits, multiplier.digits));
}

@Override
Expand All @@ -90,9 +92,17 @@ public PAdicInteger negation() {
return null;
}

public PAdicInteger leftShift(int i) {
return new PAdicInteger(structure, digits.leftShift(i));
}

public PAdicInteger rightShift(int i) {
return new PAdicInteger(structure, digits.leftShift(i));
}

@Override
public String toString() {
return DigitUtils.adicToString(structure.base, digits);
return adicToString(structure.base, digits);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,34 @@

import java.math.BigInteger;
import java.util.Map;
import java.util.NavigableSet;
import java.util.concurrent.ConcurrentHashMap;

import org.meeuw.math.DigitUtils.AdicDigits;
import org.meeuw.math.IntegerUtils;
import org.meeuw.math.abstractalgebra.Cardinality;
import org.meeuw.math.abstractalgebra.Field;
import org.meeuw.math.exceptions.InvalidStructureCreationException;
import org.meeuw.math.operators.AbstractAlgebraicIntOperator;
import org.meeuw.math.operators.AlgebraicIntOperator;
import org.meeuw.math.text.TextUtils;
import org.meeuw.math.validation.Prime;

import static org.meeuw.configuration.ReflectionUtils.getDeclaredMethod;
import static org.meeuw.math.CollectionUtils.navigableSet;

public class PAdicIntegers implements Field<PAdicInteger> {
final int base;
// could be byte, but that give a lot of casting, and stuff with toUnsignedInt
// there are only a few instances of this class, memory usage is no issue.

final BigInteger bbase;

@Override
public NavigableSet<AlgebraicIntOperator> getSupportedIntOperators() {
return navigableSet(INT_OPERATORS, LEFT_SHIFT, RIGHT_SHIFT);
}

private static final Map<Byte, PAdicIntegers> CACHE = new ConcurrentHashMap<>();

private PAdicIntegers(@Prime int base) {
Expand Down Expand Up @@ -71,4 +82,8 @@ public String toString() {
return "ℚ" + TextUtils.subscript(base);
}


public static final AlgebraicIntOperator LEFT_SHIFT = new AbstractAlgebraicIntOperator("left_shift", getDeclaredMethod(PAdicInteger.class, "leftShift", int.class), (e, i) -> e + "<<" + i);

public static final AlgebraicIntOperator RIGHT_SHIFT = new AbstractAlgebraicIntOperator("right_shift", getDeclaredMethod(PAdicInteger.class, "rightShift", int.class), (e, i) -> e + ">>" + i);
}

0 comments on commit 7851e18

Please sign in to comment.