public override string ToString(ExpressionStringFormat Format, ExpressionStringVariableFormat VariableFormat, ExpressionStringConstantFormat ConstantFormat)
 {
     string L = this.LeftExpression.ToString(Format, VariableFormat, ConstantFormat);
     string R = this.RightExpression.ToString(Format, VariableFormat, ConstantFormat);
     if (Format == ExpressionStringFormat.ParseFriendly) return "(" + L + " - " + R + ")";
     return L + " - " + R;
 }
Beispiel #2
0
        public override string ToString(ExpressionStringFormat Format, ExpressionStringVariableFormat VariableFormat, ExpressionStringConstantFormat ConstantFormat)
        {
            string N = this.Numerator.ToString(Format, VariableFormat, ConstantFormat);
            string D = this.Denominator.ToString(Format, VariableFormat, ConstantFormat);

            if (Format == ExpressionStringFormat.Default)
            {
                return N + " / " + D;
            }
            else if (Format == ExpressionStringFormat.LaTeX)
            {
                return @"\frac{" + N + "}{" + D + "}";
            }
            else if (Format == ExpressionStringFormat.ParseFriendly)
            {
                return "(" + N + " / " + D + ")";
            }
            else
            {
                throw new Exceptions.ExpressionParsingException("Unable to convert product to string - Invalid ExpressionStringConstantFormat");
            }
        }
Beispiel #3
0
        public override string ToString(ExpressionStringFormat Format, ExpressionStringVariableFormat VariableFormat, ExpressionStringConstantFormat ConstantFormat)
        {
            //if (this.Val == (1.0 / 2.0)) return "½";
            //if (this.Val == (1.0 / 3.0)) return "⅓";
            //if (this.Val == (1.0 / 4.0)) return "¼";
            //if (this.Val == (1.0 / 8.0)) return "⅛";
            //if (this.Val == (2.0 / 3.0)) return "⅔";
            //if (this.Val == (3.0 / 4.0)) return "¾";
            //if (this.Val == (3.0 / 8.0)) return "⅜";
            //if (this.Val == (5.0 / 8.0)) return "⅝";
            //if (this.Val == (7.0 / 8.0)) return "⅞";

            if (Format == ExpressionStringFormat.Default)
            {
                string buildstring = "";
                if (this.Negated) buildstring += "-";
                if (this.InnerValue == (1.0 / 2)) return buildstring + "½";
                if (this.InnerValue == (1.0 / 3)) return buildstring + "⅓";
                if (this.InnerValue == (2.0 / 3)) return buildstring + "⅔";
                if (this.InnerValue == (1.0 / 4)) return buildstring + "¼";
                if (this.InnerValue == (3.0 / 4)) return buildstring + "¾";
                return buildstring + "(" + this.Numerator + "/" + this.Denominator + ")";
            }
            else
            {
                string buildstring = "";
                if (this.Negated) buildstring += "-";
                return buildstring + @"\frac{" + this.Numerator + "}{" + this.Denominator + "}";
            }
        }
Beispiel #4
0
 /// <summary>
 /// Obtains the string representation of this function.
 /// </summary>
 public override string ToString(ExpressionStringFormat Format, ExpressionStringVariableFormat VariableFormat, ExpressionStringConstantFormat ConstantFormat)
 {
     string N = this.Symbol; //FINISH ME - We need to get names right!
     string A = String.Join(", ", this.Variables.ConvertAll(x => x.ToString(Format, VariableFormat, ConstantFormat)));
     if (Format == ExpressionStringFormat.Default)
     {
         return N + "(" + A + ")";
     }
     else if (Format == ExpressionStringFormat.LaTeX)
     {
         return N + "(" + A + ")";
     }
     else if (Format == ExpressionStringFormat.ParseFriendly)
     {
         return N + "[" + A + "]";
     }
     else
     {
         throw new Exceptions.ExpressionParsingException("Unable to convert function to string - Invalid ExpressionStringFormat");
     }
 }
