Ejemplo n.º 1
0
def mixedfromstr(string):
    try:
        return nb.Mixed(int(string))
    except:
        try:
            return nb.Mixed(float(string))
        except:
            try:
                return nb.Mixed(fr.Fraction(string))
            except ValueError:
                try:
                    return nb.Mixed(uc.ufloat_fromstr(string))
                except ValueError:
                    raise (Exception(
                        "The following string looks like a number, "
                        "but I can't convert it: %s" % (string)))
Ejemplo n.º 2
0
def centre_of_gravity(liste):
    # Calculates the centre of gravity of a list of positions
    # of type geo.Pos.
    assert isinstance(liste, list), \
        "Argument of geo.centre_of_gravity(...) must be of type list."
    for item in liste:
        assert isinstance(item, Pos), \
            "Argument of geo.centre_of_gravity(...) must be a list " \
            "of objects of type geo.Pos."
    summe = Dif(nb.Matrix([[0], [0], [0], [0]]))
    for item in liste:
        summe += item - origin
    return origin + Dif((summe.value * (1 / nb.Mixed(len(liste)))))
Ejemplo n.º 3
0
 def __init__(self, a, b, c, alpha, beta, gamma):
     for number in [a, b, c, alpha, beta, gamma]:
         assert isinstance(number, nb.Mixed) \
             or isinstance(number, int) \
             or isinstance(number, float), \
             "Arguments must be of type Mixed, int or float."
     self.a = nb.Mixed(a)
     self.b = nb.Mixed(b)
     self.c = nb.Mixed(c)
     self.alpha = nb.Mixed(alpha)
     self.beta = nb.Mixed(beta)
     self.gamma = nb.Mixed(gamma)
Ejemplo n.º 4
0
def structurefactor(atomset, metric, q, wavelength):
    assert isinstance(atomset, Atomset), \
        "atomset must be of type Atomset."
    assert isinstance(metric, geo.Metric), \
        "metric must be of type geo.Metric."
    assert isinstance(q, geo.Rec), \
        "q (scattering vector) must be of type geo.Rec."
    wavelength = nb.Mixed(wavelength)
    assert isinstance(wavelength, nb.Mixed), \
        "wavelength must be of type numbers.Mixed or a type " \
        "that can be converted to this."

    sintl = 0.5 * metric.length(q)
    i2pi = np.complex(0, 1) * 2.0 * np.pi
    F = 0
    for atom in atomset.menge:
        F += tables.formfactor(atom.typ, sintl) \
           * np.exp(i2pi * float(q * (atom.pos - geo.origin)))

    return F
