Esempio n. 1
0
    def right_point(latitude, longitude, lat_point, lon_point):
        r = static_variable.radius / 6371.0
        delta_lon = abs(
            cmath.asin(cmath.sin(float(r)) / cmath.cos(float(latitude))))
        delta_lat = abs(
            cmath.asin(cmath.sin(float(r)) / cmath.cos(float(longitude))))

        # if DEBUG:
        # logging.debug("lat_point:"+str(lat_point)+" lon_point:"+str(lon_point))

        min_lat = float(latitude) - delta_lat.real
        max_lat = float(latitude) + delta_lat.real
        min_lon = float(longitude) - delta_lon.real
        max_lon = float(longitude) + delta_lon.real

        # if DEBUG:
        # logging.debug("min_lat:"+str(min_lat)+" min_lon:"+str(min_lon)+
        # " max_lat:"+str(max_lat)+" max_lon:"+str(max_lon))

        if (float(min_lat) <= float(lat_point) <= float(max_lat)) and (
                float(min_lon) <= float(lon_point) <= float(max_lon)):
            # if DEBUG:
            #     logging.debug("Inside the IF")
            return True
        else:
            return False
Esempio n. 2
0
 def asin(self, x) -> complex:
     """
     Returns the asin of the input, handles output in radians and degrees.
     """
     if self.use_radians:
         return cmath.asin(x)
     else:
         return degrees(cmath.asin(x))
Esempio n. 3
0
def test_complex_inverse_functions():
    mp.dps = 15
    iv.dps = 15
    for (z1, z2) in random_complexes(30):
        # apparently cmath uses a different branch, so we
        # can't use it for comparison
        assert sinh(asinh(z1)).ae(z1)
        #
        assert acosh(z1).ae(cmath.acosh(z1))
        assert atanh(z1).ae(cmath.atanh(z1))
        assert atan(z1).ae(cmath.atan(z1))
        # the reason we set a big eps here is that the cmath
        # functions are inaccurate
        assert asin(z1).ae(cmath.asin(z1), rel_eps=1e-12)
        assert acos(z1).ae(cmath.acos(z1), rel_eps=1e-12)
        one = mpf(1)
    for i in range(-9, 10, 3):
        for k in range(-9, 10, 3):
            a = 0.9 * j * 10**k + 0.8 * one * 10**i
            b = cos(acos(a))
            assert b.ae(a)
            b = sin(asin(a))
            assert b.ae(a)
    one = mpf(1)
    err = 2 * 10**-15
    for i in range(-9, 9, 3):
        for k in range(-9, 9, 3):
            a = -0.9 * 10**k + j * 0.8 * one * 10**i
            b = cosh(acosh(a))
            assert b.ae(a, err)
            b = sinh(asinh(a))
            assert b.ae(a, err)
Esempio n. 4
0
def test_complex_inverse_functions():
    mp.dps = 15
    iv.dps = 15
    for (z1, z2) in random_complexes(30):
        # apparently cmath uses a different branch, so we
        # can't use it for comparison
        assert sinh(asinh(z1)).ae(z1)
        #
        assert acosh(z1).ae(cmath.acosh(z1))
        assert atanh(z1).ae(cmath.atanh(z1))
        assert atan(z1).ae(cmath.atan(z1))
        # the reason we set a big eps here is that the cmath
        # functions are inaccurate
        assert asin(z1).ae(cmath.asin(z1), rel_eps=1e-12)
        assert acos(z1).ae(cmath.acos(z1), rel_eps=1e-12)
        one = mpf(1)
    for i in range(-9, 10, 3):
        for k in range(-9, 10, 3):
            a = 0.9*j*10**k + 0.8*one*10**i
            b = cos(acos(a))
            assert b.ae(a)
            b = sin(asin(a))
            assert b.ae(a)
    one = mpf(1)
    err = 2*10**-15
    for i in range(-9, 9, 3):
        for k in range(-9, 9, 3):
            a = -0.9*10**k + j*0.8*one*10**i
            b = cosh(acosh(a))
            assert b.ae(a, err)
            b = sinh(asinh(a))
            assert b.ae(a, err)
Esempio n. 5
0
def LWTDWS(alpha, c, cg, c0, H):
    alpha0 = None
    H0 = None
    errorMsg = None

    deg2rad = math.pi / 180.0

    arg = (c0 / c) * cmath.sin(alpha * deg2rad)
    if ComplexUtil.greaterThanEqual(arg, 1):
        errorMsg = "Error: Violation of assumptions for Snells Law"
        return alpha0, H0, errorMsg

    alpha0 = (cmath.asin(arg)) / deg2rad

    ksf = cmath.sqrt(c0 / (2 * cg))  # shoaling coefficient

    alphaCos = cmath.cos(alpha0 * deg2rad) / cmath.cos(alpha * deg2rad)
    if ComplexUtil.lessThan(alphaCos, 0):
        errorMsg = "Error: Alpha1 data out of range"
        return alpha0, H0, errorMsg

    krf = cmath.sqrt(alphaCos)  # refraction coefficient

    H0 = H / (ksf * krf)

    return alpha0, H0, errorMsg
Esempio n. 6
0
def brewster_angle(eps1, eps2):
    """
    :param eps1: permittivity in medium 1
    :param eps2: permittivity in medium 2
    :return: brewster angle between incident wave and normal to the surface in degrees
    """
    return 90 - cm.asin(1 / cm.sqrt(eps2 / eps1 + 1)) * 180 / cm.pi
Esempio n. 7
0
 def tmatrix_method(self, i_wave, ang, nkindex):
     #input arg:  index of wave,     current angle,     material index (n, k)
     #output arg:  T matrix for s polarization, T matrix for p polarization, angles in different layer
     length = len(nkindex)
     TS = []
     TP = []
     layer_num = 0
     thetai = np.deg2rad(ang)
     thetaList = []
     while layer_num < length - 1:
         # print 'indexlist', self.indexlist
         # print 'layernumber', layer_num, 'count', count
         n1 = nkindex[layer_num][i_wave]
         n2 = nkindex[layer_num + 1][i_wave]
         thetat = np.conj(cmath.asin(n1 / n2 * np.sin(thetai)))  # Snell's law
         thetaList.append(thetat)  # for theta in P matrix
         ts = 2 * n1 * np.conj(cmath.cos(thetai)) / \
              (n1 * np.conj(cmath.cos(thetai)) + n2 * np.conj(cmath.cos(thetat)))
         tp = 2 * n1 * np.conj(cmath.cos(thetai)) / \
              (n1 * np.conj(cmath.cos(thetat)) + n2 * np.conj(cmath.cos(thetai)))
         rs = (n1 * np.conj(cmath.cos(thetai)) - n2 * np.conj(cmath.cos(thetat))) / \
              (n1 * np.conj(cmath.cos(thetai)) + n2 * np.conj(cmath.cos(thetat)))
         rp = (n2 * np.conj(cmath.cos(thetai)) - n1 * np.conj(cmath.cos(thetat))) / \
              (n1 * np.conj(cmath.cos(thetat)) + n2 * np.conj(cmath.cos(thetai)))
         thetai = thetat  # update theta for next interface
         TS.append([[1 / ts, rs / ts], [rs / ts, 1 / ts]])
         TP.append([[1 / tp, rp / tp], [rp / tp, 1 / tp]])
         layer_num += 1
     return TS, TP, thetaList
Esempio n. 8
0
 def from_pixel(self, lat, lng, zoom):
     lat = 2 * PI * (1 - lat / (128 << zoom))
     lat = cmath.exp(lat)
     lat = (lat - 1) / (lat + 1)
     self.lat = (cmath.asin(lat) * 180 / PI).real
     self.lng = lng * 360.0 / (256 << zoom) - 180.0
     return self
Esempio n. 9
0
def test09_trig():
    for i in range(-5, 5):
        for j in range(-5, 5):
            a = ek.sin(C(i, j))
            b = C(cmath.sin(complex(i, j)))
            assert ek.allclose(a, b)

            a = ek.cos(C(i, j))
            b = C(cmath.cos(complex(i, j)))
            assert ek.allclose(a, b)

            sa, ca = ek.sincos(C(i, j))
            sb = C(cmath.sin(complex(i, j)))
            cb = C(cmath.cos(complex(i, j)))
            assert ek.allclose(sa, sb)
            assert ek.allclose(ca, cb)

            # Python appears to handle the branch cuts
            # differently from Enoki, C, and Mathematica..
            a = ek.asin(C(i, j + 0.1))
            b = C(cmath.asin(complex(i, j + 0.1)))
            assert ek.allclose(a, b)

            a = ek.acos(C(i, j + 0.1))
            b = C(cmath.acos(complex(i, j + 0.1)))
            assert ek.allclose(a, b)

            if abs(j) != 1 or i != 0:
                a = ek.atan(C(i, j))
                b = C(cmath.atan(complex(i, j)))
                assert ek.allclose(a, b, atol=1e-7)
Esempio n. 10
0
 def __init__(self, eps1, mu1, eps2, mu2, E0p, E0s, dist, lambd, theta, diam_part, indice_rifr):
     
     self.eps1 = eps1
     self.mu1 = mu1
     self.eps2 = eps2
     self.mu2 = mu2
     
     self.n1 = np.sqrt(eps1*mu1)
     self.n2 = np.sqrt(eps2*mu2)
     self.dist = dist
     self.gamma = asin(self.n1/self.n2*sin(theta))
     alpha = -np.imag(self.gamma)
     self.k = 2*pi/lambd
     exp_ = np.exp(-self.k*dist*sinh(alpha))
     
     self.Es = E0s*2*(mu2/mu1)*cos(theta)/((mu2/mu1)*cos(theta)+1j*(self.n2/self.n1)*sinh(alpha))*exp_
     self.Ep = E0p*2*(self.n2/self.n1)*cos(theta)/((eps2/eps1)*cos(theta)+1j*(self.n2/self.n1)*sinh(alpha))*exp_
     
     self.indice_rifr = indice_rifr
     self.size_param = self.k*diam_part/2
     self.raggio = diam_part / 2;
     
     an, bn = ms.Mie_ab(self.indice_rifr, self.size_param)
     self.an = an
     self.bn = bn
Esempio n. 11
0
def op_asin(x):
    """Returns the inverse sine of this mathematical object."""
    if isinstance(x, list):
        return [op_asin(a) for a in x]
    elif isinstance(x, complex):
        return cmath.asin(x)
    else:
        return math.asin(x)
Esempio n. 12
0
    def test_complex_asin(self):
        raise unittest.SkipTest("Implement complex math")

        @jit
        def f(x):
            return mathlib.asin(x)

        self.assertAlmostEqual(f(0.9+05.j), cmath.asin(0.9+0.5j))
Esempio n. 13
0
 def __init__(self, nc0, nc1, theta0, wsuc, spessore):
     
     self.nc0=nc0
     self.nc1=nc1
     self.theta0=theta0
     self.wsuc=wsuc
     self.spessore=spessore
     self.theta1 = cmath.asin( nc0*cmath.sin(theta0)/nc1 )
def haversine(lon1, lat1, lon2, lat2):
    lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])

    dlon = lon2 - lon1
    dlat = lat2 - lat1
    a = sin(dlat / 2)**2 + cos(lat1) * cos(lat2) * sin(dlon / 2)**2
    c = 2 * asin(sqrt(a))
    r = 6371
    return c * r
Esempio n. 15
0
 def __calc_distance(self, longitude, latitude):
     earth_radius = 6371000
     diff_lon = (longitude - float(str(self.__longitude))) * (pi / 180)
     diff_lat = (latitude - float(str(self.__latitude))) * (pi / 180)
     a = sin(diff_lat / 2) * sin(diff_lat / 2) + cos(float(str(self.__latitude)) * (pi / 180)) * cos(
         latitude * (pi / 180)) * sin(diff_lon / 2) * sin(diff_lon / 2)
     b = 2 * asin(sqrt(a))
     distance = earth_radius * b
     return distance.real
def asin(x):
    import math,cmath
    try:
        if deg_rad_var.get()==1:
            return math.asin(x)
        else:
            return math.degrees(math.asin(x))
    except:
        return cmath.asin(x)
Esempio n. 17
0
def angle_distribution(lamda, ns, ds, theta_init=0, linit=0):
    N = len(ds) - 1  # number of interfaces
    thetai = np.zeros(N + 1) + 0j
    thetai[linit] = theta_init
    ns_new = transform_ns(lamda, ns)
    for i in range(N - linit):
        nl = ns_new[i + linit]  # refractive index on the left of interface
        nr = ns_new[i + 1 +
                    linit]  # refractive index on the right of interface
        thetai[i + linit + 1] = cmath.asin(nl * np.sin(thetai[i + linit]) / nr)

    for i in range(linit):
        nl = ns_new[linit - i]  # refractive index on the left of interface
        nr = ns_new[linit - i -
                    1]  # refractive index on the right of interface
        thetai[linit - i - 1] = cmath.asin(nl * np.sin(thetai[i + linit]) / nr)

    return thetai
Esempio n. 18
0
 def diff_eq_solution_ratio(s):
     a_m1 = 1 - alpha * (self.k0 * self.dz_m)**2 * (s - beta)
     a_1 = 1 - alpha * (self.k0 * self.dz_m)**2 * (s - beta)
     c = -2 + (2 * alpha - 1) * (self.k0 * self.dz_m)**2 * (s - beta)
     mu = sqr_eq(a_1, c, a_m1)
     theta = cm.asin(
         1 / (1j * self.k0 * self.dz_m) * cm.log(mu)) / cm.pi * 180
     refl_coef = refl_coef_func(theta, -s * self.k0**2)
     return (1 / mu + refl_coef * mu) / (1 + refl_coef)
Esempio n. 19
0
def p_sine(t):
    '''e : SINE LP e RP
         | COSINE LP e RP
         | SECANT LP e RP
         | COSECANT LP e RP
         | TANGENT LP e RP
         | COTANGENT LP e RP
         | LOG LP e COMMA e RP
         | LN LP e RP
         | EXP POW LP e RP
         | ARCSINE LP e RP
         | ARCCOSINE LP e RP
         | ARCTANGENT LP e RP
         | SINEH LP e RP
         | COSINEH LP e RP
         | TANGENTH LP e RP
         | ARCSINEH LP e RP
         | ARCCOSINEH LP e RP
         | ARCTANGENTH LP e RP
    '''
    if t[1] == 'sin':
        t[0] = cmath.sin(t[3])
    elif t[1] == 'cos':
        t[0] = cmath.cos(t[3])
    elif t[1] == 'sec':
        t[0] = 1/cmath.cos(t[3])
    elif t[1] == 'cosec':
        t[0] = 1/cmath.sin(t[3])
    elif t[1] == 'tan':
        t[0] = cmath.tan(t[3])
    elif t[1] == 'cot':
        t[0] = 1/cmath.tan(t[3])
    elif t[1] == 'log':
        t[0] = cmath.log(t[3], t[5])
    elif t[1] == 'ln':
        t[0] = cmath.log(t[3], cmath.e)
    elif t[1] == 'e':
        t[0] = cmath.exp(t[4])
    elif t[1] == 'asin':
        t[0] = cmath.asin(t[3])
    elif t[1] == 'acos':
        t[0] = cmath.acos(t[3])
    elif t[1] == 'atan':
        t[0] = cmath.atan(t[3])
    elif t[1] == 'sinh':
        t[0] = cmath.sinh(t[3])
    elif t[1] == 'cosh':
        t[0] = cmath.cosh(t[3])
    elif t[1] == 'tanh':
        t[0] = cmath.tanh(t[3])
    elif t[1] == 'asinh':
        t[0] = cmath.asinh(t[3])
    elif t[1] == 'acosh':
        t[0] = cmath.acosh(t[3])
    elif t[1] == 'atanh':
        t[0] = cmath.atanh(t[3])
Esempio n. 20
0
def asin(*args, **kw):
    arg0 = args[0]
    if isinstance(arg0, (int, float, long)):
        return _math.asin(*args,**kw)
    elif isinstance(arg0, complex):
        return _cmath.asin(*args,**kw)
    elif isinstance(arg0, _sympy.Basic):
        return _sympy.asin(*args,**kw)
    else:
        return _numpy.asin(*args,**kw)
Esempio n. 21
0
def asin(*args, **kw):
    arg0 = args[0]
    if isinstance(arg0, (int, float, long)):
        return _math.asin(*args,**kw)
    elif isinstance(arg0, complex):
        return _cmath.asin(*args,**kw)
    elif isinstance(arg0, _sympy.Basic):
        return _sympy.asin(*args,**kw)
    else:
        return _numpy.arcsin(*args,**kw)
Esempio n. 22
0
def t(angle, ilayer, layer):
    # ilayer should always be 1
    if (ilayer == layer):
        return angle
    else:
        n1 = getN(ilayer)
        n2 = getN(ilayer + 1)
        sintheta = n1 * (cmath.sin(angle) / n2)
        angle = cmath.asin(sintheta)
        return t(angle, ilayer + 1, layer)
