/aamath

Reads mathematical expressions in infix notation and renders them as ASCII art

Primary LanguageC++GNU General Public License v2.0GPL-2.0

This is aamath, an ASCII art mathematics renderer.

To compile on *nix or cygwin:

  make -f Makefile.good

To compile on djgpp hosted on windows:

  make -f Makefile.evil

To test it:

  ./aamath < testcases

To run in interactive mode:

  ./aamath

To compile without readline:

  remove -DUSE_READLINE and -lreadline and -ltermcamp from Makefile.good

Please email any comments, suggestions and patches to:

  mauro_persano at yahoo dot com
  
 
++ 09-APR-2022/KFP 
--------------------------------------------------------------------------------
  
  aamath(1)                        USER COMMANDS                       aamath(1)

NAME
       aamath - renders mathematical expressions as ASCII art

SYNOPSIS
       aamath [ -q | -r ] [ expression ... ]

DESCRIPTION
       aamath is a program that accepts math expressions in infix notation and
       outputs them as ASCII art renderings. Expressions can either be entered
       as command line arguments, or supplied on standard input.

OPTIONS
       -q     Quiet mode.

       -r     More compact radicals.

EXPRESSIONS
       The simplest types of expression in aamath are constants and variables.
       The following are recognized as constants:

       number A number, optionally in scientific notation, optionally followed
              by  ellipsis.  Precision  is  limited  only by available memory,
              since numbers are represented internally as strings.

       inf    Infinity.

       nabla  The nabla operator.

       ...    Ellipsis.

       A variable is represented by an alphabetic character,  optionally  fol‐
       lowed  by  a sequence of alphanumeric characters. A variable may have a
       subscript: these are represented by an underline character (_) followed
       by  an  expression. If followed by a backslash character (\), the vari‐
       able name will be rendered with an over score. Variables names may also
       be followed by one or more primes (apostrophes).

       Functions  are represented by the function name, which follows the same
       syntax of variable names (including optional  subscripts,  over  score,
       and  primes),  followed  by  comma-separated function arguments between
       parentheses. Trigonometric functions are rendered differently  if  they
       are  raised  to  a power: the exponent will appear between the function
       name and the argument.

       Matrices are represented by a sequence of  expressions  between  square
       brackets; commas separate elements of the same row, and semicolons sep‐
       arate rows.

       Other than the standard arithmetic and logical  operators,  which  obey
       the  usual  precedence  rules, aamath also accepts the following opera‐
       tions:

       expr1 ^ expr1
              expr1 raised to expr2.

       ~(expr)
              Complex conjugate of the expression.

       expr!  Factorial of the expression.

       The following special functions are also recognized:

       sqrt(expr)
              Square root of the expression.

       root(expr, ord)
              Root of order ord of the expression.

       lim(expr, var -> lim)
              Limit of expr with var tending to lim.

       int(expr, var [= from .. to])
              Integral of expr with respect to var, optionally with with  lim‐
              its from and to.

       sum(expr, var [= from .. to])
              Sum  of  expr for values of var in the interval. The interval is
              optional.

       prod(expr, var [= from .. to])
              Product of expr for values of var in the interval. The  interval
              is optional.

BUGS
       It needs a better man page.

AUTHOR
       Mauro  Persano  (mauro_persano (at) yahoo.com), with help from bicoher‐
       ent.

Version 0.3                      March 1, 2005                       aamath(1)

-------------------------------------------------------------------------------

$ cat testcases
f(x+h) = f(x) + h*f'(x) + h^2/2*f''(x) + O(h^3)
h = -((f'(x)/f''(x))*(1 - sqrt(1 - (2*f(x)*f''(x))/f'(x)^2)))
sqrt(42)/z=root((1+1/(1+1/(x^2+1/b)))^3,6)/(3^d/(5-e + 42/(3 + f))+sqrt((2/(1-1/(1+1/7))))+sqrt(1/(2+3)+3)^(sqrt(21/(38-w))))
int(int(int(psi^2, x = -inf .. inf), y = -inf .. inf), z = -inf .. inf) = 1
A_TR = x*sqrt(x^2-1)/2 - int(sqrt(t^2-1), t = 1 .. x)
sqrt(e) = 1+1/(1+1/(1+1/(1+1/(5+1/(1+1/(1+1/(9+1/(1+1/(1+...)))))))))
e^x = 1 + x + x^2/2! + x^3/3! + x^4/4! + ... = 1 + sum(x^n/n!, n = 1 .. inf)
(1/4)*pi*sqrt(2) = sum((-1)^(k+1)/(4*k + 1) + (-1)^(k+1)/(4*k - 3), k = 1 .. inf) = 1 + 1/3 - 1/5 - 1/7 + 1/9 + 1/11 - ...
2/pi=sqrt(1/2)*sqrt(1/2+1/2*sqrt(1/2))*sqrt(1/2+1/2*sqrt(1/2+1/2*sqrt(1/2)))*...
pi = 3/4*sqrt(3) + 24*int(sqrt(x - x^2), x = 0 .. 1/4) = (3*sqrt(3))/4 + 24 * (1/12 - 1/(5*2^5) - 1/(28*2^7) - ...)
int(z^2, z = 1 .. root(3, 3)) * cos((3*pi)/9) = ln(root(e, 3))
x\ = (x_1 + x_2 + x_3 + ... + x_n)/n = (1/n)*sum(x_i, i = 1 .. n)
zeta(s) = (1 / (1 - (1/2^s))) * (1 / (1 - (1/3^s))) * (1 / (1 - (1/5^s))) * (1 / (1 - (1/7^s))) * ... = prod(1 / (1 - (1/p^s)), p_prime)
int((x^2+a)/b,x) = (1/b)*int(x^2+a,x) = (1/b)*(x^3/3 + a*x) + C
sin(a)/a = cos(a/2) * cos(a/4) * cos(a/8) * cos(a/16) * ... = prod(cos(a/2^n), n = 1 .. inf)
A_T = [sqrt(a/b), 0, 0; 0, sqrt(a/b), 0; 0, 0, sqrt(a/b)]^-1
lim(1/x^2 - (cos(x)/x)^2, x -> inf) = 1

