private NumValue unary(NumValue[] params) { switch (m_uop) { case UMINUS: return m_right.evaluate(params).neg(); case NOT: return m_right.evaluate(params).not(); default: return null; } }
public Func shift(int shift) { switch (m_type) { case VAR: return new Func(m_index + shift); case CONST: return this; case UNOP: return new Func(m_uop, m_right.shift(shift)); case BINOP: return new Func(m_left.shift(shift), m_bop, m_right.shift(shift)); default: return null; } }
public Func nest(Func[] params) { switch (m_type) { case VAR: return params[m_index].copy(); case CONST: return this; case UNOP: return new Func(m_uop, m_right.nest(params)); case BINOP: return new Func(m_left.nest(params), m_bop, m_right.nest(params)); default: return null; } }
public String toString() { switch (m_type) { case VAR: return "in[" + m_index + "]"; case CONST: return m_value.toString(); case UNOP: return uopString() + "(" + m_right.toString() + ")"; case BINOP: return "(" + m_left.toString() + " " + bopString() + " " + m_right.toString() + ")"; default: return ""; } }
public NumValue evaluate(NumValue[] params) { switch (m_utype) { case SIN: return NumLang.Func.sin(m_func.evaluate(params)); case COS: return NumLang.Func.cos(m_func.evaluate(params)); case LN: return NumLang.Func.ln(m_func.evaluate(params)); case LOG: return NumLang.Func.log(m_func.evaluate(params)); case CEIL: return NumLang.Func.ceil(m_func.evaluate(params)); case FLOOR: return NumLang.Func.floor(m_func.evaluate(params)); default: return null; } }
public String toString() { switch (m_utype) { case SIN: return "sin(" + m_func.toString() + ")"; case COS: return "cos(" + m_func.toString() + ")"; case LN: return "ln(" + m_func.toString() + ")"; case LOG: return "log(" + m_func.toString() + ")"; case CEIL: return "ceil(" + m_func.toString() + ")"; case FLOOR: return "floor(" + m_func.toString() + ")"; default: return null; } }
public SpecialFunc copy() { return new SpecialFunc(m_utype, m_func.copy()); }
public Func evaluate(Func[] paramList) { return m_function.nest(paramList); }
public NumValue evaluate(NumValue[] paramlist) { return m_function.evaluate(paramlist); }
public FuncValue(int params, Func function) { m_params = params; m_function = function.copy(); }
public FuncValue mod(NumValue other) { return new FuncValue(m_params, m_function.mod(other)); }
public FuncValue divide(NumValue other) { return new FuncValue(m_params, m_function.divide(other)); }
private NumValue binary(NumValue[] params) { switch (m_bop) { case ADD: return m_left.evaluate(params).add(m_right.evaluate(params)); case SUB: return m_left.evaluate(params).subtract(m_right.evaluate(params)); case MULT: return m_left.evaluate(params).multiply(m_right.evaluate(params)); case DIV: return m_left.evaluate(params).divide(m_right.evaluate(params)); case EXP: return m_left.evaluate(params).exp(m_right.evaluate(params)); case MOD: return m_left.evaluate(params).mod(m_right.evaluate(params)); case EQ: return m_left.evaluate(params).eq(m_right.evaluate(params)); case NEQ: return m_left.evaluate(params).neq(m_right.evaluate(params)); case LT: return m_left.evaluate(params).lt(m_right.evaluate(params)); case LEQ: return m_left.evaluate(params).leq(m_right.evaluate(params)); case GT: return m_left.evaluate(params).gt(m_right.evaluate(params)); case GEQ: return m_left.evaluate(params).geq(m_right.evaluate(params)); default: return null; } }
public FuncValue not() { return new FuncValue(m_params, m_function.not()); }
public FuncValue geq(NumValue other) { return new FuncValue(m_params, m_function.geq(other)); }
public FuncValue lt(NumValue other) { return new FuncValue(m_params, m_function.lt(other)); }
public SpecialFunc shift(int shift) { return new SpecialFunc(m_utype, m_func.shift(shift)); }
public FuncValue multiply(NumValue other) { return new FuncValue(m_params, m_function.multiply(other)); }
public SpecialFunc nest(Func[] params) { return new SpecialFunc(m_utype, m_func.nest(params)); }
public FuncValue exp(NumValue other) { return new FuncValue(m_params, m_function.exp(other)); }
/* public FuncValue nest(FuncValue[] inputs) { Func[] funcs = new Func[inputs.length]; for(int i = 0; i < inputs.length; i++) { funcs[i] = inputs[i].m_function; } int shift = inputs[0].m_params; for(int i = 1; i < inputs.length; i++) { funcs[i] = funcs[i].shift(shift); shift += inputs[i].m_params; } return new FuncValue(shift, m_function.nest(funcs)); } */ public String toString() { String output = "|in[0]"; for (int i = 1; i < m_params; i++) output += ", in[" + i + "]"; output += "| -> |" + m_function.toString() + "|"; return output; }
public FuncValue subtract(NumValue other) { return new FuncValue(m_params, m_function.subtract(other)); }