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

com.accelad.math.nilgiri.autodiff.Sum Maven / Gradle / Ivy

There is a newer version: 1.16
Show newest version
package com.accelad.math.nilgiri.autodiff;

import java.util.List;

import com.accelad.math.nilgiri.Field;


public class Sum> extends AbstractBinaryFunction {

    public Sum(DifferentialFunction i_v1, DifferentialFunction i_v2) {
        super(i_v1, i_v2);
    }

    @Override
    public X getValue() {
        return larg().getValue().plus(rarg().getValue());
    }

    @Override
    public double getReal() {
        return larg().getReal() + rarg().getReal();
    }

    @Override
    public DifferentialFunction diff(Variable i_v1) {
        return (larg() == rarg()) ? larg().diff(i_v1).mul(2L) // Field is
                                                              // commutative
                                                              // with respect to
                                                              // addition.
                : larg().diff(i_v1).plus(rarg().diff(i_v1));
    }

    @Override
    public String toString() {
        return "(" + larg().toString() + "+" + rarg().toString() + ")";
    }

    @Override
    public String getFormula(List> variables) {
        return "(" + larg().getFormula(variables) + "+" + rarg().getFormula(variables) + ")";
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy