Thursday, 10 February 2022

Need a Multithreaded Numerical Integrator in Java - See below

In Java, the quickest Thread Exector for Thread that run many times in the Fork Join Pool. You can speed up your numerical integration on multicored CPU like most computers are today. Here it is in Git Hub If we define a function
public abstract class DoubFunction {


    abstract double evalInner(double x, double params[], int i);

    public double eval(double x, int i, double ...params){
        return evalInner(x,  params, i);
    }

}

Then example Simpson Rule Integrates in Java are. With 16 Java Threads on AMD Ryzen with 8 Cores 16 CPU Threads, Standard Integrate takes 51.4 sec, and the ThreadIntegrator only 32.5 seconds.
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicReference;

public class SimpsonsRule {

    private static double third = 1.0/3.0;

    private static int THREADS = 16;

    public static double integrateThreaded(double a, double b, int N, DoubFunction f, double ...params) {         // precision parameter
        double h = (b - a) / (N - 1);     // step size
        ForkJoinPool pool = new ForkJoinPool(THREADS);
       AtomicDouble sum = new AtomicDouble();
        for(int i=0; i {
                double mul = ii%2==0? 2*third: 4*third;
                if (ii==0) { mul = third; }
                if (ii==N-1){ mul = third; }
                double mul1 = mul;
                double x = a + h * ii;
                double fi = f.eval(x,ii, params);
                if (Double.isNaN(fi) ){
                    System.err.println(f.getClass().getName() + "IS NaN at "+x);
                }
                sum.getAndAdd(mul1*fi);
            });
        }
        try {
            pool.shutdown();
            if (!pool.awaitTermination(1, TimeUnit.HOURS)){
                pool.shutdownNow();
            }
        } catch (Exception e){}
        return sum.getAndAdd(0.0) * h;
    }

    public static double integrate(double a, double b, int N, DoubFunction f, double ...params) {         // precision parameter
        double h = (b - a) / (N - 1);     // step size
        double fa = f.eval(a,0, params);
        double fb = f.eval(b, N-1, params);
        if (Double.isNaN(fa) ){
          System.err.println(f.getClass().getName() + "IS NaN at "+a);
        }
        if (Double.isNaN(fb)){
            System.err.println(f.getClass().getName() + "IS NaN at "+b);
        }
        // 1/3 terms
        double sum = third * (fa + fb);


        // 4/3 terms
        for (int i = 1; i < N - 1; i += 2) {
            double x = a + h * i;
            double fx = f.eval(x,i, params);
            if (Double.isNaN(fx)){
                System.err.println(f.getClass().getName() + "IS NaN at "+x);
            }
            sum += 4.0 * third * fx;
        }

        // 2/3 terms
        for (int i = 2; i < N - 1; i += 2) {
            double x = a + h * i;
            double fx = f.eval(x,i, params);
            if (Double.isNaN(fx)){
                System.err.println(f.getClass().getName() + "IS NaN at "+x);
            }
            sum += 2.0 * third * fx;
        }

        return sum * h;
    }

    public static double integrateConsecutive(double a, double b, int N, DoubFunction f, double ...params) {         // precision parameter
        double h = (b - a) / (N - 1);     // step size
        double fa = f.eval(a,0, params);
        if (Double.isNaN(fa) ){
            System.err.println(f.getClass().getName() + "IS NaN at "+a);
        }

        // 1/3 terms
        double sum = third*fa;


        // 4/3 terms
        boolean isOdd = true;
        for (int i = 1; i < N - 1; i += 1) {
            double x = a + h * i;
            double fx = f.eval(x,i, params);
            if (Double.isNaN(fx)){
                System.err.println(f.getClass().getName() + "IS NaN at "+x);
            }
            if (isOdd) {
                sum += 4.0 * third * fx;
            } else {
                sum += 2.0 * third * fx;
            }
            isOdd=!isOdd;
        }


        double fb = f.eval(b, N-1, params);
        if (Double.isNaN(fb)){
            System.err.println(f.getClass().getName() + "IS NaN at "+b);
        }
        sum = sum+ fb*third;

        return sum * h;
    }

    public static void main(String args[]){
        // Roots of polynumerial to integrate
        List in = Arrays.asList(-0.9, -0.8,-0.7, -0.6,-0.5, -0.4, -0.3, -0.2, -0.1, 0, .1,.2,.3,.4,.5, .6,.7, .8, .9 );
        DoubFunction func = new DoubFunction() {
            @Override
            double evalInner(double x, double[] params, int i) {
                return in.stream().map(y->y.doubleValue()-x).reduce(1.0,(a,b)->(a*b));
            }
        };
        double consec=0;
        long startConsec = System.currentTimeMillis();
        for(int i=1;i<1000; i++) {
            consec = integrateConsecutive(-1, 1, 100000, func);
        }
        double timeConsec = (System.currentTimeMillis() - startConsec)/1000.0;
        double standard=0;
        long startStandard = System.currentTimeMillis();
        for(int i=1; i<1000; i++) {
                standard = integrate(-1,1,100000,func);
        }
        double timeStandard = (System.currentTimeMillis() - startStandard)/1000.0;
        double threaded=0;
        long startThreaded = System.currentTimeMillis();
        for(int i=1;i<1000; i++) {
            threaded = integrateThreaded(-1, 1, 100000, func);
        }
        double timeThreaded = (System.currentTimeMillis() - startThreaded)/1000.0;
        System.out.println("Standard Integrator: "+standard+" time taken: "+timeStandard+" seconds");
        System.out.println("Consecutive Integrator: "+consec+" time taken: "+timeConsec+" seconds");
        System.out.println("threaded Integrator: "+threaded+" time taken: "+timeThreaded+" seconds");
    }

}