Beispiel #5
0
        public override string ToString(ExpressionStringFormat Format, ExpressionStringVariableFormat VariableFormat, ExpressionStringConstantFormat ConstantFormat)
        {

            string LS = this.LeftExpression.ToString(Format, VariableFormat, ConstantFormat);
            string RS = this.RightExpression.ToString(Format, VariableFormat, ConstantFormat);

            if (Format == ExpressionStringFormat.Default)
            {
                //Special Formats
                if ((this.LeftExpression is Value) && (this.LeftExpression as Value).InnerValue == -1) return "-" + RS;
                else if ((this.RightExpression is Value) && (this.RightExpression as Value).InnerValue == -1) return "-" + LS;
                else if ((this.LeftExpression is Value) && (this.LeftExpression as Value).IsInteger() && (this.RightExpression is Constant)) return LS + RS;
                else if ((this.RightExpression is Value) && (this.RightExpression as Value).IsInteger() && (this.LeftExpression is Constant)) return RS + LS;
                else if ((this.LeftExpression is Value) && (this.LeftExpression as Value).IsInteger() && (this.RightExpression is Exponentiation)) return LS + RS;
                else if ((this.RightExpression is Value) && (this.RightExpression as Value).IsInteger() && (this.LeftExpression is Exponentiation)) return RS + LS;
                else if ((this.LeftExpression is Value) && (this.LeftExpression as Value).IsInteger() && (this.RightExpression is Sum)) return LS + "(" + RS + ")";
                else if ((this.RightExpression is Value) && (this.RightExpression as Value).IsInteger() && (this.LeftExpression is Sum)) return RS + "(" + LS + ")";
                else if ((this.LeftExpression is Value) && (this.LeftExpression as Value).IsInteger() && (this.RightExpression is Difference)) return LS + "(" + RS + ")";
                else if ((this.RightExpression is Value) && (this.RightExpression as Value).IsInteger() && (this.LeftExpression is Difference)) return RS + "(" + LS + ")";
                else if ((this.LeftExpression is Value) && (this.LeftExpression as Value).IsInteger() && !(this.RightExpression is Value)) return LS + RS;
                else if ((this.RightExpression is Value) && (this.RightExpression as Value).IsInteger() && !(this.LeftExpression is Value)) return RS + LS;
                //else if (!(this.LeftExpression is Value) && !(this.RightExpression is Value)) return LS + RS;

                //Otherwise, just return the default:
                return LS + " * " + RS;
            }
            else if (Format == ExpressionStringFormat.LaTeX)
            {
                //Special Formats
                if ((this.LeftExpression is Value) && (this.LeftExpression as Value).InnerValue == -1) return "-" + RS;
                else if ((this.RightExpression is Value) && (this.RightExpression as Value).InnerValue == -1) return "-" + LS;
                else if ((this.LeftExpression is Value) && (this.LeftExpression as Value).IsInteger() && (this.RightExpression is Variable)) return LS + RS;
                else if ((this.RightExpression is Value) && (this.RightExpression as Value).IsInteger() && (this.LeftExpression is Variable)) return RS + LS;
                else if ((this.LeftExpression is Value) && (this.LeftExpression as Value).IsInteger() && (this.RightExpression is Constant)) return LS + RS;
                else if ((this.RightExpression is Value) && (this.RightExpression as Value).IsInteger() && (this.LeftExpression is Constant)) return RS + LS;
                else if ((this.LeftExpression is Value) && (this.LeftExpression as Value).IsInteger() && (this.RightExpression is Exponentiation)) return LS + RS;
                else if ((this.RightExpression is Value) && (this.RightExpression as Value).IsInteger() && (this.LeftExpression is Exponentiation)) return RS + LS;

                //Otherwise, just return the default:
                return LS + @" \times " + RS;
            }
            else if (Format == ExpressionStringFormat.ParseFriendly)
            {
                if ((this.LeftExpression is Value) && (this.LeftExpression as Value).InnerValue == -1) return "-(" + RS + ")";
                else if ((this.RightExpression is Value) && (this.RightExpression as Value).InnerValue == -1) return "-(" + LS + ")";
                return "(" + LS + " * " + RS + ")";
            }
            else
            {
                throw new Exceptions.ExpressionParsingException("Unable to convert product to string - Invalid ExpressionStringConstantFormat");
            }
        }
        public override string ToString(ExpressionStringFormat Format, ExpressionStringVariableFormat VariableFormat, ExpressionStringConstantFormat ConstantFormat)
        {
            string B = this.Base.ToString(Format, VariableFormat, ConstantFormat);
            string E = this.Exponent.ToString(Format, VariableFormat, ConstantFormat);

            if (Format == ExpressionStringFormat.Default)
            {
                return B + "^" + E;
            }
            else if (Format == ExpressionStringFormat.LaTeX)
            {
                return B + "^{" + E + "}";
            }
            else if (Format == ExpressionStringFormat.ParseFriendly)
            {
                return "(" + B + " ^ " + E + ")";
            }
            else
            {
                throw new Exceptions.ExpressionParsingException("Unable to convert exponentiation to string - Invalid ExpressionStringFormat");
            }
        }
