private static MathSolverLibrary.Equation.SolveResult EvaluateTerm(MathSolverLibrary.TermType.GenTermType termEval, int optionIndex, ref MathSolverLibrary.TermType.EvalData evalData) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); MathSolverLibrary.Equation.SolveResult result = termEval.ExecuteCommandIndex(optionIndex - 1, ref evalData); stopwatch.Stop(); ConsoleHelper.WriteLineColor(ConsoleColor.DarkCyan, "Evaluating took " + stopwatch.ElapsedMilliseconds.ToString() + "ms"); return result; }
private static MathSolverLibrary.TermType.GenTermType ParseInput(string input, ref MathSolverLibrary.Information_Helpers.FuncDefHelper funcDefHelper, ref MathSolverLibrary.TermType.EvalData evalData) { Stopwatch stopwatch = new Stopwatch(); // Start timing how long the parsing process takes. stopwatch.Start(); // Will contain the list of parsing errors if any. List<string> parseErrors = new List<string>(); // Parse the input using the math parsing engine. var termEval = MathSolver.ParseInput(input, ref evalData, ref parseErrors); // Stop the timing. stopwatch.Stop(); if (termEval == null) { // The user's input was invalid. ConsoleHelper.WriteLineColor(ConsoleColor.Red, "Cannot interpret."); return null; } ConsoleHelper.WriteLineColor(ConsoleColor.DarkCyan, "Parsing took " + stopwatch.ElapsedMilliseconds.ToString() + "ms"); return termEval; }
public static void UserFriendlyDisplay(MathSolverLibrary.Equation.SolveResult result, MathSolverLibrary.TermType.EvalData evalData) { if (evalData.GetMsgs() != null) { foreach (string msg in evalData.GetMsgs()) { WriteLineColor(ConsoleColor.DarkYellow, " " + msg); } } if (evalData.GetInputTypeStr() != null) { WriteLineColor(ConsoleColor.DarkGreen, "Topic is " + evalData.GetInputTypeStr()); } if (evalData.GetGraphEqStrs() != null) { string finalGraphStr = ""; for (int i = 0; i < evalData.GetGraphEqStrs().Length; ++i) { finalGraphStr += evalData.GetGraphEqStrs()[i]; if (i != evalData.GetGraphEqStrs().Length - 1) finalGraphStr += "; "; } WriteLineColor(ConsoleColor.White, "Graph " + finalGraphStr); } if (!result.Success) { WriteLineColor(ConsoleColor.DarkRed, "Failure"); foreach (string msg in evalData.GetFailureMsgs()) { WriteLineColor(ConsoleColor.Red, " " + msg); } } else { if (result.Solutions == null) return; int solCount = result.Solutions.Count; if (evalData.GetHasPartialSolutions()) { Console.WriteLine("The input was partially evaluated to..."); for (int i = 0; i < evalData.GetPartialSolutions().Count; ++i) { string partialSolStr = evalData.PartialSolToTexStr(i); partialSolStr = MathSolver.FinalizeOutput(partialSolStr); Console.WriteLine(" " + partialSolStr); } Console.WriteLine(); if (solCount > 0) { string pluralStr = solCount > 1 ? "s were" : " was"; Console.WriteLine("The following " + solCount.ToString() + " solution" + pluralStr + " also obtained..."); DisplayUserFriendlySols(result.Solutions); } } else { Console.WriteLine("The input was successfully evaluated."); if (solCount > 0) DisplayUserFriendlySols(result.Solutions); if (result.GetHasRestrictions()) DisplayUserFreindlyRests(result.Restrictions); } } }