Пример #1
0
def calculateBlackHoleLifetimeOperator( measurement ):
    validUnitTypes = [
        [ 'mass' ],
        [ 'length' ],
        [ 'acceleration' ],
        [ 'area' ],
        [ 'temperature' ],
        [ 'power' ],
        [ 'tidal_force' ],
        [ 'time' ],
    ]

    arguments = matchUnitTypes( [ measurement ], validUnitTypes )

    if not arguments:
        raise ValueError( 'black_hole_lifetime: invalid argument' )

    mass = calculateBlackHoleMass( measurement )

    lifetime = divide( getProduct( [ getPower( mass, 3 ), 5120, pi,
                                     getPower( getConstant( 'newton_constant' ), 2 ) ] ),
                       getProduct( [ getConstant( 'reduced_planck_constant' ),
                                     getPower( getConstant( 'speed_of_light' ), 4 ) ] ) )

    return lifetime.convert( 'seconds' )
Пример #2
0
def calculateOrbitalRadiusOperator( measurement1, measurement2 ):
    '''
    To solve the radius of a circular orbit, we need Newton's gravitational
    constant and two of the following three items:

    G = Newton's gravitational constant

    m = planetary mass (i.e., mass of the thing being orbited)
    T = orbital period
    v = orbital velocity

    ---- radius in terms of period and mass
    r = cbrt( T^2*G*m/4*pi^2 )

    ---- radius in terms of velocity and mass
    r = G*m/v^2

    ---- radius in terms of velocity and period
    r = v*T/2*pi
    '''
    validUnitTypes = [
        [ 'mass', 'time' ],
        [ 'velocity', 'time' ],
        [ 'mass', 'velocity' ],
    ]

    arguments = matchUnitTypes( [ measurement1, measurement2 ], validUnitTypes )

    if not arguments:
        raise ValueError( '\'orbital_radius\' requires specific measurement types (see help)' )

    if 'mass' in arguments:
        mass = arguments[ 'mass' ]

        if 'time' in arguments:
            bPeriod = True
            period = arguments[ 'time' ]
        else:
            bPeriod = False
            velocity = arguments[ 'velocity' ]
    else:
        # period and velocity
        period = arguments[ 'time' ]
        velocity = arguments[ 'velocity' ]
        radius = divide( multiply( velocity, period ), fmul( 2, pi ) )
        return radius.convert( 'meter' )

    if bPeriod:
        # period and mass
        term = divide( getProduct( [ getPower( period, 2 ), getConstant( 'newton_constant' ), mass ] ),
                       fmul( 4, power( pi, 2 ) ) )
        radius = getRoot( term, 3 )
    else:
        # velocity and mass
        radius = divide( multiply( getConstant( 'newton_constant' ), mass ), getPower( velocity, 2 ) )

    return radius.convert( 'meter' )
Пример #3
0
def calculateOrbitalRadius( measurement1, measurement2 ):
    '''
    To solve the radius of a circular orbit, we need Newton's gravitational
    constant and two of the following three items:

    G = Newton's gravitational constant

    m = planetary mass (i.e., mass of the thing being orbited)
    T = orbital period
    v = orbital velocity

    ---- radius in terms of period and mass
    r = cbrt( T^2*G*m/4*pi^2 )

    ---- radius in terms of velocity and mass
    r = G*m/v^2

    ---- radius in terms of velocity and period
    r = v*T/2*pi
    '''
    validUnitTypes = [
        [ 'mass', 'time' ],
        [ 'velocity', 'time' ],
        [ 'mass', 'velocity' ],
    ]

    arguments = matchUnitTypes( [ measurement1, measurement2 ], validUnitTypes )

    if not arguments:
        raise ValueError( '\'orbital_radius\' requires specific measurement types (see help)' )

    if 'mass' in arguments:
        mass = arguments[ 'mass' ]

        if 'time' in arguments:
            bPeriod = True
            period = arguments[ 'time' ]
        else:
            bPeriod = False
            velocity = arguments[ 'velocity' ]
    else:
        # period and velocity
        period = arguments[ 'time' ]
        velocity = arguments[ 'velocity' ]
        radius = divide( multiply( velocity, period ), fmul( 2, pi ) )
        return radius.convert( 'meter' )

    if bPeriod:
        # period and mass
        term = divide( getProduct( [ getPower( period, 2 ), getConstant( 'newton_constant' ), mass ] ),
                       fmul( 4, power( pi, 2 ) ) )
        radius = getRoot( term, 3 )
    else:
        # velocity and mass
        radius = divide( multiply( getConstant( 'newton_constant' ), mass ), getPower( velocity, 2 ) )

    return radius.convert( 'meter' )