Ejemplo n.º 5
0
def test_Mixed():
    # Create a number of type Mixed with 4 different types.
    q = fr.Fraction(2, 3)
    e = uc.ufloat(1.2, 0.1)
    i = 4
    f = 3.5
    q1 = fr.Fraction(2, 1)
    e1 = uc.ufloat(3.7, 0)
    assert isinstance(nb.Mixed(q).value, fr.Fraction)
    assert nb.Mixed(q).value == q
    assert isinstance(nb.Mixed(e).value, uc.UFloat)
    assert (nb.Mixed(e).value).n == e.n
    assert (nb.Mixed(e).value).s == e.s
    assert isinstance(nb.Mixed(i).value, int)
    assert nb.Mixed(i).value == i
    assert isinstance(nb.Mixed(f).value, float)
    assert nb.Mixed(f).value == f
    assert isinstance(nb.Mixed(q1).value, int)
    assert nb.Mixed(q1).value == 2
    assert isinstance(nb.Mixed(e1).value, uc.UFloat)
    assert nb.Mixed(e1).value == uc.ufloat(3.7, 0.0)

    # Convert a number of type Mixed to float.
    assert isinstance(float(nb.Mixed(q)), float)
    assert float(nb.Mixed(q)) == float(2 / 3)
    assert isinstance(float(nb.Mixed(e)), float)
    assert float(nb.Mixed(e)) == 1.2
    assert isinstance(float(nb.Mixed(i)), float)
    assert float(nb.Mixed(i)) == 4.0
    assert isinstance(float(nb.Mixed(f)), float)
    assert float(nb.Mixed(f)) == 3.5

    # Print a number of type Mixed as str.
    assert isinstance(nb.Mixed(q).__str__(), str)
    assert nb.Mixed(q).__str__() == "2/3"
    assert isinstance(nb.Mixed(e).__str__(), str)
    assert nb.Mixed(e).__str__() == "1.20(10)"
    assert isinstance(nb.Mixed(i).__str__(), str)
    assert nb.Mixed(i).__str__() == "4"
    assert isinstance(nb.Mixed(f).__str__(), str)
    assert nb.Mixed(f).__str__() == "3.5"

    # Hash
    assert isinstance(hash(nb.Mixed(q)), int)
    assert isinstance(hash(nb.Mixed(e)), int)
    assert isinstance(hash(nb.Mixed(i)), int)
    assert isinstance(hash(nb.Mixed(f)), int)
    assert hash(nb.Mixed(1.99999999999)) == hash(nb.Mixed(2.00000000000))
    assert (hash(nb.Mixed(1.9)) == hash(nb.Mixed(2.0))) == False
    e1 = uc.ufloat(1.2, 0.1)
    e2 = e1
    e3 = uc.ufloat(1.2, 0.1)
    me1 = nb.Mixed(e1)
    me2 = nb.Mixed(e2)
    me3 = nb.Mixed(e3)
    assert hash(me1) == hash(me2)
    assert (hash(me1) == hash(me3)) == False

    # Equal
    assert nb.Mixed(q) == nb.Mixed(q)
    assert nb.Mixed(e) == nb.Mixed(e)
    assert nb.Mixed(i) == nb.Mixed(i)
    assert nb.Mixed(f) == nb.Mixed(f)
    assert nb.Mixed(fr.Fraction(2, 3)) == nb.Mixed(fr.Fraction(2, 3))
    assert (nb.Mixed(fr.Fraction(2, 3)) == nb.Mixed(fr.Fraction(1,
                                                                3))) == False
    assert (nb.Mixed(uc.ufloat(1.2, 0.1)) == nb.Mixed(uc.ufloat(1.2,
                                                                0.1))) == False
    assert (nb.Mixed(uc.ufloat(1.2, 0.1)) == nb.Mixed(uc.ufloat(1.2, 0.2))) \
        == False
    x1 = uc.ufloat(0.5, 0.3)
    x2 = uc.ufloat(0.5, 0.4)
    x = nb.Mixed(x1) + nb.Mixed(x2)
    y = nb.Mixed(x1 + x2)
    assert x == y
    assert nb.Mixed(fr.Fraction(2, 3)) == nb.Mixed(fr.Fraction(2, 3))
    assert (nb.Mixed(fr.Fraction(2, 3)) == nb.Mixed(uc.ufloat(1.2, 0.1))) \
        == False
    assert (nb.Mixed(fr.Fraction(2, 3)) == nb.Mixed(1)) == False
    assert (nb.Mixed(fr.Fraction(2, 3)) == nb.Mixed(0.66)) == False
    assert (nb.Mixed(uc.ufloat(1.2, 0.1)) == nb.Mixed(fr.Fraction(2, 3))) \
        == False
    assert (nb.Mixed(
        uc.ufloat(1.2, 0.1) == nb.Mixed(uc.ufloat(1.2, 0.1)))) == False
    assert (nb.Mixed(uc.ufloat(1.2, 0.1)) == nb.Mixed(1)) == False
    assert (nb.Mixed(uc.ufloat(1.2, 0.1)) == nb.Mixed(0.66)) == False
    assert (nb.Mixed(1) == nb.Mixed(fr.Fraction(2, 3))) == False
    assert (nb.Mixed(1) == nb.Mixed(uc.ufloat(1.2, 0.1))) == False
    assert nb.Mixed(1) == nb.Mixed(1)
    assert (nb.Mixed(1) == nb.Mixed(1.0)) == False
    assert (nb.Mixed(1.0) == nb.Mixed(fr.Fraction(1, 1))) == False
    assert (nb.Mixed(1.0) == nb.Mixed(uc.ufloat(1.0, 0.0))) == False
    assert (nb.Mixed(1.0) == nb.Mixed(1)) == False
    assert nb.Mixed(1.0) == nb.Mixed(1.0)
    assert nb.Mixed(0) == 0
    assert (nb.Mixed(0.1) == 0) == False
    assert nb.Mixed(fr.Fraction(2, 1)) == 2

    # Other relations

    # Addition

    mq = nb.Mixed(q)
    me = nb.Mixed(e)
    mi = nb.Mixed(i)
    mf = nb.Mixed(f)

    mi0 = nb.Mixed(0)

    assert isinstance(mq + mq, nb.Mixed)
    assert isinstance((mq + mq).value, fr.Fraction)
    assert mq + mq == nb.Mixed(fr.Fraction(4, 3))
    assert isinstance(mq + q, nb.Mixed)
    assert isinstance((mq + q).value, fr.Fraction)
    assert mq + q == nb.Mixed(fr.Fraction(4, 3))
    assert isinstance(q + mq, nb.Mixed)
    assert isinstance((q + mq).value, fr.Fraction)
    assert q + mq == nb.Mixed(fr.Fraction(4, 3))

    assert isinstance(mq + me, nb.Mixed)
    assert isinstance((mq + me).value, uc.UFloat)
    assert mq + me == nb.Mixed(e + 2 / 3)
    assert isinstance(mq + e, nb.Mixed)
    assert isinstance((mq + e).value, uc.UFloat)
    assert mq + e == nb.Mixed(e + 2 / 3)
    assert isinstance(q + me, nb.Mixed)
    assert isinstance((q + me).value, uc.UFloat)
    assert q + me == nb.Mixed(e + 2 / 3)

    assert isinstance(mq + mi, nb.Mixed)
    assert isinstance((mq + mi).value, fr.Fraction)
    assert mq + mi == nb.Mixed(fr.Fraction(14, 3))
    assert isinstance(mq + i, nb.Mixed)
    assert isinstance((mq + i).value, fr.Fraction)
    assert mq + i == nb.Mixed(fr.Fraction(14, 3))
    assert isinstance(q + mi, nb.Mixed)
    assert isinstance((q + mi).value, fr.Fraction)
    assert q + mi == nb.Mixed(fr.Fraction(14, 3))

    assert isinstance(mq + mf, nb.Mixed)
    assert isinstance((mq + mf).value, float)
    assert mq + mf == nb.Mixed(3.5 + 2 / 3)
    assert isinstance(mq + f, nb.Mixed)
    assert isinstance((mq + f).value, float)
    assert mq + f == nb.Mixed(3.5 + 2 / 3)
    assert isinstance(q + mf, nb.Mixed)
    assert isinstance((q + mf).value, float)
    assert q + mf == nb.Mixed(3.5 + 2 / 3)

    assert isinstance(me + mq, nb.Mixed)
    assert isinstance((me + mq).value, uc.UFloat)
    assert me + mq == nb.Mixed(e + 2 / 3)
    assert isinstance(me + q, nb.Mixed)
    assert isinstance((me + q).value, uc.UFloat)
    assert me + q == nb.Mixed(e + 2 / 3)
    assert isinstance(e + mq, nb.Mixed)
    assert isinstance((e + mq).value, uc.UFloat)
    assert e + mq == nb.Mixed(e + 2 / 3)

    assert isinstance(me + me, nb.Mixed)
    assert isinstance((me + me).value, uc.UFloat)
    assert me + me == nb.Mixed(e + e)
    assert isinstance(me + e, nb.Mixed)
    assert isinstance((me + e).value, uc.UFloat)
    assert me + e == nb.Mixed(e + e)
    assert isinstance(e + me, nb.Mixed)
    assert isinstance((e + me).value, uc.UFloat)
    assert e + me == nb.Mixed(e + e)

    assert isinstance(me + mi, nb.Mixed)
    assert isinstance((me + mi).value, uc.UFloat)
    assert me + mi == nb.Mixed(e + i)
    assert isinstance(me + i, nb.Mixed)
    assert isinstance((me + i).value, uc.UFloat)
    assert me + i == nb.Mixed(e + i)
    assert isinstance(e + mi, nb.Mixed)
    assert isinstance((e + mi).value, uc.UFloat)
    assert me + i == nb.Mixed(e + i)
    assert me + mi0 == nb.Mixed(e)

    assert isinstance(me + mf, nb.Mixed)
    assert isinstance((me + mf).value, uc.UFloat)
    assert me + mf == nb.Mixed(e + f)
    assert isinstance(me + f, nb.Mixed)
    assert isinstance((me + f).value, uc.UFloat)
    assert me + f == nb.Mixed(e + f)
    assert isinstance(e + mf, nb.Mixed)
    assert isinstance((e + mf).value, uc.UFloat)
    assert e + mf == nb.Mixed(e + f)

    assert isinstance(mi + mq, nb.Mixed)
    assert isinstance((mi + mq).value, fr.Fraction)
    assert mi + mq == nb.Mixed(fr.Fraction(14, 3))
    assert isinstance(mi + q, nb.Mixed)
    assert isinstance((mi + q).value, fr.Fraction)
    assert mi + q == nb.Mixed(fr.Fraction(14, 3))
    assert isinstance(i + mq, nb.Mixed)
    assert isinstance((i + mq).value, fr.Fraction)
    assert i + mq == nb.Mixed(fr.Fraction(14, 3))

    assert isinstance(mi + me, nb.Mixed)
    assert isinstance((mi + me).value, uc.UFloat)
    assert mi + me == nb.Mixed(i + e)
    assert isinstance(mi + e, nb.Mixed)
    assert isinstance((mi + e).value, uc.UFloat)
    assert mi + me == nb.Mixed(i + e)
    assert isinstance(i + me, nb.Mixed)
    assert isinstance((i + me).value, uc.UFloat)
    assert i + me == nb.Mixed(i + e)

    assert isinstance(mi + mi, nb.Mixed)
    assert isinstance((mi + mi).value, int)
    assert mi + mi == nb.Mixed(8)
    assert isinstance(mi + i, nb.Mixed)
    assert isinstance((mi + i).value, int)
    assert mi + i == nb.Mixed(8)
    assert isinstance(i + mi, nb.Mixed)
    assert isinstance((i + mi).value, int)
    assert i + mi == nb.Mixed(8)

    assert isinstance(mi + mf, nb.Mixed)
    assert isinstance((mi + mf).value, float)
    assert mi + mf == nb.Mixed(7.5)
    assert isinstance(mi + f, nb.Mixed)
    assert isinstance((mi + f).value, float)
    assert mi + f == nb.Mixed(7.5)
    assert isinstance(i + mf, nb.Mixed)
    assert isinstance((i + mf).value, float)
    assert i + mf == nb.Mixed(7.5)

    assert isinstance(mf + mq, nb.Mixed)
    assert isinstance((mf + mq).value, float)
    assert mf + mq == nb.Mixed(3.5 + 2 / 3)
    assert isinstance(mf + q, nb.Mixed)
    assert isinstance((mf + q).value, float)
    assert mf + q == nb.Mixed(3.5 + 2 / 3)
    assert isinstance(f + mq, nb.Mixed)
    assert isinstance((f + mq).value, float)
    assert f + mq == nb.Mixed(3.5 + 2 / 3)

    assert isinstance(mf + me, nb.Mixed)
    assert isinstance((mf + me).value, uc.UFloat)
    assert mf + me == nb.Mixed(f + e)
    assert isinstance(mf + e, nb.Mixed)
    assert isinstance((mf + e).value, uc.UFloat)
    assert mf + e == nb.Mixed(f + e)
    assert isinstance(f + me, nb.Mixed)
    assert isinstance((f + me).value, uc.UFloat)
    assert f + me == nb.Mixed(f + e)

    # Subtraction
    q1 = fr.Fraction(1, 2)
    q2 = fr.Fraction(1, 4)
    e1 = uc.ufloat(1.2, 0.3)
    e2 = uc.ufloat(0.2, 0.4)
    i1 = 4
    i2 = 3
    f1 = 3.5
    f2 = 3.4
    mq1 = nb.Mixed(q1)
    mq2 = nb.Mixed(q2)
    me1 = nb.Mixed(e1)
    me2 = nb.Mixed(e2)
    mi1 = nb.Mixed(i1)
    mi2 = nb.Mixed(i2)
    mf1 = nb.Mixed(f1)
    mf2 = nb.Mixed(f2)

    assert isinstance(mq1 - mq2, nb.Mixed)
    assert isinstance((mq1 - mq2).value, fr.Fraction)
    assert mq1 - mq2 == nb.Mixed(fr.Fraction(1, 4))
    assert isinstance(mq1 - q2, nb.Mixed)
    assert isinstance((mq1 - q2).value, fr.Fraction)
    assert mq1 - q2 == nb.Mixed(fr.Fraction(1, 4))
    assert isinstance(q1 - mq2, nb.Mixed)
    assert isinstance((q1 - mq2).value, fr.Fraction)
    assert q1 - mq2 == nb.Mixed(fr.Fraction(1, 4))

    assert isinstance(mq1 - me1, nb.Mixed)
    assert isinstance((mq1 - me1).value, uc.UFloat)
    assert mq1 - me1 == nb.Mixed(float(q1) - e1)
    assert isinstance(mq1 - e1, nb.Mixed)
    assert isinstance((mq1 - e1).value, uc.UFloat)
    assert mq1 - e1 == nb.Mixed(float(q1) - e1)
    assert isinstance(q1 - me1, nb.Mixed)
    assert isinstance((q1 - me1).value, uc.UFloat)
    assert q1 - me1 == nb.Mixed(float(q1) - e1)

    assert isinstance(mq1 - mi1, nb.Mixed)
    assert isinstance((mq1 - mi1).value, fr.Fraction)
    assert mq1 - mi1 == nb.Mixed(q1 - i1)
    assert isinstance(mq1 - i1, nb.Mixed)
    assert isinstance((mq1 - i1).value, fr.Fraction)
    assert mq1 - i1 == nb.Mixed(q1 - i1)
    assert isinstance(q1 - mi1, nb.Mixed)
    assert isinstance((q1 - mi1).value, fr.Fraction)
    assert q1 - mi1 == nb.Mixed(q1 - i1)

    assert isinstance(mq1 - mf1, nb.Mixed)
    assert isinstance((mq1 - mf1).value, float)
    assert mq1 - mf1 == nb.Mixed(-3.0)
    assert isinstance(mq1 - f1, nb.Mixed)
    assert isinstance((mq1 - f1).value, float)
    assert mq1 - f1 == nb.Mixed(-3.0)
    assert isinstance(q1 - mf1, nb.Mixed)
    assert isinstance((q1 - mf1).value, float)
    assert q1 - mf1 == nb.Mixed(-3.0)

    assert isinstance(me1 - mq1, nb.Mixed)
    assert isinstance((me1 - mq1).value, uc.UFloat)
    assert me1 - mq1 == nb.Mixed(e1 - float(q1))
    assert isinstance(me1 - q1, nb.Mixed)
    assert isinstance((me1 - q1).value, uc.UFloat)
    assert me1 - q1 == nb.Mixed(e1 - float(q1))
    assert isinstance(e1 - mq1, nb.Mixed)
    assert isinstance((e1 - mq1).value, uc.UFloat)
    assert e1 - mq1 == nb.Mixed(e1 - float(q1))

    assert isinstance(me1 - me2, nb.Mixed)
    assert isinstance((me1 - me2).value, uc.UFloat)
    assert me1 - me2 == nb.Mixed(e1 - e2)
    assert isinstance(me1 - e2, nb.Mixed)
    assert isinstance((me1 - e2).value, uc.UFloat)
    assert me1 - e2 == nb.Mixed(e1 - e2)
    assert isinstance(e1 - me2, nb.Mixed)
    assert isinstance((e1 - me2).value, uc.UFloat)
    assert e1 - me2 == nb.Mixed(e1 - e2)

    assert isinstance(me1 - mi1, nb.Mixed)
    assert isinstance((me1 - mi1).value, uc.UFloat)
    assert me1 - mi1 == nb.Mixed(e1 - i1)
    assert isinstance(me1 - i1, nb.Mixed)
    assert isinstance((me1 - i1).value, uc.UFloat)
    assert me1 - i1 == nb.Mixed(e1 - i1)
    assert isinstance(e1 - mi1, nb.Mixed)
    assert isinstance((e1 - mi1).value, uc.UFloat)
    assert e1 - mi1 == nb.Mixed(e1 - i1)

    assert isinstance(me1 - mf1, nb.Mixed)
    assert isinstance((me1 - mf1).value, uc.UFloat)
    assert me1 - mf1 == nb.Mixed(e1 - f1)
    assert isinstance(me1 - f1, nb.Mixed)
    assert isinstance((me1 - f1).value, uc.UFloat)
    assert me1 - f1 == nb.Mixed(e1 - f1)
    assert isinstance(e1 - mf1, nb.Mixed)
    assert isinstance((e1 - mf1).value, uc.UFloat)
    assert e1 - mf1 == nb.Mixed(e1 - f1)

    assert isinstance(mi1 - mq1, nb.Mixed)
    assert isinstance((mi1 - mq1).value, fr.Fraction)
    assert mi1 - mq1 == nb.Mixed(fr.Fraction(7, 2))
    assert isinstance(mi1 - q1, nb.Mixed)
    assert isinstance((mi1 - q1).value, fr.Fraction)
    assert mi1 - q1 == nb.Mixed(fr.Fraction(7, 2))
    assert isinstance(i1 - mq1, nb.Mixed)
    assert isinstance((i1 - mq1).value, fr.Fraction)
    assert i1 - mq1 == nb.Mixed(fr.Fraction(7, 2))

    assert isinstance(mi1 - me1, nb.Mixed)
    assert isinstance((mi1 - me1).value, uc.UFloat)
    assert mi1 - me1 == nb.Mixed(i1 - e1)
    assert isinstance(mi1 - e1, nb.Mixed)
    assert isinstance((mi1 - e1).value, uc.UFloat)
    assert mi1 - e1 == nb.Mixed(i1 - e1)
    assert isinstance(i1 - me1, nb.Mixed)
    assert isinstance((i1 - me1).value, uc.UFloat)
    assert i1 - me1 == nb.Mixed(i1 - e1)

    assert isinstance(mi1 - mi2, nb.Mixed)
    assert isinstance((mi1 - mi2).value, int)
    assert mi1 - mi2 == nb.Mixed(1)
    assert isinstance(mi1 - i2, nb.Mixed)
    assert isinstance((mi1 - i2).value, int)
    assert mi1 - i2 == nb.Mixed(1)
    assert isinstance(i1 - mi2, nb.Mixed)
    assert isinstance((i1 - mi2).value, int)
    assert i1 - mi2 == nb.Mixed(1)

    assert isinstance(mi1 - mf1, nb.Mixed)
    assert isinstance((mi1 - mf1).value, float)
    assert mi1 - mf1 == nb.Mixed(0.5)
    assert isinstance(mi1 - f1, nb.Mixed)
    assert isinstance((mi1 - f1).value, float)
    assert mi1 - f1 == nb.Mixed(0.5)
    assert isinstance(i1 - mf1, nb.Mixed)
    assert isinstance((i1 - mf1).value, float)
    assert i1 - mf1 == nb.Mixed(0.5)

    assert isinstance(mf1 - mq1, nb.Mixed)
    assert isinstance((mf1 - mq1).value, float)
    assert mf1 - mq1 == nb.Mixed(3.0)
    assert isinstance(mf1 - q1, nb.Mixed)
    assert isinstance((mf1 - q1).value, float)
    assert mf1 - q1 == nb.Mixed(3.0)
    assert isinstance(f1 - mq1, nb.Mixed)
    assert isinstance((f1 - mq1).value, float)
    assert f1 - mq1 == nb.Mixed(3.0)

    assert isinstance(mf1 - me1, nb.Mixed)
    assert isinstance((mf1 - me1).value, uc.UFloat)
    assert mf1 - me1 == nb.Mixed(f1 - e1)
    assert isinstance(mf1 - e1, nb.Mixed)
    assert isinstance((mf1 - e1).value, uc.UFloat)
    assert mf1 - e1 == nb.Mixed(f1 - e1)
    assert isinstance(f1 - me1, nb.Mixed)
    assert isinstance((f1 - me1).value, uc.UFloat)
    assert f1 - me1 == nb.Mixed(f1 - e1)

    assert isinstance(mf1 - mi1, nb.Mixed)
    assert isinstance((mf1 - mi1).value, float)
    assert mf1 - mi1 == nb.Mixed(-0.5)
    assert isinstance(mf1 - i1, nb.Mixed)
    assert isinstance((mf1 - i1).value, float)
    assert mf1 - i1 == nb.Mixed(-0.5)
    assert isinstance(f1 - mi1, nb.Mixed)
    assert isinstance((f1 - mi1).value, float)
    assert f1 - mi1 == nb.Mixed(-0.5)

    assert isinstance(mf1 - mf2, nb.Mixed)
    assert isinstance((mf1 - mf2).value, float)
    assert mf1 - mf2 == nb.Mixed(3.5 - 3.4)
    assert isinstance(mf1 - f2, nb.Mixed)
    assert isinstance((mf1 - f2).value, float)
    assert mf1 - f2 == nb.Mixed(3.5 - 3.4)
    assert isinstance(f1 - mf2, nb.Mixed)
    assert isinstance((f1 - mf2).value, float)
    assert f1 - mf2 == nb.Mixed(3.5 - 3.4)

    # Multiplication

    q1 = fr.Fraction(1, 2)
    q2 = fr.Fraction(1, 4)
    e1 = uc.ufloat(1.2, 0.3)
    e2 = uc.ufloat(0.2, 0.4)
    i1 = 4
    i2 = 3
    f1 = 3.5
    f2 = 3.4
    mq1 = nb.Mixed(q1)
    mq2 = nb.Mixed(q2)
    me1 = nb.Mixed(e1)
    me2 = nb.Mixed(e2)
    mi1 = nb.Mixed(i1)
    mi2 = nb.Mixed(i2)
    mf1 = nb.Mixed(f1)
    mf2 = nb.Mixed(f2)

    assert isinstance(mq1 * mq2, nb.Mixed)
    assert isinstance((mq1 * mq2).value, fr.Fraction)
    assert mq1 * mq2 == nb.Mixed(fr.Fraction(1, 8))
    assert isinstance(mq1 * q2, nb.Mixed)
    assert isinstance((mq1 * q2).value, fr.Fraction)
    assert mq1 * q2 == nb.Mixed(fr.Fraction(1, 8))
    assert isinstance(q1 * mq2, nb.Mixed)
    assert isinstance((q1 * mq2).value, fr.Fraction)
    assert q1 * mq2 == nb.Mixed(fr.Fraction(1, 8))

    assert isinstance(mq1 * me1, nb.Mixed)
    assert isinstance((mq1 * me1).value, uc.UFloat)
    assert mq1 * me1 == nb.Mixed(float(q1) * e1)
    assert isinstance(mq1 * e1, nb.Mixed)
    assert isinstance((mq1 * e1).value, uc.UFloat)
    assert mq1 * e1 == nb.Mixed(float(q1) * e1)
    assert isinstance(q1 * me1, nb.Mixed)
    assert isinstance((q1 * me1).value, uc.UFloat)
    assert q1 * me1 == nb.Mixed(float(q1) * e1)

    assert isinstance(mq1 * mi2, nb.Mixed)
    assert isinstance((mq1 * mi2).value, fr.Fraction)
    assert mq1 * mi2 == nb.Mixed(fr.Fraction(3, 2))
    assert isinstance(mq1 * i2, nb.Mixed)
    assert isinstance((mq1 * i2).value, fr.Fraction)
    assert mq1 * i2 == nb.Mixed(fr.Fraction(3, 2))
    assert isinstance(q1 * mi2, nb.Mixed)
    assert isinstance((q1 * mi2).value, fr.Fraction)
    assert q1 * mi2 == nb.Mixed(fr.Fraction(3, 2))

    assert isinstance(mq1 * mf1, nb.Mixed)
    assert isinstance((mq1 * mf1).value, float)
    assert mq1 * mf1 == nb.Mixed(1.75)
    assert isinstance(mq1 * f1, nb.Mixed)
    assert isinstance((mq1 * f1).value, float)
    assert mq1 * f1 == nb.Mixed(1.75)
    assert isinstance(q1 * mf1, nb.Mixed)
    assert isinstance((q1 * mf1).value, float)
    assert q1 * mf1 == nb.Mixed(1.75)

    assert isinstance(me1 * mq1, nb.Mixed)
    assert isinstance((me1 * mq1).value, uc.UFloat)
    assert me1 * mq1 == nb.Mixed(e1 * float(q1))
    assert isinstance(me1 * q1, nb.Mixed)
    assert isinstance((me1 * q1).value, uc.UFloat)
    assert me1 * q1 == nb.Mixed(e1 * float(q1))
    assert isinstance(e1 * mq1, nb.Mixed)
    assert isinstance((e1 * mq1).value, uc.UFloat)
    assert e1 * mq1 == nb.Mixed(e1 * float(q1))

    assert isinstance(me1 * me2, nb.Mixed)
    assert isinstance((me1 * me2).value, uc.UFloat)
    assert me1 * me2 == nb.Mixed(e1 * e2)
    assert isinstance(me1 * e2, nb.Mixed)
    assert isinstance((me1 * e2).value, uc.UFloat)
    assert me1 * e2 == nb.Mixed(e1 * e2)
    assert isinstance(e1 * me2, nb.Mixed)
    assert isinstance((e1 * me2).value, uc.UFloat)
    assert e1 * me2 == nb.Mixed(e1 * e2)

    assert isinstance(me1 * mi1, nb.Mixed)
    assert isinstance((me1 * mi1).value, uc.UFloat)
    assert me1 * mi1 == nb.Mixed(e1 * i1)
    assert isinstance(me1 * i1, nb.Mixed)
    assert isinstance((me1 * i1).value, uc.UFloat)
    assert me1 * i1 == nb.Mixed(e1 * i1)
    assert isinstance(e1 * mi1, nb.Mixed)
    assert isinstance((e1 * mi1).value, uc.UFloat)
    assert e1 * mi1 == nb.Mixed(e1 * i1)

    assert isinstance(me1 * mf1, nb.Mixed)
    assert isinstance((me1 * mf1).value, uc.UFloat)
    assert me1 * mf1 == nb.Mixed(e1 * f1)
    assert isinstance(me1 * f1, nb.Mixed)
    assert isinstance((me1 * f1).value, uc.UFloat)
    assert me1 * f1 == nb.Mixed(e1 * f1)
    assert isinstance(e1 * mf1, nb.Mixed)
    assert isinstance((e1 * mf1).value, uc.UFloat)
    assert e1 * mf1 == nb.Mixed(e1 * f1)

    assert isinstance(nb.Mixed(3) * mq1, nb.Mixed)
    assert isinstance((nb.Mixed(3) * mq1).value, fr.Fraction)
    assert nb.Mixed(3) * mq1 == nb.Mixed(fr.Fraction(3, 2))
    assert isinstance(nb.Mixed(3) * q1, nb.Mixed)
    assert isinstance((nb.Mixed(3) * q1).value, fr.Fraction)
    assert nb.Mixed(3) * q1 == nb.Mixed(fr.Fraction(3, 2))
    assert isinstance(3 * mq1, nb.Mixed)
    assert isinstance((3 * mq1).value, fr.Fraction)
    assert 3 * mq1 == nb.Mixed(fr.Fraction(3, 2))

    assert isinstance(mi1 * me1, nb.Mixed)
    assert isinstance((mi1 * me1).value, uc.UFloat)
    assert mi1 * me1 == nb.Mixed(i1 * e1)
    assert isinstance(mi1 * e1, nb.Mixed)
    assert isinstance((mi1 * e1).value, uc.UFloat)
    assert mi1 * e1 == nb.Mixed(i1 * e1)
    assert isinstance(i1 * me1, nb.Mixed)
    assert isinstance((i1 * me1).value, uc.UFloat)
    assert i1 * me1 == nb.Mixed(i1 * e1)

    assert isinstance(mi1 * mi2, nb.Mixed)
    assert isinstance((mi1 * mi2).value, int)
    assert mi1 * mi2 == nb.Mixed(12)
    assert isinstance(mi1 * i2, nb.Mixed)
    assert isinstance((mi1 * i2).value, int)
    assert mi1 * i2 == nb.Mixed(12)
    assert isinstance(i1 * mi2, nb.Mixed)
    assert isinstance((i1 * mi2).value, int)
    assert i1 * mi2 == nb.Mixed(12)

    assert isinstance(mi1 * mf1, nb.Mixed)
    assert isinstance((mi1 * mf1).value, float)
    assert mi1 * mf1 == nb.Mixed(14.0)
    assert isinstance(mi1 * f1, nb.Mixed)
    assert isinstance((mi1 * f1).value, float)
    assert mi1 * f1 == nb.Mixed(14.0)
    assert isinstance(i1 * mf1, nb.Mixed)
    assert isinstance((i1 * mf1).value, float)
    assert i1 * mf1 == nb.Mixed(14.0)

    assert isinstance(mf1 * mq1, nb.Mixed)
    assert isinstance((mf1 * mq1).value, float)
    assert mf1 * mq1 == nb.Mixed(1.75)
    assert isinstance(mf1 * q1, nb.Mixed)
    assert isinstance((mf1 * q1).value, float)
    assert mf1 * q1 == nb.Mixed(1.75)
    assert isinstance(f1 * mq1, nb.Mixed)
    assert isinstance((f1 * mq1).value, float)
    assert f1 * mq1 == nb.Mixed(1.75)

    assert isinstance(mf1 * me1, nb.Mixed)
    assert isinstance((mf1 * me1).value, uc.UFloat)
    assert mf1 * me1 == nb.Mixed(f1 * e1)
    assert isinstance(mf1 * e1, nb.Mixed)
    assert isinstance((mf1 * e1).value, uc.UFloat)
    assert mf1 * e1 == nb.Mixed(f1 * e1)
    assert isinstance(f1 * me1, nb.Mixed)
    assert isinstance((f1 * me1).value, uc.UFloat)
    assert f1 * me1 == nb.Mixed(f1 * e1)

    assert isinstance(mf1 * mi1, nb.Mixed)
    assert isinstance((mf1 * mi1).value, float)
    assert mf1 * mi1 == nb.Mixed(14.0)
    assert isinstance(mf1 * i1, nb.Mixed)
    assert isinstance((mf1 * i1).value, float)
    assert mf1 * i1 == nb.Mixed(14.0)
    assert isinstance(f1 * mi1, nb.Mixed)
    assert isinstance((f1 * mi1).value, float)
    assert f1 * mi1 == nb.Mixed(14.0)

    assert isinstance(mf1 * mf2, nb.Mixed)
    assert isinstance((mf1 * mf2).value, float)
    assert mf1 * mf2 == nb.Mixed(11.9)
    assert isinstance(mf1 * f2, nb.Mixed)
    assert isinstance((mf1 * f2).value, float)
    assert mf1 * f2 == nb.Mixed(11.9)
    assert isinstance(f1 * mf2, nb.Mixed)
    assert isinstance((f1 * mf2).value, float)
    assert f1 * mf2 == nb.Mixed(11.9)

    # Multiplication with integer 0

    q = fr.Fraction(2, 3)
    e = uc.ufloat(1.2, 0.1)
    i = 4
    f = 3.5
    mq = nb.Mixed(q)
    me = nb.Mixed(e)
    mi = nb.Mixed(i)
    mf = nb.Mixed(f)
    m0 = nb.Mixed(0)

    for m in [mq, me, mi, mf]:
        assert m * m0 == m0
        assert m * 0 == m0
        assert m0 * m == m0
        assert 0 * m == m0

    for z in [q, e, i, f]:
        assert z * m0 == m0
        assert m0 * z == m0

    # Division
    q1 = fr.Fraction(2, 3)
    q2 = fr.Fraction(3, 4)
    e1 = uc.ufloat(0.5, 0.3)
    e2 = uc.ufloat(0.75, 0.4)
    i1 = 4
    i2 = 3
    f1 = 1.5
    f2 = 1.6
    mq1 = nb.Mixed(q1)
    mq2 = nb.Mixed(q2)
    me1 = nb.Mixed(e1)
    me2 = nb.Mixed(e2)
    mi1 = nb.Mixed(i1)
    mi2 = nb.Mixed(i2)
    mf1 = nb.Mixed(f1)
    mf2 = nb.Mixed(f2)

    assert isinstance(mq1 / mq2, nb.Mixed)
    assert isinstance((mq1 / mq2).value, fr.Fraction)
    assert mq1 / mq2 == nb.Mixed(fr.Fraction(8, 9))
    assert isinstance(mq1 / q2, nb.Mixed)
    assert isinstance((mq1 / q2).value, fr.Fraction)
    assert mq1 / q2 == nb.Mixed(fr.Fraction(8, 9))
    assert isinstance(q1 / mq2, nb.Mixed)
    assert isinstance((q1 / mq2).value, fr.Fraction)
    assert q1 / mq2 == nb.Mixed(fr.Fraction(8, 9))

    assert isinstance(mq1 / me1, nb.Mixed)
    assert isinstance((mq1 / me1).value, uc.UFloat)
    assert mq1 / me1 == nb.Mixed(float(q1) / e1)
    assert isinstance(mq1 / e1, nb.Mixed)
    assert isinstance((mq1 / e1).value, uc.UFloat)
    assert mq1 / e1 == nb.Mixed(float(q1) / e1)
    assert isinstance(q1 / me1, nb.Mixed)
    assert isinstance((q1 / me1).value, uc.UFloat)
    assert q1 / me1 == nb.Mixed(float(q1) / e1)

    assert isinstance(mq1 / mi1, nb.Mixed)
    assert isinstance((mq1 / mi1).value, fr.Fraction)
    assert mq1 / mi1 == nb.Mixed(fr.Fraction(1, 6))
    assert isinstance(mq1 / i1, nb.Mixed)
    assert isinstance((mq1 / i1).value, fr.Fraction)
    assert mq1 / i1 == nb.Mixed(fr.Fraction(1, 6))
    assert isinstance(q1 / mi1, nb.Mixed)
    assert isinstance((q1 / mi1).value, fr.Fraction)
    assert q1 / mi1 == nb.Mixed(fr.Fraction(1, 6))

    assert isinstance(mq1 / mf1, nb.Mixed)
    assert isinstance((mq1 / mf1).value, float)
    assert mq1 / mf1 == nb.Mixed(4.0 / 9.0)
    assert isinstance(mq1 / f1, nb.Mixed)
    assert isinstance((mq1 / f1).value, float)
    assert mq1 / f1 == nb.Mixed(4.0 / 9.0)
    assert isinstance(q1 / mf1, nb.Mixed)
    assert isinstance((q1 / mf1).value, float)
    assert q1 / mf1 == nb.Mixed(4.0 / 9.0)

    assert isinstance(me1 / mq1, nb.Mixed)
    assert isinstance((me1 / mq1).value, uc.UFloat)
    assert me1 / mq1 == nb.Mixed(e1 / float(q1))
    assert isinstance(me1 / q1, nb.Mixed)
    assert isinstance((me1 / q1).value, uc.UFloat)
    assert me1 / q1 == nb.Mixed(e1 / float(q1))
    assert isinstance(e1 / mq1, nb.Mixed)
    assert isinstance((e1 / mq1).value, uc.UFloat)
    assert e1 / mq1 == nb.Mixed(e1 / float(q1))

    assert isinstance(me1 / me2, nb.Mixed)
    assert isinstance((me1 / me2).value, uc.UFloat)
    assert me1 / me2 == nb.Mixed(e1 / e2)
    assert isinstance(me1 / e2, nb.Mixed)
    assert isinstance((me1 / e2).value, uc.UFloat)
    assert me1 / e2 == nb.Mixed(e1 / e2)
    assert isinstance(e1 / me2, nb.Mixed)
    assert isinstance((e1 / me2).value, uc.UFloat)
    assert e1 / me2 == nb.Mixed(e1 / e2)

    assert isinstance(me1 / mi1, nb.Mixed)
    assert isinstance((me1 / mi1).value, uc.UFloat)
    assert me1 / mi1 == nb.Mixed(e1 / i1)
    assert isinstance(me1 / i1, nb.Mixed)
    assert isinstance((me1 / i1).value, uc.UFloat)
    assert me1 / i1 == nb.Mixed(e1 / i1)
    assert isinstance(e1 / mi1, nb.Mixed)
    assert isinstance((e1 / mi1).value, uc.UFloat)
    assert e1 / mi1 == nb.Mixed(e1 / i1)

    assert isinstance(me1 / mf1, nb.Mixed)
    assert isinstance((me1 / mf1).value, uc.UFloat)
    assert me1 / mf1 == nb.Mixed(e1 / f1)
    assert isinstance(me1 / f1, nb.Mixed)
    assert isinstance((me1 / f1).value, uc.UFloat)
    assert me1 / f1 == nb.Mixed(e1 / f1)
    assert isinstance(e1 / mf1, nb.Mixed)
    assert isinstance((e1 / mf1).value, uc.UFloat)
    assert e1 / mf1 == nb.Mixed(e1 / f1)

    assert isinstance(mi1 / mq2, nb.Mixed)
    assert isinstance((mi1 / mq2).value, fr.Fraction)
    assert mi1 / mq2 == nb.Mixed(fr.Fraction(16, 3))
    assert isinstance(mi1 / q2, nb.Mixed)
    assert isinstance((mi1 / q2).value, fr.Fraction)
    assert mi1 / q2 == nb.Mixed(fr.Fraction(16, 3))
    assert isinstance(i1 / mq2, nb.Mixed)
    assert isinstance((i1 / mq2).value, fr.Fraction)
    assert i1 / mq2 == nb.Mixed(fr.Fraction(16, 3))

    assert isinstance(mi1 / me1, nb.Mixed)
    assert isinstance((mi1 / me1).value, uc.UFloat)
    assert mi1 / me1 == nb.Mixed(i1 / e1)
    assert isinstance(mi1 / e1, nb.Mixed)
    assert isinstance((mi1 / e1).value, uc.UFloat)
    assert mi1 / e1 == nb.Mixed(i1 / e1)
    assert isinstance(i1 / me1, nb.Mixed)
    assert isinstance((i1 / me1).value, uc.UFloat)
    assert i1 / me1 == nb.Mixed(i1 / e1)

    assert isinstance(mi1 / mi2, nb.Mixed)
    assert isinstance((mi1 / mi2).value, fr.Fraction)
    assert mi1 / mi2 == nb.Mixed(fr.Fraction(4, 3))
    assert isinstance(mi1 / i2, nb.Mixed)
    assert isinstance((mi1 / i2).value, fr.Fraction)
    assert mi1 / i2 == nb.Mixed(fr.Fraction(4, 3))
    assert isinstance(i1 / mi2, nb.Mixed)
    assert isinstance((i1 / mi2).value, fr.Fraction)
    assert i1 / mi2 == nb.Mixed(fr.Fraction(4, 3))

    assert isinstance(mi1 / mf1, nb.Mixed)
    assert isinstance((mi1 / mf1).value, float)
    assert mi1 / mf1 == nb.Mixed(4.0 / 1.5)
    assert isinstance(mi1 / f1, nb.Mixed)
    assert isinstance((mi1 / f1).value, float)
    assert mi1 / f1 == nb.Mixed(4.0 / 1.5)
    assert isinstance(i1 / mf1, nb.Mixed)
    assert isinstance((i1 / mf1).value, float)
    assert i1 / mf1 == nb.Mixed(4.0 / 1.5)

    assert isinstance(mf1 / mq1, nb.Mixed)
    assert isinstance((mf1 / mq1).value, float)
    assert mf1 / mq1 == nb.Mixed(2.25)
    assert isinstance(mf1 / q1, nb.Mixed)
    assert isinstance((mf1 / q1).value, float)
    assert mf1 / q1 == nb.Mixed(2.25)
    assert isinstance(f1 / mq1, nb.Mixed)
    assert isinstance((f1 / mq1).value, float)
    assert f1 / mq1 == nb.Mixed(2.25)

    assert isinstance(mf1 / me1, nb.Mixed)
    assert isinstance((mf1 / me1).value, uc.UFloat)
    assert mf1 / me1 == nb.Mixed(f1 / e1)
    assert isinstance(mf1 / e1, nb.Mixed)
    assert isinstance((mf1 / e1).value, uc.UFloat)
    assert mf1 / e1 == nb.Mixed(f1 / e1)
    assert isinstance(f1 / me1, nb.Mixed)
    assert isinstance((f1 / me1).value, uc.UFloat)
    assert f1 / me1 == nb.Mixed(f1 / e1)

    assert isinstance(mf1 / mi1, nb.Mixed)
    assert isinstance((mf1 / mi1).value, float)
    assert mf1 / mi1 == nb.Mixed(0.375)
    assert isinstance(mf1 / i1, nb.Mixed)
    assert isinstance((mf1 / i1).value, float)
    assert mf1 / i1 == nb.Mixed(0.375)
    assert isinstance(f1 / mi1, nb.Mixed)
    assert isinstance((f1 / mi1).value, float)
    assert f1 / mi1 == nb.Mixed(0.375)

    assert isinstance(mf1 / mf2, nb.Mixed)
    assert isinstance((mf1 / mf2).value, float)
    assert mf1 / mf2 == nb.Mixed(0.9375)
    assert isinstance(mf1 / f2, nb.Mixed)
    assert isinstance((mf1 / f2).value, float)
    assert mf1 / f2 == nb.Mixed(0.9375)
    assert isinstance(f1 / mf2, nb.Mixed)
    assert isinstance((f1 / mf2).value, float)
    assert f1 / mf2 == nb.Mixed(0.9375)

    # Dividing integer 0

    q = fr.Fraction(2, 3)
    e = uc.ufloat(1.2, 0.1)
    i = 4
    f = 3.5
    mq = nb.Mixed(q)
    me = nb.Mixed(e)
    mi = nb.Mixed(i)
    mf = nb.Mixed(f)
    m0 = nb.Mixed(0)

    for m in [mq, me, mi, mf]:
        assert m0 / m == m0
        assert 0 / m == m0

    for z in [q, e, i, f]:
        assert m0 / z == m0

    # negative

    q = fr.Fraction(3, 2)
    e = uc.ufloat(1.2, 0.1)
    i = 4
    f = 3.5
    mq = nb.Mixed(q)
    me = nb.Mixed(e)
    mi = nb.Mixed(i)
    mf = nb.Mixed(f)

    assert isinstance(-mq, nb.Mixed)
    assert isinstance((-mq).value, fr.Fraction)
    assert -mq == nb.Mixed(fr.Fraction(-3, 2))

    assert isinstance(-me, nb.Mixed)
    assert isinstance((-me).value, uc.UFloat)
    assert -me == nb.Mixed(-e)

    assert isinstance(-mi, nb.Mixed)
    assert isinstance((-mi).value, int)
    assert -mi == nb.Mixed(-4)

    assert isinstance(-mf, nb.Mixed)
    assert isinstance((-mf).value, float)
    assert -mf == nb.Mixed(-3.5)

    # Modulo

    q = fr.Fraction(5, 2)
    e = uc.ufloat(3.2, 0.1)
    i = 3
    f = 3.5
    mq = nb.Mixed(q)
    me = nb.Mixed(e)
    mi = nb.Mixed(i)
    mf = nb.Mixed(f)

    assert isinstance(mq % 2, nb.Mixed)
    assert isinstance((mq % 2).value, fr.Fraction)
    assert mq % 2 == nb.Mixed(fr.Fraction(1, 2))

    assert isinstance(me % 2, nb.Mixed)
    assert isinstance((me % 2).value, uc.UFloat)
    assert approx((me % 2).value.n, 1.2)
    assert approx((me % 2).value.s, 0.1)

    assert isinstance(mi % 2, nb.Mixed)
    assert isinstance((mi % 2).value, int)
    assert mi % 2 == nb.Mixed(1)

    assert isinstance(mf % 2, nb.Mixed)
    assert isinstance((mf % 2).value, float)
    assert approx((mf % 2).value, 1.5)

    # Constants

    assert isinstance(nb.pi, nb.Mixed)
    assert isinstance((nb.pi).value, float)
    assert (nb.pi).value == 3.141592653589793

    # Square-Root

    a = nb.sqrt(nb.Mixed(fr.Fraction(2, 3)))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.816496580)
    a = nb.sqrt(fr.Fraction(2, 3))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.816496580)
    a = nb.sqrt(nb.Mixed(fr.Fraction(1, 2)))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.70710678118)
    a = nb.sqrt(fr.Fraction(1, 2))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.70710678118)
    a = nb.sqrt(nb.Mixed(fr.Fraction(2, 1)))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 1.41421356237)
    a = nb.sqrt(fr.Fraction(2, 1))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 1.41421356237)
    a = nb.sqrt(nb.Mixed(fr.Fraction(4, 9)))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, fr.Fraction)
    assert a == nb.Mixed(fr.Fraction(2, 3))
    a = nb.sqrt(fr.Fraction(4, 9))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, fr.Fraction)
    assert a == nb.Mixed(fr.Fraction(2, 3))

    a = nb.sqrt(nb.Mixed(uc.ufloat(0.3, 0.1)))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, uc.UFloat)
    assert approx(a.value.n, 0.54772255750)
    assert approx(a.value.s, 0.09128709291)
    a = nb.sqrt(uc.ufloat(0.3, 0.1))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, uc.UFloat)
    assert approx(a.value.n, 0.54772255750)
    assert approx(a.value.s, 0.09128709291)

    a = nb.sqrt(nb.Mixed(3))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 1.7320508075688)
    a = nb.sqrt(3)
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 1.7320508075688)
    a = nb.sqrt(nb.Mixed(4))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, int)
    assert a.value == 2
    a = nb.sqrt(4)
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, int)
    assert a.value == 2

    a = nb.sqrt(nb.Mixed(0.5))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.7071067811)
    a = nb.sqrt(0.5)
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.7071067811)

    # Trigonometric Functions:

    a = nb.deg2rad(nb.Mixed(fr.Fraction(180, 1)))
    assert approx(a.value, 3.1415926535)
    a = nb.deg2rad(fr.Fraction(180, 1))
    assert approx(a.value, 3.1415926535)
    a = nb.deg2rad(nb.Mixed(uc.ufloat(180.0, 10.0)))
    assert approx(a.value.n, 3.1415926535)
    assert approx(a.value.s, 0.174532925199)
    a = nb.deg2rad(uc.ufloat(180.0, 10.0))
    assert approx(a.value.n, 3.1415926535)
    assert approx(a.value.s, 0.174532925199)
    a = nb.deg2rad(nb.Mixed(180))
    assert approx(a.value, 3.1415926535)
    a = nb.deg2rad(180)
    assert approx(a.value, 3.1415926535)
    a = nb.deg2rad(nb.Mixed(180.0))
    assert approx(a.value, 3.1415926535)
    a = nb.deg2rad(180.0)
    assert approx(a.value, 3.1415926535)

    a = nb.rad2deg(nb.Mixed(fr.Fraction(1, 2)))
    assert approx(a.value, 28.647889756)
    a = nb.rad2deg(fr.Fraction(1, 2))
    assert approx(a.value, 28.647889756)
    a = nb.rad2deg(nb.Mixed(uc.ufloat(3.1415926535897931,
                                      0.17453292519943295)))
    assert approx(a.value.n, 180.0)
    assert approx(a.value.s, 10.0)
    a = nb.rad2deg(uc.ufloat(3.1415926535897931, 0.17453292519943295))
    assert approx(a.value.n, 180.0)
    assert approx(a.value.s, 10.0)
    a = nb.rad2deg(nb.Mixed(1))
    assert approx(a.value, 57.295779513082323)
    a = nb.rad2deg(1)
    assert approx(a.value, 57.295779513082323)
    a = nb.rad2deg(nb.Mixed(3.1415926535897931))
    assert approx(a.value, 180.0)
    a = nb.rad2deg(3.1415926535897931)
    assert approx(a.value, 180.0)

    a = nb.sin(nb.Mixed(fr.Fraction(1, 2)))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.47942553860420301)
    a = nb.sin(fr.Fraction(1, 2))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.479425538604203)
    a = nb.sin(nb.Mixed(uc.ufloat(0.5, 0.1)))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, uc.UFloat)
    assert approx(a.value.n, 0.479425538604203)
    assert approx(a.value.s, 0.08775825618903728)
    a = nb.sin(uc.ufloat(0.5, 0.1))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, uc.UFloat)
    assert approx(a.value.n, 0.479425538604203)
    assert approx(a.value.s, 0.08775825618903728)
    a = nb.sin(nb.Mixed(1))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.8414709848078965)
    a = nb.sin(1)
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.8414709848078965)
    a = nb.sin(nb.Mixed(0.5))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.479425538604203)
    a = nb.sin(0.5)
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.479425538604203)

    a = nb.cos(nb.Mixed(fr.Fraction(1, 2)))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.8775825618903)
    a = nb.cos(fr.Fraction(1, 2))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.8775825618903)
    a = nb.cos(nb.Mixed(uc.ufloat(0.5, 0.1)))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, uc.UFloat)
    assert approx(a.value.n, 0.8775825619803)
    assert approx(a.value.s, 0.0479425538604)
    a = nb.cos(uc.ufloat(0.5, 0.1))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, uc.UFloat)
    assert approx(a.value.n, 0.8775825619803)
    assert approx(a.value.s, 0.0479425538604)
    a = nb.cos(nb.Mixed(1))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.54030230586)
    a = nb.cos(1)
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.54030230586)
    a = nb.cos(nb.Mixed(0.5))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.8775825618903)
    a = nb.cos(0.5)
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.8775825618903)

    a = nb.arcsin(nb.Mixed(fr.Fraction(1, 2)))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.52359877559829)
    a = nb.arcsin(fr.Fraction(1, 2))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.52359877559829)
    a = nb.arcsin(nb.Mixed(uc.ufloat(0.5, 0.1)))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, uc.UFloat)
    assert approx(a.value.n, 0.52359877559829)
    assert approx(a.value.s, 0.11547005383)
    a = nb.arcsin(uc.ufloat(0.5, 0.1))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, uc.UFloat)
    assert approx(a.value.n, 0.52359877559829)
    assert approx(a.value.s, 0.11547005383)
    a = nb.arcsin(nb.Mixed(1))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 1.57079632679)
    a = nb.arcsin(1)
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 1.57079632679)
    a = nb.arcsin(nb.Mixed(0.5))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.52359877559829)
    a = nb.arcsin(0.5)
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.52359877559829)

    a = nb.arccos(nb.Mixed(fr.Fraction(1, 2)))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 1.04719755119)
    a = nb.arccos(fr.Fraction(1, 2))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 1.04719755119)
    a = nb.arccos(nb.Mixed(uc.ufloat(0.5, 0.1)))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, uc.UFloat)
    assert approx(a.value.n, 1.04719755119)
    assert approx(a.value.s, 0.11547005383)
    a = nb.arccos(uc.ufloat(0.5, 0.1))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, uc.UFloat)
    assert approx(a.value.n, 1.04719755119)
    assert approx(a.value.s, 0.11547005383)
    a = nb.arccos(nb.Mixed(1))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.0)
    a = nb.arccos(1)
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.0)
    a = nb.arccos(nb.Mixed(0.5))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 1.04719755119)
    a = nb.arccos(0.5)
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 1.04719755119)

    a = nb.dsin(fr.Fraction(1, 2))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.00872653549)
    a = nb.dsin(fr.Fraction(1, 2))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.00872653549)
    a = nb.dsin(nb.Mixed(uc.ufloat(0.5, 0.1)))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, uc.UFloat)
    assert approx(a.value.n, 0.00872653549)
    assert approx(a.value.s, 0.00174526279)
    a = nb.dsin(uc.ufloat(0.5, 0.1))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, uc.UFloat)
    assert approx(a.value.n, 0.00872653549)
    assert approx(a.value.s, 0.00174526279)
    a = nb.dsin(nb.Mixed(1))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.017452406437)
    a = nb.dsin(1)
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.017452406437)
    a = nb.dsin(nb.Mixed(0.5))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.00872653549)
    a = nb.dsin(0.5)
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.00872653549)
    z = nb.Mixed(0)
    o = nb.Mixed(1)
    h = nb.Mixed(fr.Fraction(1, 2))
    xs = [0, 30, 90, 150, 180, 210, 270, 330]
    ys = [z, h, o, h, z, -h, -o, -h]
    for i in range(len(xs)):
        x = xs[i]
        y = ys[i]
        a = nb.dsin(x)
        assert a == y
        a = nb.dsin(fr.Fraction(x, 1))
        assert a == y
        a = nb.dsin(nb.Mixed(x))
        assert a == y
        a = nb.dsin(nb.Mixed(fr.Fraction(x, 1)))
        assert a == y

    a = nb.dcos(fr.Fraction(1, 2))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.999961923064)
    a = nb.dcos(fr.Fraction(1, 2))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.999961923064)
    a = nb.dcos(nb.Mixed(uc.ufloat(0.5, 0.1)))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, uc.UFloat)
    assert approx(a.value.n, 0.999961923064)
    assert approx(a.value.s, 1.5230677e-5)
    a = nb.dcos(uc.ufloat(0.5, 0.1))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, uc.UFloat)
    assert approx(a.value.n, 0.999961923064)
    assert approx(a.value.s, 1.5230677e-5)
    a = nb.dcos(nb.Mixed(1))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.9998476951)
    a = nb.dcos(1)
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.9998476951)
    a = nb.dcos(nb.Mixed(0.5))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.999961923064)
    a = nb.dcos(0.5)
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.999961923064)
    z = nb.Mixed(0)
    o = nb.Mixed(1)
    h = nb.Mixed(fr.Fraction(1, 2))
    xs = [0, 60, 90, 120, 180, 240, 270, 300]
    ys = [o, h, z, -h, -o, -h, -z, h]
    for i in range(len(xs)):
        x = xs[i]
        y = ys[i]
        a = nb.dcos(x)
        assert a == y
        a = nb.dcos(fr.Fraction(x, 1))
        assert a == y
        a = nb.dcos(nb.Mixed(x))
        assert a == y
        a = nb.dcos(nb.Mixed(fr.Fraction(x, 1)))
        assert a == y

    a = nb.darcsin(nb.Mixed(fr.Fraction(1, 3)))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 19.47122063449)
    a = nb.darcsin(fr.Fraction(1, 3))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 19.47122063449)
    a = nb.darcsin(nb.Mixed(uc.ufloat(0.5, 0.1)))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, uc.UFloat)
    assert approx(a.value.n, 30.0)
    assert approx(a.value.s, 6.615946745061)
    a = nb.darcsin(uc.ufloat(0.5, 0.1))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, uc.UFloat)
    assert approx(a.value.n, 30.0)
    assert approx(a.value.s, 6.615946745061)
    a = nb.darcsin(nb.Mixed(0.5))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 30.0)
    a = nb.darcsin(0.5)
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 30.0)
    xs = [
        -fr.Fraction(1, 1), -fr.Fraction(1, 2),
        fr.Fraction(0, 1),
        fr.Fraction(1, 2),
        fr.Fraction(1, 1)
    ]
    ys = [-90, -30, 0, 30, 90]
    for i in range(len(xs)):
        x = xs[i]
        y = ys[i]
        assert isinstance(nb.darcsin(x), nb.Mixed)
        assert isinstance(nb.darcsin(x).value, int)
        assert nb.darcsin(x) == y
        assert isinstance(nb.darcsin(nb.Mixed(x)), nb.Mixed)
        assert isinstance(nb.darcsin(nb.Mixed(x)).value, int)
        assert nb.darcsin(nb.Mixed(x)) == y
    xs = [-1, 0, 1]
    ys = [-90, 0, 90]
    for i in range(len(xs)):
        x = xs[i]
        y = ys[i]
        assert isinstance(nb.darcsin(x), nb.Mixed)
        assert isinstance(nb.darcsin(x).value, int)
        assert nb.darcsin(x) == y
        assert isinstance(nb.darcsin(nb.Mixed(x)), nb.Mixed)
        assert isinstance(nb.darcsin(nb.Mixed(x)).value, int)
        assert nb.darcsin(nb.Mixed(x)) == y

    a = nb.darccos(nb.Mixed(fr.Fraction(1, 3)))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 70.5287793655)
    a = nb.darccos(fr.Fraction(1, 3))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 70.5287793655)
    a = nb.darccos(nb.Mixed(uc.ufloat(0.5, 0.1)))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, uc.UFloat)
    assert approx(a.value.n, 60.0)
    assert approx(a.value.s, 6.615946745061)
    a = nb.darccos(uc.ufloat(0.5, 0.1))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, uc.UFloat)
    assert approx(a.value.n, 60.0)
    assert approx(a.value.s, 6.615946745061)
    a = nb.darccos(nb.Mixed(0.5))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 60.0)
    a = nb.darccos(0.5)
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 60.0)
    xs = [
        -fr.Fraction(1, 1), -fr.Fraction(1, 2),
        fr.Fraction(0, 1),
        fr.Fraction(1, 2),
        fr.Fraction(1, 1)
    ]
    ys = [180, 120, 90, 60, 0]
    for i in range(len(xs)):
        x = xs[i]
        y = ys[i]
        assert isinstance(nb.darccos(x), nb.Mixed)
        assert isinstance(nb.darccos(x).value, int)
        assert nb.darccos(x) == y
        assert isinstance(nb.darccos(nb.Mixed(x)), nb.Mixed)
        assert isinstance(nb.darccos(nb.Mixed(x)).value, int)
        assert nb.darccos(nb.Mixed(x)) == y
    xs = [-1, 0, 1]
    ys = [180, 90, 0]
    for i in range(len(xs)):
        x = xs[i]
        y = ys[i]
        assert isinstance(nb.darccos(x), nb.Mixed)
        assert isinstance(nb.darccos(x).value, int)
        assert nb.darccos(x) == y
        assert isinstance(nb.darccos(nb.Mixed(x)), nb.Mixed)
        assert isinstance(nb.darccos(nb.Mixed(x)).value, int)
        assert nb.darccos(nb.Mixed(x)) == y
