Beispiel #1
0
    public void TestOperations()
    {
        PolyNumber x   = 5;
        var        y   = x.Root(3) + x.Root(2) - 1;
        var        exp = Math.Pow(5, 1 / 3.0) + Math.Pow(5, 1 / 2.0) - 1;

        y.HasValueNear(exp.HackFix_ToApproxBigRational()).AssertTrue();
    }
Beispiel #2
0
    public void TestAdd1()
    {
        PolyNumber x1 = 1;
        PolyNumber x2 = 2;
        var        x3 = x1 + x2;

        x3.HasValue(3).AssertTrue();
    }
Beispiel #3
0
    public void TestSubtract1()
    {
        PolyNumber x1 = 1;
        PolyNumber x2 = 2;
        var        x3 = x1 - x2;

        x3.HasValue(-1).AssertTrue();
    }
Beispiel #4
0
    public void TestMultiplicativeInverse()
    {
        ((PolyNumber)1).MultiplicativeInverse().HasValue(1).AssertTrue();
        ((PolyNumber)2).MultiplicativeInverse().HasValue(new BigRational(1, 2)).AssertTrue();

        var p = new PolyNumber(Polynomial.FromRoots(1, 2, new BigRational(3, 5))).MultiplicativeInverse();

        p.HasValue(1).AssertTrue();
        p.HasValue(new BigRational(1, 2)).AssertTrue();
        p.HasValue(new BigRational(5, 3)).AssertTrue();
        p.Constraint.Degree().AssertEquals((BigInteger)3);
    }
Beispiel #5
0
    public void TestConvert()
    {
        PolyNumber x = 2;

        x.HasValue(2).AssertTrue();
        Assert.AreEqual(x.Approximates().Single(), 2, 0.001);

        PolyNumber x2 = new BigRational(3, 5);

        x2.HasValue(new BigRational(3, 5)).AssertTrue();
        Assert.AreEqual(x2.Approximates().Single(), 0.6, 0.001);
    }
Beispiel #6
0
    public void TestMultiply2()
    {
        var x = new PolyNumber(Polynomial.FromRoots(1, 4, 7)) * new PolyNumber(Polynomial.FromRoots(1, 2, 3));

        x.Constraint.Degree().AssertEquals((BigInteger)9);
        x.HasValue(1).AssertTrue();
        x.HasValue(2).AssertTrue();
        x.HasValue(3).AssertTrue();
        x.HasValue(4).AssertTrue();
        x.HasValue(8).AssertTrue();
        x.HasValue(12).AssertTrue();
        x.HasValue(7).AssertTrue();
        x.HasValue(14).AssertTrue();
        x.HasValue(21).AssertTrue();
    }
Beispiel #7
0
    public void TestAdd4()
    {
        var x = new PolyNumber(Polynomial.FromRoots(1, 4, 7)) + new PolyNumber(Polynomial.FromRoots(1, 2, 3));

        x.Constraint.Degree().AssertEquals((BigInteger)9);
        x.HasValue(2).AssertTrue();
        x.HasValue(3).AssertTrue();
        x.HasValue(4).AssertTrue();
        x.HasValue(5).AssertTrue();
        x.HasValue(6).AssertTrue();
        x.HasValue(7).AssertTrue();
        x.HasValue(8).AssertTrue();
        x.HasValue(9).AssertTrue();
        x.HasValue(10).AssertTrue();
    }