Пример #4
0
def calculateOrbitalPeriod( measurement1, measurement2 ):
    '''
    To solve the period of a circular orbit, we need Newton's gravitational
    constant and two of the following three items:

    G = Newton's gravitational constant

    m = planetary mass (i.e., mass of the thing being orbited)
    r = orbit radius (the distance from the center of mass)
    v = orbital velocity

    ---- period in terms of radius and mass
    T = 2*pi*sqrt( r^3/G*m )

    ---- period in terms of radius and velocity
    T = 2*pi*r/v

    ---- period in terms of mass and velocity
    T = 2*pi*G*m/v^3
    '''
    validUnitTypes = [
        [ 'mass', 'length' ],
        [ 'velocity', 'length' ],
        [ 'mass', 'velocity' ],
    ]

    arguments = matchUnitTypes( [ measurement1, measurement2 ], validUnitTypes )

    if not arguments:
        raise ValueError( '\'orbital_period\' requires specific measurement types (see help)' )

    if 'mass' in arguments:
        mass = arguments[ 'mass' ]

        if 'length' in arguments:
            bRadius = True
            radius = arguments[ 'length' ]
        else:
            bRadius = False
            velocity = arguments[ 'velocity' ]
    else:
        # radius and velocity
        radius = arguments[ 'length' ]
        velocity = arguments[ 'velocity' ]
        period = divide( getProduct( [ 2, pi, radius ] ), velocity )
        return period.convert( 'second' )

    if bRadius:
        # radius and mass
        term = divide( getPower( radius, 3 ), multiply( getConstant( 'newton_constant' ), mass ) )
        period = getProduct( [ 2, pi, getRoot( term, 2 ) ] )
    else:
        # velocity and mass
        period = divide( getProduct( [ 2, pi, getConstant( 'newton_constant' ), mass ] ),
                         getPower( velocity, 3 ) )

    return period.convert( 'second' )
Пример #5
0
def calculateOrbitalPeriodOperator( measurement1, measurement2 ):
    '''
    To solve the period of a circular orbit, we need Newton's gravitational
    constant and two of the following three items:

    G = Newton's gravitational constant

    m = planetary mass (i.e., mass of the thing being orbited)
    r = orbit radius (the distance from the center of mass)
    v = orbital velocity

    ---- period in terms of radius and mass
    T = 2*pi*sqrt( r^3/G*m )

    ---- period in terms of radius and velocity
    T = 2*pi*r/v

    ---- period in terms of mass and velocity
    T = 2*pi*G*m/v^3
    '''
    validUnitTypes = [
        [ 'mass', 'length' ],
        [ 'velocity', 'length' ],
        [ 'mass', 'velocity' ],
    ]

    arguments = matchUnitTypes( [ measurement1, measurement2 ], validUnitTypes )

    if not arguments:
        raise ValueError( '\'orbital_period\' requires specific measurement types (see help)' )

    if 'mass' in arguments:
        mass = arguments[ 'mass' ]

        if 'length' in arguments:
            bRadius = True
            radius = arguments[ 'length' ]
        else:
            bRadius = False
            velocity = arguments[ 'velocity' ]
    else:
        # radius and velocity
        radius = arguments[ 'length' ]
        velocity = arguments[ 'velocity' ]
        period = divide( getProduct( [ 2, pi, radius ] ), velocity )
        return period.convert( 'second' )

    if bRadius:
        # radius and mass
        term = divide( getPower( radius, 3 ), multiply( getConstant( 'newton_constant' ), mass ) )
        period = getProduct( [ 2, pi, getRoot( term, 2 ) ] )
    else:
        # velocity and mass
        period = divide( getProduct( [ 2, pi, getConstant( 'newton_constant' ), mass ] ),
                         getPower( velocity, 3 ) )

    return period.convert( 'second' )
Пример #6
0
def calculateBlackHoleMass( measurement ):
    validUnitTypes = [
        [ 'mass' ],
        [ 'length' ],
        [ 'acceleration' ],
        [ 'area' ],
        [ 'temperature' ],
        [ 'power' ],
        [ 'tidal_force' ],
        [ 'time' ],
    ]

    arguments = matchUnitTypes( [ measurement ], validUnitTypes )

    if not arguments:
        raise ValueError( 'black_hole_mass: invalid argument' )

    if 'mass' in arguments:
        return arguments[ 'mass' ].convert( 'kilogram' )
    elif 'length' in arguments:
        radius = arguments[ 'length' ]

        return divide( getProduct( [ getPower( getConstant( 'speed_of_light' ), 2 ), radius ] ),
                       getProduct( [ 2, getConstant( 'newton_constant' ) ] ) ).convert( 'kilogram' )
    elif 'acceleration' in arguments:
        gravity = arguments[ 'acceleration' ]

        return divide( getPower( getConstant( 'speed_of_light' ), 4 ),
                       getProduct( [ 4, getConstant( 'newton_constant' ), gravity ] ) ).convert( 'kilogram' )
    elif 'area' in arguments:
        area = arguments[ 'area' ].convert( 'meters^2' )

        return getRoot( divide( getProduct( [ getPower( getConstant( 'speed_of_light' ), 4 ), area ] ),
                                getProduct( [ 16, pi, getPower( getConstant( 'newton_constant' ), 2 ) ] ) ), 2 ).convert( 'kilogram' )
    elif 'temperature' in arguments:
        temperature = arguments[ 'temperature' ]

        return divide( getProduct( [ getConstant( 'reduced_planck_constant' ), getPower( getConstant( 'speed_of_light' ), 3 ) ] ),
                       getProduct( [ temperature, 8, getConstant( 'boltzmann_constant' ), pi, getConstant( 'newton_constant' ) ] ) ).convert( 'kilogram' )
    elif 'power' in arguments:
        luminosity = arguments[ 'power' ]

        return getRoot( divide( getProduct( [ getConstant( 'reduced_planck_constant' ), getPower( getConstant( 'speed_of_light' ), 6 ) ] ),
                                getProduct( [ luminosity.convert( 'kilogram*meter^2/second^3' ), 15360, pi,
                                     getPower( getConstant( 'newton_constant' ), 2 ) ] ) ), 2  ).convert( 'kilogram' )
    elif 'tidal_force' in arguments:
        tidal_force = arguments[ 'tidal_force' ]

        return getRoot( divide( getPower( getConstant( 'speed_of_light' ), 6 ),
                                getProduct( [ 4, tidal_force, getPower( getConstant( 'newton_constant' ), 2 ) ] ) ), 2 ).convert( 'kilogram' )
    elif 'time' in arguments:
        lifetime = arguments[ 'time' ]

        return getRoot( divide( getProduct( [ lifetime, getConstant( 'reduced_planck_constant' ), getPower( getConstant( 'speed_of_light' ), 4 ) ] ),
                                getProduct( [ 5120, pi, getPower( getConstant( 'newton_constant' ), 2 ) ] ) ), 3 ).convert( 'kilogram' )

    raise ValueError( 'invalid arguments to black hole operator' )