Ejemplo n.º 6
0
def test_Transformation():
    t1 = geo.Transformation(nb.Matrix([[0, 1, 0, 0],
                                       [1, 0, 0, 0],
                                       [0, 0, 1, 0],
                                       [0, 0, 0, 1]]))

    assert t1.__str__() == "Transformation O -> (0, 0, 0)\n" \
                           "               then\n" \
                           "               a' = b\n" \
                           "               b' = a\n" \
                           "               c' = c"

    t2 = geo.Transformation(nb.Matrix([[1, 0, 0, fr.Fraction(1, 2)],
                                       [0, 1, 0, fr.Fraction(1, 4)],
                                       [0, 0, 1, fr.Fraction(1, 3)],
                                       [0, 0, 0, 1]]))

    assert t2.__str__() == "Transformation O -> (-1/2, -1/4, -1/3)\n" \
                           "               then\n" \
                           "               a' = a\n" \
                           "               b' = b\n" \
                           "               c' = c"

    assert isinstance(t2.inv(), geo.Transformation)
    assert t2 * t2.inv() == geo.Transformation(nb.Matrix.onematrix(4))

    t3 = geo.Transformation(nb.Matrix([[1.0, 0, 0, 0],
                                       [0, 1, 0, 0],
                                       [0, 0, 1, 0],
                                       [0, 0, 0, 1]]))
    print(t3.value)
    assert t3.__str__() == "Transformation O -> (0, 0, 0)\n" \
                           "               then\n" \
                           "               a' = 1.0a\n" \
                           "               b' = b\n" \
                           "               c' = c"

    q1 = geo.Rec(nb.Matrix([[1, 0, 0, 0]]))
    t = geo.Transformation(nb.Matrix([[0, 1, 0, 0],
                                      [0, 0, 1, 0],
                                      [1, 0, 0, 0],
                                      [0, 0, 0, 1]]))
    assert isinstance(t ** q1, geo.Rec)
    assert (t ** q1) == geo.Rec(nb.Matrix([[0, 0, 1, 0]]))

    q1 = geo.Rec(nb.Matrix([[1, 0, 0, 0]]))
    t = geo.Transformation(nb.Matrix([[0, 1, 0, 0.3],
                                      [0, 0, 1, 0.7],
                                      [1, 0, 0, 100],
                                      [0, 0, 0, 1]]))
    assert isinstance(t ** q1, geo.Rec)
    assert (t ** q1) == geo.Rec(nb.Matrix([[0, 0, 1, 0]]))

    q1 = geo.Rec(nb.Matrix([[0, 0, 1, 0]]))
    t = geo.Transformation(nb.Matrix([[1, 0, 0, 0],
                                      [0, 1, 0, 0],
                                      [0, 0, 2, 0],
                                      [0, 0, 0, 1]]))
    assert t.__str__()  == "Transformation O -> (0, 0, 0)\n" \
                           "               then\n" \
                           "               a' = a\n" \
                           "               b' = b\n" \
                           "               c' = 1/2c"
    assert isinstance(t ** q1, geo.Rec)
    assert (t ** q1) == \
        geo.Rec(nb.Matrix([[0, 0, nb.Mixed(fr.Fraction(1, 2)), 0]]))

    q1 = geo.Rec(nb.Matrix([[0, 0, 1, 0]]))
    t = geo.Transformation(nb.Matrix([[1, 0, 0, 0],
                                      [0, 0, 2, 0],
                                      [0, -1, 0, 0],
                                      [0, 0, 0, 1]]))
    assert t.__str__()  == "Transformation O -> (0, 0, 0)\n" \
                           "               then\n" \
                           "               a' = a\n" \
                           "               b' = 1/2c\n" \
                           "               c' = -b"
    assert isinstance(t ** q1, geo.Rec)
    print(t)
    assert (t ** q1) == \
        geo.Rec(nb.Matrix([[0, nb.Mixed(fr.Fraction(1, 2)), 0, 0]]))
