----BEGIN CLASS---- [13:59] #startclass [13:59] Roll call [13:59] Priyanka Saggu [13:59] Mayank Singhal [13:59] Akshay Gaikwad [14:00] Bhavin Gandhi [14:00] Anu Kumari Gupta [14:00] I did not have power, and it just came back. Hopefully, it lasts. If I disconnect, do not panic. I will try to login through my mobile connection. [14:00] Pranjal Aswani [14:01] Prashant Sharma [14:01] Today is a good day to have a session. [14:01] 0pooja sulakhe [14:01] pooja sulakhe [14:02] Today, we will go through Calc. [14:02] Souvik Haldar [14:02] Calc is an advanced calculator and mathematical tool that is part of GNUU Emacs. [14:02] First, open Emacs using "emacs -Q" [14:02] s/GNUU/GNU/ [14:03] You can do a quick calculation in the minibuffer using: [14:03] => C-x * q [14:03] At the minibuffer, it will prompt with "Quick calc:", and you can input "2 + 3" [14:04] And the result is shown in the minibuffer as "Result: 2 + 3 => 5 (16#5, 8#5, 2#101, "^E") [14:04] But, if you want to open Calc inside GNU Emacs, you can use: [14:04] => C-x * c [14:04] It will open two windows, Calc and *Calc Trail* [14:05] The Calc window has "--- Emacs Calculator Mode ---" in it. [14:05] You can stop Calc using: [14:05] => q [14:05] Sandeep Kumar Choudhary [14:06] What you see in the "Calc" window is a representation of a stack. [14:06] You can enter your calculation either in RPN (Reverse Polish Notation) or in algebraic form [14:06] For example: [14:07] => '2+3 [14:07] When you input ' (single quote), at the minibuffer, you will be prompted with "Algebraic:", where you can input '2 + 3' and hit enter [14:08] The result 5 is displayed in the Calc window [14:08] If you want to do this using the RPN syntax, you will have to do: [14:08] => 2 RET 3 + [14:09] When you input '2 RET' (RET is ), it is pushed to the Calc window. [14:09] Then you input 3, and when you immediately give the '+' operator, it takes '3' and the top of the stack '2' and computes the sum [14:10] Anytime, if you make a mistake and you want to abort the operation, use: [14:10] => C-g [14:10] You can undo the last operation using: [14:10] => U [14:10] You can also redo the last operation using: [14:10] => D [14:11] Let us try another example: [14:11] => '2*(3+4) RET [14:11] The above is the algebraic form. [14:11] The same in RPN style will be: [14:12] => 2 RET 3 RET 4 + * [14:12] You should see the result 14 in the Calc window [14:12] As you input commands and results are computed, these are also visible in the *Calc Trail* window [14:13] If you want to reset Calc to initial state, you can use: [14:13] => C-x * 0 [14:13] Or, you can also keep pressing "C-d" to remove the entries in the Calc window [14:14] If you want to recall the last arguments, you can use: [14:14] => M-RET [14:14] The other arithmetic operators which you are familiar with are -, *, / [14:14] If you want to raise to a power, you can use: [14:14] => ^ [14:14] For example: [14:15] => 2 RET 4 ^ [14:15] The result is 2 raised to the power 4 which is 16. [14:15] You can find nth root using: [14:15] => I ^ [14:16] For example: [14:16] => 16 RET 2 RET I ^ [14:16] The result will be 4. [14:16] You can change the sign of a number using: [14:16] => n [14:17] The sign of the top-most element of the stack will be updated. [14:17] You can find the reciprocal 1/x using: [14:17] => & [14:18] If you have 5 in the stack, and used '&', it will result in 0.2 [14:18] You can find the square root of a number using: [14:18] => Q [14:18] Using RPN style, for example: "4 Q" will give you 2. [14:19] You can refer to the previous result in the next computation using '$'. So, if you have 2 in the top of the stack [14:19] And you executed the arithmetic expression: [14:19] => '3*$^2 [14:20] It will yield the result 12 (=3 * 2^2). [14:20] If you want, you can change the precision using: [14:20] => p [14:20] If you have a long arithmetic expression, you can scroll horizontally using: [14:20] => < [14:20] OR [14:20] => > [14:21] You can scroll the Calc buffer vertically using: [14:21] => { [14:21] or [14:21] => } [14:21] By default, you see the line numbers. You can toggle them on/off using: [14:21] => d l [14:22] If you do not want to see the trail display, you can also turn it on/off using: [14:22] => t d [14:22] If you are using large numbers, and you want to group the digits with comma for readability, you can use: [14:22] => d g [14:22] When you issue the command, you will see "Grouping is on" in the minibuffer [14:23] So, if you input, say "100000", it will be displayed as "100,000". [14:23] Let us know look at some basic notations that are used in Calc [14:24] The scientific notation can be written as 6.02e23 [14:24] Fractions can be written as 3:4 [14:24] So, if you will get the result if you add 1:4 and 3:4 [14:25] => 1:4 RET 3:4 + [14:25] Complex numbers are written as (x, y) [14:25] Polar representation of complex numbers are written as (r; 0) [14:26] Vectors are written as [1, 2, 3] (The comma is optional) [14:26] You can do matrix computation as well! Matrices or nested vectors are represented as [1, 2; 3, 4] [14:27] The Hour-Minute-Second (HMS) notation is 5@ 30' 0" [14:27] The modulo form is 6 mod 24 [14:27] Let us know look at few scientific functions [14:27] s/know/now/ [14:28] The Natural log function is given by: [14:28] => ln [14:28] The natural log of 1 is 0. The same in RPN style is as follows: [14:28] => 1 ln [14:28] And the result 0 is in the top of the stack. [14:29] You can find logarithm to the base 10 using: [14:29] => H L [14:29] The logarithm of 2 to the base 10 is 0.3010, as can be seen using: [14:29] => 2 H L [14:29] When you press 'H', the minibuffer will say "Hyperbolic..." [14:30] You can of course find logarithm to any base 'b' using: [14:30] => B [14:31] Let us try the same logarithm of 2 to base 10 using any base style: [14:31] => 2 RET 10 B [14:31] This should again give you the result 0.3010 [14:31] You can find exponential e^x as well using: [14:31] => E [14:32] You know that e^1 = 2.7182 [14:32] The RPN syntax for the above is: [14:32] => 1 E [14:32] You can also compute 10^x using: [14:32] => H E [14:33] So, for 10^2 = 100, in RPN style: [14:33] => 2 H E [14:34] But, there is more. You can do trigonometry as well! [14:34] You know that sin 90 is 1. You can compute sin using: [14:34] => S [14:34] => 90 S [14:34] The above is for computing sin 90 which will result in 1. [14:35] You can compute cosine using: [14:35] => C [14:35] You know that cos 0 is also 1. So, the RPN style is: [14:35] => 0 C [14:35] For tan, you can use: [14:35] => T [14:35] You know that tangent 45 is 1. [14:35] => 45 T [14:36] Similarly, there are other trigonometric functions. For arcsin: [14:36] => I S [14:36] For arccos, use: [14:36] => I C [14:36] For arctan, use: [14:36] => I T [14:36] If you want the value of Pi, just use: [14:37] => P [14:37] You will the value 3.14159265359 in the stack [14:37] If you want the angles to be measured in degrees, you can set this using: [14:37] => m d [14:38] If you want to switch to using radian mode, use: [14:38] => m r [14:38] You can also compute factorial using: [14:38] => ! [14:38] The factorial of 5 is 120. In RPN style: [14:38] => 5 ! [14:38] The factorial of 0 is 1. In RPN style: [14:38] => 0 ! [14:39] You can also do permutations and combinations. [14:39] To find combinations, use: [14:39] => k c [14:40] So, 5C3 is 10. In RPN style: [14:40] => 5 RET 3 k c [14:40] To find permutations, use: [14:40] => H k c [14:41] So, 5P3 is 60. In RPN style: [14:41] => 5 RET 3 H k c [14:42] You can find prime factorization for a number using: [14:42] => k f [14:42] For the number 60, if you find the prime factorization, you will get [2, 2, 3, 5] [14:42] In RPN style: [14:42] => 60 k f [14:43] You can find the GCD of two numbers using: [14:43] => k g [14:43] The GCD of 10 and 5 is 5. In RPN style: [14:43] => 10 RET 5 k g [14:43] The LCM of two numbers can be found using: [14:43] => k l [14:44] The LCM of 10 and 5 is 10. In RPN style: [14:44] => 10 RET 5 k l [14:45] A number units can also be mentioned when you input numbers. [14:45] For distance, the following units are supported: m, cm, mm, km, in, ft, mi, point [14:45] For volume: l or L, ml; gal, cup, tbsp [14:45] For mass: g, mg, kg, lb, oz, ton [14:45] For time: s or sec, ms, us, ns, min, hr, day, wk [14:46] For temperature: degC, degF, K [14:46] Let us now look at some Programmer's functions [14:46] You can display a number in binary using: [14:46] => d 2 [14:47] So, if you have the number 10 in the top of the stack, and you issued 'd 2', you should see 2#1010, which is the binary equivalent of 10. [14:47] If you want to display in octal, use: [14:47] => d 8 [14:47] If you want to display in Hex, use: [14:47] => d 6 [14:47] If you want to display it back in decimal, use: [14:47] => d 0 [14:48] You can do a binary AND operation using: [14:48] => b a [14:48] You can perform a binary OR operation using: [14:48] => b o [14:49] A binary XOR can be performed using: [14:49] => b x [14:49] And a binary NOT operation can be done using: [14:49] => b n [14:49] You can perform a left shift operation using: [14:50] => b l [14:50] You can do a logical shift right using: [14:50] => b r [14:51] So, the number 5 in binary is 2#101. If you do a logical shift right, it will become 2#10, or the decimal number 2. [14:51] You can do an arithmetic right shift using: [14:51] => b R [14:51] In this operation, the signed bit value is retained. For example: [14:52] => 5 n b R d 2 [14:52] You will see that the leading bits are '1' [14:52] The integer quotient in division can be found using: [14:52] => \ [14:52] The remainder can be found using: [14:52] => % [14:53] You can find the floor of a number using: [14:53] => F [14:53] For example, if you want to find the floor of Pi, use: [14:53] => P F [14:53] It should show the result 3. [14:53] You can find the ceiling of a number using: [14:53] => I F [14:54] Let us now look at some Vector operations [14:55] You can create a vector of 1, 2, ..., n using: [14:55] => v x n [14:55] So, if you do 'v x 3', it will create the vector [1, 2, 3]. After you type 'x', it will prompt in the minibuffer with the message "Size of vector =". [14:55] You can find the length of a vector using: [14:55] =. v l [14:56] => v l [14:56] In the above example, it will return the result 3. [14:56] You can reverse a vector using: [14:56] => v v [14:57] You can of course key in your own vector using the numbers separated by space, but, the vector will be displayed with the elements separated by comma. [14:58] For example, to create the vector [1, 4, 5, 3, 2], you can input: [ 1 4 5 3 2 ] [14:58] You can sort a vector using: [14:58] => v S [14:58] If you try this command in the above unsorted vector, the result will be [1, 2, 3, 4, 5] [14:58] You can extract an element from the vector using: [14:58] => v r [14:59] So, "v r 2" will yield 2 in the above vector (after it has been sorted) [15:01] You can create a two-dimensional matrix, for example, [ [ 1 2 ] [ 3 4 ] ] [15:01] You can create an identity matrix using: [15:01] => v i [15:01] Emacs will prompt in the minibuffer with the message "Dimension of identity matrix =", and if you input '2' [15:02] It will create the identity matrix for the two-dimension [1, 0; 0, 1] [15:02] Just as how you can extract elements from a vector, you can extract a matrix row using: [15:02] => v r [15:02] So, if you extract row 1 from the identity matrix, you will get [1, 0] [15:02] You can extract a matrix column using: [15:03] => v c [15:03] You can add the vectors element wise using: [15:03] => V M + [15:04] You can sum the elements in a vector using: [15:04] => V R + [15:04] Calc also has the option of storing values to variables. [15:04] You can store to a variable using: [15:04] => s t [15:05] Suppose you have the number 10 in the top of the stack. You can store it to a variable, say 'x' using: [15:05] => s t x [15:06] After you type 't', it will prompt in the minibuffer with the message "Store:" [15:06] You can recall from a variable using: [15:06] => s r [15:06] You can also edit the variable using: [15:06] => s e [15:07] Now that we have a value for x, if you give an algebraic expression, Emacs can substitute the value for 'x' and give you an answer [15:08] Let us create an algebraic expression that uses 'x': [15:08] => 'x+x^2 RET [15:08] This is in the top-most entry of the stack. To make Calc compute the result, just use: [15:08] => = [15:08] It will substitute the value of x with 10, and compute the result for you, which is 110. [15:09] If you have large exponential expressions, you can opt to use the "big" display mode using: [15:09] => d B [15:09] At the minibuffer, you will see the message "Big" language mode. [15:10] If you have numbers or expressions in another buffer, and you want to select the region and push it to Calc stack, you can use: [15:10] => C-x * g [15:10] On the other hand, if you want to copy the result (top of the stack) from Calc to (yank) another buffer, you can use: [15:11] => C-x * y [15:11] Let us finally look at ways to get help in Calc [15:11] If you want to describe a key briefly, you can use: [15:11] => h c [15:12] When you input this, at the minibuffer, you will get a prompt "Describe key briefly:". Try '+' [15:12] It tells you - + runs calc-plus: a b '+' => add(a,b) a+b (?=notes 2) [15:13] If you want to describe the key fully, you can use: [15:13] => h k [15:13] Try the '+' function for 'h k'. [15:13] It will open the relevant section in the manual. [15:14] You can open the Calc Info manual using: [15:14] => h i [15:14] If you want to get a Calc summary, you can use: [15:14] => h s [15:14] There is also a built-in Calc tutorial that you can try using: [15:14] => C-x * t [15:15] These are some basic Calc commands for various arithmetic and scientific computation. [15:15] I have barely scratched the surface. I will encourage you to try it out at your pace, and learn to use it. [15:15] This can be quite handy, if you are doing lot of mathematics. [15:16] Are there any questions? [15:17] Roll Call [15:17] Priyanka saggu [15:17] Mayank Singhal [15:17] Pranjal Aswani [15:17] Shaikh_farhan [15:17] Akshay Gaikwad [15:17] Anu Kumari Gupta ----END CLASS----