Beispiel #7
0
 /// <summary>
 /// Obtains the string representation of this mathematical expression with specific formatting options.
 /// </summary>
 /// <param name="Format">The general format to use for the output</param>
 /// <param name="VariableFormat">The format to use for variables in the output</param>
 /// <param name="ConstantFormat">The format to use for constants and values in the output</param>
 public override string ToString(ExpressionStringFormat Format, ExpressionStringVariableFormat VariableFormat, ExpressionStringConstantFormat ConstantFormat)
 {
     if (ConstantFormat == ExpressionStringConstantFormat.Default)
     {
         if (this.Symbol != string.Empty)
         {
             if (this.Subscript != string.Empty)
             {
                 if (Format == ExpressionStringFormat.Default || Format == ExpressionStringFormat.ParseFriendly)
                 {
                     return this.Symbol + "_[" + this.Subscript + "]";
                 }
                 else if (Format == ExpressionStringFormat.LaTeX)
                 {
                     return this.Symbol + "_{" + this.Subscript + "}";
                 }
                 else
                 {
                     throw new Exceptions.ExpressionParsingException("Unable to convert constant to string - Invalid ExpressionStringFormat");
                 }
             }
             else
             {
                 return this.Symbol;
             }
         }
         else
         {
             if (this.HasDescreteValue)
             {
                 return this.Value.ToString(Format, VariableFormat, ConstantFormat);
             }
             else
             {
                 return "\"[UNKNOWN CONSTANT]\"";
             }
         }
     }
     else if (ConstantFormat == ExpressionStringConstantFormat.Numeric)
     {
         if (this.HasDescreteValue)
         {
             return this.Value.ToString(Format, VariableFormat, ConstantFormat);
         }
         else
         {
             if (this.Symbol != string.Empty)
             {
                 if (this.Subscript != string.Empty)
                 {
                     if (Format == ExpressionStringFormat.Default || Format == ExpressionStringFormat.ParseFriendly)
                     {
                         return this.Symbol + "_[" + this.Subscript + "]";
                     }
                     else if (Format == ExpressionStringFormat.LaTeX)
                     {
                         return this.Symbol + "_{" + this.Subscript + "}";
                     }
                     else
                     {
                         throw new Exceptions.ExpressionParsingException("Unable to convert constant to string - Invalid ExpressionStringFormat");
                     }
                 }
                 else
                 {
                     return this.Symbol;
                 }
             }
             else
             {
                 return "\"[UNKNOWN CONSTANT]\"";
             }
         }
     }
     else if (ConstantFormat == ExpressionStringConstantFormat.Symbolic)
     {
         if (this.Symbol != string.Empty)
         {
             if (this.Subscript != string.Empty)
             {
                 if (Format == ExpressionStringFormat.Default || Format == ExpressionStringFormat.ParseFriendly)
                 {
                     return this.Symbol + "_[" + this.Subscript + "]";
                 }
                 else if (Format == ExpressionStringFormat.LaTeX)
                 {
                     return this.Symbol + "_{" + this.Subscript + "}";
                 }
                 else
                 {
                     throw new Exceptions.ExpressionParsingException("Unable to convert constant to string - Invalid ExpressionStringFormat");
                 }
             }
             else
             {
                 return this.Symbol;
             }
         }
         else
         {
             return "C";
         }
     }
     else
     {
         throw new Exceptions.ExpressionParsingException("Unable to convert constant to string - Invalid ExpressionStringConstantFormat");
     }
 }
 public override string ToString(ExpressionStringFormat Format, ExpressionStringVariableFormat VariableFormat, ExpressionStringConstantFormat ConstantFormat)
 {
     string BuildString = "(" + this.ChildExpressions[0].ToString(Format, VariableFormat, ConstantFormat);
     for (int i = 1; i < this.ChildExpressions.Count; i++)
     {
         BuildString += " * " + this.ChildExpressions[i].ToString(Format, VariableFormat, ConstantFormat);
     }
     return BuildString + ")";
 }
 public override string ToString(ExpressionStringFormat Format, ExpressionStringVariableFormat VariableFormat, ExpressionStringConstantFormat ConstantFormat)
 {
     return "i";
 }