Ejemplo n.º 7
0
def test_Mixed():
    # Create a number of type Mixed with 4 different types.
    q = fr.Fraction(2, 3)
    e = uc.ufloat(1.2, 0.1)
    i = 4
    f = 3.5
    q1 = fr.Fraction(2, 1)
    e1 = uc.ufloat(3.7, 0)
    assert isinstance(nb.Mixed(q).value, fr.Fraction)
    assert nb.Mixed(q).value == q
    assert isinstance(nb.Mixed(e).value, uc.UFloat)
    assert (nb.Mixed(e).value).n == e.n
    assert (nb.Mixed(e).value).s == e.s
    assert isinstance(nb.Mixed(i).value, int)
    assert nb.Mixed(i).value == i
    assert isinstance(nb.Mixed(f).value, float)
    assert nb.Mixed(f).value == f
    assert isinstance(nb.Mixed(q1).value, int)
    assert nb.Mixed(q1).value == 2
    assert isinstance(nb.Mixed(e1).value, uc.UFloat)
    assert nb.Mixed(e1).value == uc.ufloat(3.7, 0.0)

    # Convert a number of type Mixed to float.
    assert isinstance(float(nb.Mixed(q)), float)
    assert float(nb.Mixed(q)) == float(2 / 3)
    assert isinstance(float(nb.Mixed(e)), float)
    assert float(nb.Mixed(e)) == 1.2
    assert isinstance(float(nb.Mixed(i)), float)
    assert float(nb.Mixed(i)) == 4.0
    assert isinstance(float(nb.Mixed(f)), float)
    assert float(nb.Mixed(f)) == 3.5

    # Print a number of type Mixed as str.
    assert isinstance(nb.Mixed(q).__str__(), str)
    assert nb.Mixed(q).__str__() == "2/3"
    assert isinstance(nb.Mixed(e).__str__(), str)
    assert nb.Mixed(e).__str__() == "1.20(10)"
    assert isinstance(nb.Mixed(i).__str__(), str)
    assert nb.Mixed(i).__str__() == "4"
    assert isinstance(nb.Mixed(f).__str__(), str)
    assert nb.Mixed(f).__str__() == "3.5"

    # Hash
    assert isinstance(hash(nb.Mixed(q)), int)
    assert isinstance(hash(nb.Mixed(e)), int)
    assert isinstance(hash(nb.Mixed(i)), int)
    assert isinstance(hash(nb.Mixed(f)), int)

    # Equal
    assert nb.Mixed(q) == nb.Mixed(q)
    assert nb.Mixed(e) == nb.Mixed(e)
    assert nb.Mixed(i) == nb.Mixed(i)
    assert nb.Mixed(f) == nb.Mixed(f)
    assert nb.Mixed(fr.Fraction(2, 3)) == nb.Mixed(fr.Fraction(2, 3))
    assert (nb.Mixed(fr.Fraction(2, 3)) == nb.Mixed(fr.Fraction(1, 3))) == False
    assert nb.Mixed(uc.ufloat(1.2, 0.1)) == nb.Mixed(uc.ufloat(1.2, 0.1))
    assert (nb.Mixed(uc.ufloat(1.2, 0.1)) == nb.Mixed(uc.ufloat(1.2, 0.2))) \
        == False
    x = nb.Mixed(uc.ufloat(0.5, 0.3) + uc.ufloat(0.5, 0.4))
    y = nb.Mixed(uc.ufloat(1.0, 0.5))
    assert x == y
    assert nb.Mixed(fr.Fraction(2, 3)) == nb.Mixed(fr.Fraction(2, 3))
    assert (nb.Mixed(fr.Fraction(2, 3)) == nb.Mixed(uc.ufloat(1.2, 0.1))) \
        == False
    assert (nb.Mixed(fr.Fraction(2, 3)) == nb.Mixed(1)) == False
    assert (nb.Mixed(fr.Fraction(2, 3)) == nb.Mixed(0.66)) == False
    assert (nb.Mixed(uc.ufloat(1.2, 0.1)) == nb.Mixed(fr.Fraction(2, 3))) \
        == False
    assert nb.Mixed(uc.ufloat(1.2, 0.1) == nb.Mixed(uc.ufloat(1.2, 0.1)))
    assert (nb.Mixed(uc.ufloat(1.2, 0.1)) == nb.Mixed(1)) == False
    assert (nb.Mixed(uc.ufloat(1.2, 0.1)) == nb.Mixed(0.66)) == False
    assert (nb.Mixed(1) == nb.Mixed(fr.Fraction(2, 3))) == False
    assert (nb.Mixed(1) == nb.Mixed(uc.ufloat(1.2, 0.1))) == False
    assert nb.Mixed(1) == nb.Mixed(1)
    assert (nb.Mixed(1) == nb.Mixed(1.0)) == False
    assert (nb.Mixed(1.0) == nb.Mixed(fr.Fraction(1, 1))) == False
    assert (nb.Mixed(1.0) == nb.Mixed(uc.ufloat(1.0, 0.0))) == False
    assert (nb.Mixed(1.0) == nb.Mixed(1)) == False
    assert nb.Mixed(1.0) == nb.Mixed(1.0)
    assert nb.Mixed(0) == 0
    assert (nb.Mixed(0.1) == 0) == False
    assert nb.Mixed(fr.Fraction(2, 1)) == 2

    # Other relations

    # Addition

    mq = nb.Mixed(q)
    me = nb.Mixed(e)
    mi = nb.Mixed(i)
    mf = nb.Mixed(f)

    """for x1 in [q, e, i, f]:
        for x2 in [q, e, i, f]:
            m1 = nb.Mixed(x1)
            m2 = nb.Mixed(x2)
            assert isinstance(m1 + m2, nb.Mixed)
            assert isinstance((m1 + m2).value
            assert isinstance(m1 + x2, nb.Mixed)
            assert isinstance(
            assert isinstance(m2 + m1, nb.Mixed)"""

    assert isinstance(mq + mq, nb.Mixed)
    assert isinstance((mq + mq).value, fr.Fraction)
    assert mq + mq == nb.Mixed(fr.Fraction(4, 3))
    assert isinstance(mq + q, nb.Mixed)
    assert isinstance((mq + q).value, fr.Fraction)
    assert mq + q == nb.Mixed(fr.Fraction(4, 3))
    assert isinstance(q + mq, nb.Mixed)
    assert isinstance((q + mq).value, fr.Fraction)
    assert q + mq == nb.Mixed(fr.Fraction(4, 3))

    assert isinstance(mq + me, nb.Mixed)
    assert isinstance((mq + me).value, uc.UFloat)
    assert mq + me == nb.Mixed(uc.ufloat(1.2, 0.10) + 2 / 3)
    assert isinstance(mq + e, nb.Mixed)
    assert isinstance((mq + e).value, uc.UFloat)
    assert mq + e == nb.Mixed(uc.ufloat(1.2, 0.10) + 2 / 3)
    assert isinstance(q + me, nb.Mixed)
    assert isinstance((q + me).value, uc.UFloat)
    assert q + me == nb.Mixed(uc.ufloat(1.2, 0.10) + 2 / 3)

    assert isinstance(mq + mi, nb.Mixed)
    assert isinstance((mq + mi).value, fr.Fraction)
    assert mq + mi == nb.Mixed(fr.Fraction(14, 3))
    assert isinstance(mq + i, nb.Mixed)
    assert isinstance((mq + i).value, fr.Fraction)
    assert mq + i == nb.Mixed(fr.Fraction(14, 3))
    assert isinstance(q + mi, nb.Mixed)
    assert isinstance((q + mi).value, fr.Fraction)
    assert q + mi == nb.Mixed(fr.Fraction(14, 3))

    assert isinstance(mq + mf, nb.Mixed)
    assert isinstance((mq + mf).value, float)
    assert mq + mf == nb.Mixed(3.5 + 2 / 3)
    assert isinstance(mq + f, nb.Mixed)
    assert isinstance((mq + f).value, float)
    assert mq + f == nb.Mixed(3.5 + 2 / 3)
    assert isinstance(q + mf, nb.Mixed)
    assert isinstance((q + mf).value, float)
    assert q + mf == nb.Mixed(3.5 + 2 / 3)

    assert isinstance(me + mq, nb.Mixed)
    assert isinstance((me + mq).value, uc.UFloat)
    assert me + mq == nb.Mixed(uc.ufloat(1.2, 0.1) + 2 / 3)
    assert isinstance(me + q, nb.Mixed)
    assert isinstance((me + q).value, uc.UFloat)
    assert me + q == nb.Mixed(uc.ufloat(1.2, 0.1) + 2 / 3)
    assert isinstance(e + mq, nb.Mixed)
    assert isinstance((e + mq).value, uc.UFloat)
    assert e + mq == nb.Mixed(uc.ufloat(1.2, 0.1) + 2 / 3)

    assert isinstance(me + me, nb.Mixed)
    assert isinstance((me + me).value, uc.UFloat)
    assert me + me == nb.Mixed(uc.ufloat(1.2, 0.1) + uc.ufloat(1.2, 0.1))
    assert isinstance(me + e, nb.Mixed)
    assert isinstance((me + e).value, uc.UFloat)
    assert me + e == nb.Mixed(uc.ufloat(1.2, 0.1) + uc.ufloat(1.2, 0.1))
    assert isinstance(e + me, nb.Mixed)
    assert isinstance((e + me).value, uc.UFloat)
    assert e + me == nb.Mixed(uc.ufloat(1.2, 0.1) + uc.ufloat(1.2, 0.1))

    assert isinstance(me + mi, nb.Mixed)
    assert isinstance((me + mi).value, uc.UFloat)
    assert me + mi == nb.Mixed(uc.ufloat(5.2, 0.1))
    assert isinstance(me + i, nb.Mixed)
    assert isinstance((me + i).value, uc.UFloat)
    assert me + i == nb.Mixed(uc.ufloat(5.2, 0.1))
    assert isinstance(e + mi, nb.Mixed)
    assert isinstance((e + mi).value, uc.UFloat)
    assert me + i == nb.Mixed(uc.ufloat(5.2, 0.1))

    assert isinstance(me + mf, nb.Mixed)
    assert isinstance((me + mf).value, uc.UFloat)
    assert me + mf == nb.Mixed(uc.ufloat(4.7, 0.1))
    assert isinstance(me + f, nb.Mixed)
    assert isinstance((me + f).value, uc.UFloat)
    assert me + f == nb.Mixed(uc.ufloat(4.7, 0.1))
    assert isinstance(e + mf, nb.Mixed)
    assert isinstance((e + mf).value, uc.UFloat)
    assert e + mf == nb.Mixed(uc.ufloat(4.7, 0.1))

    assert isinstance(mi + mq, nb.Mixed)
    assert isinstance((mi + mq).value, fr.Fraction)
    assert mi + mq == nb.Mixed(fr.Fraction(14, 3))
    assert isinstance(mi + q, nb.Mixed)
    assert isinstance((mi + q).value, fr.Fraction)
    assert mi + q == nb.Mixed(fr.Fraction(14, 3))
    assert isinstance(i + mq, nb.Mixed)
    assert isinstance((i + mq).value, fr.Fraction)
    assert i + mq == nb.Mixed(fr.Fraction(14, 3))

    assert isinstance(mi + me, nb.Mixed)
    assert isinstance((mi + me).value, uc.UFloat)
    assert mi + me == nb.Mixed(uc.ufloat(5.2, 0.1))
    assert isinstance(mi + e, nb.Mixed)
    assert isinstance((mi + e).value, uc.UFloat)
    assert mi + me == nb.Mixed(uc.ufloat(5.2, 0.1))
    assert isinstance(i + me, nb.Mixed)
    assert isinstance((i + me).value, uc.UFloat)
    assert i + me == nb.Mixed(uc.ufloat(5.2, 0.1))

    assert isinstance(mi + mi, nb.Mixed)
    assert isinstance((mi + mi).value, int)
    assert mi + mi == nb.Mixed(8)
    assert isinstance(mi + i, nb.Mixed)
    assert isinstance((mi + i).value, int)
    assert mi + i == nb.Mixed(8)
    assert isinstance(i + mi, nb.Mixed)
    assert isinstance((i + mi).value, int)
    assert i + mi == nb.Mixed(8)

    assert isinstance(mi + mf, nb.Mixed)
    assert isinstance((mi + mf).value, float)
    assert mi + mf == nb.Mixed(7.5)
    assert isinstance(mi + f, nb.Mixed)
    assert isinstance((mi + f).value, float)
    assert mi + f == nb.Mixed(7.5)
    assert isinstance(i + mf, nb.Mixed)
    assert isinstance((i + mf).value, float)
    assert i + mf == nb.Mixed(7.5)

    assert isinstance(mf + mq, nb.Mixed)
    assert isinstance((mf + mq).value, float)
    assert mf + mq == nb.Mixed(3.5 + 2 / 3)
    assert isinstance(mf + q, nb.Mixed)
    assert isinstance((mf + q).value, float)
    assert mf + q == nb.Mixed(3.5 + 2 / 3)
    assert isinstance(f + mq, nb.Mixed)
    assert isinstance((f + mq).value, float)
    assert f + mq == nb.Mixed(3.5 + 2 / 3)

    assert isinstance(mf + me, nb.Mixed)
    assert isinstance((mf + me).value, uc.UFloat)
    assert mf + me == nb.Mixed(uc.ufloat(4.7, 0.1))
    assert isinstance(mf + e, nb.Mixed)
    assert isinstance((mf + e).value, uc.UFloat)
    assert mf + e == nb.Mixed(uc.ufloat(4.7, 0.1))
    assert isinstance(f + me, nb.Mixed)
    assert isinstance((f + me).value, uc.UFloat)
    assert f + me == nb.Mixed(uc.ufloat(4.7, 0.1))

    # Subtraction
    q1 = fr.Fraction(1, 2)
    q2 = fr.Fraction(1, 4)
    e1 = uc.ufloat(1.2, 0.3)
    e2 = uc.ufloat(0.2, 0.4)
    i1 = 4
    i2 = 3
    f1 = 3.5
    f2 = 3.4
    mq1 = nb.Mixed(q1)
    mq2 = nb.Mixed(q2)
    me1 = nb.Mixed(e1)
    me2 = nb.Mixed(e2)
    mi1 = nb.Mixed(i1)
    mi2 = nb.Mixed(i2)
    mf1 = nb.Mixed(f1)
    mf2 = nb.Mixed(f2)

    assert isinstance(mq1 - mq2, nb.Mixed)
    assert isinstance((mq1 - mq2).value, fr.Fraction)
    assert mq1 - mq2 == nb.Mixed(fr.Fraction(1, 4))
    assert isinstance(mq1 - q2, nb.Mixed)
    assert isinstance((mq1 - q2).value, fr.Fraction)
    assert mq1 - q2 == nb.Mixed(fr.Fraction(1, 4))
    assert isinstance(q1 - mq2, nb.Mixed)
    assert isinstance((q1 - mq2).value, fr.Fraction)
    assert q1 - mq2 == nb.Mixed(fr.Fraction(1, 4))

    assert isinstance(mq1 - me1, nb.Mixed)
    assert isinstance((mq1 - me1).value, uc.UFloat)
    assert mq1 - me1 == nb.Mixed(uc.ufloat(-0.7, 0.3))
    assert isinstance(mq1 - e1, nb.Mixed)
    assert isinstance((mq1 - e1).value, uc.UFloat)
    assert mq1 - e1 == nb.Mixed(uc.ufloat(-0.7, 0.3))
    assert isinstance(q1 - me1, nb.Mixed)
    assert isinstance((q1 - me1).value, uc.UFloat)
    assert q1 - me1 == nb.Mixed(uc.ufloat(-0.7, 0.3))

    assert isinstance(mq1 - mi1, nb.Mixed)
    assert isinstance((mq1 - mi1).value, fr.Fraction)
    assert mq1 - mi1 == nb.Mixed(fr.Fraction(-7, 2))
    assert isinstance(mq1 - i1, nb.Mixed)
    assert isinstance((mq1 - i1).value, fr.Fraction)
    assert mq1 - i1 == nb.Mixed(fr.Fraction(-7, 2))
    assert isinstance(q1 - mi1, nb.Mixed)
    assert isinstance((q1 - mi1).value, fr.Fraction)
    assert q1 - mi1 == nb.Mixed(fr.Fraction(-7, 2))

    assert isinstance(mq1 - mf1, nb.Mixed)
    assert isinstance((mq1 - mf1).value, float)
    assert mq1 - mf1 == nb.Mixed(-3.0)
    assert isinstance(mq1 - f1, nb.Mixed)
    assert isinstance((mq1 - f1).value, float)
    assert mq1 - f1 == nb.Mixed(-3.0)
    assert isinstance(q1 - mf1, nb.Mixed)
    assert isinstance((q1 - mf1).value, float)
    assert q1 - mf1 == nb.Mixed(-3.0)

    assert isinstance(me1 - mq1, nb.Mixed)
    assert isinstance((me1 - mq1).value, uc.UFloat)
    assert me1 - mq1 == nb.Mixed(uc.ufloat(0.7, 0.3))
    assert isinstance(me1 - q1, nb.Mixed)
    assert isinstance((me1 - q1).value, uc.UFloat)
    assert me1 - q1 == nb.Mixed(uc.ufloat(0.7, 0.3))
    assert isinstance(e1 - mq1, nb.Mixed)
    assert isinstance((e1 - mq1).value, uc.UFloat)
    assert e1 - mq1 == nb.Mixed(uc.ufloat(0.7, 0.3))

    assert isinstance(me1 - me2, nb.Mixed)
    assert isinstance((me1 - me2).value, uc.UFloat)
    assert me1 - me2 == nb.Mixed(uc.ufloat(1.0, 0.5))
    assert isinstance(me1 - e2, nb.Mixed)
    assert isinstance((me1 - e2).value, uc.UFloat)
    assert me1 - e2 == nb.Mixed(uc.ufloat(1.0, 0.5))
    assert isinstance(e1 - me2, nb.Mixed)
    assert isinstance((e1 - me2).value, uc.UFloat)
    assert e1 - me2 == nb.Mixed(uc.ufloat(1.0, 0.5))

    assert isinstance(me1 - mi1, nb.Mixed)
    assert isinstance((me1 - mi1).value, uc.UFloat)
    assert me1 - mi1 == nb.Mixed(uc.ufloat(-2.8, 0.3))
    assert isinstance(me1 - i1, nb.Mixed)
    assert isinstance((me1 - i1).value, uc.UFloat)
    assert me1 - i1 == nb.Mixed(uc.ufloat(-2.8, 0.3))
    assert isinstance(e1 - mi1, nb.Mixed)
    assert isinstance((e1 - mi1).value, uc.UFloat)
    assert e1 - mi1 == nb.Mixed(uc.ufloat(-2.8, 0.3))

    assert isinstance(me1 - mf1, nb.Mixed)
    assert isinstance((me1 - mf1).value, uc.UFloat)
    assert me1 - mf1 == nb.Mixed(uc.ufloat(-2.3, 0.3))
    assert isinstance(me1 - f1, nb.Mixed)
    assert isinstance((me1 - f1).value, uc.UFloat)
    assert me1 - f1 == nb.Mixed(uc.ufloat(-2.3, 0.3))
    assert isinstance(e1 - mf1, nb.Mixed)
    assert isinstance((e1 - mf1).value, uc.UFloat)
    assert e1 - mf1 == nb.Mixed(uc.ufloat(-2.3, 0.3))

    assert isinstance(mi1 - mq1, nb.Mixed)
    assert isinstance((mi1 - mq1).value, fr.Fraction)
    assert mi1 - mq1 == nb.Mixed(fr.Fraction(7, 2))
    assert isinstance(mi1 - q1, nb.Mixed)
    assert isinstance((mi1 - q1).value, fr.Fraction)
    assert mi1 - q1 == nb.Mixed(fr.Fraction(7, 2))
    assert isinstance(i1 - mq1, nb.Mixed)
    assert isinstance((i1 - mq1).value, fr.Fraction)
    assert i1 - mq1 == nb.Mixed(fr.Fraction(7, 2))

    assert isinstance(mi1 - me1, nb.Mixed)
    assert isinstance((mi1 - me1).value, uc.UFloat)
    assert mi1 - me1 == nb.Mixed(uc.ufloat(2.8, 0.3))
    assert isinstance(mi1 - e1, nb.Mixed)
    assert isinstance((mi1 - e1).value, uc.UFloat)
    assert mi1 - e1 == nb.Mixed(uc.ufloat(2.8, 0.3))
    assert isinstance(i1 - me1, nb.Mixed)
    assert isinstance((i1 - me1).value, uc.UFloat)
    assert i1 - me1 == nb.Mixed(uc.ufloat(2.8, 0.3))

    assert isinstance(mi1 - mi2, nb.Mixed)
    assert isinstance((mi1 - mi2).value, int)
    assert mi1 - mi2 == nb.Mixed(1)
    assert isinstance(mi1 - i2, nb.Mixed)
    assert isinstance((mi1 - i2).value, int)
    assert mi1 - i2 == nb.Mixed(1)
    assert isinstance(i1 - mi2, nb.Mixed)
    assert isinstance((i1 - mi2).value, int)
    assert i1 - mi2 == nb.Mixed(1)

    assert isinstance(mi1 - mf1, nb.Mixed)
    assert isinstance((mi1 - mf1).value, float)
    assert mi1 - mf1 == nb.Mixed(0.5)
    assert isinstance(mi1 - f1, nb.Mixed)
    assert isinstance((mi1 - f1).value, float)
    assert mi1 - f1 == nb.Mixed(0.5)
    assert isinstance(i1 - mf1, nb.Mixed)
    assert isinstance((i1 - mf1).value, float)
    assert i1 - mf1 == nb.Mixed(0.5)

    assert isinstance(mf1 - mq1, nb.Mixed)
    assert isinstance((mf1 - mq1).value, float)
    assert mf1 - mq1 == nb.Mixed(3.0)
    assert isinstance(mf1 - q1, nb.Mixed)
    assert isinstance((mf1 - q1).value, float)
    assert mf1 - q1 == nb.Mixed(3.0)
    assert isinstance(f1 - mq1, nb.Mixed)
    assert isinstance((f1 - mq1).value, float)
    assert f1 - mq1 == nb.Mixed(3.0)

    assert isinstance(mf1 - me1, nb.Mixed)
    assert isinstance((mf1 - me1).value, uc.UFloat)
    assert mf1 - me1 == nb.Mixed(uc.ufloat(2.3, 0.3))
    assert isinstance(mf1 - e1, nb.Mixed)
    assert isinstance((mf1 - e1).value, uc.UFloat)
    assert mf1 - e1 == nb.Mixed(uc.ufloat(2.3, 0.3))
    assert isinstance(f1 - me1, nb.Mixed)
    assert isinstance((f1 - me1).value, uc.UFloat)
    assert f1 - me1 == nb.Mixed(uc.ufloat(2.3, 0.3))

    assert isinstance(mf1 - mi1, nb.Mixed)
    assert isinstance((mf1 - mi1).value, float)
    assert mf1 - mi1 == nb.Mixed(-0.5)
    assert isinstance(mf1 - i1, nb.Mixed)
    assert isinstance((mf1 - i1).value, float)
    assert mf1 - i1 == nb.Mixed(-0.5)
    assert isinstance(f1 - mi1, nb.Mixed)
    assert isinstance((f1 - mi1).value, float)
    assert f1 - mi1 == nb.Mixed(-0.5)

    assert isinstance(mf1 - mf2, nb.Mixed)
    assert isinstance((mf1 - mf2).value, float)
    assert mf1 - mf2 == nb.Mixed(3.5 - 3.4)
    assert isinstance(mf1 - f2, nb.Mixed)
    assert isinstance((mf1 - f2).value, float)
    assert mf1 - f2 == nb.Mixed(3.5 - 3.4)
    assert isinstance(f1 - mf2, nb.Mixed)
    assert isinstance((f1 - mf2).value, float)
    assert f1 - mf2 == nb.Mixed(3.5 - 3.4)

    # Multiplication

    q1 = fr.Fraction(1, 2)
    q2 = fr.Fraction(1, 4)
    e1 = uc.ufloat(1.2, 0.3)
    e2 = uc.ufloat(0.2, 0.4)
    i1 = 4
    i2 = 3
    f1 = 3.5
    f2 = 3.4
    mq1 = nb.Mixed(q1)
    mq2 = nb.Mixed(q2)
    me1 = nb.Mixed(e1)
    me2 = nb.Mixed(e2)
    mi1 = nb.Mixed(i1)
    mi2 = nb.Mixed(i2)
    mf1 = nb.Mixed(f1)
    mf2 = nb.Mixed(f2)

    assert isinstance(mq1 * mq2, nb.Mixed)
    assert isinstance((mq1 * mq2).value, fr.Fraction)
    assert mq1 * mq2 == nb.Mixed(fr.Fraction(1, 8))
    assert isinstance(mq1 * q2, nb.Mixed)
    assert isinstance((mq1 * q2).value, fr.Fraction)
    assert mq1 * q2 == nb.Mixed(fr.Fraction(1, 8))
    assert isinstance(q1 * mq2, nb.Mixed)
    assert isinstance((q1 * mq2).value, fr.Fraction)
    assert q1 * mq2 == nb.Mixed(fr.Fraction(1, 8))

    assert isinstance(mq1 * me1, nb.Mixed)
    assert isinstance((mq1 * me1).value, uc.UFloat)
    assert mq1 * me1 == nb.Mixed(uc.ufloat(0.6, 0.15))
    assert isinstance(mq1 * e1, nb.Mixed)
    assert isinstance((mq1 * e1).value, uc.UFloat)
    assert mq1 * e1 == nb.Mixed(uc.ufloat(0.6, 0.15))
    assert isinstance(q1 * me1, nb.Mixed)
    assert isinstance((q1 * me1).value, uc.UFloat)
    assert q1 * me1 == nb.Mixed(uc.ufloat(0.6, 0.15))

    assert isinstance(mq1 * mi2, nb.Mixed)
    assert isinstance((mq1 * mi2).value, fr.Fraction)
    assert mq1 * mi2 == nb.Mixed(fr.Fraction(3, 2))
    assert isinstance(mq1 * i2, nb.Mixed)
    assert isinstance((mq1 * i2).value, fr.Fraction)
    assert mq1 * i2 == nb.Mixed(fr.Fraction(3, 2))
    assert isinstance(q1 * mi2, nb.Mixed)
    assert isinstance((q1 * mi2).value, fr.Fraction)
    assert q1 * mi2 == nb.Mixed(fr.Fraction(3, 2))

    assert isinstance(mq1 * mf1, nb.Mixed)
    assert isinstance((mq1 * mf1).value, float)
    assert mq1 * mf1 == nb.Mixed(1.75)
    assert isinstance(mq1 * f1, nb.Mixed)
    assert isinstance((mq1 * f1).value, float)
    assert mq1 * f1 == nb.Mixed(1.75)
    assert isinstance(q1 * mf1, nb.Mixed)
    assert isinstance((q1 * mf1).value, float)
    assert q1 * mf1 == nb.Mixed(1.75)

    assert isinstance(me1 * mq1, nb.Mixed)
    assert isinstance((me1 * mq1).value, uc.UFloat)
    assert me1 * mq1 == nb.Mixed(uc.ufloat(0.6, 0.15))
    assert isinstance(me1 * q1, nb.Mixed)
    assert isinstance((me1 * q1).value, uc.UFloat)
    assert me1 * q1 == nb.Mixed(uc.ufloat(0.6, 0.15))
    assert isinstance(e1 * mq1, nb.Mixed)
    assert isinstance((e1 * mq1).value, uc.UFloat)
    assert e1 * mq1 == nb.Mixed(uc.ufloat(0.6, 0.15))

    assert isinstance(me1 * me2, nb.Mixed)
    assert isinstance((me1 * me2).value, uc.UFloat)
    assert me1 * me2 == nb.Mixed(uc.ufloat(1.2, 0.3) * uc.ufloat(0.2, 0.4))
    assert isinstance(me1 * e2, nb.Mixed)
    assert isinstance((me1 * e2).value, uc.UFloat)
    assert me1 * e2 == nb.Mixed(uc.ufloat(1.2, 0.3) * uc.ufloat(0.2, 0.4))
    assert isinstance(e1 * me2, nb.Mixed)
    assert isinstance((e1 * me2).value, uc.UFloat)
    assert e1 * me2 == nb.Mixed(uc.ufloat(1.2, 0.3) * uc.ufloat(0.2, 0.4))

    assert isinstance(me1 * mi1, nb.Mixed)
    assert isinstance((me1 * mi1).value, uc.UFloat)
    assert me1 * mi1 == nb.Mixed(uc.ufloat(4.8, 1.2))
    assert isinstance(me1 * i1, nb.Mixed)
    assert isinstance((me1 * i1).value, uc.UFloat)
    assert me1 * i1 == nb.Mixed(uc.ufloat(4.8, 1.2))
    assert isinstance(e1 * mi1, nb.Mixed)
    assert isinstance((e1 * mi1).value, uc.UFloat)
    assert e1 * mi1 == nb.Mixed(uc.ufloat(4.8, 1.2))

    assert isinstance(me1 * mf1, nb.Mixed)
    assert isinstance((me1 * mf1).value, uc.UFloat)
    assert me1 * mf1 == nb.Mixed(uc.ufloat(4.2, 1.05))
    assert isinstance(me1 * f1, nb.Mixed)
    assert isinstance((me1 * f1).value, uc.UFloat)
    assert me1 * f1 == nb.Mixed(uc.ufloat(4.2, 1.05))
    assert isinstance(e1 * mf1, nb.Mixed)
    assert isinstance((e1 * mf1).value, uc.UFloat)
    assert e1 * mf1 == nb.Mixed(uc.ufloat(4.2, 1.05))

    assert isinstance(nb.Mixed(3) * mq1, nb.Mixed)
    assert isinstance((nb.Mixed(3) * mq1).value, fr.Fraction)
    assert nb.Mixed(3) * mq1 == nb.Mixed(fr.Fraction(3, 2))
    assert isinstance(nb.Mixed(3) * q1, nb.Mixed)
    assert isinstance((nb.Mixed(3) * q1).value, fr.Fraction)
    assert nb.Mixed(3) * q1 == nb.Mixed(fr.Fraction(3, 2))
    assert isinstance(3 * mq1, nb.Mixed)
    assert isinstance((3 * mq1).value, fr.Fraction)
    assert 3 * mq1 == nb.Mixed(fr.Fraction(3, 2))

    assert isinstance(mi1 * me1, nb.Mixed)
    assert isinstance((mi1 * me1).value, uc.UFloat)
    assert mi1 * me1 == nb.Mixed(uc.ufloat(4.8, 1.2))
    assert isinstance(mi1 * e1, nb.Mixed)
    assert isinstance((mi1 * e1).value, uc.UFloat)
    assert mi1 * e1 == nb.Mixed(uc.ufloat(4.8, 1.2))
    assert isinstance(i1 * me1, nb.Mixed)
    assert isinstance((i1 * me1).value, uc.UFloat)
    assert i1 * me1 == nb.Mixed(uc.ufloat(4.8, 1.2))

    assert isinstance(mi1 * mi2, nb.Mixed)
    assert isinstance((mi1 * mi2).value, int)
    assert mi1 * mi2 == nb.Mixed(12)
    assert isinstance(mi1 * i2, nb.Mixed)
    assert isinstance((mi1 * i2).value, int)
    assert mi1 * i2 == nb.Mixed(12)
    assert isinstance(i1 * mi2, nb.Mixed)
    assert isinstance((i1 * mi2).value, int)
    assert i1 * mi2 == nb.Mixed(12)

    assert isinstance(mi1 * mf1, nb.Mixed)
    assert isinstance((mi1 * mf1).value, float)
    assert mi1 * mf1 == nb.Mixed(14.0)
    assert isinstance(mi1 * f1, nb.Mixed)
    assert isinstance((mi1 * f1).value, float)
    assert mi1 * f1 == nb.Mixed(14.0)
    assert isinstance(i1 * mf1, nb.Mixed)
    assert isinstance((i1 * mf1).value, float)
    assert i1 * mf1 == nb.Mixed(14.0)

    assert isinstance(mf1 * mq1, nb.Mixed)
    assert isinstance((mf1 * mq1).value, float)
    assert mf1 * mq1 == nb.Mixed(1.75)
    assert isinstance(mf1 * q1, nb.Mixed)
    assert isinstance((mf1 * q1).value, float)
    assert mf1 * q1 == nb.Mixed(1.75)
    assert isinstance(f1 * mq1, nb.Mixed)
    assert isinstance((f1 * mq1).value, float)
    assert f1 * mq1 == nb.Mixed(1.75)

    assert isinstance(mf1 * me1, nb.Mixed)
    assert isinstance((mf1 * me1).value, uc.UFloat)
    assert mf1 * me1 == nb.Mixed(uc.ufloat(4.2, 1.05))
    assert isinstance(mf1 * e1, nb.Mixed)
    assert isinstance((mf1 * e1).value, uc.UFloat)
    assert mf1 * e1 == nb.Mixed(uc.ufloat(4.2, 1.05))
    assert isinstance(f1 * me1, nb.Mixed)
    assert isinstance((f1 * me1).value, uc.UFloat)
    assert f1 * me1 == nb.Mixed(uc.ufloat(4.2, 1.05))

    assert isinstance(mf1 * mi1, nb.Mixed)
    assert isinstance((mf1 * mi1).value, float)
    assert mf1 * mi1 == nb.Mixed(14.0)
    assert isinstance(mf1 * i1, nb.Mixed)
    assert isinstance((mf1 * i1).value, float)
    assert mf1 * i1 == nb.Mixed(14.0)
    assert isinstance(f1 * mi1, nb.Mixed)
    assert isinstance((f1 * mi1).value, float)
    assert f1 * mi1 == nb.Mixed(14.0)

    assert isinstance(mf1 * mf2, nb.Mixed)
    assert isinstance((mf1 * mf2).value, float)
    assert mf1 * mf2 == nb.Mixed(11.9)
    assert isinstance(mf1 * f2, nb.Mixed)
    assert isinstance((mf1 * f2).value, float)
    assert mf1 * f2 == nb.Mixed(11.9)
    assert isinstance(f1 * mf2, nb.Mixed)
    assert isinstance((f1 * mf2).value, float)
    assert f1 * mf2 == nb.Mixed(11.9)

    # Multiplication with integer 0

    q = fr.Fraction(2, 3)
    e = uc.ufloat(1.2, 0.1)
    i = 4
    f = 3.5
    mq = nb.Mixed(q)
    me = nb.Mixed(e)
    mi = nb.Mixed(i)
    mf = nb.Mixed(f)
    m0 = nb.Mixed(0)

    for m in [mq, me, mi, mf]:
        assert m * m0 == m0
        assert m * 0 == m0
        assert m0 * m == m0
        assert 0 * m == m0

    for z in [q, e, i, f]:
        assert z * m0 == m0
        assert m0 * z == m0

    # Division
    q1 = fr.Fraction(2, 3)
    q2 = fr.Fraction(3, 4)
    e1 = uc.ufloat(0.5, 0.3)
    e2 = uc.ufloat(0.75, 0.4)
    i1 = 4
    i2 = 3
    f1 = 1.5
    f2 = 1.6
    mq1 = nb.Mixed(q1)
    mq2 = nb.Mixed(q2)
    me1 = nb.Mixed(e1)
    me2 = nb.Mixed(e2)
    mi1 = nb.Mixed(i1)
    mi2 = nb.Mixed(i2)
    mf1 = nb.Mixed(f1)
    mf2 = nb.Mixed(f2)

    assert isinstance(mq1 / mq2, nb.Mixed)
    assert isinstance((mq1 / mq2).value, fr.Fraction)
    assert mq1 / mq2 == nb.Mixed(fr.Fraction(8, 9))
    assert isinstance(mq1 / q2, nb.Mixed)
    assert isinstance((mq1 / q2).value, fr.Fraction)
    assert mq1 / q2 == nb.Mixed(fr.Fraction(8, 9))
    assert isinstance(q1 / mq2, nb.Mixed)
    assert isinstance((q1 / mq2).value, fr.Fraction)
    assert q1 / mq2 == nb.Mixed(fr.Fraction(8, 9))

    assert isinstance(mq1 / me1, nb.Mixed)
    assert isinstance((mq1 / me1).value, uc.UFloat)
    assert mq1 / me1 == nb.Mixed(uc.ufloat(4 / 3, 0.3 * 2 / 3 / (1 / 2) ** 2))
    assert isinstance(mq1 / e1, nb.Mixed)
    assert isinstance((mq1 / e1).value, uc.UFloat)
    assert mq1 / e1 == nb.Mixed(uc.ufloat(4 / 3, 0.3 * 2 / 3 / (1 / 2) ** 2))
    assert isinstance(q1 / me1, nb.Mixed)
    assert isinstance((q1 / me1).value, uc.UFloat)
    assert q1 / me1 == nb.Mixed(uc.ufloat(4 / 3, 0.3 * 2 / 3 / (1 / 2) ** 2))

    assert isinstance(mq1 / mi1, nb.Mixed)
    assert isinstance((mq1 / mi1).value, fr.Fraction)
    assert mq1 / mi1 == nb.Mixed(fr.Fraction(1, 6))
    assert isinstance(mq1 / i1, nb.Mixed)
    assert isinstance((mq1 / i1).value, fr.Fraction)
    assert mq1 / i1 == nb.Mixed(fr.Fraction(1, 6))
    assert isinstance(q1 / mi1, nb.Mixed)
    assert isinstance((q1 / mi1).value, fr.Fraction)
    assert q1 / mi1 == nb.Mixed(fr.Fraction(1, 6))

    assert isinstance(mq1 / mf1, nb.Mixed)
    assert isinstance((mq1 / mf1).value, float)
    assert mq1 / mf1 == nb.Mixed(4.0 / 9.0)
    assert isinstance(mq1 / f1, nb.Mixed)
    assert isinstance((mq1 / f1).value, float)
    assert mq1 / f1 == nb.Mixed(4.0 / 9.0)
    assert isinstance(q1 / mf1, nb.Mixed)
    assert isinstance((q1 / mf1).value, float)
    assert q1 / mf1 == nb.Mixed(4.0 / 9.0)

    assert isinstance(me1 / mq1, nb.Mixed)
    assert isinstance((me1 / mq1).value, uc.UFloat)
    assert me1 / mq1 == nb.Mixed(uc.ufloat(0.5, 0.3) / (2 / 3))
    assert isinstance(me1 / q1, nb.Mixed)
    assert isinstance((me1 / q1).value, uc.UFloat)
    assert me1 / q1 == nb.Mixed(uc.ufloat(0.5, 0.3) / (2 / 3))
    assert isinstance(e1 / mq1, nb.Mixed)
    assert isinstance((e1 / mq1).value, uc.UFloat)
    assert e1 / mq1 == nb.Mixed(uc.ufloat(0.5, 0.3) / (2 / 3))

    assert isinstance(me1 / me2, nb.Mixed)
    assert isinstance((me1 / me2).value, uc.UFloat)
    assert me1 / me2 == nb.Mixed(uc.ufloat(0.5, 0.3) / uc.ufloat(0.75, 0.4))
    assert isinstance(me1 / e2, nb.Mixed)
    assert isinstance((me1 / e2).value, uc.UFloat)
    assert me1 / e2 == nb.Mixed(uc.ufloat(0.5, 0.3) / uc.ufloat(0.75, 0.4))
    assert isinstance(e1 / me2, nb.Mixed)
    assert isinstance((e1 / me2).value, uc.UFloat)
    assert e1 / me2 == nb.Mixed(uc.ufloat(0.5, 0.3) / uc.ufloat(0.75, 0.4))

    assert isinstance(me1 / mi1, nb.Mixed)
    assert isinstance((me1 / mi1).value, uc.UFloat)
    assert me1 / mi1 == nb.Mixed(uc.ufloat(0.125, 0.075))
    assert isinstance(me1 / i1, nb.Mixed)
    assert isinstance((me1 / i1).value, uc.UFloat)
    assert me1 / i1 == nb.Mixed(uc.ufloat(0.125, 0.075))
    assert isinstance(e1 / mi1, nb.Mixed)
    assert isinstance((e1 / mi1).value, uc.UFloat)
    assert e1 / mi1 == nb.Mixed(uc.ufloat(0.125, 0.075))

    assert isinstance(me1 / mf1, nb.Mixed)
    assert isinstance((me1 / mf1).value, uc.UFloat)
    assert me1 / mf1 == nb.Mixed(uc.ufloat(0.5 / 1.5, 0.3 / 1.5))
    assert isinstance(me1 / f1, nb.Mixed)
    assert isinstance((me1 / f1).value, uc.UFloat)
    assert me1 / f1 == nb.Mixed(uc.ufloat(0.5 / 1.5, 0.3 / 1.5))
    assert isinstance(e1 / mf1, nb.Mixed)
    assert isinstance((e1 / mf1).value, uc.UFloat)
    assert e1 / mf1 == nb.Mixed(uc.ufloat(0.5 / 1.5, 0.3 / 1.5))

    assert isinstance(mi1 / mq2, nb.Mixed)
    assert isinstance((mi1 / mq2).value, fr.Fraction)
    assert mi1 / mq2 == nb.Mixed(fr.Fraction(16, 3))
    assert isinstance(mi1 / q2, nb.Mixed)
    assert isinstance((mi1 / q2).value, fr.Fraction)
    assert mi1 / q2 == nb.Mixed(fr.Fraction(16, 3))
    assert isinstance(i1 / mq2, nb.Mixed)
    assert isinstance((i1 / mq2).value, fr.Fraction)
    assert i1 / mq2 == nb.Mixed(fr.Fraction(16, 3))

    assert isinstance(mi1 / me1, nb.Mixed)
    assert isinstance((mi1 / me1).value, uc.UFloat)
    assert mi1 / me1 == nb.Mixed(uc.ufloat(8.0, 4.8))
    assert isinstance(mi1 / e1, nb.Mixed)
    assert isinstance((mi1 / e1).value, uc.UFloat)
    assert mi1 / e1 == nb.Mixed(uc.ufloat(8.0, 4.8))
    assert isinstance(i1 / me1, nb.Mixed)
    assert isinstance((i1 / me1).value, uc.UFloat)
    assert i1 / me1 == nb.Mixed(uc.ufloat(8.0, 4.8))

    assert isinstance(mi1 / mi2, nb.Mixed)
    assert isinstance((mi1 / mi2).value, fr.Fraction)
    assert mi1 / mi2 == nb.Mixed(fr.Fraction(4, 3))
    assert isinstance(mi1 / i2, nb.Mixed)
    assert isinstance((mi1 / i2).value, fr.Fraction)
    assert mi1 / i2 == nb.Mixed(fr.Fraction(4, 3))
    assert isinstance(i1 / mi2, nb.Mixed)
    assert isinstance((i1 / mi2).value, fr.Fraction)
    assert i1 / mi2 == nb.Mixed(fr.Fraction(4, 3))

    assert isinstance(mi1 / mf1, nb.Mixed)
    assert isinstance((mi1 / mf1).value, float)
    assert mi1 / mf1 == nb.Mixed(4.0 / 1.5)
    assert isinstance(mi1 / f1, nb.Mixed)
    assert isinstance((mi1 / f1).value, float)
    assert mi1 / f1 == nb.Mixed(4.0 / 1.5)
    assert isinstance(i1 / mf1, nb.Mixed)
    assert isinstance((i1 / mf1).value, float)
    assert i1 / mf1 == nb.Mixed(4.0 / 1.5)

    assert isinstance(mf1 / mq1, nb.Mixed)
    assert isinstance((mf1 / mq1).value, float)
    assert mf1 / mq1 == nb.Mixed(2.25)
    assert isinstance(mf1 / q1, nb.Mixed)
    assert isinstance((mf1 / q1).value, float)
    assert mf1 / q1 == nb.Mixed(2.25)
    assert isinstance(f1 / mq1, nb.Mixed)
    assert isinstance((f1 / mq1).value, float)
    assert f1 / mq1 == nb.Mixed(2.25)

    assert isinstance(mf1 / me1, nb.Mixed)
    assert isinstance((mf1 / me1).value, uc.UFloat)
    assert mf1 / me1 == nb.Mixed(uc.ufloat(3.0, 0.3 * 1.5 / 0.5 ** 2))
    assert isinstance(mf1 / e1, nb.Mixed)
    assert isinstance((mf1 / e1).value, uc.UFloat)
    assert mf1 / e1 == nb.Mixed(uc.ufloat(3.0, 0.3 * 1.5 / 0.5 ** 2))
    assert isinstance(f1 / me1, nb.Mixed)
    assert isinstance((f1 / me1).value, uc.UFloat)
    assert f1 / me1 == nb.Mixed(uc.ufloat(3.0, 0.3 * 1.5 / 0.5 ** 2))

    assert isinstance(mf1 / mi1, nb.Mixed)
    assert isinstance((mf1 / mi1).value, float)
    assert mf1 / mi1 == nb.Mixed(0.375)
    assert isinstance(mf1 / i1, nb.Mixed)
    assert isinstance((mf1 / i1).value, float)
    assert mf1 / i1 == nb.Mixed(0.375)
    assert isinstance(f1 / mi1, nb.Mixed)
    assert isinstance((f1 / mi1).value, float)
    assert f1 / mi1 == nb.Mixed(0.375)

    assert isinstance(mf1 / mf2, nb.Mixed)
    assert isinstance((mf1 / mf2).value, float)
    assert mf1 / mf2 == nb.Mixed(0.9375)
    assert isinstance(mf1 / f2, nb.Mixed)
    assert isinstance((mf1 / f2).value, float)
    assert mf1 / f2 == nb.Mixed(0.9375)
    assert isinstance(f1 / mf2, nb.Mixed)
    assert isinstance((f1 / mf2).value, float)
    assert f1 / mf2 == nb.Mixed(0.9375)

    # Dividing integer 0

    q = fr.Fraction(2, 3)
    e = uc.ufloat(1.2, 0.1)
    i = 4
    f = 3.5
    mq = nb.Mixed(q)
    me = nb.Mixed(e)
    mi = nb.Mixed(i)
    mf = nb.Mixed(f)
    m0 = nb.Mixed(0)

    for m in [mq, me, mi, mf]:
        assert m0 / m == m0
        assert 0 / m == m0

    for z in [q, e, i, f]:
        assert m0 / z == m0

    # negative

    q = fr.Fraction(3, 2)
    e = uc.ufloat(1.2, 0.1)
    i = 4
    f = 3.5
    mq = nb.Mixed(q)
    me = nb.Mixed(e)
    mi = nb.Mixed(i)
    mf = nb.Mixed(f)

    assert isinstance(-mq, nb.Mixed)
    assert isinstance((-mq).value, fr.Fraction)
    assert -mq == nb.Mixed(fr.Fraction(-3, 2))

    assert isinstance(-me, nb.Mixed)
    assert isinstance((-me).value, uc.UFloat)
    assert -me == nb.Mixed(uc.ufloat(-1.2, 0.1))

    assert isinstance(-mi, nb.Mixed)
    assert isinstance((-mi).value, int)
    assert -mi == nb.Mixed(-4)

    assert isinstance(-mf, nb.Mixed)
    assert isinstance((-mf).value, float)
    assert -mf == nb.Mixed(-3.5)

    # Modulo

    q = fr.Fraction(5, 2)
    e = uc.ufloat(3.2, 0.1)
    i = 3
    f = 3.5
    mq = nb.Mixed(q)
    me = nb.Mixed(e)
    mi = nb.Mixed(i)
    mf = nb.Mixed(f)

    assert isinstance(mq % 2, nb.Mixed)
    assert isinstance((mq % 2).value, fr.Fraction)
    assert mq % 2 == nb.Mixed(fr.Fraction(1, 2))

    assert isinstance(me % 2, nb.Mixed)
    assert isinstance((me % 2).value, uc.UFloat)
    assert approx((me % 2).value.n, 1.2)
    assert approx((me % 2).value.s, 0.1)

    assert isinstance(mi % 2, nb.Mixed)
    assert isinstance((mi % 2).value, int)
    assert mi % 2 == nb.Mixed(1)

    assert isinstance(mf % 2, nb.Mixed)
    assert isinstance((mf % 2).value, float)
    assert approx((mf % 2).value, 1.5)

    # Constants

    assert isinstance(nb.pi, nb.Mixed)
    assert isinstance((nb.pi).value, float)
    assert (nb.pi).value == 3.141592653589793

    # Square-Root

    a = nb.sqrt(nb.Mixed(fr.Fraction(2, 3)))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.816496580)
    a = nb.sqrt(fr.Fraction(2, 3))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.816496580)
    a = nb.sqrt(nb.Mixed(fr.Fraction(1, 2)))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.70710678118)
    a = nb.sqrt(fr.Fraction(1, 2))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.70710678118)
    a = nb.sqrt(nb.Mixed(fr.Fraction(2, 1)))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 1.41421356237)
    a = nb.sqrt(fr.Fraction(2, 1))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 1.41421356237)
    a = nb.sqrt(nb.Mixed(fr.Fraction(4, 9)))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, fr.Fraction)
    assert a == nb.Mixed(fr.Fraction(2, 3))
    a = nb.sqrt(fr.Fraction(4, 9))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, fr.Fraction)
    assert a == nb.Mixed(fr.Fraction(2, 3))

    a = nb.sqrt(nb.Mixed(uc.ufloat(0.3, 0.1)))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, uc.UFloat)
    assert approx(a.value.n, 0.54772255750)
    assert approx(a.value.s, 0.09128709291)
    a = nb.sqrt(uc.ufloat(0.3, 0.1))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, uc.UFloat)
    assert approx(a.value.n, 0.54772255750)
    assert approx(a.value.s, 0.09128709291)

    a = nb.sqrt(nb.Mixed(3))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 1.7320508075688)
    a = nb.sqrt(3)
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 1.7320508075688)
    a = nb.sqrt(nb.Mixed(4))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, int)
    assert a.value == 2
    a = nb.sqrt(4)
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, int)
    assert a.value == 2

    a = nb.sqrt(nb.Mixed(0.5))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.7071067811)
    a = nb.sqrt(0.5)
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.7071067811)

    # Trigonometric Functions:

    a = nb.deg2rad(nb.Mixed(fr.Fraction(180, 1)))
    assert approx(a.value, 3.1415926535)
    a = nb.deg2rad(fr.Fraction(180, 1))
    assert approx(a.value, 3.1415926535)
    a = nb.deg2rad(nb.Mixed(uc.ufloat(180.0, 10.0)))
    assert approx(a.value.n, 3.1415926535)
    assert approx(a.value.s, 0.174532925199)
    a = nb.deg2rad(uc.ufloat(180.0, 10.0))
    assert approx(a.value.n, 3.1415926535)
    assert approx(a.value.s, 0.174532925199)
    a = nb.deg2rad(nb.Mixed(180))
    assert approx(a.value, 3.1415926535)
    a = nb.deg2rad(180)
    assert approx(a.value, 3.1415926535)
    a = nb.deg2rad(nb.Mixed(180.0))
    assert approx(a.value, 3.1415926535)
    a = nb.deg2rad(180.0)
    assert approx(a.value, 3.1415926535)

    a = nb.rad2deg(nb.Mixed(fr.Fraction(1, 2)))
    assert approx(a.value, 28.647889756)
    a = nb.rad2deg(fr.Fraction(1, 2))
    assert approx(a.value, 28.647889756)
    a = nb.rad2deg(nb.Mixed(uc.ufloat(3.1415926535897931, 0.17453292519943295)))
    assert approx(a.value.n, 180.0)
    assert approx(a.value.s, 10.0)
    a = nb.rad2deg(uc.ufloat(3.1415926535897931, 0.17453292519943295))
    assert approx(a.value.n, 180.0)
    assert approx(a.value.s, 10.0)
    a = nb.rad2deg(nb.Mixed(1))
    assert approx(a.value, 57.295779513082323)
    a = nb.rad2deg(1)
    assert approx(a.value, 57.295779513082323)
    a = nb.rad2deg(nb.Mixed(3.1415926535897931))
    assert approx(a.value, 180.0)
    a = nb.rad2deg(3.1415926535897931)
    assert approx(a.value, 180.0)

    a = nb.sin(nb.Mixed(fr.Fraction(1, 2)))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.47942553860420301)
    a = nb.sin(fr.Fraction(1, 2))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.479425538604203)
    a = nb.sin(nb.Mixed(uc.ufloat(0.5, 0.1)))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, uc.UFloat)
    assert approx(a.value.n, 0.479425538604203)
    assert approx(a.value.s, 0.08775825618903728)
    a = nb.sin(uc.ufloat(0.5, 0.1))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, uc.UFloat)
    assert approx(a.value.n, 0.479425538604203)
    assert approx(a.value.s, 0.08775825618903728)
    a = nb.sin(nb.Mixed(1))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.8414709848078965)
    a = nb.sin(1)
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.8414709848078965)
    a = nb.sin(nb.Mixed(0.5))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.479425538604203)
    a = nb.sin(0.5)
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.479425538604203)

    a = nb.cos(nb.Mixed(fr.Fraction(1, 2)))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.8775825618903)
    a = nb.cos(fr.Fraction(1, 2))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.8775825618903)
    a = nb.cos(nb.Mixed(uc.ufloat(0.5, 0.1)))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, uc.UFloat)
    assert approx(a.value.n, 0.8775825619803)
    assert approx(a.value.s, 0.0479425538604)
    a = nb.cos(uc.ufloat(0.5, 0.1))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, uc.UFloat)
    assert approx(a.value.n, 0.8775825619803)
    assert approx(a.value.s, 0.0479425538604)
    a = nb.cos(nb.Mixed(1))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.54030230586)
    a = nb.cos(1)
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.54030230586)
    a = nb.cos(nb.Mixed(0.5))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.8775825618903)
    a = nb.cos(0.5)
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.8775825618903)

    a = nb.arccos(nb.Mixed(fr.Fraction(1, 2)))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 1.04719755119)
    a = nb.arccos(fr.Fraction(1, 2))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 1.04719755119)
    a = nb.arccos(nb.Mixed(uc.ufloat(0.5, 0.1)))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, uc.UFloat)
    assert approx(a.value.n, 1.04719755119)
    assert approx(a.value.s, 0.11547005383)
    a = nb.arccos(uc.ufloat(0.5, 0.1))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, uc.UFloat)
    assert approx(a.value.n, 1.04719755119)
    assert approx(a.value.s, 0.11547005383)
    a = nb.arccos(nb.Mixed(1))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.0)
    a = nb.arccos(1)
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 0.0)
    a = nb.arccos(nb.Mixed(0.5))
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 1.04719755119)
    a = nb.arccos(0.5)
    assert isinstance(a, nb.Mixed)
    assert isinstance(a.value, float)
    assert approx(a.value, 1.04719755119)
