Ask.Moe's calculator is powered by Rob Pike's Ivy, an interpreter for an APL-like language. Input values may be integers (3, -1), rationals (1/3, -45/67) or floating point values (1e3, -1.5 (representing 1000 and -3/2)).
Please be aware that operators always have the same precedence and expressions are evaluated in right-associative order. That is, unary operators apply to everything to the right, and binary operators apply to the operand immediately to the left and to everything to the right. Thus, 3*4+5 is 27 (it groups as 3*(4+5)) and iota 3+2 is 1 2 3 4 5 while 3+iota 2 is 4 5. A vector is a single operand, so 1 2 3 + 3 + 3 4 5 is (1 2 3) + 3 + (3 4 5), or 7 9 11. Arithmetic has the obvious operations: + - * etc. ** is exponentiation. mod is modulo.
Try the following examples:
- 2*3+4. Parsed as 2*(3+4), not the usual (2*3)+4.
- 2**2+3. Parsed as 2**5, not (2**2) + 3.
- (2**2)+3. Use parentheses if you need to group differently.
- 3/1e10. Not an integer, but an exact rational.
- 2**6400. A really big integer.
- (2**1e3)/(3**1e2). Rationals can be very big too.
- char 0x1f4a9. Char is an operator: character with given value.
- 1 2 3 + 4 5 6. Arithmetic works elementwise on vectors.
- (1 << 1 2 3 4 5) == (2 ** 1 2 3 4 5). Note: true is 1, false is 0.
- pi; e. pi and e are built-in, high-precision constants.
- sqrt 2. Ivy stores irrational results in high-precision (default 256-bit) floating point numbers.
- a=5; a; a*10. Assign variables with the = operator, use semicolons to perform multiple operations.
- op primes N = (not T in T o.* T) sel T = 1 drop iota N; primes 50. primes less than N (unary).
- 3 20 rho 1. Ivy allows multidimensional arrays. The binary shape operator, rho, builds them.
- 5 5 rho iota 25. Dimension (which may be a vector) on the left, data on the right.
Check out Ivy's list of supported operations. You can contribute to Ask.Moe's calculator by contributing to Ivy.