/// <summary> /// Base class for all unary operators. /// </summary> /// <param name="Operand">Operand.</param> /// <param name="Start">Start position in script expression.</param> /// <param name="Length">Length of expression covered by node.</param> /// <param name="Expression">Expression containing script.</param> public UnaryOperator(ScriptNode Operand, int Start, int Length, Expression Expression) : base(Start, Length, Expression) { this.op = Operand; }
/// <summary> /// Base class for binary double operators. /// </summary> /// <param name="Left">Left operand.</param> /// <param name="Right">Right operand.</param> /// <param name="Start">Start position in script expression.</param> /// <param name="Length">Length of expression covered by node.</param> /// <param name="Expression">Expression containing script.</param> public BinaryDoubleOperator(ScriptNode Left, ScriptNode Right, int Start, int Length, Expression Expression) : base(Left, Right, Start, Length, Expression) { }
/// <summary> /// Base class for all quaternary operators. /// </summary> /// <param name="Left">Left operand.</param> /// <param name="Middle1">First Middle operand.</param> /// <param name="Middle2">Second Middle operand.</param> /// <param name="Right">Right operand.</param> /// <param name="Start">Start position in script expression.</param> /// <param name="Length">Length of expression covered by node.</param> /// <param name="Expression">Expression containing script.</param> public QuaternaryOperator(ScriptNode Left, ScriptNode Middle1, ScriptNode Middle2, ScriptNode Right, int Start, int Length, Expression Expression) : base(Left, Middle1, Right, Start, Length, Expression) { this.middle2 = Middle2; }
/// <summary> /// Base class for all unary operators performing operand null checks. /// </summary> /// <param name="Left">Left operand.</param> /// <param name="Middle">Middle operand.</param> /// <param name="Right">Right operand.</param> /// <param name="NullCheck">If null should be returned if left operand is null.</param> /// <param name="Start">Start position in script expression.</param> /// <param name="Length">Length of expression covered by node.</param> /// <param name="Expression">Expression containing script.</param> public NullCheckTernaryOperator(ScriptNode Left, ScriptNode Middle, ScriptNode Right, bool NullCheck, int Start, int Length, Expression Expression) : base(Left, Middle, Right, Start, Length, Expression) { this.nullCheck = NullCheck; }
/// <summary> /// Base class for funcions of one scalar variable. /// </summary> /// <param name="Argument1">Argument 1.</param> /// <param name="Argument2">Argument 2.</param> /// <param name="Start">Start position in script expression.</param> /// <param name="Length">Length of expression covered by node.</param> /// <param name="Expression">Expression containing script.</param> public FunctionTwoScalarVariables(ScriptNode Argument1, ScriptNode Argument2, int Start, int Length, Expression Expression) : base(Argument1, Argument2, Start, Length, Expression) { }
/// <summary> /// Base class for funcions of one variable. /// </summary> /// <param name="Argument">Argument.</param> /// <param name="Start">Start position in script expression.</param> /// <param name="Length">Length of expression covered by node.</param> /// <param name="Expression">Expression containing script.</param> public FunctionOneVariable(ScriptNode Argument, int Start, int Length, Expression Expression) : base(Start, Length, Expression) { this.argument = Argument; }
/// <summary> /// Implements the differentiation chain rule, by differentiating the argument and multiplying it to the differentiation of the main node. /// </summary> /// <param name="VariableName">Name of variable to differentiate on.</param> /// <param name="Variables">Collection of variables.</param> /// <param name="Argument">Inner argument</param> /// <param name="Differentiation">Differentiation of main node.</param> /// <returns><paramref name="Differentiation"/>*D(<paramref name="Argument"/>)</returns> protected ScriptNode DifferentiationChainRule(string VariableName, Variables Variables, ScriptNode Argument, ScriptNode Differentiation) { if (Argument is IDifferentiable Differentiable) { ScriptNode ChainFactor = Differentiable.Differentiate(VariableName, Variables); if (ChainFactor is ConstantElement ConstantElement && ConstantElement.Constant is DoubleNumber DoubleNumber) { if (DoubleNumber.Value == 0) { return(ConstantElement); } else if (DoubleNumber.Value == 1) { return(Differentiation); } } int Start = this.Start; int Len = this.Length; Expression Exp = this.Expression; if (Differentiation is Invert Invert) { if (Invert.Operand is Negate Negate) { return(new Negate(new Divide(ChainFactor, Negate.Operand, Start, Len, Expression), Start, Len, Exp)); } else { return(new Divide(ChainFactor, Invert.Operand, Start, Len, Exp)); } } else if (Differentiation is Negate Negate) { if (Negate.Operand is Invert Invert2) { return(new Negate(new Divide(ChainFactor, Invert2.Operand, Start, Len, Expression), Start, Len, Exp)); } else { return(new Negate(new Multiply(Negate.Operand, ChainFactor, Start, Len, Expression), Start, Len, Exp)); } } else { return(new Multiply(Differentiation, ChainFactor, Start, Len, Exp)); } } else { throw new ScriptRuntimeException("Argument not differentiable.", this); } }
/// <summary> /// Calculates a hash code for the contents of an array. /// </summary> /// <param name="Node">Node. Can be null.</param> /// <returns>Hash code</returns> public static int GetHashCode(ScriptNode Node) { return(Node?.GetHashCode() ?? 0); }
/// <summary> /// Base class for all binary operators. /// </summary> /// <param name="Left">Left operand.</param> /// <param name="Right">Right operand.</param> /// <param name="Start">Start position in script expression.</param> /// <param name="Length">Length of expression covered by node.</param> /// <param name="Expression">Expression containing script.</param> public BinaryOperator(ScriptNode Left, ScriptNode Right, int Start, int Length, Expression Expression) : base(Start, Length, Expression) { this.left = Left; this.right = Right; }
/// <summary> /// Base class for binary double operators. /// </summary> /// <param name="Operand">Operand.</param> /// <param name="Start">Start position in script expression.</param> /// <param name="Length">Length of expression covered by node.</param> /// <param name="Expression">Expression containing script.</param> public UnaryDoubleOperator(ScriptNode Operand, int Start, int Length, Expression Expression) : base(Operand, Start, Length, Expression) { }
/// <summary> /// Base class for funcions of one variable. /// </summary> /// <param name="Argument1">Argument 1.</param> /// <param name="Argument2">Argument 2.</param> /// <param name="Start">Start position in script expression.</param> /// <param name="Length">Length of expression covered by node.</param> /// <param name="Expression">Expression containing script.</param> public FunctionTwoVariables(ScriptNode Argument1, ScriptNode Argument2, int Start, int Length, Expression Expression) : base(Start, Length, Expression) { this.argument1 = Argument1; this.argument2 = Argument2; }
/// <summary> /// Base class for all ternary operators. /// </summary> /// <param name="Left">Left operand.</param> /// <param name="Middle">Middle operand.</param> /// <param name="Right">Right operand.</param> /// <param name="Start">Start position in script expression.</param> /// <param name="Length">Length of expression covered by node.</param> /// <param name="Expression">Expression containing script.</param> public TernaryOperator(ScriptNode Left, ScriptNode Middle, ScriptNode Right, int Start, int Length, Expression Expression) : base(Left, Right, Start, Length, Expression) { this.middle = Middle; }
/// <summary> /// Base class for funcions of one vector variable. /// </summary> /// <param name="Argument">Argument.</param> /// <param name="Start">Start position in script expression.</param> /// <param name="Length">Length of expression covered by node.</param> /// <param name="Expression">Expression containing script.</param> public FunctionOneVectorVariable(ScriptNode Argument, int Start, int Length, Expression Expression) : base(Argument, Start, Length, Expression) { }