Ejemplo n.º 8
0
def test_Row():

    # Create
    e = uc.ufloat(1.2, 0.1)
    R = nb.Row([nb.Mixed(fr.Fraction(1, 2)),
                nb.Mixed(e),
                nb.Mixed(1),
                nb.Mixed(0.5)])
    assert isinstance(R.liste, list)
    assert isinstance(R.liste[0], nb.Mixed)
    assert isinstance(R.liste[0].value, fr.Fraction)
    assert R.liste[0] == nb.Mixed(fr.Fraction(1, 2))
    assert isinstance(R.liste[1], nb.Mixed)
    assert isinstance(R.liste[1].value, uc.UFloat)
    assert R.liste[1] == nb.Mixed(e)
    assert isinstance(R.liste[2], nb.Mixed)
    assert isinstance(R.liste[2].value, int)
    assert R.liste[2] == nb.Mixed(1)
    assert isinstance(R.liste[3], nb.Mixed)
    assert isinstance(R.liste[3].value, float)
    assert approx(R.liste[3].value, 0.5)

    R = nb.Row([fr.Fraction(1, 2),
                e,
                1,
                0.5])
    assert isinstance(R.liste, list)
    assert isinstance(R.liste[0], nb.Mixed)
    assert isinstance(R.liste[0].value, fr.Fraction)
    assert R.liste[0] == nb.Mixed(fr.Fraction(1, 2))
    assert isinstance(R.liste[1], nb.Mixed)
    assert isinstance(R.liste[1].value, uc.UFloat)
    assert R.liste[1] == nb.Mixed(e)
    assert isinstance(R.liste[2], nb.Mixed)
    assert isinstance(R.liste[2].value, int)
    assert R.liste[2] == nb.Mixed(1)
    assert isinstance(R.liste[3], nb.Mixed)
    assert isinstance(R.liste[3].value, float)
    assert approx(R.liste[3].value, 0.5)

    # len

    R = nb.Row([fr.Fraction(1, 2),
                uc.ufloat(1.2, 0.1),
                1,
                0.5])
    assert len(R) == 4

    assert R.__str__() == "(  1/2  1.20(10)  1  0.5  )"

    # Equal

    e = uc.ufloat(1.2, 0.1)
    R1 = nb.Row([fr.Fraction(1, 2),
                e,
                1,
                0.5])
    R2 = nb.Row([fr.Fraction(1, 2),
                e,
                1,
                0.5])
    R2wrong = nb.Row([fr.Fraction(1, 2),
                      uc.ufloat(1.2, 0.1),
                      1,
                      0.5])
    R3 = nb.Row([fr.Fraction(1, 2),
                e,
                1,
                fr.Fraction(1, 2)])
    R4 = nb.Row([fr.Fraction(1, 2),
                e,
                1])

    assert R1 == R2
    assert (R1 == R2wrong) == False
    assert (R1 == R3) == False
    assert (R1 == R4) == False
    assert (R1 == 5) == False

    # Hash
    R1 = nb.Row([0, 0, 1.00000000])
    R2 = nb.Row([0, 0, 0.99999999])
    assert hash(R1) == hash(R2)
    e1 = uc.ufloat(1.2, 0.1)
    R1 = nb.Row([0, 0, e1])
    R2 = nb.Row([0, 0, e1])
    R3 = nb.Row([0, 0, uc.ufloat(1.2, 0.1)])
    assert hash(R1) == hash(R2)
    assert (hash(R1) == hash(R3)) == False


    # canonical

    assert nb.Row.canonical(5, 3) == nb.Row([0, 0, 0, 1, 0])

    # block

    R = nb.Row([1, 2, 3, 4])
    assert R.block(1, 3) == nb.Row([2, 3])

    # Addition

    R1 = nb.Row([1, 2, fr.Fraction(1, 2)])
    R2 = nb.Row([2, 3, 4])
    assert R1 + R2 == nb.Row([3, 5, fr.Fraction(9, 2)])

    # Subtraction

    R1 = nb.Row([1, 2, fr.Fraction(1, 2)])
    R2 = nb.Row([2, 3, 4])
    assert R1 - R2 == nb.Row([-1, -1, fr.Fraction(-7, 2)])

    # Multiplication

    R1 = nb.Row([1, 2, fr.Fraction(1, 2)])
    assert R1 * nb.Mixed(2) == nb.Row([2, 4, 1])
    assert nb.Mixed(2) * R1 == nb.Row([2, 4, 1])
    assert R1 * 2 == nb.Row([2, 4, 1])
    assert 2 * R1 == nb.Row([2, 4, 1])

    # neg
    R1 = nb.Row([1, 2, 3])
    assert -R1 == nb.Row([-1, -2, -3])