class AtomicDouble {
    private AtomicReference value = new AtomicReference(Double.valueOf(0.0));
    double getAndAdd(double delta) {
        while (true) {
            Double currentValue = value.get();
            Double newValue = Double.valueOf(currentValue.doubleValue() + delta);
            if (value.compareAndSet(currentValue, newValue))
                return currentValue.doubleValue();
        }
    }
}

Tuesday, 11 January 2022

Neutrino experiments point to new interactions, a sterile neutrino or lorentz violation

Neutrinos are behaving unusually again. Rahaman, Razaque and Sankar in a recent preprint . Review results from the T2K and Nova Experiments. They check three hypothesis,
  1. Non Unitary Three Neutrino Oscillations, i.e. a fourth sterile neutrino.
  2. Lorentz Invariance Violation, i.e. neutrinos not obeying relativity
  3. Non Standard Neutrino Interactions
In each case the standard model is disfavoured at 1 to 2 confidences levels, while the new physics is favoured at the same level. In there analysis present data is not enough to see which new physics is favoured. As they say, T2K and Nova continue to collect data, and new experiments such as DUNE, will help improve the tensions, and find which hypothesis is likely.

Tuesday, 19 October 2021

Signs of extra neutron star and white drawf cooling.

Any light new boson coupling to matter, would lead to extra cooling of white drawfs and neutron stars. And this has been used to limit parameters of extra forces. Quanta Magazine, reports that signs of such cooling have been found . The most popular candidate is the one they mentioned the axion, but any boson might of low mass might be responseable.

Friday, 8 October 2021

Sterile Neutrino Oscillations Found at Baksan

Baksan Experiment on Sterile Transitions (BEST) https://arxiv.org/abs/2109.14654 found results pointing to a sterile neutrino, produced from oscillating electron neutrinos, squared mass difference 7.3 ev^2. The Axial force force predicts right handed neutrinos, (wouldn't be called sterile if they have another force), but not oscillation, but does predict conversion via scatterin so as would oscillation in matter would be predicted. I could not tell from the paper, weather they was a vacuum or material between the neutrino source.

Thursday, 7 October 2021

CONUS Experiment probes nucleus neutrino non standard interactions.

CONUS yesterday, released results on non standard neutrino interactions, Arxiv link. As usual they ignore axial-vector interaction. But they can limit vector interaction to 5*10^-5 force constant for low (<1Mev) mass mediates. If that maps exactly to axial vector, its limits a new force constant to half as much i my estimate, 10^-4 of the new interaction strength. However axial vector interaction seems to be weaker as the neutrino energy increase. CONUS's neutrinos top out 1.8MeV. I need to take the time to calculate how much weaker the neutrino scattering is at these energies.

Wednesday, 22 September 2021

I am published

My Paper U(1) axial as a force between neutrinos has been published here. That is a paid journal. Now free on Research Gate,

Sunday, 8 August 2021

Found paper on Secret Interactions of Neutrinos.

Probing Secret Interactions of Neutrinos in the High-Statistic Era Looks at Ice Cube 2, detecting extra neutrinos interactions at high energy. Our axial force, seems to have less interactions as the energy goes up, so might not show up. Esteban et als, paper, references a paper i missed, Constraining the self-interacting neutrino interpretation of the Hubble Tension Where the Hubble tension (different measurements of the Hubble Constant having different values), is solved by the force on neutrinos with mass in Kev to 100 MeV range. There force needs to be on tau-neutrinos only to match bounds.