Esempio n. 23
0
def transmitted_k(k, normal, n1, n2):
    alpha = angle_between(k, normal)
    beta = cmath.asin((n1 / n2) * np.sin(alpha)).real
    if n1 > n2:
        beta = -beta
    if np.abs(beta) < np.pi / 2:
        transmitted = rotate_vector(normal, beta)
    else:
        transmitted = np.array([np.NaN, np.NaN])
    return transmitted
Esempio n. 24
0
def fromCartToPol(x,y,z):

    r = np.sqrt(x**2+y**2+z**2)
    if x!=0 and y!=0:
        phi = acos(x/np.sqrt(x**2+y**2))
        theta = asin(np.sqrt(x**2+y**2)/np.sqrt(x**2+y**2+z**2))
    else:
        phi = 1e-15;
        theta = 1e-15;

    return theta, phi, r
Esempio n. 25
0
def asin(y):
  """Compute ArcSin
    >>> from pol import *
    >>> x,y=mkpol('x,y')
    >>> asin(sin(.4+x+y))
    0.4 + x + y
  """
  x0=pol(math.asin(y.zero()))
  for i in range(y.order):
    x0=x0 + (y-sin(x0))/cos(x0)
  return x0
Esempio n. 26
0
def ASIN(df, price='Close'):
    """
    Arc Sine
    """
    asin_list = []
    i = 0
    while i < len(df[price]):
        asin = cmath.asin(df[price][i]).real
        asin_list.append(asin)
        i += 1
    return asin_list
def thetaphi(complexAlpha):
    phi = cmath.acos(complexAlpha[2])
    theta = complex(pi_2)
    sinphi = np.sin(phi)

    if sinphi != 0:
        sintheta = complexAlpha[1] / sinphi
        theta = cmath.asin(sintheta)
        if complexAlpha[0] / sinphi < 0:  # cos(t)<0
            theta = np.pi - theta

    return theta, phi
Esempio n. 28
0
def asin(z):
    """ An AlComplex compatible arcsine function. It gets the main value.

        Parameters
        ----------
        z : Python numeric type or AlComplex

        Returns
        -------
        AlComplex
    """
    return AlComplex.from_python_complex(cm.asin(z.to_python_complex()))
Esempio n. 29
0
def _fresneln(t0, wl, layers):
    """
    
    Determine the transmission and reflection coefficients of 
    fresnel coefficients of a multilayer for two or
    more interfaces.

    Arguments:
    t0: incident angle (in radians or degrees if deg=True)
    wl: wavelength (same units as thickness)
    layers: list [(n, k), (n, k, thickness),..., (n, k)]
    
    It returns the tuple (rp, rs, tp, ts) with the reflection
    and transmission Fresnel coefficients for the p and s
    polarizations.
    
    """

    N0 = makeindex(layers[0][0], layers[0][1])
    NS = makeindex(layers[-1][0], layers[-1][1])
    layers = layers[1:-1]

    mlp = []
    mls = []
    Nold = N0
    told = t0
    for layer in layers:
        Nnew = makeindex(layer[0], layer[1])
        mp, ms = _matinterface(Nold, Nnew, told)
        tnew = cm.asin(Nold * cm.sin(told) / Nnew)
        dnorm = layer[2] / wl * cm.cos(tnew)
        ml = _matlayer(Nnew, dnorm)
        mlp.append(mp)
        mls.append(ms)
        mlp.append(ml)
        mls.append(ml)
        Nold = Nnew
        told = tnew

    mp, ms = _matinterface(Nold, NS, told)
    mlp.append(mp)
    mls.append(ms)

    mp = _nmatmult(mlp)
    ms = _nmatmult(mls)

    rp = mp[2] / mp[0]
    rs = ms[2] / ms[0]
    tp = 1. / mp[0]
    ts = 1. / ms[0]

    return rp, rs, tp, ts
Esempio n. 30
0
def _fresneln(t0, wl, layers):
    """
    
    Determine the transmission and reflection coefficients of 
    fresnel coefficients of a multilayer for two or
    more interfaces.

    Arguments:
    t0: incident angle (in radians or degrees if deg=True)
    wl: wavelength (same units as thickness)
    layers: list [(n, k), (n, k, thickness),..., (n, k)]
    
    It returns the tuple (rp, rs, tp, ts) with the reflection
    and transmission Fresnel coefficients for the p and s
    polarizations.
    
    """

    N0 = makeindex(layers[0][0], layers[0][1])
    NS = makeindex(layers[-1][0], layers[-1][1])
    layers = layers[1:-1]
    
    mlp = []
    mls = []
    Nold = N0
    told = t0
    for layer in layers:
        Nnew = makeindex(layer[0], layer[1])
        mp, ms = _matinterface(Nold, Nnew, told)
        tnew = cm.asin(Nold*cm.sin(told)/Nnew)
        dnorm = layer[2]/wl*cm.cos(tnew)
        ml = _matlayer(Nnew, dnorm)
        mlp.append(mp)
        mls.append(ms)
        mlp.append(ml)
        mls.append(ml)
        Nold = Nnew
        told = tnew

    mp, ms = _matinterface(Nold, NS, told)
    mlp.append(mp)
    mls.append(ms)

    mp = _nmatmult(mlp)
    ms = _nmatmult(mls)

    rp = mp[2]/mp[0]
    rs = ms[2]/ms[0]
    tp = 1./mp[0]
    ts = 1./ms[0]

    return rp, rs, tp, ts
Esempio n. 31
0
def oneArgFuncEval(function, value):
        # Evaluates functions that take a complex number input
        if function == "sin":
                return cmath.sin(value)
        elif function == "cos":
                return cmath.cos(value)
        elif function == "tan":
                return cmath.tan(value)
        elif function == "asin":
                return cmath.asin(value)
        elif function == "acos":
                return cmath.acos(value)
        elif function == "atan":
                return cmath.atan(value)
        elif function == "csc":
                return 1.0 / cmath.sin(value)
        elif function == "sec":
                return 1.0 / cmath.cos(value)
        elif function == "cot":
                return 1.0 / cmath.tan(value)        
        elif function == "ln":
                return cmath.log(value)
        elif function == "sqr":
                return cmath.sqrt(value)
        elif function == "abs":
                return cmath.sqrt((value.real ** 2) + (value.imag ** 2))
        elif function == "exp":
                return cmath.exp(value)
        if function == "sinh":
                return cmath.sinh(value)
        elif function == "cosh":
                return cmath.cosh(value)
        elif function == "tanh":
                return cmath.tanh(value)
        elif function == "asinh":
                return cmath.asinh(value)
        elif function == "acosh":
                return cmath.acosh(value)
        elif function == "atanh":
                return cmath.atanh(value)
        elif function == "ceil":
                return math.ceil(value.real) + complex(0, 1) * math.ceil(value.imag)
        elif function == "floor":
                return math.floor(value.real) + complex(0, 1) * math.floor(value.imag)
        elif function == "trunc":
                return math.trunc(value.real) + complex(0, 1) * math.trunc(value.imag)
        elif function == "fac":
                if value.imag == 0 and value < 0 and value.real == int(value.real):
                        return "Error: The factorial function is not defined on the negative integers."
                return gamma(value + 1)
        elif function == "log":
                return cmath.log10(value)
Esempio n. 32
0
    def execute_pcode(self, z):
        def pop2():
            return stack.pop(), stack.pop()

        pc = 0
        stack = []

        while pc < self.pc:
            c = self.code[pc]
            if c == SPUSHC:
                stack.append(self.const_tab[self.code[pc + 1]])
                pc += 1
            elif c == SPUSHZ:
                stack.append(z)
            elif c == SADD:
                z1, z0 = pop2()
                stack.append(z0 + z1)
            elif c == SSUB:
                z1, z0 = pop2()
                stack.append(z0 - z1)
            elif c == SMUL:
                z1, z0 = pop2()
                stack.append(z0 * z1)
            elif c == SDIV:
                z1, z0 = pop2()
                stack.append(z0 / z1)
            elif c == SPOW:
                z1, z0 = pop2()
                stack.append(z0**z1)
            elif c == SNEG:
                stack[-1] = -stack[-1]
            elif c == SSIN:
                stack[-1] = sin(stack[-1])
            elif c == SCOS:
                stack[-1] = cos(stack[-1])
            elif c == STAN:
                stack[-1] = tan(stack[-1])
            if c == SASIN:
                stack[-1] = asin(stack[-1])
            elif c == SACOS:
                stack[-1] = acos(stack[-1])
            elif c == SATAN:
                stack[-1] = atan(stack[-1])
            elif c == SLOG:
                stack[-1] = log(stack[-1])
            elif c == SEXP:
                stack[-1] = exp(stack[-1])
            elif c == SEND:
                break

            pc += 1
        return stack[0]
