def test_qsimplify_rec(): q3 = Q(2, s) assert qsimplify(Mul(Add(q1, q2), q3)) == q1.add(q2).mul(q3)
# gram; used to define its prefixed units g = Unit(mass, abbrev="g") # derived units v = Unit(velocity) a = Unit(acceleration) p = Unit(momentum) J = Unit(energy, factor=10 ** 3, abbrev="J") N = Unit(force, factor=10 ** 3, abbrev="N") W = Unit(power, factor=10 ** 3, abbrev="W") Pa = Unit(pressure, factor=10 ** 3, abbrev="Pa") Hz = Unit(frequency, abbrev="Hz") # constants # Newton constant G = Constant(qsimplify(m ** 3 * kg ** -1 * s ** -2).as_unit, factor=6.67384e-11, abbrev="G") # speed of light c = Constant(velocity, factor=299792458, abbrev="c") units = [m, g, s, J, N, W, Pa, Hz] all_units = [] # Prefixes of units like g, J, N etc get added using `prefix_unit` # in the for loop, but the actual units have to be added manually. all_units.extend([g, J, N, W, Pa, Hz]) for u in units: all_units.extend(prefix_unit(u, PREFIXES)) all_units.extend([v, a, p, G, c]) # unit system
def test_qsimplify_pow(): assert qsimplify(Pow(q1, 2)) == q1.pow(2)
def test_qsimplify_mul(): q3 = Q(2, s) assert qsimplify(Mul(q1, q2)) == q1.mul(q2) assert qsimplify(Mul(q1, q3)) == q1.mul(q3)
def test_qsimplify_add(): assert qsimplify(Add(q1, q2)) == q1.add(q2)
# gram; used to define its prefixed units g = Unit(mass, abbrev="g") # derived units v = Unit(velocity) a = Unit(acceleration) p = Unit(momentum) J = Unit(energy, factor=10**3, abbrev="J") N = Unit(force, factor=10**3, abbrev="N") W = Unit(power, factor=10**3, abbrev="W") Pa = Unit(pressure, factor=10**3, abbrev="Pa") Hz = Unit(frequency, abbrev="Hz") # constants # Newton constant G = Constant(qsimplify(m**3*kg**-1*s**-2).as_unit, factor=6.67384e-11, abbrev="G") # speed of light c = Constant(velocity, factor=299792458, abbrev="c") units = [m, g, s, J, N, W, Pa, Hz] all_units = [] # Prefixes of units like g, J, N etc get added using `prefix_unit` # in the for loop, but the actual units have to be added manually. all_units.extend([g, J, N, W, Pa, Hz]) for u in units: all_units.extend(prefix_unit(u, PREFIXES)) all_units.extend([v, a, p, G, c]) # unit system
# gram; used to define its prefixed units g = Unit(mass, abbrev="g") # derived units v = Unit(velocity) a = Unit(acceleration) p = Unit(momentum) J = Unit(energy, factor=10**3, abbrev="J") N = Unit(force, factor=10**3, abbrev="N") W = Unit(power, factor=10**3, abbrev="W") Pa = Unit(pressure, factor=10**3, abbrev="Pa") Hz = Unit(frequency, abbrev="Hz") # constants # Newton constant G = Constant(qsimplify(m**3 * kg**-1 * s**-2).as_unit, factor=6.67384e-11, abbrev="G") # speed of light c = Constant(velocity, factor=299792458, abbrev="c") units = [m, g, s, J, N, W, Pa, Hz] all_units = [] for u in units: all_units.extend(prefix_unit(u, PREFIXES)) all_units.extend([v, a, p, G, c]) # unit system mks = UnitSystem(base=(m, kg, s), units=all_units, name="MKS")