README for CUI CALCULATOR Mu-CALC Ver 1.8 99/5/10 H.Miura [1]INTRODUCTION Mu-CALC is a CUI based function calculator. In numerical calculation c language double is used. Therefore, calculation accuracy is the same as c language double. Mu-CALC treats data like LISP. The input section and the syntax-analysis section of LISP are changed, and it can be made to perform the interpretation of numerical expression. The newest version of Mu-CALC can be obtained from http://www2.famille.ne.jp/~miura7/mu-calc/C/index.html [2]REGISTRATION Program "Mu-CALC" is owned by Hideo Miura. Anyone can use Mu-CALC free of charge. It permits re-distributing the kit of Mu-CALC gratuitously. When expecting commercial circulation, connection is wished in advance. The author does not warrant all results you may obtain by using this program. Use this program at your own risk. Send me BUG report, request, comment etc by e-mail. miura7@opal.famille.ne.jp [3]HOW TO MAKE Mu-CALC If your system has gcc, only type "make". ( Maybe.) When using the edit and the history function using GNU readline Library, Please replace the line of CC and LIB with that which has carried out comment out in Makefile. [4]HOW TO USE Mu-CALC If Mu-CALC is started, the following prompts will be taken out and it will become the waiting for an input. ---------------------------------------- unix% calc Mu-CALC Ver 1.8 calc> ---------------------------------------- A calculation result will be displayed if expression is inputted here. ---------------------------------------- calc> 3+4 7 ---------------------------------------- It calculates in consideration of an operator precedence and a parenthesis. As follows, the operator which can be used. Its priority are made the same as that of an expression as usual as possible. Priority High ! (factorial) - (single clause minus) P C (permutation & combination) ^ (power) * / % + - = (set value) == > < >= <= <>(compare) ; (joint) Low Instead of "^", "**" can also be used. ---------------------------------------- calc> 1+2*(3+4) 15 ---------------------------------------- Using substitution operator "=", value can be substituted for a variable. Before the variable to substitute, "'"(single quart) is attached. The variable which substituted value can be referred to by the name. Variable name is the character string of less than 31 characters which starts by Alphabet and consists only of Alphabet and number. Alphabet distinguishes a capital letter and a small letter. ---------------------------------------- calc> 'a=3 3 calc> a+1 4 ---------------------------------------- Formulas can be judged using a relational operator. Relational operator which can be used. == > < >= <= <> Instead of "<>", "!=" can also be used. When the judgment result is right, last value is returned, else nil is returned. ---------------------------------------- calc> 3 == 4 nil calc> 5 > 4 > 3 3 ---------------------------------------- By using joint operator ";" (semicolon), two or more formulas can be evaluated continuously. The total evaluation result is the result of last formula. ---------------------------------------- calc> 'a=3; 'b=4; a+b 7 ---------------------------------------- Some functions are supported. The mathematics function currently supported by the present version is as follows. exp log log10 sqrt sin cos tan asin acos atan hsin hcos htan abs sign round random The default mode of angle used by the trigonometric function is radian. The mode of angle radian/degree can be specified with "RAD" / "DEG" command. ---------------------------------------- calc> DEG; sin 30 0.5 ---------------------------------------- "round" gives the approximate value by rounding off. "round" has two arguments. 1st argument is the value to round, and the 2nd argument are the grades which were expressed with the exponentiation of 10 to approximate. ---------------------------------------- calc> round 1.23 0 1 calc> round 1.23 -1 1.2 ---------------------------------------- "PI" and "E" has default value. ---------------------------------------- calc> PI 3.141593 calc> E 2.718282 ---------------------------------------- The last calculation result can be referred by "@". ---------------------------------------- calc> 1+2 3 calc> @+3 6 ---------------------------------------- Execution is controllable by the result of "if". ---------------------------------------- calc> 'x=0; if (PI == 3) ('x=1); x 0 calc> if (4 > PI > 3) 1 else 0 1 ---------------------------------------- Repetition control can be performed using "for" / "while". The evaluation result of a formula is the result of last formula in loop. ---------------------------------------- calc> 'x=0; for (('i=0)(i<10)('i=i+1)) ('x=x+i) 45 calc> 'x=0; 'i=1; while (i<10) ('x=x+i; 'i=i+1); x 45 ---------------------------------------- User function can be defined by "def". Since a definition of a function and the value of a variable are stored in the same place, the same thing as a function name and a variable name cannot use it. ---------------------------------------- calc> def plus (x y) (x + y) plus calc> plus 3 4 7 ---------------------------------------- 3 ways are allowed to input number. Fix style (ex. 1.23) Exp style (ex. 1.5e-5) Hex style (ex. 0x1fff) ... only integer. ---------------------------------------- calc> 1.23 1.23 calc> 1.5e-5 0.000015 calc> 0x1fff 8191 ---------------------------------------- The default output style of number is Fix style. Output style of number can be changed using "FIX" / "EXP" / "HEX". Only a part for integer part is displayed in Hex style. ---------------------------------------- calc> PI 3.141593 calc> EXP; PI 3.141592653589793e+00 calc> HEX; PI 0x3 ---------------------------------------- The length of 1 line is to about 250 characters. It divides and inputs into 2 lines to input a formula longer than it. If a new line is started without closing a parenthesis, it can input into the following line continuously. ---------------------------------------- calc> (1+2 calc> +3) 6 ---------------------------------------- Type quit to end program. ---------------------------------------- calc> quit unix% ---------------------------------------- [5] HOW TO USE Mu-CALC [Upper editing] Read and Write of the reading / standard output from the standard input of a variable is made by read/print. ---------------------------------------- calc> 'a=read; print a; a+1 >> 3 3 4 ---------------------------------------- Some LISP functions can be used in addition to a mathematics function. Function which can be used by the present version is as follows. quote eval car cdr caar cadr cdar cddr. "quote" is the function by which an argument is not evaluated. "'f" is the same as "quote f". ---------------------------------------- calc> 1 + 2 3 calc> '(1 + 2) ( 1 + 2 ) ---------------------------------------- "car". The element of the beginning of cell is shown. "cdr". The remainder except the element of the beginning of cell is shown. "caar" "cadr" "cdar" "cddr". The combination of car and cdr. For example, "cadr x" is the same as "car cdr x". ---------------------------------------- calc> 'f='(1 + 2) ( 1 + 2 ) calc> car f 1 calc> cdr f ( + 2 ) calc> cadr f + ---------------------------------------- "eval" is the function by which an argument is evaluated too much. A formula is calculable, if the formula is substituted for the variable and eval is performed. ---------------------------------------- calc> 'f='(1 + 2) ( 1 + 2 ) calc> eval f 3 ---------------------------------------- "#" As a comment, the starting line is processed and is not performed. ---------------------------------------- calc> # comment calc> ---------------------------------------- Reading and saving the value of a variable or a definition of a function can perform by "load" / "save". ---------------------------------------- calc> def plus (x y) (x+y) plus calc> save plus plus calc> quit unix% calc Mu-CALC Ver 1.8 calc> load plus ( lambda ( x y ) ( x + y ) ) plus calc> plus 3 4 7 calc> ---------------------------------------- [6] HOW TO USE Mu-CALC [Super editing] If a file name is specified to be an argument at the time of the starting application, the formula in a file can be evaluated. The result which evaluated 'sosu.clc'(calculate the prime number under 100) is shown. ---------------------------------------- unix% calc sosu.clc 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 NUM 25 unix% ---------------------------------------- If "-c" option is used, the formula of a command line can be evaluated. ---------------------------------------- unix% calc -c 3+4 7 unix% ---------------------------------------- If the command of Mu-CALC is written in $HOME/.calcrc (or .calcrc which is in same folder of CALC.exe [Windows]), it will read at the time of starting. For example, default mode of the angle to make degree, ".calcrc" is created as follows. ---------------------------------------- # $HOME/.calcrc DEG; 'DEG ----------------------------------------