Esempio n. 33
0
def oneArgFuncEval(function, value):
    # Evaluates functions that take a complex number input
    if function == "sin":
        return cmath.sin(value)
    elif function == "cos":
        return cmath.cos(value)
    elif function == "tan":
        return cmath.tan(value)
    elif function == "asin":
        return cmath.asin(value)
    elif function == "acos":
        return cmath.acos(value)
    elif function == "atan":
        return cmath.atan(value)
    elif function == "csc":
        return 1.0 / cmath.sin(value)
    elif function == "sec":
        return 1.0 / cmath.cos(value)
    elif function == "cot":
        return 1.0 / cmath.tan(value)
    elif function == "ln":
        return cmath.log(value)
    elif function == "sqr":
        return cmath.sqrt(value)
    elif function == "abs":
        return cmath.sqrt((value.real**2) + (value.imag**2))
    elif function == "exp":
        return cmath.exp(value)
    if function == "sinh":
        return cmath.sinh(value)
    elif function == "cosh":
        return cmath.cosh(value)
    elif function == "tanh":
        return cmath.tanh(value)
    elif function == "asinh":
        return cmath.asinh(value)
    elif function == "acosh":
        return cmath.acosh(value)
    elif function == "atanh":
        return cmath.atanh(value)
    elif function == "ceil":
        return math.ceil(value.real) + complex(0, 1) * math.ceil(value.imag)
    elif function == "floor":
        return math.floor(value.real) + complex(0, 1) * math.floor(value.imag)
    elif function == "trunc":
        return math.trunc(value.real) + complex(0, 1) * math.trunc(value.imag)
    elif function == "fac":
        if value.imag == 0 and value < 0 and value.real == int(value.real):
            return "Error: The factorial function is not defined on the negative integers."
        return gamma(value + 1)
    elif function == "log":
        return cmath.log10(value)
Esempio n. 34
0
def LWTTWS(alpha0, c, cg, c0, H0):

    deg2rad = math.pi / 180

    arg = (c / c0) * cmath.sin(alpha0 * deg2rad)
    alpha = (cmath.asin(arg)) / deg2rad

    ksf = cmath.sqrt(c0 / (2 * cg))
    krf = cmath.sqrt(cmath.cos(alpha0 * deg2rad) / cmath.cos(alpha * deg2rad))

    H = H0 * ksf * krf

    return alpha, H, krf, ksf
Esempio n. 35
0
def gendib(tree, height, mdib):
    """gendib takes a commercial tree entry and determines the diameter inside bark at a given height.
    PICO equation taken from the corrected Garber and Maguire 2002, all others from Hann 2016."""
    if tree[9] != 5:
        cs = tree[9]
        pdib = (mdib[cs][0] * (tree[1]**mdib[cs][1])) * cmath.exp(
            (mdib[cs][2]) * ((1 - tree[4])**0.5))
        hd = (tree[2] - 4.5) / tree[1]
        height = height - 4.5
        rh = height / (tree[2] - 4.5)
        wlt = (mdib[cs][7] * tree[11] - 4.5) / (tree[2] - 4.5)
        i1 = 0
        i2 = 0
        if rh >= 0 and wlt >= rh:
            i1 = 0
        if wlt < rh and rh <= 1:
            i1 = 1
        if wlt <= 0:
            i2 = 0
        if wlt > 0:
            i2 = 1
        jp1 = (rh - 1) / (wlt - 1)
        jp2 = (wlt - rh) / (wlt - 1)
        x1 = mdib[cs][3] + (mdib[cs][4] * cmath.exp(mdib[cs][5] * (hd**2)))
        x2 = mdib[cs][6]
        z0 = 1.0 - rh + i2 * (rh + i1 *
                              (jp1 *
                               (1.0 + jp2) - 1.0)) - (rh - 1) * (rh - i2 * rh)
        z1 = (i2 * (rh + i1 * (jp1 * (rh + (wlt * jp2)) - rh)) -
              ((rh - 1) * (rh - i2 * rh)))
        z2 = i2 * ((rh**2) + i1 * (jp1 * wlt * (2 * rh - wlt +
                                                (wlt * jp2)) - rh**2))
        dib = pdib * (z0 + (x1 * z1) + (x2 * z2))
        dib = dib.real
    if tree[9] == 5:
        cs = tree[9]
        mdbh = tree[1] * 2.54
        mht = tree[2] / 3.28084
        height = height / 3.28084
        z = height / mht
        q = 1 - z**0.5
        p = 1.37 / mht
        x = q / (1 - p**0.5)
        d = (mdbh**2) / mht
        c = (mdib[cs][1] * cmath.asin(q)) + (mdib[cs][2] * cmath.log(x)) + (
            mdib[cs][3] * cmath.log(z)) + (mdib[cs][4] * cmath.exp(z)) + (
                mdib[cs][5] * d) + (mdib[cs][6] * cmath.exp(z) * d)
        dib = mdib[cs][0] * mdbh * (x**c)
        dib = dib.real
        dib = dib / 2.54
    return dib
Esempio n. 36
0
 def do_func(self, funcstr, x):
     return eval(
         funcstr, {
             "x": x,
             "e": cmath.e,
             "pi": cmath.pi,
             "i": 1j,
             "exp": cmath.exp,
             "sin": cmath.sin,
             "cos": cmath.cos,
             "tan": cmath.tan,
             "sinh": cmath.sinh,
             "cosh": cmath.cosh,
             "tanh": cmath.tanh,
             "sec": lambda x: 1 / cmath.cos(x),
             "csc": lambda x: 1 / cmath.sin(x),
             "cot": lambda x: cmath.cos(x) / cmath.sin(x),
             "sech": lambda x: 1 / cmath.cosh(x),
             "csch": lambda x: 1 / cmath.sinh(x),
             "coth": lambda x: cmath.cosh(x) / cmath.sinh(x),
             "arcsin": cmath.asin,
             "arccos": cmath.acos,
             "arctan": cmath.atan,
             "arsinh": cmath.asinh,
             "arcosh": cmath.acosh,
             "artanh": cmath.atanh,
             "arcsec": lambda x: cmath.acos(1 / x),
             "arccsc": lambda x: cmath.asin(1 / x),
             "arccot": lambda x: cmath.atan(1 / x),
             "arsech": lambda x: cmath.acosh(1 / x),
             "arcsch": lambda x: cmath.asinh(1 / x),
             "arcoth": lambda x: cmath.atanh(1 / x),
             "abs": abs,
             "sgn": sign,
             "arg": cmath.phase,
             "cis": lambda x: cmath.cos(x) + 1j * cmath.sin(x),
             "pow": pow,
             "sqrt": cmath.sqrt,
             "nrt": lambda x, n: x**(1 / n),
             "log": cmath.log,
             "ln": lambda x: cmath.log(x),
             "floor": math.floor,
             "ceil": math.ceil,
             "trunc": math.trunc,
             "round": round,
             "gamma": math_gamma,
             "weierstrauss": math_weierstrauss,
             "choose": math_choose,
             "max": max,
             "min": min
         }, {})
Esempio n. 37
0
 def asin(self,command_position,args):
     try:
         if ((type(self.stack[command_position+1])==complex) or (self.stack[command_position+1]>1)):
             value=cmath.asin(self.stack[command_position+1])
         else:
             value=math.asin(self.stack[command_position+1])
         self.stack.pop(command_position+1)
         self.stack[command_position]=value
         return command_position
     except:
         self.statstrings.append("Bad arc sine attempted, ignoring command")
         self.error=True
         self.stack.pop(command_position)
         return command_position
Esempio n. 38
0
    def goto(self, brng, dist):
        if isinstance(brng, LatLng):
            brng = self.bearing_to(brng)
        brng = to_rad(brng)
        dist = float(dist) / self.R

        lat1 = to_rad(self.lat)
        lng1 = to_rad(self.lng)

        lat2 = cmath.asin(cmath.sin(lat1) * cmath.cos(dist) + 
                          cmath.cos(lat1) * cmath.sin(dist) * cmath.cos(brng))
        lng2 = lng1 + math.atan2((cmath.sin(brng) * cmath.sin(dist) * cmath.cos(lat1)).real,
                                  (cmath.cos(dist) - cmath.sin(lat1) * cmath.sin(lat2)).real)
        lng2 = (lng2+3*PI) % (2*PI) - PI

        return LatLng(to_deg(lat2.real), to_deg(lng2.real))
