THE 86-BASIC LIBRARY v1.0 by Daniel Bishop ***** INTRODUCTION ***** I own both a TI-83 and a TI-86 and have written quite a few BASIC math programs. One of the difficulties with this is that both calculators lack some of the functions I would like to use. To compensate for this deficiency, I created the 86-Basic library. ***** LEGAL STUFF ***** The subroutines contained in this .zip file are freeware. You may freely use and distribute the .86p files provided that (1) the code can only be used in programs intended for noncommercial use, and (2) documentation for programs using these functions must give proper credit to their author (Daniel J. Bishop). ***** FILE INFORMATION ***** readme.txt: this file! fn______.86p (70 of them): the 86-BASIC library functions ***** HOW TO USE THESE FUNCTIONS ***** Functions are called with: _parameter(s)_ -> Par fn_FUNCTION_ The return value is always stored in the variable Ret. If a function requires parameters of more than one type, the variables Par2 and Par3 are used. A few of these functions use temporary variables. To avoid side effects from these functions, avoid starting variable names with temp. ***** HOW TO CONTACT ME ***** If you have any questions, comments, or complaints about these programs, e-mail me at danb2k@hotmail.com. ***** FUNCTION DESCRIPTIONS BY CATEGORY ***** *** STACK OPERATIONS *** For more info on stacks, ask any asm programmer. These functions are useful mainly for recursive subroutines. STKCLR *Syntax:fnSTKCLR clears the stack (must be executed at the beginning of every program using stack fn's. POP *Syntax:fnPOP pops a single number from STACK and stores it in Ret PUSH *Syntax:X -> Par:fnPUSH pushes the single number X onto the stack LPOP *Syntax:fnLPOP pops a list from the stack and stores in in Ret LPUSH *Syntax:L -> Par:fnLPUSH pushes list L onto the stack Example :fnSTKCLR :1 -> Par:fnPUSH :{2,3,4 -> Par:fnLPUSH :fnLPOP:Disp Ret // displays {2 3 4} :fnPOP:Disp Ret // displays 1 *** TRIGONOMETRY *** ACOT: arccotangent *Syntax:x -> Par OR {x1,x2,...} -> Par :fnACOT *Other functions required: none *Return value: the inverse secant of x. *Return type: real OR list (same type as Par) *Note: return value depends on whether calc is in radian or degree mode *Example: ACSC: arccosecant ASEC: arcsecant *See ACOT. ATRI: area of triangle *Syntax:{a,b,c} -> Par :fnATRI *Parameter: real a, b, c = the lengths of the sides of a triangle *Other functions required: none *Return value: the area of the triangle *Return type: real *Example: :{3,4,5} -> Par :fnATRI :Disp Ret // displays 6 CSC:cosecant COT:cotangent *See SEC. IsTRI: triangle inequality test *Syntax:{a,b,c} -> Par :fnIsTRI *Parameters: real a, b, c = possible side lengths for a triangle *Other functions required: none *Return value: 1 if a triagle with sides a,b,c can exist, 0 otherwise *Return type: integer *Example: :{3,4,5 -> Par :fnIsTRI:Disp Ret // displays 1 :8 -> Par(3 :fnIsTRI:Disp Ret // displays 0 SEC: secant *Syntax:theta -> Par OR {theta1,theta2,...} -> Par :fnSEC\ *Parameters: real theta = an angle *Other functions required: none *Return value: the secant of theta *Return type: real OR list (same type as Par) *Note: return value depends on whether calc is in radian or degree mode *** PROBABILITY AND STATISTICS *** BINCDF: binomial cumulative density function *Syntax:{n,p,x} -> Par :fnBINCDF *Parameters: int n = number of trials real p = probability of success on each trial int x *Other functions required: none *Return value: the probability that AT MOST x trials will be successful if there are n trials, each with a probability p of being successful *Return type: real *Example: :{10,.5,5} -> Par :fnBINCDF :Disp Ret // displays .6220703125 BINPDF: binomial probability density function *Syntax:{n,p,x} -> Par :fnBINPDF *Parameters: int n = number of trials real p = probability of success on each trial int x *Other functions required: none *Return value: the probabily that EXACTLY x trials will be successful if there are n trials, each with a probability p of being successful. *Return type: real *Example: :{10,.5,5} -> Par :fnBINPDF :Disp Ret // displays .24609375 CHISQ1: univariate chi-squared test statistic *Syntax:obs -> Par :exp -> Par2 :fnCHISQ1 *Parameters: list obs = observed counts list exp = expected counts *Other functions required: none *Return value: chi-squared value *Return type: real *Example: :{6,8,9,10,12 -> Par :{9,9,9,9,9 -> Par2 :fnCHISQ1 :Disp Ret // displays 2.22222222222 CHISQ2: bivariate chi-squared test statistic *Syntax:obs -> Par :fnCHISQ2 *Parameters: list obs = observed counts *Other functions required: none *Return value: X² statistic for chi-squared independence test *Return type: real *Example: :[[2,3,4,5][5,6,8,9][7,9,12,14 -> Par :fnCHISQ2 :Disp Ret // displays .107142857143 GEOCDF: geometic cumulative distibution function *Syntax:{p,x} -> Par :fnGEOCDF *Parameters: real p = probability of success on each trial int x *Other functions required: none *Return value: The probability that at least one of the first x trials is successful GEOPDF: geometric probability distribution function *Syntax:{p,x} -> Par :fnGEOPDF *Parameters: real p = probability of success on each trial int x *Other functions required: none *Return value: the probability that the xth trial is the first succesful trial GMEAN: geometric mean *Syntax:L -> Par :fnGMEAN *Parameters: list L = a list of positive real numbers *Other functions required: none *Return value: the geometric mean of L. *Return type: real *Example: :{2,4,8} -> Par:fnGMEAN:Disp Ret // displays 4 HMEAN: harmonic mean *Syntax:L -> Par :fnHMEAN *Parameter: list L = a list of nonzero real numbers *Other functions required: none *Return value: the harmonic mean of L *Return type: real *Example: :{1,2,4,4} -> Par:fnHMEAN:Disp Ret // displays 2 MEAN: arithmetic mean *Syntax:L -> Par :fnMEAN *Parameter: list L = any list *Other functions requiredL none *Return value: the arithmetic mean of L *Example: :{6,5.5,5,4.5,6,5.5,5} -> Par :fnMEAN:Disp Ret // displays 5.35714285714 POICDF: poisson cumulative distibution function *Syntax:{lambda,x} -> Par :fnPOICDF equivalent to the 83 statement poissoncdf(lambda,x) -> Ret POIPDF: poisson probability distibution function *Syntax:{lambda,x} -> Par :fnPOIPDF equivalent to the 83 statement poissonpdf(lambda,x) -> Ret STDDEV: standard devation *Syntax:L -> Par :fnSTDDEV *Parameters: list L = the list for which you need to find Sx *Other functions required: none *Return value: the sample standard deviation of L. *Return type: real *Example: :{7,7,8,8,9} -> Par :fnSTDDEV :Disp Ret // displays .836660026534 ZCDF *Syntax:{z1,z2} -> Par OR {x1,x2,mu,sigma} -> Par :fnZCDF equivalent to the normalcdf() function on the 83 ZPDF *Syntax:{x,mu,sigma} -> Par :fnZPDF equivalent to the normalpdf() function on the 83 ZSCORE *Syntax:{x,mu,sigma} -> Par :fnZSCORE *Parameters: real x real mu = population mean real sigma = population standard deviation *Other functions required: none *Return value: normal score for x *Return type: real *** POLYNOMIAL OPERATIONS *** DISCR: discriminant *Syntax:{a,b,c -> Par :fnDISCR *Parameters: real a, b, c = coefficents for ax²+bx+c=0 *Other functions required: none *Return value: the discriminant of the quadratic equation *Return type: real *Example: :{1,4,4 -> Par:fnDISCR:Disp Ret // displays 0 PDER: polynomial derivative *Syntax:CoefList -> Par :fnPDER *Parameter: CoefList = list of coefficients for p(x) (as used for pEval()) *Other functions required: none *Return value: coefficient list for p'(x) *Return type: list *Example: :{1,2,3,4 -> Par :fnPDER:Disp Ret // displays {3 4 3} QSOLVE: quadratic solver *Syntax:{a,b,c -> Par :fnQSOLVE *Parameters: real a, b, c = coeffecients for equation ax²+bx+c=0 *Other functions required: none *Return value: solutions to the quadratic equation *Return type: list (elements may be real or complex) *** RANDOM NUMBER GENERATORS *** DICE *Syntax:{n[,sides]} -> Par :fnDICE *Parameters: int n = the number of times to roll the die int sides = number of sides on the die: default is 6 *Other functions required: none *Return value: a list of integers representing the results of the die rolls *Return type: list RAND *Syntax:n -> Par :fnRAND *Parameter: int n *Other functions required: none *Return value: n randomly-generated real numbers between 0 and 1 *Return type: list SHUFFL *Syntax:L -> Par :fnSHUFFL *Parameter: list L *Other functions required: none *Return value: the elements of L random order *Return type: list *** OTHER MATH FUNCTIONS *** CEIL: ceiling *Syntax:X -> Par :fnCEIL *Parameter: real/list X *Other functions required: none *Return value: the smallest integer greater than or equal to X. *Return type: real *Example: :3.6 -> Par:fnCEIL:Disp Ret // displays 4 :{-1.3,.1,3}:fnCEIL:Disp Ret // displays {-1 1 3} CIS *Syntax:{r,theta -> Par :fnCIS *Parameters: real r = magnitude of a complex number : real theta = an angle *Other functions required: none *Return value: r(cos theta+i*sin theta) *Return type: complex *Example: :{2^.5,45° -> Par :fnCIS :Disp Ret // displays (1,1) DIST: distance between 2 points *Syntax:{x1,y1,x2,y2 -> Par :fnDIST *Parameters: real x1, y1, x2, y2 = coordinates of points (x1,y1) and (x2,y2) *Other functions required: none *Return value: the distance between points (x1,y1) and (x2,y2) *Return type: real *Example: :{1,1,4,5 -> Par:fnDIST:Disp Ret // displays 5 FACTOR: prime factorization *Syntax:num -> Par :fnFACTOR *Parameter: int num = number to factor *Other functions required: none *Return value: prime factorization of num *Example: :231 -> Par:fnFACTOR:Disp Ret // displays {3 7 11} FIBO: Fibonacci numbers *Syntax:n -> Par OR {n1,n2,... -> Par :fnFIBO *Parameter: int n *Other functions required: none *Return value: the nth Fibonacci number *Return type: integer or list *Example: :5 -> Par :fnFIBO:Disp Ret // displays 5 :{3,4,5,6,7 -> Par :fnFIBO:Disp Ret // displays {2 3 5 8 13} GCD: greatest common divisor *Syntax:L -> par :fnGCD *Parameter: list L (all elements must be integers) *Other functions required: none *Return value: the greatest common divisor of the elements in list L *Return type: integer *Example: :{24,48,60} -> Par:fnGCD:Disp Ret // displays 12 INTER2: quadratic interpolation *Syntax:{x1,y1,x2,y2,x3,y3,x -> Par *Parameters: real x1...y3 = coordinaes of known points: (x1,y1), (x2,y2), (x3,y3) *Other functions required: none *Return value: interpolated value for y using the parabola though the 3 known points *Return type: real *Example: :{1,0,2,3,4,15,3 -> Par :fnINTER2:Disp Ret // displays 8 IsDIV: divisibility test *Syntax:{num,fact -> Par :fnIsDIV *Parameters: int num, fact *Other functions required: none *Return value: 1 if fact is a factor of num, 0 otherwise *Return type: integer *Example: :{5280,11 -> Par :fnIsDIV:Disp Ret // displays 1 :13 -> Par(2 :fnIsDIV:Disp Ret // displays 0 LCM: lowest common multiple *Syntax:L -> Par :fnLCM *Parameter: list L (all elements must be integers) *Other functions required: none *Return value: the lowest common multiple of the elements in list L *Return type: integer PRIME *Syntax:num -> Par :fnPRIME *Return value: 1 if num is prime, 0 if not RED1 *Syntax:L -> Par :fnRED1 *Parameter: list L (all elements must be positive) *Other functions required: none *Return value: reduction of Par so that lowest element is 1 *Return type: list *Example: :{24,36,60 -> Par :fnRED1:Disp Ret // displays {1 1.5 2.5} REDI *Syntax:L -> Par :fnREDI *Parameter: list L (all elements must be positive integers) *Other functions required: none *Return value: reduction of Par so that all elements are integers *Return type: list *Example: :{24,36,60 -> Par :fnREDI:Disp Ret // displays {2 3 5} ROUND *Syntax:{x,y -> Par :fnROUND *Parameters: real x, y *Other functions required: none *Return value: x rounded to the nearest multiple of y *Return type: list *Example: :{6366,100 -> Par :fnROUND:Disp Ret // displays 6400 SIGN *Syntax:x -> Par OR {x1,x2...} -> Par :fnSIGN *Parameter: real x *Other functions required: none *Return value: -1 if x<0, 0 if x=0, 1 if x>0 *Return type: integer or list *Example: :-10 -> Par:fnSIGN:Disp Ret // displays -1 :{3,4,0,-14} -> Par :fnSIGN:Disp Ret // displays {1 1 0 -1} SRSIMP: square root simplification *Syntax:n -> Par :fnSRSIMP *Parameter: int n = the radicand *Other functions required: none *Return value: {A B} such that sqrt N==A*sqrt B *Example: :20 -> Par:fnSRSIMP:Disp Ret // displays {2 5} TRINUM: triangular numbers: *Syntax:n -> Par OR {n1,n2,n3 -> Par *Parameter: real n *Other functions required: none *Return value: the nth triangular number *Return type: real or list (same type as Par) *Example: :4 -> Par:fnTRINUM:Disp Ret // displays 10 :{5,6,7,8 -> Par:fnTRINUM:Disp Ret // displays {15 21 28 36} *** DATE AND TIME *** DATEST: date-to-string *Syntax:{Year,Month,Day -> Par :fnDATEST *Parameters: int Year = the year (1-9999) int Month = the month (1-12) int Day = the day of the month *Other functions required: INTSTR *Return value: string represenation of date in international format (year-month-day) *Return type: string *Example: :{2000,10,15 -> Par :fnDATEST:Disp Ret // displays 2000-10-15 DAYWK: day of the week *Syntax:{Year,Month,Day -> Par :fnDAYWK *Parameters: SEE DATEST *Other functions required: none *Return value: the day of the week the date is on (0=Sunday, 1=Monday...6=Saturday) *Return type: integer *Example: :{1983,4,18 -> Par :fnDAYWK:Disp Ret // displays 1 (Monday) DWKSTR: day of week as string *Syntax:dow -> Par :fnDWKSTR *Parameters: int dow = numeric representation of day of week (0=Sun, 1=Mon...6=Sat) *Other functions required: none *Return value: string representation of dow *Return type: string *Example: :1 -> Par :fnDWKSTR:Disp Ret // displays Monday IsLeap: leap-year test *Syntax:year -> Par :fnIsLEAP *Parameter:int year *Other functions required: none *Return value: 1 if year is a leap year, 0 otherwise *Return type: integer *** STRING MANIPULATION *** INSTR: inString() function *Syntax:BigStr -> Par :SmStr -> Par2 :StartPos -> Par3 :fnINSTR *Parameters: string BigStr = the string to search in string SmStr = the string to search for int StartPos = position in BigStr to begin the search *Other functions required: none *Return value: position of first occurence of SmStr within BigStr. If SmStr is not contained in BigStr, returns 0. This is equivalent to the statement inString(SmStr,BigStr,StartPos) -> Ret on the 83 and 89. *Example: :"TI CALCULATORS ARE AWESOME" -> Par :"ARE" -> Par2 :1 -> Par3 :fnINSTR:Disp Ret // displays 16 ("ARE" begins at position #16 in Par) INTSTR: integer to string *Syntax:num -> Par :fnINTSTR *Parameter: int num = number to convert to string *Other functions required: none *Return value: string representation of num *Return type: string *Example: :86 -> Par :fnINTSTR :Disp "TI-"+Ret // displays TI-86 LSTSTR: list to string *Syntax:{asc1,asc2...} -> Par :fnLSTSTR *Parameters: int asc_ = the ASCII codes for characters *Other functions required: none *Return value: string of characters representing the ASCII codes in Par *Return type: string *Example: :{84,74,56,54} -> Par :fnLSTSTR :Disp Ret // displays TI86 NUMSTR: real number to string SEE INTSTR. The only difference is than num can have a decimal part. SPACES *Syntax:n -> Par :fnSPACES *Parameter: int n = number of spaces desired *Return value: n spaces *Return type: string *Example: :5 -> Par :fnSPACES :Disp "TI"+Ret+"86" // displays TI 86 STRCMP: string comparison *Syntax:Str1 -> Par :Str2 -> Par2 :fnSTRCMP *Parameters: string Str1, Str1 *Other functions required: STRLST *Return value: -1 if Str1Str2 *Return type: integer *Example: :"TI-85" -> Par :"TI-86" -> Par2 :fnSTRCMP :Disp RET // displays -1 STRNUM: string to number the inverse of the NUMSTR function STRLST: string to list *Syntax:str -> Par :fnSTRLST *Parameter: string str *Other functions required: none *Return value: ACII codes for characters in str *Return type: list *Example: :"TI-86" -> Par :fnSTRLST :Disp Ret // displays {84 73 221 56 54} TELTYP *Syntax:str -> Par :{row,col -> Par2 *Parameter: string str = text to display int row = row (1-8) to display text int col = starting column *Other functions required: none *Return type: void displays str one character at a time, like a teletype *** MISCELLANEOUS *** DELAY *Syntax:T -> Par :fnDELAY *Parameter: real T = time to delay (in seconds) *Other functions required: none *Return type: void *Example: :.5 -> Par:fnDELAY // waits half a second GETKEY *Syntax:fnGETKEY *Parameters: none *Other functions required: none *Return value: same as getKy, but does not return a value until a key is pressed *Return type: integer GETWIN *Syntax:fnGETWIN *Parameters: none *Other functions required: none *Return value: {xMin,xMax,xScl,yMin,yMax,yScl} *Return type: list *Example: :ZDECM:fnGETWIN:Disp Ret // displays {-6.3,6.3,1,-3.1,3.1,1} LTRGRD: letter grade *Syntax:grade -> Par :fnLTRGRD *Parameter: int grade = a numeic grade on a 0-100 scale *Other functions required: none *Return value: the letter grade (A, B, C, or F) associated with the numeric grade *Return type: string *Example: :86 -> Par:fnLTRGRD:Disp Ret // displays B REV *Syntax:L -> Par :fnREV *Parameter: list L *Other functions required: none *Return value: elements of L in reverse order *Return type: list SETWIN *Syntax:{xMin,xMax,xScl,yMin,yMax,yScl -> Par:fnSETWIN *Alternate syntax:{xCenter,deltaX,xScl,yCenter,deltaY,yScl,1 -> Par:fnSETWIN changes the graph window