#
#	icalc.init
#
#	Default startup file for icalc, containing definitions for many
#	useful functions.
#
#	Martin W Scott, August 1991
#

silent		# switch off confirmation of definitions

func deg(z) = DEG*z		# convert radians to degrees
func rad(z) = z/DEG		# and degrees to radians
func log(z) = ln(z)/LOG10	# base-10 logarithm
func lg(z) = ln(z)/LOG2		# base-2 logarithm

# inverse hyperbolic trig functions
func asinh(z) = ln(z+sqrt(sqr(z)+1))
func acosh(z) = ln(z+sqrt(sqr(z)-1))
func atanh(z) = 0.5*ln((1+z)/(1-z))

# gamma(z+1)...very accurate
# NB: gamma(0) undefined
func gamma(z) = sqrt(2*PI*z)*z^z*exp(-z)*(1+(1+(1-139/(180*z))/(24*z))/(12*z))

# combinatorics
func fact(n) = Prod(_n=1,n,_n)
func perm(n,r) = Prod(_n=n-r+1,n,_n)
func comb(n,r) = perm(n,r)/fact(r)

# miscellaneous

# round real & imag parts
func round(z,places) = int(z*10^places)/10^places

# create complex number from modulus and argument
func polar(r,theta) = exp(i*r*theta)

# create complex number from real and imaginary parts
func complex(real,imag) = real + i*imag

verbose		# restore display of results, messages