Esempio n. 39
0
def asin(x):
    """
    Return the arc sine of x, in radians.
    """
    if isinstance(x,ADF):
        ad_funcs = list(map(to_auto_diff,[x]))

        x = ad_funcs[0].x
        
        ########################################
        # Nominal value of the constructed ADF:
        f = asin(x)
        
        ########################################

        variables = ad_funcs[0]._get_variables(ad_funcs)
        
        if not variables or isinstance(f, bool):
            return f

        ########################################

        # Calculation of the derivatives with respect to the arguments
        # of f (ad_funcs):

        lc_wrt_args = [1/sqrt(1 - x**2)]
        qc_wrt_args = [-x/(sqrt(1 - x**2)*(x**2 - 1))]
        cp_wrt_args = 0.0

        ########################################
        # Calculation of the derivative of f with respect to all the
        # variables (Variable) involved.

        lc_wrt_vars,qc_wrt_vars,cp_wrt_vars = _apply_chain_rule(
                                    ad_funcs,variables,lc_wrt_args,qc_wrt_args,
                                    cp_wrt_args)
                                    
        # The function now returns an ADF object:
        return ADF(f, lc_wrt_vars, qc_wrt_vars, cp_wrt_vars)
    else:
#        try: # pythonic: fails gracefully when x is not an array-like object
#            return [asin(xi) for xi in x]
#        except TypeError:
        if x.imag:
            return cmath.asin(x)
        else:
            return math.asin(x.real)
Esempio n. 40
0
#coding:utf-8

x = 4 + 3j
print x.real
print x.imag
print x

import cmath

print cmath.sqrt(-1)
print cmath.asin(100)
print cmath.asin(4 + 3j)
Esempio n. 41
0
                    'asech': lambda x: acosh(1/x), '': lambda x: x,
                    'acoth': lambda x: atanh(1/x), 'floor': lambda x: floor(x),
                    'ceil': lambda x: ceil(x), 
                    'point': lambda x: x/(10 ** floor(1+log(x)/log(10)))
                    }
                    