Пример #7
0
def getConeSurfaceArea( r, h ):
    if not isinstance( r, RPNMeasurement ):
        return getConeSurfaceArea( RPNMeasurement( real( r ), 'meter' ), h )

    if r.getDimensions( ) != { 'length' : 1 }:
        raise ValueError( '\'cone_area\' argument 1 must be a length' )

    if not isinstance( h, RPNMeasurement ):
        return getConeSurfaceArea( r, RPNMeasurement( real( h ), 'meter' ) )

    if h.getDimensions( ) != { 'length' : 1 }:
        raise ValueError( '\'cone_area\' argument 2 must be a length' )

    hypotenuse = getRoot( add( getPower( r, 2 ), getPower( h, 2 ) ), 2 )

    return getProduct( [ pi, r, add( r, hypotenuse ) ] )
Пример #8
0
def calculateBlackHoleTemperatureOperator( measurement ):
    validUnitTypes = [
        [ 'mass' ],
        [ 'length' ],
        [ 'acceleration' ],
        [ 'area' ],
        [ 'temperature' ],
        [ 'power' ],
        [ 'tidal_force' ],
        [ 'time' ],
    ]

    arguments = matchUnitTypes( [ measurement ], validUnitTypes )

    if not arguments:
        raise ValueError( 'black_hole_temperature: invalid argument' )

    mass = calculateBlackHoleMass( measurement )

    temperature = divide( getProduct( [ getConstant( 'reduced_planck_constant' ),
                                        getPower( getConstant( 'speed_of_light' ), 3 ) ] ),
                          getProduct( [ mass, 8, getConstant( 'boltzmann_constant' ), pi,
                                        getConstant( 'newton_constant' ) ] ) )

    return temperature.convert( 'kelvin' )
Пример #9
0
def getIcosahedronVolume( n ):
    if not isinstance( n, RPNMeasurement ):
        return getIcosahedronVolume( RPNMeasurement( real( n ), 'meter' ) )

    if n.getDimensions( ) != { 'length' : 1 }:
        raise ValueError( '\'icosahedron_volume\' argument must be a length' )

    return getProduct( [ fdiv( 5, 12 ), fadd( 3, sqrt( 5 ) ), getPower( n, 3 ) ] ).convert( 'meter^3' )
Пример #10
0
def getDodecahedronVolume( n ):
    if not isinstance( n, RPNMeasurement ):
        return getDodecahedronVolume( RPNMeasurement( real( n ), 'meter' ) )

    if n.getDimensions( ) != { 'length' : 1 }:
        raise ValueError( '\'dodecahedron_volume\' argument must be a length' )

    return divide( multiply( fadd( 15, fmul( 7, sqrt( 5 ) ) ), getPower( n, 3 ) ), 4 ).convert( 'meter^3' )
Пример #11
0
def getOctahedronVolume( n ):
    if not isinstance( n, RPNMeasurement ):
        return getOctahedronVolume( RPNMeasurement( real( n ), 'meter' ) )

    if n.getDimensions( ) != { 'length' : 1 }:
        raise ValueError( '\'octahedron_volume\' argument must be a length' )

    return divide( multiply( sqrt( 2 ), getPower( n, 3 ) ), 3 )
Пример #12
0
def getTetrahedronVolume( n ):
    if not isinstance( n, RPNMeasurement ):
        return getTetrahedronVolume( RPNMeasurement( real( n ), 'meter' ) )

    if n.getDimensions( ) != { 'length' : 1 }:
        raise ValueError( '\'tetrahedron_volume\' argument must be a length' )

    return divide( getPower( n, 3 ), fmul( 6, sqrt( 2 ) ) )
Пример #13
0
def getTetrahedronSurfaceArea( n ):
    if not isinstance( n, RPNMeasurement ):
        return getTetrahedronSurfaceArea( RPNMeasurement( real( n ), 'meter' ) )

    if n.getDimensions( ) != { 'length' : 1 }:
        raise ValueError( '\'tetrahedron_area\' argument must be a length' )

    return multiply( sqrt( 3 ), getPower( n, 2 ) )
Пример #14
0
def getIcosahedronSurfaceArea( n ):
    if not isinstance( n, RPNMeasurement ):
        return getIcosahedronSurfaceArea( RPNMeasurement( real( n ), 'meter' ) )

    if n.getDimensions( ) != { 'length' : 1 }:
        raise ValueError( '\'icosahedron_area\' argument must be a length' )

    return getProduct( [ 5, sqrt( 3 ), getPower( n, 2 ) ] ).convert( 'meter^2' )
Пример #15
0
def calculateTidalForce( mass, distance, delta ):
    mass.validateUnits( 'mass' )
    distance.validateUnits( 'length' )
    delta.validateUnits( 'length' )

    tidal_force = divide( getProduct( [ 2, getConstant( 'newton_constant' ), mass, delta ] ),
                          getPower( distance, 3 ) )

    return tidal_force.convert( 'meter/second^2' )
