sequence function: arithmetic

    description:
        arithmetic(ket, ket, ket)
        the arithmetic function
        supported operators: + - * / % ^
        if the categories are different, return |>
      
    examples:
        arithmetic(|number: 3>, |symbol: +>, |number: 8>)
            |number: 11>
        
        arithmetic(|3>, |^>, |4>)
            |81>
      
        -- the categories are not the same, so return |>
        arithmetic(|price: 37>, |->, |number: 5.20>)
            |>
        
        -- one way to make sure the categories are the same:
        number-to-price |number: *> #=> |price:> __ extract-value |_self>
        arithmetic(|price: 37>, |->, number-to-price |number: 5.20>)
            |price: 31.8>
      
        -- simple Fibonacci and factorial:
        fib |0> => |0>
        fib |1> => |1>
        n-1 |*> #=> arithmetic(|_self>, |->, |1>)
        n-2 |*> #=> arithmetic(|_self>, |->, |2>)
        fib |*> !=> arithmetic( fib n-1 |_self>, |+>, fib n-2 |_self>)
        fact |0> => |1>
        fact |*> !=> arithmetic(|_self>, |*>, fact n-1 |_self>)
        table[number,fib,fact] range(|1>, |10>)
            +--------+-----+---------+
            | number | fib | fact    |
            +--------+-----+---------+
            | 1      | 1   | 1       |
            | 2      | 1   | 2       |
            | 3      | 2   | 6       |
            | 4      | 3   | 24      |
            | 5      | 5   | 120     |
            | 6      | 8   | 720     |
            | 7      | 13  | 5040    |
            | 8      | 21  | 40320   |
            | 9      | 34  | 362880  |
            | 10     | 55  | 3628800 |
            +--------+-----+---------+

    see also:
        algebra, worked example Fibonacci-and-factorial

Home