はじめに

Macで記事を書いているので、brew で入れられる面白いソフトはないかなーと思って調べてみたところ、下記のページから探せることがわかった。
https://formulae.brew.sh/
適当に見てみると、aamathというソフトで数式をアスキーアートで表現できるらしいので試してみる。

環境

1
2
MacOS Ventura 13.3.1
Homebrew 4.1.14

aamathのインストール

1
brew install aamath
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
==> Downloading https://ghcr.io/v2/homebrew/core/aamath/manifests/0.3
############################################################################################################################################### 100.0%
==> Fetching aamath
==> Downloading https://ghcr.io/v2/homebrew/core/aamath/blobs/sha256:1edd59508421089d629ab153c03d9db3c5e0e3cad0a75d3baea36b533a5b1d0a
############################################################################################################################################### 100.0%
==> Pouring aamath--0.3.ventura.bottle.tar.gz
🍺  /usr/local/Cellar/aamath/0.3: 8 files, 166.2KB
==> Running `brew cleanup aamath`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

入った。

使ってみる

まずは manで使い方を見てみる。

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
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 followed by a sequence of alphanumeric characters. A variable may have a
horiba-MacBook-Pro:blog-hugo horibahiroto$ qq
bash: qq: command not found
horiba-MacBook-Pro:blog-hugo horibahiroto$ 
horiba-MacBook-Pro:blog-hugo horibahiroto$ man aamath
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 followed 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
       variable 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
       separate rows.
 
       Other than the standard arithmetic and logical operators, which obey the usual precedence rules, aamath also accepts the following
       operations:
 
       expr1 ^ expr1
              expr1 raised to expr2.
 
       ~(expr)
              Complex conjugate of the expression.
       ~(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 limits 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.

なるほど?

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
$ aamath

aamath version 0.3
aamath> sum(1,x) + prod(2,y)

=====     =====
\          | |
 >    1 +  | |  2
/          | |
=====      | |
  x         y

## 指数表現
aamath> x ^ 5

 5
x

## インテグラル
aamath> int(x,x)

  /
 |
 | x dx
 |
/

## ルート
aamath> sqrt(x)

  _
\/x

aamath> root(x,y)

 y_
\/x

## limit
aamath> lim(x,x->2)

 lim   x

x -> 2

## !
aamath> 100!

100!

という感じになる。

おわりに

普通はLaTeXとか使うところだが、アスキーアートを使うのもの面白い。
まあ使う機会はほとんどなさそうだ・・・。