Пример #16
0
def calculateTidalForceOperator( mass, distance, delta ):
    mass.validateUnits( 'mass' )
    distance.validateUnits( 'length' )
    delta.validateUnits( 'length' )

    tidalForce = divide( getProduct( [ 2, getConstant( 'newton_constant' ), mass, delta ] ),
                         getPower( distance, 3 ) )

    return tidalForce.convert( 'meter/second^2' )
Пример #17
0
def getDodecahedronSurfaceArea( n ):
    if not isinstance( n, RPNMeasurement ):
        return getDodecahedronSurfaceArea( RPNMeasurement( real( n ), 'meter' ) )

    if n.getDimensions( ) != { 'length' : 1 }:
        raise ValueError( '\'dodecahedron_area\' argument must be a length' )

    area = getProduct( [ 3, getRoot( add( 25, fmul( 10, sqrt( 5 ) ) ), 2 ), getPower( n, 2 ) ] )
    return area.convert( 'meter^2' )
Пример #18
0
def getAntiprismSurfaceArea( n, k ):
    if real( n ) < 3:
        raise ValueError( 'the number of sides of the prism cannot be less than 3,' )

    if not isinstance( k, RPNMeasurement ):
        return getAntiprismSurfaceArea( n, RPNMeasurement( real( k ), 'meter' ) )

    if k.getDimensions( ) != { 'length' : 1 }:
        raise ValueError( '\'antiprism_area\' argument 2 must be a length' )

    result = getProduct( [ fdiv( n, 2 ), fadd( cot( fdiv( pi, n ) ), sqrt( 3 ) ), getPower( k, 2 ) ] )
    return result.convert( 'meter^2' )
Пример #19
0
def calculateVelocity( measurement1, measurement2 ):
    validUnitTypes = [
        [ 'length', 'time' ],
        [ 'acceleration', 'length' ],
        [ 'jerk', 'length' ],
        [ 'jounce', 'length' ],
        [ 'velocity', 'time' ],
        [ 'velocity', 'length' ],
        [ 'acceleration', 'time' ],
        [ 'jerk', 'time' ],
        [ 'jounce', 'time' ],
    ]

    arguments = matchUnitTypes( [ measurement1, measurement2 ], validUnitTypes )

    if 'velocity' in arguments:
        velocity = arguments[ 'velocity' ]
    elif 'length' in arguments:
        if 'time' in arguments:
            velocity = divide( arguments[ 'length' ], arguments[ 'time' ] )
        elif 'acceleration' in arguments:
            acceleration = arguments[ 'acceleration' ]
            time = getRoot( multiply( divide( arguments[ 'length' ], acceleration ), 2 ), 2 )
            velocity = multiply( acceleration, time )
        elif 'jerk' in arguments:
            jerk = arguments[ 'jerk' ]
            time = getRoot( multiply( divide( arguments[ 'length' ], jerk ), 6 ), 3 )
            velocity = getProduct( [ jerk, time, time, fdiv( 1, 2 ) ] )
        elif 'jounce' in arguments:
            jounce = arguments[ 'jounce' ]
            time = getRoot( multiply( divide( arguments[ 'length' ], jounce ), 24 ), 4 )
            velocity = getProduct( [ jounce, time, time, time, fdiv( 1, 6 ) ] )
    elif 'acceleration' in arguments:
        velocity = divide( multiply( arguments[ 'acceleration' ], arguments[ 'time' ] ), 2 )
    elif 'jerk' in arguments:
        velocity = divide( multiply( arguments[ 'jerk' ], getPower( arguments[ 'time' ], 2 ) ), 4 )
    elif 'jounce' in arguments:
        velocity = divide( multiply( arguments[ 'jounce' ], getPower( arguments[ 'time' ], 3 ) ), 8 )

    return velocity.convert( 'meter/second' )
Пример #20
0
def calculateVelocityOperator( measurement1, measurement2 ):
    validUnitTypes = [
        [ 'length', 'time' ],
        [ 'acceleration', 'length' ],
        [ 'jerk', 'length' ],
        [ 'jounce', 'length' ],
        [ 'velocity', 'time' ],
        [ 'velocity', 'length' ],
        [ 'acceleration', 'time' ],
        [ 'jerk', 'time' ],
        [ 'jounce', 'time' ],
    ]

    arguments = matchUnitTypes( [ measurement1, measurement2 ], validUnitTypes )

    if 'velocity' in arguments:
        velocity = arguments[ 'velocity' ]
    elif 'length' in arguments:
        if 'time' in arguments:
            velocity = divide( arguments[ 'length' ], arguments[ 'time' ] )
        elif 'acceleration' in arguments:
            acceleration = arguments[ 'acceleration' ]
            time = getRoot( multiply( divide( arguments[ 'length' ], acceleration ), 2 ), 2 )
            velocity = multiply( acceleration, time )
        elif 'jerk' in arguments:
            jerk = arguments[ 'jerk' ]
            time = getRoot( multiply( divide( arguments[ 'length' ], jerk ), 6 ), 3 )
            velocity = getProduct( [ jerk, time, time, fdiv( 1, 2 ) ] )
        elif 'jounce' in arguments:
            jounce = arguments[ 'jounce' ]
            time = getRoot( multiply( divide( arguments[ 'length' ], jounce ), 24 ), 4 )
            velocity = getProduct( [ jounce, time, time, time, fdiv( 1, 6 ) ] )
    elif 'acceleration' in arguments:
        velocity = divide( multiply( arguments[ 'acceleration' ], arguments[ 'time' ] ), 2 )
    elif 'jerk' in arguments:
        velocity = divide( multiply( arguments[ 'jerk' ], getPower( arguments[ 'time' ], 2 ) ), 4 )
    elif 'jounce' in arguments:
        velocity = divide( multiply( arguments[ 'jounce' ], getPower( arguments[ 'time' ], 3 ) ), 8 )

    return velocity.convert( 'meter/second' )
