public SyntaxBlock Simplify() { A = A.Simplify(); B = B.Simplify(); var a = A as NumericConstant; var b = B as NumericConstant; if (a == null && b == null) //Neither A nor B are numeric constants, return this quotient in its existing state. { return(this); } if (a != null && b != null) //Both A and B are numeric constants, return new numeric constant that is the quotient of both. { return(new NumericConstant(a.value / b.value)); } if (a?.value == 0) { return(new NumericConstant(0)); } if (b?.value == 1) { return(A); } else if (b?.value == 0) { throw new DivideByZeroException("Can't devide by zero!"); } return(this); //No simplification possible, return this quotient in its existing state. }
public override bool ParallelEquals(SyntaxBlock ToCompare, int Depth) { if (Depth == 0) { return(Equals(ToCompare)); } var casted = ToCompare as AbstractOrderstrictOperator; if (casted == null) { return(false); } if (ToCompare.GetType() != GetType()) { return(false); } bool a = false; bool b = false; Parallel.Invoke( () => { a = A.Equals(casted.A); }, () => { b = B.Equals(casted.B); } ); return(a && b); }
public override bool Equals(SyntaxBlock ToCompare) { var casted = ToCompare as AbstractOrderirrelevantOperator; if (casted == null) { return(false); } if (ToCompare.GetType() != GetType()) { return(false); } if (A.Equals(casted.A)) { if (B.Equals(casted.B)) { return(true); } } if (B.Equals(casted.A)) { if (A.Equals(casted.B)) { return(true); } } return(false); }
public SyntaxBlock Simplify() { A = A.Simplify(); B = B.Simplify(); var a = A as NumericConstant; var b = B as NumericConstant; if (a == null && b == null) //Neither A nor B are numeric constants, return this sum in its existing state. { return(this); } if (a != null && b != null) //Both A and B are numeric constants, return new numeric constant that is the sum of both. { return(new NumericConstant(a.value + b.value)); } if (a?.value == 0) //if a is zero, return B; { return(B); } if (b?.value == 0) //if b is zero, return A; { return(A); } return(this); //No simplification possible, return this sum in its existing state. }
public bool Equals(SyntaxBlock ToCompare) { var casted = ToCompare as NumericConstant; if (casted?.value == value) { return(true); } return(false); }
public bool Equals(SyntaxBlock ToCompare) { Abstract_variable casted = ToCompare as Abstract_variable; if (casted?.Argument == Argument) { return(true); } return(false); }
public SyntaxBlock ParallelSimplify(int Depth) { if (Depth == 0) { return(Simplify()); } Parallel.Invoke( () => { A = A.ParallelSimplify(Depth - 1); }, () => { B = B.ParallelSimplify(Depth - 1); } ); return(SimplifySelf()); }
/// <summary> /// Calculates the derivative of a simple formula with only one variable. /// </summary> /// <param name="Formula">The formula for which to calculate the derivative for.</param> /// <returns>The derives formula.</returns> /// <exception cref="DerivativeException">Throws a DerivativeException when the formula contains more than one variable.</exception> public static SyntaxBlock CalculateDerivative(SyntaxBlock Formula) { var listOfPartials = CalculatePartialDerivatives(Formula); if (listOfPartials.Count > 1) { throw new DerivativeException("Formula has more than one variable"); } if (listOfPartials.Count < 1) { throw new DerivativeException("Formula has no derivatives"); } return(listOfPartials[0].Item2); }
public override bool Equals(SyntaxBlock ToCompare) { var casted = ToCompare as AbstractOrderstrictOperator; if (casted == null) { return(false); } if (ToCompare.GetType() != GetType()) { return(false); } return(A.Equals(casted.A) && B.Equals(casted.B)); }
public SyntaxBlock ParallelDerivative(VariableArgumentValue ArgumentToDerive, int Depth) { if (Depth == 0) { return(Derivative(ArgumentToDerive)); } SyntaxBlock adir = null; SyntaxBlock bdir = null; Parallel.Invoke( () => { adir = A.ParallelDerivative(ArgumentToDerive, Depth - 1); }, () => { bdir = B.ParallelDerivative(ArgumentToDerive, Depth - 1); } ); return(DerivativeFormulate(adir, bdir)); }
public override bool ParallelEquals(SyntaxBlock ToCompare, int Depth) { if (Depth == 0) { return(Equals(ToCompare)); } var casted = ToCompare as AbstractOrderirrelevantOperator; if (casted == null) { return(false); } if (ToCompare.GetType() != GetType()) { return(false); } bool aisa, aisb; aisa = false; aisb = false; Parallel.Invoke( () => { if (A.Equals(casted.A)) { if (B.Equals(casted.B)) { aisa = true; } } }, () => { if (B.Equals(casted.A)) { if (A.Equals(casted.B)) { aisb = true; } } } ); return(aisa || aisb); }
public override SyntaxBlock DerivativeFormulate(SyntaxBlock Adir, SyntaxBlock Bdir) { //(A'*B + -1(B' * A))/ (B * B) => (A'*B - B' * A)/ B ^ 2 return(new Quotient(new Sum(new Product(Adir, B), new Product(new NumericConstant(-1), new Product(Bdir, A))), new Product(B, B))); }
/// <summary> /// Creates a sum syntax block which adds argument A and B together. /// </summary> /// <param name="A">The left side of the sum.</param> /// <param name="B">The right side of the sum.</param> public Sum(SyntaxBlock A, SyntaxBlock B) { this.A = A; this.B = B; }
public Quotient(SyntaxBlock A, SyntaxBlock B) { this.A = A; this.B = B; }
public AbstractOrderstrictOperator(SyntaxBlock A, SyntaxBlock B) : base(A, B) { }
public AbstractOrderirrelevantOperator(SyntaxBlock A, SyntaxBlock B) : base(A, B) { }
public Quotient(SyntaxBlock A, SyntaxBlock B) : base(A, B) { }
/// <summary> /// Creates a product syntax block, which multiplies argument A and B together. /// </summary> /// <param name="A">The left side of the product.</param> /// <param name="B">The right side of the product.</param> public Product(SyntaxBlock A, SyntaxBlock B) : base(A, B) { }
public bool ParallelEquals(SyntaxBlock ToCompare, int Depth) { return(Equals(ToCompare)); }
public AbstractOperator(SyntaxBlock A, SyntaxBlock B) { this.A = A; this.B = B; }
/// <summary> /// Calculates all the partial derivatives of a given formula. /// </summary> /// <param name="Formula">The formula for which to calculate all partial derivatives.</param> /// <returns>A list of tuples, containing the ArgumentValue for which it was calculated (item1) and the formula itself(item2).</returns> public static List <Tuple <ArgumentValue, SyntaxBlock> > CalculatePartialDerivatives(SyntaxBlock Formula) { var AllVariableVariables = Formula.GetAllVariables(true); var distinctVariables = AllVariableVariables.Distinct(); List <Tuple <ArgumentValue, SyntaxBlock> > PartialDerivatives = new List <Tuple <ArgumentValue, SyntaxBlock> >(); foreach (ArgumentValue i in distinctVariables) { PartialDerivatives.Add(new Tuple <ArgumentValue, SyntaxBlock>((ArgumentValue)i, Formula.Derivative((ArgumentValue)i).Simplify())); } return(PartialDerivatives); }
/// <summary> /// Creates a product syntax block, which multiplies argument A and B together. /// </summary> /// <param name="A">The left side of the product.</param> /// <param name="B">The right side of the product.</param> public Product(SyntaxBlock A, SyntaxBlock B) { this.A = A; this.B = B; }
public SyntaxBlock Simplify() { A = A.Simplify(); B = B.Simplify(); return(SimplifySelf()); }
public abstract SyntaxBlock DerivativeFormulate(SyntaxBlock Adir, SyntaxBlock Bdir);
/// <summary> /// Creates a sum syntax block which adds argument A and B together. /// </summary> /// <param name="A">The left side of the sum.</param> /// <param name="B">The right side of the sum.</param> public Sum(SyntaxBlock A, SyntaxBlock B) : base(A, B) { }
public abstract bool ParallelEquals(SyntaxBlock ToCompare, int Depth);
public override SyntaxBlock DerivativeFormulate(SyntaxBlock Adir, SyntaxBlock Bdir) { return(new Sum(new Product(Adir, B), new Product(A, Bdir))); }
public abstract bool Equals(SyntaxBlock ToCompare);