complex_functions = {'sin': lambda x: cmath.sin(x), 
                    'cos': lambda x: cmath.cos(x),
                    'tan': lambda x: cmath.tan(x), 
                    'csc': lambda x: 1/cmath.sin(x),
                    'sec': lambda x: 1/cmath.cos(x), 
                    'cot': lambda x: 1/cmath.tan(x),
                    'ln': lambda x: cmath.log(x), 
                    'log': lambda x: cmath.log(x)/cmath.log(10),
                    'fact': lambda x: factorial(int(x)),
                    'asin': lambda x: cmath.asin(x), 
                    'acos': lambda x: cmath.acos(x),
                    'atan': lambda x: cmath.atan(x), 
                    'acsc': lambda x: cmath.asin(1/x),
                    'asec': lambda x: cmath.acos(1/x), 
                    'acot': lambda x: cmath.atan(1/x),
                    'sinh': lambda x: cmath.sinh(x), 
                    'cosh': lambda x: cmath.cosh(x),
                    'tanh': lambda x: cmath.tanh(x), 
                    'csch': lambda x: 1/cmath.sinh(x),
                    'sech': lambda x: 1/cmath.cosh(x),
                    'coth': lambda x: 1/cmath.tanh(x),
                    'asinh': lambda x: cmath.asinh(x), 
                    'acosh': lambda x: cmath.acosh(x),
                    'atanh': lambda x: cmath.atanh(x), 
                    'acsch': lambda x: cmath.asinh(1/x),
def measure(schlafli, i0,i1):

    if i0 == i1:
        return 0.,0.
    if i0 > i1:
        i0,i1 = i1,i0

    if len(schlafli) == 0:
        # 0 dimensional surface, {}
        # can't get here-- i0,i1 must be 0,0 which was handled above
        assert False
    if len(schlafli) == 1:
        # 1 dimensional surface, {p}
        p = schlafli
        if (i0,i1) == (0,1):
            assert False # I don't think this is well-defined... maybe infinite?
        else:
            assert False
    elif len(schlafli) == 2:
        # 2 dimensional surface, {p,q}
        p,q = schlafli
        if (i0,i1) == (0,1):
            # half edge length
            coshValue = cos(pi/p)/sin(pi/q)
        elif (i0,i1) == (1,2):
            # face in-radius
            coshValue = cos(pi/q)/sin(pi/p)
        elif (i0,i1) == (0,2):
            # face circum-radius
            coshValue = 1/(tan(pi/p)*tan(pi/q))
        else:
            assert False
    elif len(schlafli) == 3:
        # 3 dimensional surface, {p,q,r}
        p,q,r = schlafli
        def sin_pi_over_h(p,q):
            # = sqrt(1 - cos^2 (pi / h(p,q)))
            # = sqrt(1 - (cos(pi/p)^2 + cos(pi/q)^2)
            return sqrt(1 - (cos(pi/p)**2 + cos(pi/q)**2))
        if (i0,i1) == (0,1):
            # half edge length
            coshValue = cos(pi/p)*sin(pi/r)/sin_pi_over_h(q,r)
        elif (i0,i1) == (2,3):
            # cell in-radius
            coshValue = sin(pi/p)*cos(pi/r)/sin_pi_over_h(p,q)
        elif (i0,i1) == (0,3):
            # cell circum-radius
            coshValue = cos(pi/p)*cos(pi/q)*cos(pi/r)/(sin_pi_over_h(p,q)*sin_pi_over_h(q,r))
        elif (i0,i1) == (0,2):
            # 2d face circum-radius
            cosh2_r01,cosh_r01,r01 = measure(schlafli,0,1)
            sinh_r01 = sqrt(cosh2_r01-1)
            sinhValue = sinh_r01/sin(pi/p)
            coshValue = sqrt(1+sinhValue**2)
            #do('coshValue')

            # hmm, this doesn't seem to be simplifying much
            sinh2Value = ((cos(pi/p)*sin(pi/r))**2/(1 - (cos(pi/q)**2 + cos(pi/r)**2))-1)/sin(pi/p)**2
            cosh2Value = 1+sinh2Value
            coshValue = sqrt(cosh2Value)
            #do('coshValue')
            # oh wait, wolframalpha says sinh2Value is equal to cot^2(pi/p)cos^2(pi/q)/(sin^2(pi/q)-cos^2(pi/r))
            # maybe get h back out of the equation and it wil turn somewhat nice
            # TODO: try to simplify some more

            h = pi/asin(sin_pi_over_h(q,r))
            sinhValue = sqrt((cos(pi/p)*sin(pi/r)/sin(pi/h))**2-1)/sin(pi/p)
            coshValue = sqrt(1+sinhValue**2)
            coshValue = sqrt(1+((cos(pi/p)*sin(pi/r)/sin(pi/h))**2-1)/sin(pi/p)**2)
            #do('coshValue')

            # huh? this is wacked, it's not equal to what I thought above
            #sinh2Value = sin(pi/p)**2*cos(pi/q)**2/sin_pi_over_h(q,r)**2/cos(pi/p)**2
            sinh2Value = cos(pi/p)**2/sin(pi/p)**2 * cos(pi/q)**2 / (sin(pi/q)**2 - cos(pi/r)**2)
            cosh2Value = 1+sinh2Value
            coshValue = sqrt(cosh2Value)
            #do('coshValue')



        elif (i0,i1) == (1,3):
            # cell mid-radius
            return measure([r,q,p], 0,2)
        elif (i0,i1) == (1,2):
            # 2d face in-radius
            # We can calculate this in one of two ways,
            # using the hyperbolic right triangle identities:
            #   cos A = tanh b / tanh c
            #   sinh a / sin A = sinh c / 1
            # => sinh a = sinh c * sqrt(1 - (tanh b / tanh c)^2)
            # with either: b=r01, c=r02
            #          or: b=r23, c=r13
            # But, it simplifies to the simplest of all
            # (don't ask me how, I used wolframalpha
            # on a horrendous expression after
            # breaking it up into bite sized pieces):

            coshValue = cos(pi/q) / (sin(pi/p) * sin(pi/r))

        else:
            assert False # illegal
    elif len(schlafli) == 4:
        # 4 dimensional surface, {p,q,r,s}
        p,q,r,s = schlafli
        if (i0,i1) == (0,1):
            # half edge length
            assert False # unimplemented
        elif (i0,i1) == (3,4):
            # facet in-radius
            assert False # unimplemented
        elif (i0,i1) == (0,4):
            # facet circum-radius
            assert False # unimplemented
        else:
            assert False # illegal
    else:
        assert False # unimplemented

    return coshValue**2, coshValue,acosh(coshValue)
Esempio n. 43
0
def create_expression():
    """This function takes no arguments and returns an expression that
    generates a number between -1.0 and 1.0, given x and y coordinates."""
    expr15 = lambda x: math.sin(pi*x)
    expr14 = lambda x: math.cos(pi*x)
    expr13 = lambda x: math.atan(x)
    expr12 = lambda x: 1/(1+x) if x != -1 else 1

    expr11 = lambda x: random.choice([x.real, x.imag])
    expr10 = lambda x: abs(x)

    expr9 = lambda x: cmath.asin(pi*x)
    expr8 = lambda x: x*cmath.asinh(1j*x.real - x.imag)
    expr7 = lambda x: (1j-x)*(1j+x) if x != -1j else 1/(1-x)
    expr6 = lambda x: (1+x)/(1-x) if x !=1 else 1/(1+x)

    ave = lambda x,y: (x+y)/2
    unave = lambda x,y: (x-y)/2

    expr5 = lambda x,y:  (x+1j*y)*cmath.exp(1j*random.uniform(-.5,.5))
    expr4 = lambda x,y: (x+y)/2
    expr3 = lambda x,y: (x-y)/2
    expr2 = lambda x,y: random.choice([x,y])
    expr1 = lambda x,y: x*y

    list_1 = [expr1, expr2, expr3, expr4, expr5] # real/complex, 2 -> 2
    list_2 = [expr6, expr7, expr8, expr9] # real/complex 1 -> 1
    list_3 = [expr12, expr13, expr14, expr15] # real 1 -> 1
    reals = [expr10, expr11] # complex -> real, 1 -> 1


    num_start = random.randint(1,10)
    num_choices = random.randint(1,10)
    num_real = random.randint(1,10)
    start = []
    choices = []
    final = []

    average = random.choice([ave, unave]) # averages or not...
    real = random.choice(reals) # makes it real

    for _ in range(num_start):
        start.append((random.choice(list_1), random.choice(list_1)))

    for _ in range(num_choices):
        choices.append(random.choice(list_2))

    for _ in range(num_real):
        final.append(random.choice(list_3))




    def returner(x, y):
        start_x, start_y = x, y


        for item1, item2 in start:
            start_x, start_y = item1(start_x, start_y), item2(start_y, start_x)

        num = average(start_x, start_y)

        for item in choices:
            num = item(num)

        num = real(num)

        for item in final:
            num = item(num)

        return num

    return returner
 def test_asin(self):
     self.assertAlmostEqual(complex(0.633984, 2.30551),
                            cmath.asin(complex(3, 4)))
Esempio n. 45
0
    j=8.89

    print(abs(i))
    print(pow(j,2))#求j的2次方的值
    print(math.sqrt(j))
    print(min(i,j))
    print(max(i,j))

#随机函数
    print(u"常用随机函数")
    a = ['uie',2,4,5,6,7,'yui','ywe','yuwe783iop']
    print(random.choice(a))#从序列中随机获取到一个元素,序列可以是list,tuple

    print(random.random()) #输出0-1的浮点数
    print(random.randrange(10,20,2))#生成指定范围内的按一定长度的数
    print(random.uniform(10,20))#指定范围内的随机浮点数
    print(random.uniform(20,10))
    random.shuffle(a) #将a中的元素打乱
    print(a)

    list=['test','001',2,3,7,9,'testone','tet','uisfs']
    newlist = random.sample(list,3)#随机截取3个长度的元素组成一个片断并返回,新序列无序,原序列有序且不变
    print(newlist)
    print(list)

#三角函数
    q=99
    print(cmath.sin(q))
    print(cmath.cos(q))
    print(cmath.asin(q))
    print(cmath.pi)
Esempio n. 46
0
File: GF.py Progetto: duffyj2/JGF
def gSISPA(DZ,DA,E):
  sig = copysign(1.0,-E.real)

  temp1 = 2.0*1j*sig*( E*exp(sig*2*1j*DA*acos(- sqrt( 1.0 - E**2/t**2 ) ) ) )*sin( DZ*asin(sqrt(E**2+3*t**2)/(2*t)) )**2
  temp2 = sqrt(3*t**2 + E**2)*( E**2*(t**2 - E**2) )**(1.0/4.0)
  temp3 = sqrt( sig*(1j/(pi*DA)) )
  g = (temp1/temp2)*temp3
  
  return g
Esempio n. 47
0
 def __new__(cls, argument):
     if isinstance(argument, (RealValue, Zero)):
         return FloatValue(math.asin(float(argument)))
     if isinstance(argument, (ComplexValue)):
         return ComplexValue(cmath.asin(complex(argument)))
     return MathFunction.__new__(cls)
Esempio n. 48
0
#!/usr/bin/python3.2
#
z = 3+4j;
print("z is ... ", z);
#
import cmath
#
x = 3.14159265j/4
print("x is ... ", x);
print("sqrt(x) is ", cmath.sqrt(x))
print("sin(x) is ", cmath.sin(x))
print("asin(sin(x)) is ", cmath.asin(cmath.sin(x)))
#
quit()
print('tau =', cmath.tau)
print('Positive infinity =', cmath.inf)
print('Positive Complex infinity =', cmath.infj)
print('NaN =', cmath.nan)
print('NaN Complex =', cmath.nanj)

# power and log functions
c = 2 + 2j
print('e^c =', cmath.exp(c))
print('log2(c) =', cmath.log(c, 2))
print('log10(c) =', cmath.log10(c))
print('sqrt(c) =', cmath.sqrt(c))

# trigonometric functions
c = 2 + 2j
print('arc sine =', cmath.asin(c))
print('arc cosine =', cmath.acos(c))
print('arc tangent =', cmath.atan(c))

print('sine =', cmath.sin(c))
print('cosine =', cmath.cos(c))
print('tangent =', cmath.tan(c))

# hyperbolic functions
c = 2 + 2j
print('inverse hyperbolic sine =', cmath.asinh(c))
print('inverse hyperbolic cosine =', cmath.acosh(c))
print('inverse hyperbolic tangent =', cmath.atanh(c))

print('hyperbolic sine =', cmath.sinh(c))
print('hyperbolic cosine =', cmath.cosh(c))
Esempio n. 50
0
def asin_usecase(x):
    return cmath.asin(x)
Esempio n. 51
0
def rpn_calc(input, angle_mode = 0):
	global stack
	single_arg_funcs = ['exp','sqrt','sin','asin','cos','acos','tan','atan', 'sinh','asinh','cosh','acosh','tanh',
                        'atanh','!', 'polar']
	
	num, arg, option = parse(input)
	#print(num, arg, option)
	#print('\n')
	
	if arg == None and (num != None or num != 'Error'):
		config.stack.append(num)
		history.append('Entered number: ' + str(num) )
		return config.stack

	

# Simple arithmatic-----------------------------------------------------------------------	
	if option == None and num != None:
		if arg not in single_arg_funcs:
			last = config.stack.pop()
	
		if arg == '+':
			try:
				result = Decimal(last) + Decimal(num)
				hist = str(last) + '+' + str(num) + '=' + str(result)
			except TypeError:
				result = last + num
				hist = str(last) + '+' + str(num) + '=' + str(result)
				
		if arg == '-':
			try:
				result = Decimal(last) - Decimal(num)
				hist = str(last) + '-' + str(num) + '=' + str(result)
			except TypeError:
				result = last - num
				hist = str(last) + '-' + str(num) + '=' + str(result)
			
		if arg == '*':
			try:
				result = Decimal(last) * Decimal(num)
				hist = str(last) + '*' + str(num) + '=' + str(result)
			except TypeError:
				result = last * num
				hist = str(last) + '*' + str(num) + '=' + str(result)
				
		if arg == '/':
			try:
				result = Decimal(last) / Decimal(num)
				hist = str(last) + '/' + str(num) + '=' + str(result)
			except TypeError:
				result = last / num
				hist = str(last) + '/' + str(num) + '=' + str(result)
				
		if arg == '**':
			try:
				result = pow(Decimal(last), Decimal(num) )
				hist = str(last) + '**' + str(num) + '=' + str(result)
			except TypeError:
				result = last ** num
				hist = str(last) + '**' + str(num) + '=' + str(result)
				
		if arg == 'rt':
			try:
				result = root(Decimal(last), Decimal(num) )
				hist = str(last) + 'raised to 1 over ' + str(num) + '=' + str(result)
			except TypeError:
				result = root(last + num)
				hist = str(last) + 'raised to 1 over ' + str(num) + '=' + str(result)
				
		if arg == '%':
			try:
				result = Decimal(last) % Decimal(num)
				hist = str(last) + '%' + str(num) + '=' + str(result)
			except TypeError:
				result = last % num
				hist = str(last) + '%' + str(num) + '=' + str(result)
		
		if arg == '!':
			try:
				result = Decimal(math.factorial(num))
				hist = str(num) + '!' + '=' + str(result)
			except TypeError:
				result = math.factorial(num)
				hist = str(num) + '!' + '=' + str(result)
				
		if arg == 'exp':
			try:
				result = math.exp(Decimal(num))
				hist = str(num) + 'exp' + '=' + str(result)
			except ValueError:
				result = cmath.exp(Decimal(num))
				hist = str(num) + 'exp' + '=' + str(result)
			except TypeError:
				result = cmath.exp(num)
				hist = str(num) + 'exp' + '=' + str(result)
				
		if arg == 'sqrt':
			try:
				result = math.sqrt(Decimal(num))
				hist = str(num) + 'sqrt' + '=' + str(result)
			except ValueError:
				result = cmath.sqrt(Decimal(num))
				hist = str(num) + 'sqrt' + '=' + str(result)
			except TypeError:
				result = cmath.sqrt(num)
				hist = str(num) + 'sqrt' + '=' + str(result)
				
		if arg == 'log':
			try:
				result = math.log10(Decimal(num))
				hist = str(num) + 'log10' + '=' + str(result)
			except ValueError:
				result = cmath.log10(Decimal(num))
				hist = str(num) + 'log10' + '=' + str(result)
			except TypeError:
				result = cmath.log10(num)
				hist = str(num) + 'log10' + '=' + str(result)
		#=================================
		if arg == 'ln':
			try:
				result = math.log(Decimal(num))
				hist = str(num) + 'ln' + '=' + str(result)
			except ValueError:
				result = cmath.log(Decimal(num))
				hist = str(num) + 'ln' + '=' + str(result)
			except TypeError:
				result = cmath.log(num)
				hist = str(num) + 'ln' + '=' + str(result)
		#--------TRIG--------------------------------
		if arg == 'sin':
			if angle_mode == 1:
				try:
					result = math.sin(Decimal(num))
					hist = 'sin' + str(num) + '=' + str(result)
				except TypeError:
					result = cmath.sin(num)
					hist = 'sin' + str(num) + '=' + str(result)
			elif angle_mode == 0:
				try:
					result = math.sin(math.radians(Decimal(num)))
					hist = 'sin' + str(num) + '=' + str(result)
				except TypeError:
					result = cmath.sin(num)
					hist = 'sin' + str(num) + '=' + str(result)
		
		if arg == 'cos':
			if angle_mode == 1:
				try:
					result = math.cos(Decimal(num))
					hist = 'cos' + str(num) + '=' + str(result)
				except TypeError:
					result = cmath.cos(num)
					hist = 'cos' + str(num) + '=' + str(result)
			elif angle_mode == 0:
				try:
					result = math.cos(math.radians(Decimal(num)))
					hist = 'cos' + str(num) + '=' + str(result)
				except TypeError:
					result = cmath.cos(num)
					hist = 'cos' + str(num) + '=' + str(result)

		if arg == 'tan':
			if angle_mode == 1:
				try:
					result = math.tan(Decimal(num))
					hist = 'tan' + str(num) + '=' + str(result)
				except TypeError:
					result = cmath.tan(num)
					hist = 'tan' + str(num) + '=' + str(result)
			elif angle_mode == 0:
				try:
					result = math.tan(math.radians(Decimal(num)))
					hist = 'tan' + str(num) + '=' + str(result)
				except TypeError:
					result = cmath.tan(num)
					hist = 'tan' + str(num) + '=' + str(result)
			
		if arg == 'asin':
			if angle_mode == 1:
				try:
					result = math.asin(Decimal(num))
					hist = 'asin' + str(num) + '=' + str(result)
				except TypeError:
					result = cmath.asin(num)
					hist = 'asin' + str(num) + '=' + str(result)
			elif angle_mode == 0:
				try:
					result = math.asin(math.radians(Decimal(num)))
					hist = 'asin' + str(num) + '=' + str(result)
				except TypeError:
					result = cmath.asin(num)
					hist = 'asin' + str(num) + '=' + str(result)
		
		if arg == 'acos':
			if angle_mode == 1:
				try:
					result = math.acos(Decimal(num))
					hist = 'acos' + str(num) + '=' + str(result)
				except TypeError:
					result = cmath.acos(num)
					hist = 'acos' + str(num) + '=' + str(result)
			elif angle_mode == 0:
				try:
					result = math.acos(math.radians(Decimal(num)))
					hist = 'acos' + str(num) + '=' + str(result)
				except TypeError:
					result = cmath.acos(num)
					hist = 'acos' + str(num) + '=' + str(result)

		if arg == 'atan':
			if angle_mode == 1:
				try:
					result = math.atan(Decimal(num))
					hist = 'atan' + str(num) + '=' + str(result)
				except TypeError:
					result = cmath.atan(num)
					hist = 'atan' + str(num) + '=' + str(result)
			elif angle_mode == 0:
				try:
					result = math.atan(math.radians(Decimal(num)))
					hist = 'atan' + str(num) + '=' + str(result)
				except TypeError:
					result = cmath.atan(num)
					hist = 'atan' + str(num) + '=' + str(result)
			
		if arg == 'sinh':
			try:
				result = math.sinh(Decimal(num))
				hist = 'sinh' + str(num) + '=' + str(result)
			except TypeError:
				result = cmath.sinh(num)
				hist = 'sinh' + str(num) + '=' + str(result)
		
		if arg == 'cosh':
			try:
				result = math.cosh(Decimal(num))
				hist = 'cosh' + str(num) + '=' + str(result)
			except TypeError:
				result = cmath.cosh(num)
				hist = 'cosh' + str(num) + '=' + str(result)

		if arg == 'tanh':
			try:
				result = math.tanh(Decimal(num))
				hist = 'tanh' + str(num) + '=' + str(result)
			except TypeError:
				result = cmath.tanh(num)
				hist = 'tanh' + str(num) + '=' + str(result)
			
		if arg == 'asinh':
			try:
				result = math.asinh(Decimal(num))
				hist = 'asinh' + str(num) + '=' + str(result)
			except TypeError:
				result = cmath.asinh(num)
				hist = 'asinh' + str(num) + '=' + str(result)
		
		if arg == 'acosh':
			try:
				result = math.acosh(Decimal(num))
				hist = 'acosh' + str(num) + '=' + str(result)
			except TypeError:
				result = cmath.acosh(num)
				hist = 'acosh' + str(num) + '=' + str(result)

		if arg == 'atanh':
			try:
				result = math.atanh(Decimal(num))
				hist = 'atanh' + str(num) + '=' + str(result)
			except TypeError:
				result = cmath.atanh(num)
				hist = 'atanh' + str(num) + '=' + str(result)

		if arg == 'rect': #continue here....
			try:
				result = rect(last, num)
				hist = 'Convert ' + str(last) + ',' + str(num) + ' to rectangular coords.'

			except TypeError:
				result = 'Error'
				hist = 'Error in attempted conversion to rectangular coords.  No result.'

		if arg == 'polar':
			try:
				result = polar(num)
				hist = 'Convert ' + str(num) + ' to polar coords.'
			except TypeError:
				result = 'Error'
				hist = 'Error in attempted conversion to polar coords.  No result.'
		
			
		config.stack.append(result)
		history.append(hist)
		return config.stack
#=======================================================================================================================
#----Only argument passed-----------------------------------------------------------------------------------------------
#=======================================================================================================================
	elif option == None and num == None:
		last = config.stack.pop()
		if arg not in single_arg_funcs:
			try:
				n_minus1 = config.stack.pop()
			except IndexError:
				try:
					config.stack.append(Decimal(last))
				except TypeError:
					config.stack.append(last)
			except TypeError:
				config.stack.append(last)
			except Exception as e:
				return 'Error'

		if arg == '+':
			try:
				result = Decimal(n_minus1) + Decimal(last)
				hist = str(n_minus1) + '+' + str(last) + '=' + str(result)
			except TypeError:
				result = n_minus1 + last
				hist = str(n_minus1) + '+' + str(last) + '=' + str(result)
				
		if arg == '-':
			try:
				result = Decimal(n_minus1) -  Decimal(last)
				hist = str(n_minus1) + '-' + str(last) + '=' + str(result)
			except TypeError:
				result = n_minus1 - last
				hist = str(n_minus1) + '-' + str(last) + '=' + str(result)
				
		if arg == '*':
			try:
				result = Decimal(n_minus1) * Decimal(last)
				hist = str(n_minus1) + '*' + str(last) + '=' + str(result)
			except TypeError:
				result = n_minus1 * last
				hist = str(n_minus1) + '*' + str(last) + '=' + str(result)
				
		if arg == '/':
			try:
				result = Decimal(n_minus1) / Decimal(last)
				hist = str(n_minus1) + '/' + str(last) + '=' + str(result)
			except TypeError:
				result = n_minus1 / last
				hist = str(n_minus1) + '/' + str(last) + '=' + str(result)
				
		if arg == '!':
			try:
				result = Decimal(math.factorial(last))
				hist = str(last) + '!' '=' + str(result)
			except TypeError:
				result = math.factorial(last)
				hist = str(last) + '!' '=' + str(result)
			except OverflowError:
				config.stack.append(last)
				hist = str('Factorial overflow error, no result.')
				return 'Error'
				
		if arg == '**':
			try:
				result = pow(Decimal(last), Decimal(last))
				hist = str(n_minus1) + '**' + str(last) + '=' + str(result)
			except TypeError:
				result = last ** last
				hist = str(n_minus1) + '**' + str(last) + '=' + str(result)
				
		if arg == 'log':
			try:
				result = math.log10(Decimal(last))
				hist = str(last) +'log10' + '=' + str(result)
			except ValueError:
				result = cmath.log10(Decimal(last))
				hist = str(last) +'log10' + '=' + str(result)
			except TypeError:
				result = cmath.log10(last)
				hist = str(last) +'log10' + '=' + str(result)
		
		if arg == 'ln':
			try:
				result = math.log(Decimal(last))
				hist = str(last) +'ln' + '=' + str(result)
			except ValueError:
				result = cmath.log(Decimal(last))
				hist = str(last) +'ln' + '=' + str(result)
			except TypeError:
				result = cmath.log(last)
				hist = str(last) +'ln' + '=' + str(result)
			
		if arg == 'rt':
			try:
				result = root(Decimal(last), Decimal(n_minus1))
				hist = str(n_minus1) + 'root' + str(last) + '=' + str(result)
			except TypeError:
				result = root(last), (n_minus1)
				hist = str(n_minus1) + 'root' + str(last) + '=' + str(result)
				
		if arg == 'exp':
			try:
				result = math.exp(Decimal(last))
				hist = str(last) +'exp' + '=' + str(result)
			except TypeError:
				result = cmath.exp(last)
				hist = str(last) +'exp' + '=' + str(result)
			
				
		if arg == 'sqrt':
			try:
				result = math.sqrt(Decimal(last))
				hist = 'Square root of ' + str(last) + '=' + str(result)
			except ValueError:
				result = cmath.sqrt(Decimal(last))
				hist = 'Square root of ' + str(last) + '=' + str(result)
			except TypeError:
				result = cmath.sqrt(last)
				hist = 'Square root of ' + str(last) + '=' + str(result)
#----------Trig----------------------------------------				
		#--------TRIG--------------------------------
		if arg == 'sin':
			if angle_mode == 1:
				try:
					result = math.sin(Decimal(last))
					hist = 'sin' + str(last) + '=' + str(result)
				except TypeError:
					result = cmath.sin(last)
					hist = 'sin' + str(last) + '=' + str(result)
			elif angle_mode == 0:
				try:
					result = math.sin(math.radians(Decimal(last)))
					hist = 'sin' + str(last) + '=' + str(result)
				except TypeError:
					result = cmath.sin(last)
					hist = 'sin' + str(last) + '=' + str(result)
					
		if arg == 'cos':
			if angle_mode == 1:
				try:
					result = math.cos(Decimal(last))
					hist = 'cos' + str(last) + '=' + str(result)
				except TypeError:
					result = cmath.cos(last)
					hist = 'cos' + str(last) + '=' + str(result)
			elif angle_mode == 0:
				try:
					result = math.cos(math.radians(Decimal(last)))
					hist = 'cos' + str(last) + '=' + str(result)
				except TypeError:
					result = cmath.cos(last)
					hist = 'cos' + str(last) + '=' + str(result)
					
		if arg == 'tan':
			if angle_mode == 1:
				try:
					result = math.tan(Decimal(last))
					hist = 'tan' + str(last) + '=' + str(result)
				except TypeError:
					result = cmath.tan(last)
					hist = 'tan' + str(last) + '=' + str(result)
			elif angle_mode == 0:
				try:
					result = math.tan(math.radians(Decimal(last)))
					hist = 'tan' + str(last) + '=' + str(result)
				except TypeError:
					result = cmath.tan(last)
					hist = 'tan' + str(last) + '=' + str(result)
					
		if arg == 'asin':
			if angle_mode == 1:
				try:
					result = math.asin(Decimal(last))
					hist = 'asin' + str(last) + '=' + str(result)
				except TypeError:
					result = cmath.asin(last)
					hist = 'asin' + str(last) + '=' + str(result)
			elif angle_mode == 0:
				try:
					result = math.asin(math.radians(Decimal(last)))
					hist = 'asin' + str(last) + '=' + str(result)
				except TypeError:
					result = cmath.asin(last)
					hist = 'asin' + str(last) + '=' + str(result)
					
		if arg == 'acos':
			if angle_mode == 1:
				try:
					result = math.acos(Decimal(last))
					hist = 'acos' + str(last) + '=' + str(result)
				except TypeError:
					result = cmath.acos(last)
					hist = 'acos' + str(last) + '=' + str(result)
			elif angle_mode == 0:
				try:
					result = math.acos(math.radians(Decimal(last)))
					hist = 'acos' + str(last) + '=' + str(result)
				except TypeError:
					result = cmath.acos(last)
					hist = 'acos' + str(last) + '=' + str(result)

		if arg == 'atan':
			if angle_mode == 1:
				try:
					result = math.atan(Decimal(last))
					hist = 'atan' + str(last) + '=' + str(result)
				except TypeError:
					result = cmath.atan(last)
					hist = 'atan' + str(last) + '=' + str(result)
			elif angle_mode == 0:
				try:
					result = math.atan(math.radians(Decimal(last)))
					hist = 'atan' + str(last) + '=' + str(result)
				except TypeError:
					result = cmath.atan(last)
					hist = 'atan' + str(last) + '=' + str(result)
			
		if arg == 'sinh':
			try:
				result = math.sinh(Decimal(last))
				hist = 'sinh' + str(last) + '=' + str(result)
			except TypeError:
				result = math.sinh(last)
				hist = 'sinh' + str(last) + '=' + str(result)
		
		if arg == 'cosh':
			try:
				result = math.cosh(Decimal(last))
				hist = 'cosh' + str(last) + '=' + str(result)
			except TypeError:
				result = math.cosh(last)
				hist = 'cosh' + str(last) + '=' + str(result)

		if arg == 'tanh':
			try:
				result = math.tanh(Decimal(last))
				hist = 'tanh' + str(last) + '=' + str(result)
			except TypeError:
				result = math.tanh(last)
				hist = 'tanh' + str(last) + '=' + str(result)
			
		if arg == 'asinh':
			try:
				result = math.asinh(Decimal(last))
				hist = 'asinh' + str(last) + '=' + str(result)
			except TypeError:
				result = math.asinh(last)
				hist = 'asinh' + str(last) + '=' + str(result)
		
		if arg == 'acosh':
			try:
				result = math.acosh(Decimal(last))
				hist = 'acosh' + str(last) + '=' + str(result)
			except TypeError:
				result = math.acosh(last)
				hist = 'acosh' + str(last) + '=' + str(result)

		if arg == 'atanh':
			try:
				result = math.atanh(Decimal(last))
				hist = 'atanh' + str(last) + '=' + str(result)
			except TypeError:
				result = math.atanh(last)
				hist = 'atanh' + str(last) + '=' + str(result)
				
		if arg == 'rect': #continue here....
			try:
				result = rect(n_minus1, last)
				hist = 'Convert ' + str(n_minus1) + ',' + str(last) + ' to rectangular coords.'

			except TypeError:
				result = 'Error'
				hist = 'Error in attempted conversion to rectangular coords.  No result.'

		if arg == 'polar':
			try:
				result = polar(last)
				hist = 'Convert complex value ' + str(last) + ' to rectangular coords.'
			except TypeError:
				result = 'Error'
				hist = 'Error in attempted conversion to polar coords.  No result.'

		config.stack.append(result)
		history.append(hist)
		return config.stack