Пример #21
0
def calculateBlackHoleSurfaceArea( measurement ):
    validUnitTypes = [
        [ 'mass' ],
        [ 'length' ],
        [ 'acceleration' ],
        [ 'area' ],
        [ 'temperature' ],
        [ 'power' ],
        [ 'tidal_force' ],
        [ 'time' ],
    ]

    arguments = matchUnitTypes( [ measurement ], validUnitTypes )

    if not arguments:
        raise ValueError( 'black_hole_surface_area: invalid argument' )

    mass = calculateBlackHoleMass( measurement )

    area = divide( getProduct( [ 16, pi, getPower( getConstant( 'newton_constant' ), 2 ), getPower( mass, 2 ) ] ),
                   getPower( getConstant( 'speed_of_light' ), 4 ) )
    return area.convert( 'meter^2' )
Пример #22
0
def getRegularPolygonArea( n, k ):
    if real( n ) < 3:
        raise ValueError( 'the number of sides of the polygon cannot be less than 3,' )

    if not isinstance( k, RPNMeasurement ):
        return getRegularPolygonArea( n, RPNMeasurement( real( k ), 'meter' ) )

    dimensions = k.getDimensions( )

    if dimensions != { 'length' : 1 }:
        raise ValueError( '\'polygon_area\' argument 2 must be a length' )

    return multiply( fdiv( n, fmul( 4, tan( fdiv( pi, n ) ) ) ), getPower( k, 2 ) ).convert( 'meter^2' )
Пример #23
0
def calculateAccelerationOperator( measurement1, measurement2 ):
    validUnitTypes = [
        [ 'velocity', 'length' ],
        [ 'velocity', 'time' ],
        [ 'length', 'time' ],
        [ 'acceleration', 'time' ],
        [ 'acceleration', 'length' ],
    ]

    arguments = matchUnitTypes( [ measurement1, measurement2 ], validUnitTypes )

    if 'acceleration' in arguments:
        acceleration = arguments[ 'acceleration' ]
    elif 'velocity' in arguments:
        if 'length' in arguments:
            acceleration = divide( getPower( arguments[ 'velocity' ], 2 ), multiply( arguments[ 'length' ], 2 ) )
        else:
            acceleration = divide( arguments[ 'velocity' ], arguments[ 'time' ] )
    elif 'length' in arguments and 'time' in arguments:
        acceleration = multiply( 2, divide( arguments[ 'length' ], getPower( arguments[ 'time' ], 2 ) ) )

    return acceleration.convert( 'meter/second^2' )
Пример #24
0
def getAntiprismVolumeOperator(n, k):
    result = getProduct([
        fdiv(
            fprod([
                n,
                sqrt(fsub(fmul(4, cos(cos(fdiv(pi, fmul(n, 2))))), 1)),
                sin(fdiv(fmul(3, pi), fmul(2, n)))
            ]), fmul(12, sin(sin(fdiv(pi, n))))),
        sin(fdiv(fmul(3, pi), fmul(2, n))),
        getPower(k, 3)
    ])

    return result.convert('meter^3')
Пример #25
0
def calculateAcceleration( measurement1, measurement2 ):
    validUnitTypes = [
        [ 'velocity', 'length' ],
        [ 'velocity', 'time' ],
        [ 'length', 'time' ],
        [ 'acceleration', 'time' ],
        [ 'acceleration', 'length' ],
    ]

    arguments = matchUnitTypes( [ measurement1, measurement2 ], validUnitTypes )

    if 'acceleration' in arguments:
        acceleration = arguments[ 'acceleration' ]
    elif 'velocity' in arguments:
        if 'length' in arguments:
            acceleration = divide( getPower( arguments[ 'velocity' ], 2 ), multiply( arguments[ 'length' ], 2 ) )
        else:
            acceleration = divide( arguments[ 'velocity' ], arguments[ 'time' ] )
    elif 'length' in arguments and 'time' in arguments:
        acceleration = multiply( 2, divide( arguments[ 'length' ], getPower( arguments[ 'time' ], 2 ) ) )

    return acceleration.convert( 'meter/second^2' )
Пример #26
0
def calculateBlackHoleSurfaceAreaOperator( measurement ):
    validUnitTypes = [
        [ 'mass' ],
        [ 'length' ],
        [ 'acceleration' ],
        [ 'area' ],
        [ 'temperature' ],
        [ 'power' ],
        [ 'tidal_force' ],
        [ 'time' ],
    ]

    arguments = matchUnitTypes( [ measurement ], validUnitTypes )

    if not arguments:
        raise ValueError( 'black_hole_surface_area: invalid argument' )

    mass = calculateBlackHoleMass( measurement )

    area = divide( getProduct( [ 16, pi, getPower( getConstant( 'newton_constant' ), 2 ), getPower( mass, 2 ) ] ),
                   getPower( getConstant( 'speed_of_light' ), 4 ) )
    return area.convert( 'meter^2' )
