### Moving incomplete complex numbers with stack commands Source: https://www.gnu.org/software/emacs/manual/html_node/calc/RPN-Tutorial.html Demonstrates that incomplete objects can be moved around using stack commands like M-TAB. The example shows entering 2 and 3, starting an incomplete object, and using M-TAB to rearrange entries before closing with ). ```calc 2: 2 3: 2 3: 3 1: ( ... 1: (2, 3) 1: 3 2: 3 2: ( ... 2 . . 1: ( ... 1: 2 3 . . . 2 `RET` 3 `RET` ( M-`TAB` M-`TAB` ) ``` -------------------------------- ### Example defmath with qualifiers and its expansion Source: https://www.gnu.org/software/emacs/manual/html_node/calc/Argument-Qualifiers.html An example defmath definition using qualifiers (constp, not-matrixp, float, integer) and its expansion into a defun with checks and conversions. The expansion shows how qualifiers are implemented. ```lisp (defmath foo (a (constp (not-matrixp b)) &optional (float c) &rest (integer d)) body) ``` ```lisp (defun calcFunc-foo (a b &optional c &rest d) (and (math-matrixp b) (math-reject-arg b 'not-matrixp)) (or (math-constp b) (math-reject-arg b 'constp)) (and c (setq c (math-check-float c))) (setq d (mapcar 'math-check-integer d)) body) ``` -------------------------------- ### Examples of gpoly decompositions Source: https://www.gnu.org/software/emacs/manual/html_node/calc/Decomposing-Polynomials.html A table of example expressions and their gpoly decompositions, showing how gpoly recognizes polynomials in terms like sin(x), x^2, or x^a. ```plaintext sin(x) - 1 [sin(x), [-1, 1], 1] x + 1/x - 1 [x, [1, -1, 1], 1/x] x + 1/x [x^2, [1, 1], 1/x] x^3 + 2 x [x^2, [2, 1], x] x + x^2:3 + sqrt(x) [x^1:6, [1, 1, 0, 1], x^1:2] x^(2a) + 2 x^a + 5 [x^a, [5, 2, 1], 1] (exp(-x) + exp(x)) / 2 [e^(2 x), [0.5, 0.5], e^-x] ``` -------------------------------- ### Apply function rewrite rule example Source: https://www.gnu.org/software/emacs/manual/html_node/calc/Other-Features-of-Rewrite-Rules.html An example of using the apply function to match function calls and perform transformations on arguments. ```Calc apply(f,[x+n]) := n + apply(f,[x]) :: in(f, [floor,ceil,round,trunc]) :: integer(n) ``` -------------------------------- ### Big Language Mode Example Source: https://www.gnu.org/software/emacs/manual/html_node/calc/Normal-Language-Modes.html Example of Big mode displaying a square root expression using textual approximations. ```text ____________ | a + 1 2 | ----- + c \| b ``` -------------------------------- ### Conditional rewrite rule example Source: https://www.gnu.org/software/emacs/manual/html_node/calc/Rewrites-Tutorial.html Demonstrates a conditional rewrite rule using the '::' symbol. ```Calc 1: sin(x + 2 pi) + sin(x + 3 pi) + sin(x + 4 pi) . ' sin(x+2pi) + sin(x+3pi) + sin(x+4pi) `RET` ``` ```Calc 1: sin(x + 3 pi) + 2 sin(x) . a r sin(a + k pi) := sin(a) :: k % 2 = 0 `RET` ``` -------------------------------- ### Expansion of defmath to defun Source: https://www.gnu.org/software/emacs/manual/html_node/calc/Defining-Functions.html Shows the Lisp code that the previous defmath example expands to. The function name gets the 'calcFunc-' prefix, and math functions like math-posp and math-mul are used. ```lisp (defun calcFunc-myfact (n) (if (math-posp n) (math-mul n (calcFunc-myfact (math-add n -1))) 1)) ``` -------------------------------- ### Calculate polynomial from roots Source: https://www.gnu.org/software/emacs/manual/html_node/calc/Algebra-Answer-2.html Demonstrates the initial setup of roots and the use of the 'a P x' command to expand the polynomial. ```text 1: 34 x - 24 x^3 1: [1.19023, -1.19023, 0] . . r 2 a P x `RET` ``` -------------------------------- ### Verify tan(x) = sin(x) / cos(x) using / and I T Source: https://www.gnu.org/software/emacs/manual/html_node/calc/Arithmetic-Tutorial.html Divides the sine by the cosine from the previous example to get the tangent (-2.0503), then applies the inverse tangent (I T) to recover the original angle -64 degrees. ```calc 2: -0.89879 1: -2.0503 1: -64. 1: 0.43837 . . . U / I T ``` -------------------------------- ### Apply Fibonacci rewrite rules Source: https://www.gnu.org/software/emacs/manual/html_node/calc/Rewrites-Tutorial.html Demonstrates the initial setup and application of Fibonacci rewrite rules in Calc. ```text 1: [fib(1) := ...] . 1: [8, 13] . . s r fib `RET` s t EvalRules `RET` ' [fib(6), fib(7)] `RET` ``` -------------------------------- ### Find polynomial roots of x^4 = 1 Source: https://www.gnu.org/software/emacs/manual/html_node/calc/Multiple-Solutions.html Use the roots command (a P) to solve a polynomial equation and get all solutions. The example 'roots(x^4 = 1, x)' returns '[1, -1, (0, 1), (0, -1)]'. ```calc ' roots(x^4 = 1, x) `RET` ``` -------------------------------- ### Define dummy z s program Source: https://www.gnu.org/software/emacs/manual/html_node/calc/Programming-Answer-11.html Create a dummy definition for the z s key to ensure the stack is handled correctly during initial setup. ```text 2: 4 1: 4 2: 4 1: 2 . 1: 2 . . 4 `RET` 2 C-x ( `DEL` C-x ) Z K s `RET` 2 ``` -------------------------------- ### Solve x^2 = y with Hyperbolic flag Source: https://www.gnu.org/software/emacs/manual/html_node/calc/Multiple-Solutions.html Use H a S to solve an equation and get a general solution with arbitrary signs. The example ' x^2 = y RET H a S x RET solves to 'x = s1 sqrt(y)', indicating two solutions: sqrt(y) and -sqrt(y). ```calc ' x^2 = y `RET` H a S x `RET` ``` -------------------------------- ### Using Infinite mode for division by zero Source: https://www.gnu.org/software/emacs/manual/html_node/calc/Types-Tutorial.html Shows how to enable Infinite mode with 'm i' to handle division by zero. ```Calc 3: nan 2: nan 2: nan 2: nan 1: nan 2: 1 1: 1 / 0 1: uinf 1: uinf . 1: 0 . . . . 1 `RET` 0 / m i U / 17 n * + ``` -------------------------------- ### Plan ahead with stack order for division Source: https://www.gnu.org/software/emacs/manual/html_node/calc/RPN-Tutorial.html Shows the correct order to enter numbers for division: 20 RET 2 RET 3 + / computes 20 / (2+3) = 4. This is the planning-ahead version of the previous example. ```calc 1: 20 2: 20 3: 20 2: 20 1: 4 . 1: 2 2: 2 1: 5 . . 1: 3 . . 20 `RET` 2 `RET` 3 + / ``` -------------------------------- ### Enable Fraction Mode Source: https://www.gnu.org/software/emacs/manual/html_node/calc/Modes-Tutorial.html Shows how to enable Fraction mode using m f to produce exact rational numbers instead of floating-point results during integer division. ```text 2: 12 1: 1.33333333333 1: 4:3 1: 9 . . . 12 `RET` 9 / m f U / m f ``` -------------------------------- ### Inverse sine in radians and degrees Source: https://www.gnu.org/software/emacs/manual/html_node/calc/Modes-Tutorial.html This example shows how inverse trigonometric functions (I S) produce results in the current angular mode. It starts with 0.5, takes the square root, switches to radian mode, computes inverse sine, then switches to degree mode and undoes the inverse sine to show the angle in degrees. ```calc 1: 0.707106781187 1: 0.785398163398 1: 45. . . . .5 Q m r I S m d U I S ``` -------------------------------- ### Implement the repeat loop Source: https://www.gnu.org/software/emacs/manual/html_node/calc/Programming-Answer-8.html Setting up a repeat loop with a 20-repetition limit to converge on the root. ```text 1: 4.5 3: 4.5 2: 4.5 . 2: x + (sin(cos(x)) ... 1: 5.24196456928 1: 4.5 . . 20 Z < `RET` r 1 `TAB` s l x `RET` ``` -------------------------------- ### Algebraic expression example Source: https://www.gnu.org/software/emacs/manual/html_node/calc/Algebraic-Tutorial.html An example of a complex algebraic expression using standard operators. ```text 2 + 3*4*5 / 6*7^8 - 9 ``` -------------------------------- ### Create a vector of x values from 1 to 1.9 with step 0.1 Source: https://www.gnu.org/software/emacs/manual/html_node/calc/Basic-Algebra-Tutorial.html Builds a vector of ten values from 1 to 1.9 using the extended v x command. The stack shows the inputs and result. ```calc 3: 10 1: [1, 1.1, 1.2, ... , 1.8, 1.9] 2: 1 . 1: 0.1 . 10 `RET` 1 `RET` .1 `RET` C-u v x ``` -------------------------------- ### Big-O Notation Example Source: https://www.gnu.org/software/emacs/manual/html_node/calc/Rewrites-Tutorial.html An example of a truncated Taylor series representation using big-O notation. ```text cos(x) = 1 - x^2 / 2! + O(x^3) ``` -------------------------------- ### RPN stack operations for first method Source: https://www.gnu.org/software/emacs/manual/html_node/calc/RPN-Answer-2.html Shows the stack states and key sequence for the first method: compute 2*4, then 7*9.5, then 5/4, and finally add all results with '+ +'. ```text 2: 2 1: 8 3: 8 2: 8 1: 4 . 2: 7 1: 66.5 . 1: 9.5 . . 2 `RET` 4 * 7 `RET` 9.5 * ``` ```text 4: 8 3: 8 2: 8 1: 75.75 3: 66.5 2: 66.5 1: 67.75 . 2: 5 1: 1.25 . 1: 4 . . 5 `RET` 4 / + + ``` -------------------------------- ### calc-unary-op implementation example Source: https://www.gnu.org/software/emacs/manual/html_node/calc/Stack-Lisp-Functions.html An example of implementing a unary operator using calc-unary-op with a numeric prefix argument. ```elisp (defun calc-zeta (arg) (interactive "P") (calc-unary-op "zeta" 'calcFunc-zeta arg)) ``` -------------------------------- ### Compare Depreciation Methods Matrix Source: https://www.gnu.org/software/emacs/manual/html_node/calc/Depreciation-Functions.html This example demonstrates how to map the sln, syd, and ddb functions over a vector of periods to generate a matrix comparing different depreciation methods. ```text [ [ 2000, 3333, 4800 ] [ 2000, 2667, 2880 ] [ 2000, 2000, 1728 ] [ 2000, 1333, 592 ] [ 2000, 667, 0 ] ] ``` -------------------------------- ### Unformatted Language Mode Example Source: https://www.gnu.org/software/emacs/manual/html_node/calc/Normal-Language-Modes.html Example of Unformatted mode displaying a formula without operator notation. ```text sqrt(add(div(add(a, 1), b), pow(c, 2))) ``` -------------------------------- ### Big Language Mode Rational Number Example Source: https://www.gnu.org/software/emacs/manual/html_node/calc/Normal-Language-Modes.html Example of Big mode displaying a negative rational number. ```text 3 - - 4 ``` -------------------------------- ### Exercise 6: Build a triangular list of lists Source: https://www.gnu.org/software/emacs/manual/html_node/calc/List-Tutorial.html Build a list of lists that looks like the diagram. The v / command enables multi-line display of vectors. ```calc 1: [ [1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5, 6] ] ``` -------------------------------- ### Enter the trigonometric expression to simplify Source: https://www.gnu.org/software/emacs/manual/html_node/calc/Rewrites-Tutorial.html Starts the rewrite rule tutorial by entering the expression 2 sec(x)^2/tan(x)^2 - 2/tan(x)^2 into the stack and storing it in variable 1. ```calc ' 2sec(x)^2/tan(x)^2 - 2/tan(x)^2 `RET` s 1 ``` -------------------------------- ### Custom Rewrite Rule Example Source: https://www.gnu.org/software/emacs/manual/html_node/calc/Rewrites-Tutorial.html An example of a custom rewrite rule added to EvalRules that replaces the sum of 2 and 3 with 6. ```text 2+3 := 6 ``` -------------------------------- ### Creating and manipulating fractions Source: https://www.gnu.org/software/emacs/manual/html_node/calc/Types-Tutorial.html Demonstrates creating fractions using the colon operator and converting between floating-point and fractional formats. ```Calc 1: 3628800 2: 3628800 1: 518400:7 1: 518414:7 1: 7:518414 . 1: 49 . . . . 10 ! 49 `RET` : 2 + & ``` -------------------------------- ### Using f T (arctan2) to recover full angle from quotient Source: https://www.gnu.org/software/emacs/manual/html_node/calc/Arithmetic-Tutorial.html Shows how the f T command (arctan2) computes the inverse tangent of a quotient using the original two numbers, yielding a full 360-degree answer. The example starts with the stack containing 0.89879 and -0.43837, then uses U U to undo the division, f T to compute arctan2, M-`RET` M-2 n to negate the second argument, f T again, and finally - to subtract, resulting in angles differing by 180 degrees. ```calc 2: 0.89879 1: 116. 3: 116. 2: 116. 1: 180. 1: -0.43837 . 2: -0.89879 1: -64. . . 1: 0.43837 . . U U f T M-`RET` M-2 n f T - ``` -------------------------------- ### Example rule set with phase markers Source: https://www.gnu.org/software/emacs/manual/html_node/calc/Multi_002dPhase-Rewrite-Rules.html Shows a rewrite rule set using `phase` markers to assign rules to phases. The default schedule executes phases in ascending order: phase 1, then phase 2, then phase 3, with the final rule belonging to both phases 1 and 2. ```calc [ f0(x) := g0(x), phase(1), f1(x) := g1(x), phase(2), f2(x) := g2(x), phase(3), f3(x) := g3(x), phase(1,2), f4(x) := g4(x) ] ```