public ActionResult <ComputationResponse> Compute([FromBody] ComputationRequest request) { try { var doc = new XmlDocument(); doc.LoadXml(request.XmlExpression); var symbol = ReplaceBuiltInStringSymbols(doc.AsExpressionInfo().Symbol); var(context, inputs) = symbol.Visit(new FormInputReader()); var(steps, result) = new SymbolicContext(context).Run(symbol); var points = ListOfListToTuples((result as Expression)?.Arguments?.Last() as Expression) .ToImmutableArray(); return(new ComputationResponse { RawInput = symbol.Visit(MathematicaPrinter.Default), Steps = steps.WithoutDuplicates().Select(x => x.Visit(MathematicaPrinter.Default)), Result = result.Visit(MathematicaPrinter.Default), // Points = points, FormInputs = inputs.Select(x => new ComputationResponse.FormInput { Variable = x.Item1, Default = x.Item2 }).ToImmutableArray() }); } catch (Exception e) { logger.LogError("{error}:\n{stack}", e.Message, e.StackTrace); return(BadRequest(e.Message)); } }
public static void EvaluateAndAssert( Expression expression, Symbol expectedResult, ITestOutputHelper output, Expression context = null, ImmutableList <Symbol> topLevelProcessors = null, int?maxIterations = null ) { Logger.Log = output.WriteLine; var(steps, actual) = new SymbolicContext(context, topLevelProcessors, maxIterations).Run(expression); // steps.Print(output); // output.WriteLine(""); // output.WriteLine(expression.ToString()); // output.WriteLine(actual.ToString()); // output.WriteLine(expectedResult.ToString()); Assert.Equal(expectedResult, actual); }