Пример #27
0
def getConeVolume( r, h ):
    if not isinstance( r, RPNMeasurement ):
        return getConeVolume( RPNMeasurement( real( r ), 'meter' ), h )

    if r.getDimensions( ) != { 'length' : 1 }:
        raise ValueError( '\'cone_volume\' argument 1 must be a length' )

    if not isinstance( h, RPNMeasurement ):
        return getConeVolume( r, RPNMeasurement( real( h ), 'meter' ) )

    if h.getDimensions( ) != { 'length' : 1 }:
        raise ValueError( '\'cone_volume\' argument 2 must be a length' )

    return getProduct( [ pi, getPower( r, 2 ), divide( h, 3 ) ] )
Пример #28
0
def calculateBlackHoleSurfaceTidesOperator( measurement ):
    validUnitTypes = [
        [ 'mass' ],
        [ 'length' ],
        [ 'acceleration' ],
        [ 'area' ],
        [ 'temperature' ],
        [ 'power' ],
        [ 'tidal_force' ],
        [ 'time' ],
    ]

    arguments = matchUnitTypes( [ measurement ], validUnitTypes )

    if not arguments:
        raise ValueError( 'black_hole_surface_tides: invalid argument' )

    mass = calculateBlackHoleMass( measurement )

    tidalForce = divide( getPower( getConstant( 'speed_of_light' ), 6 ),
                         getProduct( [ 4, getPower( getConstant( 'newton_constant' ), 2 ), getPower( mass, 2 ) ] ) )

    return tidalForce.convert( '1/second^2' )
Пример #29
0
def getTorusVolume( R, s ):
    if not isinstance( R, RPNMeasurement ):
        return getTorusVolume( RPNMeasurement( real( R ), 'meter' ), s )

    if R.getDimensions( ) != { 'length' : 1 }:
        raise ValueError( '\'torus_volume\' argument 1 must be a length' )

    if not isinstance( s, RPNMeasurement ):
        return getTorusVolume( R, RPNMeasurement( real( s ), 'meter' ) )

    if s.getDimensions( ) != { 'length' : 1 }:
        raise ValueError( '\'torus_volume\' argument 2 must be a length' )

    return getProduct( [ 2, power( pi, 2 ), R, getPower( s, 2 ) ] )
Пример #30
0
def calculateBlackHoleLifetime( measurement ):
    validUnitTypes = [
        [ 'mass' ],
        [ 'length' ],
        [ 'acceleration' ],
        [ 'area' ],
        [ 'temperature' ],
        [ 'power' ],
        [ 'tidal_force' ],
        [ 'time' ],
    ]

    arguments = matchUnitTypes( [ measurement ], validUnitTypes )

    if not arguments:
        raise ValueError( 'black_hole_lifetime: invalid argument' )

    mass = calculateBlackHoleMass( measurement )

    lifetime = divide( getProduct( [ getPower( mass, 3 ), 5120, pi, getPower( getConstant( 'newton_constant' ), 2 ) ] ),
                       getProduct( [ getConstant( 'reduced_planck_constant' ), getPower( getConstant( 'speed_of_light' ), 4 ) ] ) )

    return lifetime.convert( 'seconds' )
Пример #31
0
def calculateSurfaceGravity( measurement1, measurement2 ):
    validUnitTypes = [
        [ 'mass', 'density' ],
        [ 'mass', 'length' ],
        [ 'mass', 'volume' ],
        [ 'density', 'length' ],
        [ 'density', 'volume' ],
    ]

    arguments = matchUnitTypes( [ measurement1, measurement2 ], validUnitTypes )

    if not arguments:
        raise ValueError( '\'surface_gravity\' requires length and mass measurements' )

    if 'mass' in arguments:
        mass = arguments[ 'mass' ]

        if 'length' in arguments:
            length = arguments[ 'length' ]
        elif 'density' in arguments:
            volume = divide( mass, arguments[ 'density' ] )
            length = getKSphereRadius( volume, 3 )
        else:
            length = getKSphereRadius( arguments[ 'volume' ], 3 )
    elif 'volume' in arguments:
        # density, volume
        volume = arguments[ 'volume' ]
        mass = multiply( arguments[ 'density' ], volume )
        length = getKSphereRadius( volume, 3 )
    else:
        # density, length
        length = arguments[ 'length' ]
        volume = getPower( length, 3 )
        mass = multiply( arguments[ 'density' ], volume )

    gravity = multiply( divide( mass, getPower( length, 2 ) ), getConstant( 'newton_constant' ) )
    return gravity.convert( 'meters/seconds^2' )
Пример #32
0
def calculateSurfaceGravityOperator( measurement1, measurement2 ):
    validUnitTypes = [
        [ 'mass', 'density' ],
        [ 'mass', 'length' ],
        [ 'mass', 'volume' ],
        [ 'density', 'length' ],
        [ 'density', 'volume' ],
    ]

    arguments = matchUnitTypes( [ measurement1, measurement2 ], validUnitTypes )

    if not arguments:
        raise ValueError( '\'surface_gravity\' requires length and mass measurements' )

    if 'mass' in arguments:
        mass = arguments[ 'mass' ]

        if 'length' in arguments:
            length = arguments[ 'length' ]
        elif 'density' in arguments:
            volume = divide( mass, arguments[ 'density' ] )
            length = getKSphereRadius( volume, 3 )
        else:
            length = getKSphereRadius( arguments[ 'volume' ], 3 )
    elif 'volume' in arguments:
        # density, volume
        volume = arguments[ 'volume' ]
        mass = multiply( arguments[ 'density' ], volume )
        length = getKSphereRadius( volume, 3 )
    else:
        # density, length
        length = arguments[ 'length' ]
        volume = getPower( length, 3 )
        mass = multiply( arguments[ 'density' ], volume )

    gravity = multiply( divide( mass, getPower( length, 2 ) ), getConstant( 'newton_constant' ) )
    return gravity.convert( 'meters/seconds^2' )
