public void AutoSimplify_RationalNumberExpression() { // A Signal a = StdBuilder.Add( StdBuilder.Divide(IntegerValue.Constant(2), IntegerValue.Constant(3)), RationalValue.Constant(3, 4)); Assert.AreEqual("2/3+3/4", _f.Format(a, FormattingOptions.Compact), "A1"); Signal aS = Std.AutoSimplify(a); Assert.AreEqual("17/12", _f.Format(aS, FormattingOptions.Compact), "A2"); // B Signal b = StdBuilder.Power( StdBuilder.Divide(IntegerValue.Constant(4), IntegerValue.Constant(2)), IntegerValue.Constant(3)); Assert.AreEqual("(4/2)^3", _f.Format(b, FormattingOptions.Compact), "B1"); Signal bS = Std.AutoSimplify(b); Assert.AreEqual("8", _f.Format(bS, FormattingOptions.Compact), "B2"); // C Signal c = StdBuilder.Divide( IntegerValue.ConstantOne, StdBuilder.Subtract( RationalValue.Constant(2, 4), RationalValue.ConstantHalf)); Assert.AreEqual("1/(1/2-1/2)", _f.Format(c, FormattingOptions.Compact), "C1"); Signal cS = Std.AutoSimplify(c); Assert.AreEqual("Std.Undefined", _f.Format(cS, FormattingOptions.Compact), "C2"); // D Signal d = StdBuilder.Power( StdBuilder.Power( IntegerValue.Constant(5), IntegerValue.Constant(2)), StdBuilder.Power( IntegerValue.Constant(3), IntegerValue.Constant(1))); Assert.AreEqual("(5^2)^(3^1)", _f.Format(d, FormattingOptions.Compact), "D1"); Signal dS = Std.AutoSimplify(d); Assert.AreEqual("15625", _f.Format(dS, FormattingOptions.Compact), "D2"); }
public static void RegisterTheorems(ILibrary library) { Analysis.DerivativeTransformation.Provider.Add( new Analysis.DerivativeTransformation(_entityId, delegate(Port port, SignalSet manipulatedInputs, Signal variable, bool hasManipulatedInputs) { return(new SignalSet(Std.Subtract(manipulatedInputs))); })); Algebra.AutoSimplifyTransformation.Provider.Add( new Algebra.AutoSimplifyTransformation(_entityId, delegate(Port port) { // TODO return(ManipulationPlan.DoAlter); }, delegate(Port port, SignalSet manipulatedInputs, bool hasManipulatedInputs) { if (SimplifySummandsForceAddition(manipulatedInputs) || hasManipulatedInputs) { if (manipulatedInputs.Count == 0) { return(new SignalSet(IntegerValue.ConstantAdditiveIdentity)); } if (manipulatedInputs.Count == 1) { return(manipulatedInputs); } return(new SignalSet(StdBuilder.Subtract(manipulatedInputs))); } else { return(port.OutputSignals); } })); }