---

$ aamath < testcases

                             2
                            h            / 3\
f(x + h) = f(x) + h f'(x) + -- f''(x) + O\h /
                             2

             /         _________________\
       f'(x) |        /    2 f(x) f''(x)|
h = - ------ |1 -    / 1 - -------------|
      f''(x) |      /              2    |
             \    \/          f'(x)     /

                                6_________________
                                /                3
                               / /         1    \
                              /  |1 + ----------|
                             /   |           1  |
                            /    |    1 + ------|
                           /     |         2   1|
  __                      /      |        x  + -|
\/42                    \/       \             b/
---- = -------------------------------------------------------------
  z                                                           ______
                                                             /  21
                                                            / ------
                                                          \/  38 - w
             d                 _________   /    _________\
            3                 /    2       |   /  1      |
       ------------- +       / --------- + |  / ----- + 3|
                42          /        1     \\/  2 + 3    /
       5 - e + -----       /   1 - -----
               3 + f      /            1
                         /         1 + -
                       \/              7

   oo    oo    oo
  /     /     /
 |     |     |    2
 |     |     | psi  dx dy dz = 1
 |     |     |
/     /     /
 -oo   -oo   -oo

                       x
           ______     /
          / 2        |    ______
      x \/ x  - 1    |   / 2
A   = ----------- -  | \/ t  - 1 dt
 TR        2         |
                     |
                    /
                     1

  _                          1
\/e = 1 + ---------------------------------------
                               1
          1 + -----------------------------------
                                 1
              1 + -------------------------------
                                   1
                  1 + ---------------------------
                                     1
                      5 + -----------------------
                                       1
                          1 + -------------------
                                         1
                              1 + ---------------
                                           1
                                  9 + -----------
                                             1
                                      1 + -------
                                          1 + ...

                                       oo
              2    3    4             =====  n
 x           x    x    x              \     x
e  = 1 + x + -- + -- + -- + ... = 1 +  >    --
             2!   3!   4!             /     n!
                                      =====
                                      n = 1

            oo
           ===== /    k + 1       k + 1\
1 __   _   \     |(-1)        (-1)     |       1   1   1   1    1
- || \/2 =  >    |--------- + ---------| = 1 + - - - - - + - + -- - ...
4          /     \ 4 k + 1     4 k - 3 /       3   5   7   9   11
           =====
           k = 1

                                  ______________________
                ___________      /           ___________
         _     /          _     /           /          _
 2      /1    / 1   1    /1    /  1   1    / 1   1    /1
-- =   / -   /  - + -   / -   /   - + -   /  - + -   / - ...
__   \/  2 \/   2   2 \/  2 \/    2   2 \/   2   2 \/  2
||

                   1
                   -
                   4
                  /
                 |    ______          _
__   3   _       |   /     2      3 \/3      / 1     1      1        \
|| = - \/3 + 24  | \/ x - x  dx = ----- + 24 |-- - ---- - ----- - ...|
     4           |                  4        |12      5       7      |
                 |                           \     5 2    28 2       /
                /
                 0

    3_
   \/3
  /            __
 |  2        3 ||     / 3_\
 | z  dz cos ---- = ln\\/e/
 |             9
/
 1

                                  n
    x  + x  + x  + ... + x      =====
_    1    2    3          n   1 \
x = ----------------------- = -  >    x
               n              n /      i
                                =====
                                i = 1

                                             =====
             1      1      1      1           | |     1
zeta(s) = ------ ------ ------ ------ ... =   | |  ------
               1      1      1      1         | |       1
          1 - -- 1 - -- 1 - -- 1 - --         | |  1 - --
               s      s      s      s       p           s
              2      3      5      7         prime     p

  /
 |  2              /                / 3      \
 | x  + a      1  | / 2    \      1 |x       |
 | ------ dx = -  | \x  + a/ dx = - |-- + a x| + C
 |    b        b  |               b \ 3      /
 |               /
/

                                        oo
                                       =====
sin a       a     a     a      a        | |       a
----- = cos - cos - cos - cos -- ... =  | |  cos --
  a         2     4     8     16        | |       n
                                        | |      2
                                       n = 1

                          -1
     /     _             \
     |    /a             |
     |   / -   0     0   |
     | \/  b             |
     |                   |
     |           _       |
     |          /a       |
A  = |   0     / -   0   |
 T   |       \/  b       |
     |                   |
     |                 _ |
     |                /a |
     |   0     0     / - |
     \             \/  b /

        /            2\
        | 1   /cos x\ |
 lim    |-- - |-----| | = 1
        | 2   \  x  / |
x -> oo \x            /

kfp@NUC MINGW64 ~/devel/aamath (master)
$