Пример #33
0
def getPrismVolume( n, k, h ):
    if real( n ) < 3:
        raise ValueError( 'the number of sides of the prism cannot be less than 3,' )

    if not isinstance( k, RPNMeasurement ):
        return getPrismVolume( n, RPNMeasurement( real( k ), 'meter' ), h )

    if not isinstance( h, RPNMeasurement ):
        return getPrismVolume( n, k, RPNMeasurement( real( h ), 'meter' ) )

    if k.getDimensions( ) != { 'length' : 1 }:
        raise ValueError( '\'prism_volume\' argument 2 must be a length' )

    if h.getDimensions( ) != { 'length' : 1 }:
        raise ValueError( '\'prism_volume\' argument 3 must be a length' )

    return getProduct( [ fdiv( n, 4 ), h, getPower( k, 2 ), cot( fdiv( pi, n ) ) ] ).convert( 'meter^3' )
Пример #34
0
def getAntiprismVolume( n, k ):
    if real( n ) < 3:
        raise ValueError( 'the number of sides of the prism cannot be less than 3,' )

    if not isinstance( k, RPNMeasurement ):
        return getAntiprismVolume( n, RPNMeasurement( real( k ), 'meter' ) )

    if k.getDimensions( ) != { 'length' : 1 }:
        raise ValueError( '\'antiprism_volume\' argument 2 must be a length' )

    result = getProduct( [ fdiv( fprod( [ n, sqrt( fsub( fmul( 4, cos( cos( fdiv( pi, fmul( n, 2 ) ) ) ) ), 1 ) ),
                                   sin( fdiv( fmul( 3, pi ), fmul( 2, n ) ) ) ] ),
                           fmul( 12, sin( sin( fdiv( pi, n ) ) ) ) ),
                           sin( fdiv( fmul( 3, pi ), fmul( 2, n ) ) ),
                           getPower( k, 3 ) ] )

    return result.convert( 'meter^3' )
Пример #35
0
def calculateBlackHoleSurfaceGravity( measurement ):
    validUnitTypes = [
        [ 'mass' ],
        [ 'length' ],
        [ 'acceleration' ],
        [ 'area' ],
        [ 'temperature' ],
        [ 'power' ],
        [ 'tidal_force' ],
        [ 'time' ],
    ]

    arguments = matchUnitTypes( [ measurement ], validUnitTypes )

    if not arguments:
        raise ValueError( 'black_hole_surface_gravity: invalid argument' )

    mass = calculateBlackHoleMass( measurement )

    gravity = divide( getPower( getConstant( 'speed_of_light' ), 4 ), getProduct( [ mass, 4, getConstant( 'newton_constant' ) ] ) )
    return gravity.convert( 'meter/second^2' )
Пример #36
0
def calculateBlackHoleRadius( measurement ):
    validUnitTypes = [
        [ 'mass' ],
        [ 'length' ],
        [ 'acceleration' ],
        [ 'area' ],
        [ 'temperature' ],
        [ 'power' ],
        [ 'tidal_force' ],
        [ 'time' ],
    ]

    arguments = matchUnitTypes( [ measurement ], validUnitTypes )

    if not arguments:
        raise ValueError( 'black_hole_radius: invalid argument' )

    mass = calculateBlackHoleMass( measurement )

    radius = getProduct( [ 2, getConstant( 'newton_constant' ), mass ] ).divide( getPower( getConstant( 'speed_of_light' ), 2 ) )
    return radius.convert( 'meter' )
Пример #37
0
def calculateBlackHoleRadiusOperator( measurement ):
    validUnitTypes = [
        [ 'mass' ],
        [ 'length' ],
        [ 'acceleration' ],
        [ 'area' ],
        [ 'temperature' ],
        [ 'power' ],
        [ 'tidal_force' ],
        [ 'time' ],
    ]

    arguments = matchUnitTypes( [ measurement ], validUnitTypes )

    if not arguments:
        raise ValueError( 'black_hole_radius: invalid argument' )

    mass = calculateBlackHoleMass( measurement )

    radius = getProduct( [ 2, getConstant( 'newton_constant' ), mass ] ). \
             divide( getPower( getConstant( 'speed_of_light' ), 2 ) )
    return radius.convert( 'meter' )
Пример #38
0
def calculateBlackHoleEntropy( measurement ):
    validUnitTypes = [
        [ 'mass' ],
        [ 'length' ],
        [ 'acceleration' ],
        [ 'area' ],
        [ 'temperature' ],
        [ 'power' ],
        [ 'tidal_force' ],
        [ 'time' ],
    ]

    arguments = matchUnitTypes( [ measurement ], validUnitTypes )

    if not arguments:
        raise ValueError( 'black_hole_entropy: invalid argument' )

    mass = calculateBlackHoleMass( measurement )

    entropy = divide( getProduct( [ getPower( mass, 2 ), 4, pi, getConstant( 'newton_constant' ) ] ),
                     getProduct( [ getConstant( 'reduced_planck_constant' ), getConstant( 'speed_of_light' ), getLog( 10.0 ) ] ) )

    return getConstant( 'boltzmann_constant' ).multiply( entropy ).convert( 'bit' )
