ShikiPL computes mathematical formulae written by ASCII art.
ShikiPL translates ASCII art to JavaScript code.

Install

To install ShikiPL, type the command shown as follows.

$ npm install -g shikipl

How to use

A ShikiPL code which you want to bury in JavaScript is written in \[…​\] block.

var f = \[
a = 1

         2
f(x) = 2x  + 1
\]

In above example, the variable f has two properties.
One of property is a, which is a constant value 1, and another property is f which is a function with argument x.

You can use object which is generated by ShikiPL by shown as follows.

console.log(f.f(2));  // outputs 9

To translate ShikiPL to JavaScript, executes the command shown as follows.

$ shikipl filename.js.shikipl

Details of code

Constants and Functions

If left side is f(x) or an alphabet with subscript, the left side will be a function.
If left side is a simple alphabet, the left side will be a constant.
Multiple arguments can be specified by separating each arguments by comma.

// f.a is a constant, f.f, f.g are functions
var f = \[
a = 27

f(x) = x + 1

f  = x + 1
 x
\]

A formula can be referred from formulae written below.

var f = \[
a = 27

f(x) = x + a
\]
console.log(f.f(2));  // outputs 29

Addition and Subtraction

Symbols +, - are used by addition and subtraction, respectively.

var f = \[
f(x) = 2x + 1
\]
console.log(f.f(2));  // outputs 5

Multiplication

Sequence of numbers or factors represents multiplication.

var f = \[
f(x) = 2x
\]
console.log(f.f(3));  // outputs 6

Multiplication has higher priority than addtion or subtraction.
Parenthesis can change the priority.

var f = \[
f(x) = 2x + 1

g(x) = 2(x + 1)
\]
console.log(f.f(3));  // outputs 7
console.log(f.g(3));  // outputs 8

Exponentation

Exponentation represents superscript of a factor.

var f = \[
        2
f(x) = x
\]
console.log(f.f(3));  // output 9

Exponentation has higher priority than multiplication.
Parenthesis can change the priority.

var f = \[
         2
f(x) = 2x

           2
g(x) = (2x)
\]
console.log(f.f(3));  // outputs 18
console.log(f.g(3));  // outputs 36

Fraction

Fraction represents numerator and denominator divided up and down by hyphens.

var f = \[
        x + 1
f(x) = -------
          2
\]
console.log(f.f(1));  // outputs 1

Square root

Square root represents surrounding a formula by ASCII art square root symbol.
The example shown as follows computes one of solution of quadratic equation.

var f = \[
                     ________
                    / 2
              -b + v b  - 4ac
f(a, b, c) = -----------------
                     2a
\]
console.log(f.f(2, -4, 2));  // outputs 1

Absolute value

To compute absolute value, surrounds a formula by |…​|.

var f = \[
f(x) = |x|
\]
console.log(f.f(-1));  // outputs 1

Trigonometric functions

To compute trigonometric function, writes sin, cos or tan before destination formula.
"sin a sin b" represents (sin a)(sin b).

var f = \[
f(a) = sin a
\]
console.log(f.f(Math.PI / 2));  // outputs 1

Exponentation of trigonometric function represents by superscript of sin, cos, tan.

var f = \[
          2        2
f(a) = sin  a + cos  a
\]
console.log(f.f(8.765346283));  // outputs 1

Inverted trigonometric function can compute by setting superscript -1.

var f = \[
          -1
f(x) = tan   x
\]
console.log(4 * f.f(1));  // outputs 3.14159...

Hyperbolic functions

To compute hyperbolic function, writes sinh, cosh or tanh before destination formula.
"sinh a sin b" represents (sinh a)(sin b).
In JavaScript engine which do not support hyperbolic functions, polyfill is needed.

var f = \[
f(a) = sinh a
\]
console.log(f.f(1));  // outputs 1.17520119...

Exponentation of hyperbolic function represents by superscript of sinh, cosh, tanh.

var f = \[
           2         2
f(a) = sinh  a + cosh  a
\]
console.log(f.f(1));  // outputs 3.762195...

Inverted hyperbolic function can compute by setting superscript -1.

Angle

By setting superscript of a factor o, converts angle to radian.

var f = \[
            o
f(x) = sin x
\]
console.log(f.f(90));  // outputs 1

Exponent function

To compute exponent function, writes exp before destination formula.

var f = \[
f(x) = exp x
\]
console.log(f.f(1));  // outpus 2.71828...

Logarithm function

To compute logarithm function, writes log or ln before destination formula.

var f = \[
f(a) = log a
\]
console.log(f.f(Math.E));  // outputs 1

By setting subscript of a factor, you can specify a base of logarithm. It can specify only log, not ln.

var f = \[
f(a) = log  a
          2
\]
console.log(f.f(8));  // outputs 3

Predefined constants

e, π(\pi) are predefined constants.

var f = \[
a = e

b = π
\]
console.log(f.a);  // outputs 2.71828...
console.log(f.b);  // outputs 3.14159...

Finite summation

Summation sign can be used to compute finite summation.

var f = \[
          3
       ---        2
f(a) =  >       an
       ---
          n = 1
\]
console.log(f.f(2));  // outputs 28

Infinite series

To compute infinite series, upper limit of summation is set to infinity.

var f = \[
          oo    n
       ---     x
f(x) =  >     ----
       ---     n!
          n=0
\]
console.log(f.f(1))  // outputs 2.71828...

Numerical integration

Integral sign can be used to compute numerial integration.
Variable to integrate must be set after integral sign.
Range of integration must be finite.

var f = \[
          a
        /\      2
f(a) =  |   dx x
       \/
          0
\]
console.log(f.f(2));  // outputs 2.666...

Example

Ackermann function

Ackermann function is a function shown as follows.

tex
tex
tex
var f = \[
A    = n+1
 0,n

A    = A
 m,0    m-1,1

A    = A
 m,n    m-1,A
             m,n-1
\]
console.log(f.A(3, 3)) // outputs 61

Bessel function at zeroth order

Bessel function at zeroth order is shown as follows.

tex
var f = \[
          oo       m
       ---     (-1)     x  2m
J(x) =  >     ------- (---)
       ---     m!m!     2
          m=0
\]
console.log(f.J(1)) // outputs 0.76519...

Gudermannian function

Gudermannian function is defined shown as follows.

tex

Formulae shown as follows are equivalent to Gudermannian function.

tex
tex
var f = \[
          x
        /\        1
g(x) =  |   dt --------
       \/       cosh t
          0
\]
console.log(f.g(2)) // outputs 1.3017603...
var f = \[
          -1
g(x) = sin   tanh x
\]
console.log(f.g(2)) // outputs 1.3017603...
var f = \[
          -1
g(x) = tan   sinh x
\]
console.log(f.g(2)) // outputs 1.3017603...
var f = \[
           -1        x
g(x) = 2tan   (tanh ---)
                     2
\]
console.log(f.g(2)) // outputs 1.3017603...
var f = \[
           -1  x    π
g(x) = 2tan  (e ) - --
                    2
\]
console.log(f.g(2)) // outputs 1.3017603...