Ejemplo n.º 1
0
        public string Output(OutputType type, INumber[] parameters, INumber pow)
        {
            switch (type)
            {
            case OutputType.String: {
                string res = "√(" + parameters[0].Output(type) + ")";
                if (!(pow is Number && (pow as Number).Value == 1))
                {
                    res += "^" + pow.Output(type);
                }
                return(res);
            }

            case OutputType.Mathjax: {
                string res = "\\sqrt {" + parameters[0].Output(type) + "}";
                if (!(pow is Number && (pow as Number).Value == 1))
                {
                    res += "^ {" + pow.Output(type) + "}";
                }
                return(res);
            }

            default:
                throw new NotImplementedException();
            }
        }
Ejemplo n.º 2
0
        public string Output(OutputType type, INumber[] num, INumber pow)
        {
            StringBuilder sb = new StringBuilder();

            if (num[0] is Variable && (num[0] as Variable).Name == "x")
            {
                sb.Append(string.Format("({0})'", num[1]));
            }
            else
            {
                sb.Append(string.Format("Diff({0}, {1})", num[0], num[1]));
            }

            if (!(pow is Number && (pow as Number).Value == 1))
            {
                sb.Insert(0, "(");
                sb.Append("^");
                if (type == OutputType.String)
                {
                    sb.Append(pow.Output(type));
                }
                else if (type == OutputType.Mathjax)
                {
                    sb.Append("{");
                    sb.Append(pow.Output(type));
                    sb.Append("}");
                }
                else
                {
                    throw new NotImplementedException();
                }
                sb.Append(")");
            }

            return(sb.ToString());
        }
Ejemplo n.º 3
0
        public string Output(OutputType type, INumber[] parameters, INumber pow)
        {
            if (type == OutputType.Mathjax)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("log");
                if (!(pow is Number && (pow as Number).Value == 1))
                {
                    sb.Append("^");
                    sb.Append(pow.Output(type));
                }
                if (!(parameters[0] is NaturalLogarithm) ||
                    !(parameters[0].Pow is Number) || (parameters[0].Pow as Number).Value != 1)
                {
                    sb.Append("_");
                    sb.Append("{");
                    sb.Append(parameters[0].Output(type));
                    sb.Append("}");
                }
                sb.Append("{");
                sb.Append(parameters[1].Output(type));
                sb.Append("}");
                return(sb.ToString());
            }
            if (type == OutputType.String)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("log");
                if (!(pow is Number && (pow as Number).Value == 1))
                {
                    sb.Append("^{");
                    sb.Append(pow.Output(type));
                    sb.Append("}");
                }
                sb.Append("(");
                if (parameters.Length >= 2)
                {
                    if (((parameters[0] is NaturalLogarithm) && ((parameters[0] as NaturalLogarithm).Pow is Number) &&
                         (parameters[0].Pow as Number).Value == 1))
                    {
                        sb.Append(parameters[1].Output(type));
                    }
                    else
                    {
                        sb.Append(parameters[0].Output(type));
                        sb.Append(", ");
                        sb.Append(parameters[1].Output(type));
                    }
                }
                else
                {
                    sb.Append(parameters[0].Output(type));
                }
                sb.Append(")");
                return(sb.ToString());
            }

            return(this.ToString());

            // return base.Output(type, parameters);
        }