Пример #39
0
def calculateBlackHoleTemperature( measurement ):
    validUnitTypes = [
        [ 'mass' ],
        [ 'length' ],
        [ 'acceleration' ],
        [ 'area' ],
        [ 'temperature' ],
        [ 'power' ],
        [ 'tidal_force' ],
        [ 'time' ],
    ]

    arguments = matchUnitTypes( [ measurement ], validUnitTypes )

    if not arguments:
        raise ValueError( 'black_hole_temperature: invalid argument' )

    mass = calculateBlackHoleMass( measurement )

    temperature = divide( getProduct( [ getConstant( 'reduced_planck_constant' ), getPower( getConstant( 'speed_of_light' ), 3 ) ] ),
                          getProduct( [ mass, 8, getConstant( 'boltzmann_constant' ), pi, getConstant( 'newton_constant' ) ] ) )

    return temperature.convert( 'kelvin' )
Пример #40
0
def calculateBlackHoleEntropyOperator( measurement ):
    validUnitTypes = [
        [ 'mass' ],
        [ 'length' ],
        [ 'acceleration' ],
        [ 'area' ],
        [ 'temperature' ],
        [ 'power' ],
        [ 'tidal_force' ],
        [ 'time' ],
    ]

    arguments = matchUnitTypes( [ measurement ], validUnitTypes )

    if not arguments:
        raise ValueError( 'black_hole_entropy: invalid argument' )

    mass = calculateBlackHoleMass( measurement )

    entropy = divide( getProduct( [ getPower( mass, 2 ), 4, pi, getConstant( 'newton_constant' ) ] ),
                      getProduct( [ getConstant( 'reduced_planck_constant' ),
                                    getConstant( 'speed_of_light' ), ln( 10.0 ) ] ) )

    return getConstant( 'boltzmann_constant' ).multiply( entropy ).convert( 'bit' )
Пример #41
0
def getOctahedronVolumeOperator(n):
    return divide(multiply(sqrt(2), getPower(n, 3)), 3)
Пример #42
0
def getRegularPolygonArea(n, k):
    return multiply(fdiv(n, fmul(4, tan(fdiv(pi, n)))),
                    getPower(k, 2)).convert('meter^2')
Пример #43
0
def getOctahedronSurfaceAreaOperator(n):
    return getProduct([2, sqrt(3), getPower(n, 2)])
Пример #44
0
def getTetrahedronVolumeOperator(n):
    return divide(getPower(n, 3), fmul(6, sqrt(2)))
Пример #45
0
def getStefanBoltzmannConstant( ):
    return getProduct( [ 4, getPower( pi, 5 ), getPower( g.k, 4 ) ] ).divide(
                   getProduct( [ 15, getPower( g.h, 3 ), getPower( g.c, 2 ) ] ) )
Пример #46
0
def getAntiprismSurfaceAreaOperator(n, k):
    result = getProduct(
        [fdiv(n, 2),
         fadd(cot(fdiv(pi, n)), sqrt(3)),
         getPower(k, 2)])
    return result.convert('meter^2')
Пример #47
0
def getIcosahedronSurfaceAreaOperator(n):
    return getProduct([5, sqrt(3), getPower(n, 2)]).convert('meter^2')
Пример #48
0
def getvonKlitzingConstant( ):
    return g.h.divide( getPower( g.e, 2 ) ).convert( 'ohm' )
Пример #49
0
def getPrismSurfaceAreaOperator(n, k, h):
    result = add(getProduct([fdiv(n, 2),
                             getPower(k, 2),
                             cot(fdiv(pi, n))]), getProduct([n, k, h]))
    return result.convert('meter^2')
Пример #50
0
def getStefanBoltzmannConstant( ):
    nSubA = RPNMeasurement( getConstant( 'avogadro_number' ), 'mole^-1' )

    return getProduct( [ 2, getPower( pi, 5 ), getPower( getConstant( 'molar_gas_constant' ), 4 ) ] ).divide(
        getProduct( [ 15, getPower( g.h, 3 ), getPower( g.c, 2 ),
                      getPower( nSubA, 4 ) ] ) )
Пример #51
0
def getDodecahedronSurfaceAreaOperator(n):
    area = getProduct(
        [3, getRoot(add(25, fmul(10, sqrt(5))), 2),
         getPower(n, 2)])
    return area.convert('meter^2')
Пример #52
0
def getConeSurfaceAreaOperator(radius, height):
    hypotenuse = getRoot(add(getPower(radius, 2), getPower(height, 2)), 2)
    return getProduct([pi, radius, add(radius, hypotenuse)])
Пример #53
0
def getDodecahedronVolumeOperator(n):
    return divide(multiply(fadd(15, fmul(7, sqrt(5))), getPower(n, 3)),
                  4).convert('meter^3')
Пример #54
0
def getConeVolumeOperator(radius, height):
    return getProduct([pi, getPower(radius, 2), divide(height, 3)])
Пример #55
0
def getIcosahedronVolumeOperator(n):
    return getProduct([fdiv(5, 12),
                       fadd(3, sqrt(5)),
                       getPower(n, 3)]).convert('meter^3')
Пример #56
0
def getTetrahedronSurfaceAreaOperator(n):
    return multiply(sqrt(3), getPower(n, 2))
Пример #57
0
def getvonKlitzingConstant( ):
    return g.h.divide( getPower( g.e, 2 ) ).convert( 'ohm' )
Пример #58
0
def getPlanckAcceleration( ):
    return getRoot( getPower( g.c, 7 ).divide( g.h_bar.multiply( g.G ) ), 2 )
Пример #59
0
def getPrismVolumeOperator(n, k, h):
    return getProduct([fdiv(n, 4), h,
                       getPower(k, 2),
                       cot(fdiv(pi, n))]).convert('meter^3')
Пример #60
0
def getTorusVolumeOperator(major, minor):
    return getProduct([2, power(pi, 2), major, getPower(minor, 2)])