Ejemplo n.º 9
0
def test_Matrix():

    # create and shape

    M1 = nb.Matrix([nb.Row([1, 2, 3]), nb.Row([4, 5, 6])])
    M2 = nb.Matrix([[1, 2, 3], [4, 5, 6]])
    assert M1.shape() == (2, 3)
    assert M2.shape() == (2, 3)

    # Equal

    M1 = nb.Matrix([nb.Row([1, 2, 3]), nb.Row([4, 5, 6])])
    M2 = nb.Matrix([[1, 2, 3], [4, 5, 6]])
    M3 = nb.Matrix([[1, 2, 3], [4, 5.1, 6]])
    M4 = nb.Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
    M5 = nb.Matrix([[1, 2], [4, 5]])
    M6 = nb.Matrix([[1, 2, 3], [4, 5.0, 6]])
    M7 = nb.Matrix([[1, 2, 3], [4, fr.Fraction(5, 1), 6]])
    assert M1 == M2
    assert (M1 == M3) == False
    assert (M1 == M4) == False
    assert (M1 == M5) == False
    assert (M1 == M6) == False
    assert M1 == M7

    M1 = nb.Matrix([nb.Row([1, 2, 3.0]), nb.Row([4, 5, 6])])
    M2 = nb.Matrix([nb.Row([1, 2, 2.999999999999]), nb.Row([4, 5, 6])])
    print(hash(M1))
    print(hash(M2))
    assert hash(M1) == hash(M2)

    e = uc.ufloat(1.2, 0.1)
    M1 = nb.Matrix([nb.Row([1, 2, e]), nb.Row([4, 5, 6])])
    M2 = nb.Matrix([nb.Row([1, 2, e]), nb.Row([4, 5, 6])])
    M3 = nb.Matrix([nb.Row([1, 2, uc.ufloat(1.2, 0.1)]), nb.Row([4, 5, 6])])
    assert M1 == M2
    assert (M1 == M3) == False
    assert hash(M1) == hash(M2)
    assert (hash(M1) == hash(M3)) == False

    # print

    assert nb.Matrix([[1, 2]]).__str__() == " <  1  2  > "
    assert nb.Matrix([[1, 2], [3, 4]]).__str__() == " /  1  2  \ \n" \
                                                    " \  3  4  / "
    assert nb.Matrix([[1, 2, 3], [4, 5, 6], [7, 800, 9]]).__str__() == \
        " /  1    2  3  \ \n" \
        "|   4    5  6   |\n" \
        " \  7  800  9  / "

    # Addition

    assert nb.Matrix([[1, 2], [3, 4]]) + nb.Matrix([[5, 6], [7, 8]]) == \
        nb.Matrix([[6, 8], [10, 12]])

    assert nb.Matrix([[1, 2], [3, 4], [5, 6]]) + \
           nb.Matrix([[1, 1], [1, 1], [1, 1]]) == \
           nb.Matrix([[2, 3], [4, 5], [6, 7]])

    # Subtraction

    assert nb.Matrix([[1, 2], [3, 4]]) - nb.Matrix([[5, 6], [7, 8]]) == \
        nb.Matrix([[-4, -4], [-4, -4]])

    assert nb.Matrix([[1, 2], [3, 4], [5, 6]]) - \
           nb.Matrix([[1, 1], [1, 1], [1, 1]]) == \
           nb.Matrix([[0, 1], [2, 3], [4, 5]])

    # neg

    M1 = nb.Matrix([[1, 2, 3], [4, 5, 6]])
    assert -M1 == nb.Matrix([[-1, -2, -3], [-4, -5, -6]])

    # Multiplication "Matrix * Matrix"

    M1 = nb.Matrix([[1, 2], [3, 4]])
    M2 = nb.Matrix([[5, 6], [7, 8]])
    assert isinstance(M1 * M2, nb.Matrix)
    assert M1 * M2 == nb.Matrix([[19, 22], [43, 50]])

    M1 = nb.Matrix([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
    M2 = nb.Matrix([[uc.ufloat(1.2, 0.1)], [1], [2]])
    print(M2)
    print(M1*M2)
    assert (M1 * M2).liste[1].liste[0] == M2.liste[1].liste[0]
    assert M1 * M2 == M2


    # Multiplication "Scalar * Matrix"

    M1 = nb.Matrix([[1, 2], [3, 4]])
    assert M1 * nb.Mixed(fr.Fraction(1, 2)) == \
        nb.Matrix([[fr.Fraction(1, 2), 1], [fr.Fraction(3, 2), 2]])
    assert M1 * fr.Fraction(1, 2) == \
        nb.Matrix([[fr.Fraction(1, 2), 1], [fr.Fraction(3, 2), 2]])
    assert nb.Mixed(fr.Fraction(1, 2)) * M1 == \
        nb.Matrix([[fr.Fraction(1, 2), 1], [fr.Fraction(3, 2), 2]])
    assert fr.Fraction(1, 2) * M1 == \
        nb.Matrix([[fr.Fraction(1, 2), 1], [fr.Fraction(3, 2), 2]])

    M = M1 * nb.Mixed(uc.ufloat(1.2, 0.1))
    assert approx(M.liste[0].liste[0].value.n, 1.2)
    assert approx(M.liste[0].liste[0].value.s, 0.1)
    assert approx(M.liste[0].liste[1].value.n, 2.4)
    assert approx(M.liste[0].liste[1].value.s, 0.2)
    assert approx(M.liste[1].liste[0].value.n, 3.6)
    assert approx(M.liste[1].liste[0].value.s, 0.3)
    assert approx(M.liste[1].liste[1].value.n, 4.8)
    assert approx(M.liste[1].liste[1].value.s, 0.4)
    M = M1 * uc.ufloat(1.2, 0.1)
    assert approx(M.liste[0].liste[0].value.n, 1.2)
    assert approx(M.liste[0].liste[0].value.s, 0.1)
    assert approx(M.liste[0].liste[1].value.n, 2.4)
    assert approx(M.liste[0].liste[1].value.s, 0.2)
    assert approx(M.liste[1].liste[0].value.n, 3.6)
    assert approx(M.liste[1].liste[0].value.s, 0.3)
    assert approx(M.liste[1].liste[1].value.n, 4.8)
    assert approx(M.liste[1].liste[1].value.s, 0.4)
    M = nb.Mixed(uc.ufloat(1.2, 0.1)) * M1
    assert approx(M.liste[0].liste[0].value.n, 1.2)
    assert approx(M.liste[0].liste[0].value.s, 0.1)
    assert approx(M.liste[0].liste[1].value.n, 2.4)
    assert approx(M.liste[0].liste[1].value.s, 0.2)
    assert approx(M.liste[1].liste[0].value.n, 3.6)
    assert approx(M.liste[1].liste[0].value.s, 0.3)
    assert approx(M.liste[1].liste[1].value.n, 4.8)
    assert approx(M.liste[1].liste[1].value.s, 0.4)
    M = uc.ufloat(1.2, 0.1) * M1
    assert approx(M.liste[0].liste[0].value.n, 1.2)
    assert approx(M.liste[0].liste[0].value.s, 0.1)
    assert approx(M.liste[0].liste[1].value.n, 2.4)
    assert approx(M.liste[0].liste[1].value.s, 0.2)
    assert approx(M.liste[1].liste[0].value.n, 3.6)
    assert approx(M.liste[1].liste[0].value.s, 0.3)
    assert approx(M.liste[1].liste[1].value.n, 4.8)
    assert approx(M.liste[1].liste[1].value.s, 0.4)

    assert M1 * nb.Mixed(2) == nb.Matrix([[2, 4], [6, 8]])
    assert M1 * 2 == nb.Matrix([[2, 4], [6, 8]])
    assert nb.Mixed(2) * M1 == nb.Matrix([[2, 4], [6, 8]])
    assert 2 * M1 == nb.Matrix([[2, 4], [6, 8]])

    M = M1 * nb.Mixed(2.5)
    assert approx(M.liste[0].liste[0].value, 2.5)
    assert approx(M.liste[0].liste[1].value, 5.0)
    assert approx(M.liste[1].liste[0].value, 7.5)
    assert approx(M.liste[1].liste[1].value, 10.0)
    M = M1 * 2.5
    assert approx(M.liste[0].liste[0].value, 2.5)
    assert approx(M.liste[0].liste[1].value, 5.0)
    assert approx(M.liste[1].liste[0].value, 7.5)
    assert approx(M.liste[1].liste[1].value, 10.0)
    M = nb.Mixed(2.5) * M1
    assert approx(M.liste[0].liste[0].value, 2.5)
    assert approx(M.liste[0].liste[1].value, 5.0)
    assert approx(M.liste[1].liste[0].value, 7.5)
    assert approx(M.liste[1].liste[1].value, 10.0)
    M = 2.5 * M1
    assert approx(M.liste[0].liste[0].value, 2.5)
    assert approx(M.liste[0].liste[1].value, 5.0)
    assert approx(M.liste[1].liste[0].value, 7.5)
    assert approx(M.liste[1].liste[1].value, 10.0)

    # onematrix

    assert nb.Matrix.onematrix(2) == nb.Matrix([[1, 0], [0, 1]])
    assert nb.Matrix.onematrix(3) == nb.Matrix([[1, 0, 0], [0, 1, 0], [0, 0, 1]])

    # block

    M = nb.Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
    assert M.block(0, 2, 0, 2) == nb.Matrix([[1, 2], [4, 5]])
    assert M.block(1, 2, 0, 3) == nb.Matrix([[4, 5, 6]])
    M = nb.Matrix([[1, 2, 3, 4]])
    assert M.block(0, 1, 0, 3) == nb.Matrix([[1, 2, 3]])

    # swap_rows

    M = nb.Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
    assert M.swap_rows(0, 1) == nb.Matrix([[4, 5, 6], [1, 2, 3], [7, 8, 9]])

    # vglue

    M1 = nb.Matrix([[1, 2, 3]])
    M2 = nb.Matrix([[4, 5, 6]])
    assert nb.Matrix.vglue(M1, M2) == nb.Matrix([[1, 2, 3], [4, 5, 6]])

    # subtract_x_times_rowj_from_rowi

    M = nb.Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
    assert M.subtract_x_times_rowj_from_rowi(2, 2, 0) == \
        nb.Matrix([[1, 2, 3], [4, 5, 6], [5, 4, 3]])

    # inv

    assert nb.Matrix([[2, 3],
                      [4, 5]]).inv() == \
        nb.Matrix([[-fr.Fraction(5, 2), fr.Fraction(3, 2)],
                   [2,                -1]])
    assert nb.Matrix([[0, 1,  1],
                      [1, 0,  0],
                      [0, 0, -1]]).inv() == \
           nb.Matrix([[0, 1,  0],
                      [1, 0,  1],
                      [0, 0, -1]])

    assert nb.Matrix([[0, 0, 1, 0],
                      [1, 0, 0, 0],
                      [0, 1, 0, 0],
                      [0, 0, 0, 1]]).inv() == \
           nb.Matrix([[0, 1, 0, 0],
                      [0, 0, 1, 0],
                      [1, 0, 0, 0],
                      [0, 0, 0, 1]])

    # transpose

    assert nb.Matrix([[1, 2, 3], [4, 5, 6]]).transpose() == \
           nb.Matrix([[1, 4], [2, 5], [3, 6]])

    # delete_ith_row_and_first_column
    M = nb.Matrix([[1, 2, 3, 4],
                   [5, 6, 7, 8],
                   [9, 10, 11, 12]])
    assert M.delete_ith_row_and_first_column(1) == nb.Matrix([[2, 3, 4],
                                                              [10, 11, 12]])

    # det
    M = nb.Matrix([[3]])
    assert M.det() == 3
    M = nb.Matrix([[1, 2],
                   [3, 4]])
    assert M.det() == -2
    M = nb.Matrix([[1, 2, 3],
                   [4, 5, 6],
                   [7, 8, 9]])
    assert M.det() == 0
    M = nb.Matrix([[1, 2, 3, 4],
                   [5, 6, 7, 8],
                   [9, 8, 11, 12],
                   [13, 14, 15, 17]])
    assert M.det() == -16

    # delete_translation

    M = nb.Matrix([[1,  2,  3,  4],
                   [5,  6,  7,  8],
                   [9, 10, 11, 12],
                   [0,  0,  0,  1]])

    assert M.delete_translation() == nb.Matrix([[1,  2,  3, 0],
                                              [5,  6,  7, 0],
                                              [9, 10, 11, 0],
                                              [0,  0,  0, 1]])
Ejemplo n.º 10
0
def test_fromstr():
    string = "1/2"
    assert isinstance(fs(string), nb.Mixed)
    assert fs(string) == nb.Mixed(fr.Fraction(1, 2))
    string = "1.2+/-0.1"
    assert fs(string).value.n == nb.Mixed(uc.ufloat(1.2, 0.1)).value.n
    assert fs(string).value.s == nb.Mixed(uc.ufloat(1.2, 0.1)).value.s
    string = "1.2(1)"
    assert fs(string).value.n == nb.Mixed(uc.ufloat(1.2, 0.1)).value.n
    assert fs(string).value.s == nb.Mixed(uc.ufloat(1.2, 0.1)).value.s
    string = "4"
    assert fs(string) == nb.Mixed(fr.Fraction(4, 1))
    string = "4.5"
    assert fs(string) == nb.Mixed(4.5)

    string = "1 2 3"
    assert fromstr.typefromstr(string) == nb.Matrix
    assert fs(string) == nb.Matrix([[1, 2, 3]])

    string = "/ 1 2 \ \n \ 3 4 /"
    assert fs(string) == \
        nb.Matrix([nb.Row([nb.Mixed(1), nb.Mixed(2)]),
                   nb.Row([nb.Mixed(3), nb.Mixed(4)])])
    string = "1 2 \n 3 4"
    assert fs(string) == \
        nb.Matrix([nb.Row([nb.Mixed(1), nb.Mixed(2)]),
                   nb.Row([nb.Mixed(3), nb.Mixed(4)])])
    string = "x+y,y - x +1/3,2z"
    g = fs(string)
    assert g == geo.Symmetry(
        fs("/ 1 1 0 0 \n"
           " -1 1 0 1/3 \n"
           "  0 0 2 0 \n"
           "  0 0 0 1"))
    string = "O->(0,0,0)\n" \
             "then\n" \
             "a' = a-b \n" \
             "b' = b+a \n" \
             "c' = 2c"
    g = fs(string)
    assert g == geo.Transformation(
        fs(" 1 1 0 0 \n"
           "-1 1 0 0 \n"
           " 0 0 2 0 \n"
           " 0 0 0 1").inv())

    string = "O->(0,0,0) \n" \
             "then\n" \
             "a' = c \n" \
             "b' = a \n" \
             "c' = b"
    g = fs(string)
    assert g == geo.Transformation(
        fs("0 1 0 0 \n"
           "0 0 1 0 \n"
           "1 0 0 0 \n"
           "0 0 0 1").inv())
    string = "O -> (1/2, 0, 0) \n" \
             "then\n" \
             "a' = a \n" \
             "b' = b \n" \
             "c' = c"
    g = fs(string)
    assert g == geo.Transformation(
        fs("1 0 0 -1/2 \n"
           "0 1 0    0 \n"
           "0 0 1    0 \n"
           "0 0 0    1"))

    string1 = "O -> (1/2, 0, 0) \n" \
              "then\n" \
              "a' = a \n" \
              "b' = b \n" \
              "c' = c"

    string2 = "O -> (0,0,0) \n" \
              "then\n" \
              "a' = b\n" \
              "b' = a\n" \
              "c' = c"
    string = "O -> (1/2, 0, 0) \n" \
             "then\n"\
             "a' = b\n"\
             "b' = a\n"\
             "c' = c"

    g1 = fs(string1)
    g2 = fs(string2)
    g = fs(string)
    assert g == g2 * g1

    string = "O -> (1/2, 0, 0) \n" \
             "then\n" \
             "a' = a + b\n" \
             "b' = b\n" \
             "c' = c"
    print("--------")
    g = fs(string)
    print(g.value)
    assert g**fs("p 1/2 0 0") == fs("p 0 0 0")
    assert g**fs("p 1/2 1/3 0") == fs("p 0 1/3 0")
    assert g**fs("p 0 0 0") == fs("p -1/2 1/2 0")

    assert g * g.inv() == geo.Transformation(nb.Matrix.onematrix(4))

    string = "p0 0 0"
    p = fs(string)
    assert p == geo.Pos(fs("0 \n 0 \n 0 \n 1"))
    string = "P0 0 0"
    p = fs(string)
    assert p == geo.Pos(fs("0 \n 0 \n 0 \n 1"))
    string = "r0 0 0"
    p = fs(string)
    assert p == geo.Pos(fs("0 \n 0 \n 0 \n 1"))
    string = "R0 0 0"
    p = fs(string)
    assert p == geo.Pos(fs("0 \n 0 \n 0 \n 1"))
    string = p.__str__()
    assert string == "Pos /  0  \ \n" \
                     "   |   0   |\n" \
                     "    \  0  / "
    p1 = fs(string)
    assert p == p1
    string = "R1/2 1/2 1/2"
    p = fs(string)
    assert p == geo.Pos(fs("1/2 \n 1/2 \n 1/2 \n 1"))

    q = fs("k1 2 3")
    assert q == geo.Rec(fs("1 2 3 0"))
    q = fs("K 1 2 3")
    assert q == geo.Rec(fs("1 2 3 0"))
    q = fs("q 1/2 1/2 0")
    assert q == geo.Rec(fs("1/2 1/2 0 0"))
    q = fs("Q0 0 0")
    assert q == geo.Rec(fs("0 0 0 0"))
    q = fs("Rec <  1  2  3  > ")
    assert q == geo.Rec(fs("1 2 3 0"))