All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cc.redberry.rings.scaladsl.JavaConversions Maven / Gradle / Ivy

The newest version!
package cc.redberry.rings.scaladsl;

import cc.redberry.rings.poly.FiniteField;
import cc.redberry.rings.poly.multivar.AMonomial;
import cc.redberry.rings.poly.multivar.AMultivariatePolynomial;
import cc.redberry.rings.poly.multivar.MultivariateDivision;
import cc.redberry.rings.poly.univar.IUnivariatePolynomial;
import cc.redberry.rings.poly.univar.UnivariatePolynomialZp64;
import scala.NotImplementedError;

/** Ugly type erasures for interoperability with Java */
final class JavaConversions {
    private JavaConversions() {}

    @SuppressWarnings("unchecked")
    static  Poly[] divideAndRemainder(Poly dividend, Poly... dividers) {
        return (Poly[]) MultivariateDivision.divideAndRemainder((AMultivariatePolynomial) dividend, (AMultivariatePolynomial[]) dividers);
    }

    @SuppressWarnings("unchecked")
    static  Poly remainder(Poly dividend, Poly... dividers) {
        return (Poly) MultivariateDivision.remainder((AMultivariatePolynomial) dividend, (AMultivariatePolynomial[]) dividers);
    }

    @SuppressWarnings("unchecked")
    static  Poly swapVariables(Poly poly, int i, int j) {
        return (Poly) AMultivariatePolynomial.swapVariables((AMultivariatePolynomial) poly, i, j);
    }

    @SuppressWarnings("unchecked")
    static , C> SimpleFieldExtension
    mkScalaFieldExtension(cc.redberry.rings.poly.IPolynomialRing javaRing, String variable) {
        if (javaRing instanceof FiniteField && javaRing.factory() instanceof UnivariatePolynomialZp64)
            return (SimpleFieldExtension) new GaloisField64((FiniteField) javaRing, variable);
        if (javaRing instanceof FiniteField)
            return (SimpleFieldExtension) new GaloisField((FiniteField) javaRing, variable, null);
        if (javaRing instanceof cc.redberry.rings.poly.AlgebraicNumberField)
            return (SimpleFieldExtension) new AlgebraicNumberField((cc.redberry.rings.poly.AlgebraicNumberField) javaRing, variable, null);

        throw new NotImplementedError();
    }

    @SuppressWarnings("unchecked")
    static ,
            mPoly extends AMultivariatePolynomial,
            sPoly extends IUnivariatePolynomial,
            C> MultipleFieldExtension
    mkSimpleToMultiple(SimpleFieldExtension ext) {
        IPolynomialRing pr = (IPolynomialRing) ext;
        MultipleFieldExtension result = new MultipleFieldExtension((cc.redberry.rings.poly.MultipleFieldExtension)
                ext.implicitConversions().asMultipleExtension(), pr.variables());
        result.coder().withEncoder(pr.coder());
        return result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy