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...

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...

Example

Spherical Mercator projection

Translation formulae of spherical Mercator projection are given as follows.

tex
tex

where φ is latitude(Breite) and λ is longitude(Länge).
ShikiPL code which projects longitude is shown as follows.

var f = \[
                      o
               \pi   b
y(b) = ln tan (--- + --)
                4    2
\]
console.log(f.y(27));  // outputs 0.48971537442745056

Haversine formula

To obtain distance of two geometrical coordinates, use haversine formula shown as follows.

tex

where R is Earth radius, φ is latitude(Breite) and λ is longitude(Länge).
ShikiPL code which compute distance of the points is shown as follows.

var f = \[
r = 3956

                             ____________________________________________
                            /       o   o                         o   o
                      -1   /    2  B - b          o      o    2  L - l
d(B, b, L, l) = 2r sin    /  sin  -------- + cos B  cos b  sin  --------
                         v           2                             2
\]
console.log(f.d(3.046685, 3.146685, 100.686656, 101.686656));  // outputs 69.2892623017496