Working with Yttrium

The intention "Make the simple things simple and the hard things possible" of the Designing Reusable Class Libraries PDC05 presentation is continuously realized in Yttrium (although some other guidelines are still violated - one of the reasons why I still have not published any code yet). At least many things can be implemented in a general way (thus "hard things" are possible), or one constrains them and profits from lot of support for the simpler cases. If you only want to consume (but not extend) the framework, you work first of all with the classes in the workplace namespace, as well as with the static classes most modules provide (Std in the standard module, Dsp in the Neodym signalprocessing module etc., just like System.Math). You may still dive gradually deeper into the depths of the framework till you finally work directly with ports and architectures.

I've written a small test case (unit tests integrated in VisualStudio 2005), pointing out what such a simple case could look like. The following case tests (among other things) the Evaluate functionality of MathSystems. Of course the asserts are included only to test the correct behavior...

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
31: 
32: 
[TestMethod]
public void SimpleSystemAsFunction()
{
    Project p = new Project();
    MathSystem s = p.CurrentSystem;
    Builder b = p.Builder;
    Context c = p.Context;

    Signal x = new Signal(c); // x
    x.AddConstraint(RealSetProperty.Instance); // x is real
    Signal x2 = b.Square(x); // x^2
    Signal sinx2 = Std.Sine(c,x2); // sin(x^2)

    Assert.AreEqual<int>(0, s.InputSignalCount, "Input A");
    Assert.AreEqual<int>(0, s.OutputSignalCount, "Output A");
    Assert.AreEqual<int>(0, s.BusCount, "Bus A");
    Assert.AreEqual<int>(3, s.SignalCount, "Signal A");
    Assert.AreEqual<int>(2, s.PortCount, "Port A");

    s.PromoteAsInput(x);
    s.PromoteAsOutput(sinx2);

    Assert.AreEqual<int>(1, s.InputSignalCount, "Input B");
    Assert.AreEqual<int>(1, s.OutputSignalCount, "Output B");
    Assert.AreEqual<int>(0, s.BusCount, "Bus B");
    Assert.AreEqual<int>(3, s.SignalCount, "Signal B");
    Assert.AreEqual<int>(2, s.PortCount, "Port B");

    double ret = Math.Round(s.Evaluate(Math.PI)[0],4);

    Assert.AreEqual<double>(-0.4303, ret, "Result");
}

In practice this will probably more look like the following:

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
Project p = new Project();
MathSystem s = p.CurrentSystem;
Context c = p.Context;

Signal x = new Signal(c); // x
Signal x2 = p.Builder.Square(x); // x^2
Signal secx2 = Std.Secant(c, x2); // sec(x^2)
Signal diff = Std.Derive(c, secx2, x); // d/dx sec(x^2)
Signal diffSimple = Std.AutoSimplify(c, diff);

s.PromoteAsInput(x);
s.PromoteAsOutput(diffSimple);
s.RemoveUnusedObjects();

ComplexValue cv = (ComplexValue)s.Evaluate(ComplexValue.I)[0];
// cv.Value = 0 - I*5.7649 (Complex Number)