com.accelad.math.nilgiri.autodiff.Constant Maven / Gradle / Ivy
The newest version!
package com.accelad.math.nilgiri.autodiff;
import java.util.List;
import com.accelad.math.nilgiri.AbstractIdentityFactory;
import com.accelad.math.nilgiri.Field;
public class Constant> extends DifferentialFunction {
private X m_x;
private AbstractIdentityFactory m_factory;
protected Constant(X i_v, AbstractIdentityFactory i_factory) {
if (i_v != null && i_factory != null) {
m_x = i_v;
m_factory = i_factory;
} else {
throw new IllegalArgumentException("Input not null value.");
}
}
protected AbstractIdentityFactory factory() {
return m_factory;
}
@Override
public boolean isConstant() {
return true;
}
@Override
public X getValue() {
return m_x;
}
@Override
public double getReal() {
return m_x.getReal();
}
@Override
public DifferentialFunction diff(Variable i_v) {
return new Zero(m_factory);
}
@Override
public String toString() {
return getValue().toString();
}
@Override
public String getFormula(List> variables) {
return getValue().toString();
}
@Override
protected DifferentialFunction plused(DifferentialFunction i_v) {
return i_v.isConstant() ? new Constant(i_v.getValue().plus(this.m_x), m_factory)
: super.plused(i_v);
}
@Override
protected DifferentialFunction muled(DifferentialFunction i_v) {
return i_v.isConstant() ? new Constant(i_v.getValue().mul(this.m_x), m_factory)
: super.muled(i_v);
}
// public DifferentialFunction inverse() {
@Override
public Constant inverse() {
return new Constant(m_x.inverse(), m_factory);
}
// public DifferentialFunction negate() {
@Override
public Constant negate() {
return new Constant(m_x.negate(), m_factory);
}
// This class must be immutable.
// set and assign must not be implemented.
@SuppressWarnings("unused")
private final void set(X i_x) {
}
@SuppressWarnings("unused")
private final void assign(X i_x) {
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy