Skip to content
This repository has been archived by the owner on Jan 4, 2022. It is now read-only.
/ 42-ComputorV2 Public archive

Maths interpreter handling complex numbers, matrix and advanced functions to list some.

License

Notifications You must be signed in to change notification settings

kibotrel/42-ComputorV2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

42-ComputorV2

CodeFactor GitHub GitHub code size in bytes Lines of code

This project provides you an advanced maths interpreter interface highly inspired by Linux bc.

📦 Install

First, you'll need to get yourself node.js v16 and install some packages to get plotter dependency working as expected.

  • Linux, use your distribution packets manager:

    $> sudo apt-get install gnuplot ghostscript
  • macOS, use Homebrew:

    $> brew install gnuplot ghostscript

Then all you have to do is installing package dependencies:

$> npm install

💻 Usage

Run the interpeter with:

$> node computor.js

Run test suites with:

$> npm run tests

Features

  • Computing:

    Handles simple expression with addition, substraction, multiplication, division, power and modulus operators with brakect priorities.

    > 2 + 23 * (8.23 / (2 - 7)) = ?
    

    It also supports complex numbers and unary operators.

    > -2.23 + (-2.1) / 3.08i = ?
    

    This evaluation algorithm also support variables which are explained bellow, both Numeral and Matrix variables are used in the same way, call its name and it will be evaluated before the whole input.

    > 57 + x / 723.2 = ?
    

    For Expression variables, you get to give them the right amount of parameters to evaluate their images.

    > 2.8211 * f(23) = ?
    

    All of the variable types supports unary operator which means you can get the opposite of any variable by putting a minus sign before in your input.

  • Storing variables:

    This program allows you to compute and keep three different types of variables. First, Numeral, basically representing numbers from integers to complex ones.

    > x = -7.5 + 82i
    

    It computes the result of the left term and then assign it to the requested variable.

    Then we have Matrix type that holds 2D Matrix only.

    > m = [[ 2, 0, -3 ]; [ 7, 0.82, -12 ]]
    

    Supports other Numerals and Expression images as well (described bellow) in each term of the matrix.

    Finally, Expression which are simply functions that take variables.

    > f(x, y, z) = x - 6.2 / y + 2 * z
    

    You can create Expression with arbitrary number of variables, no limit.

  • Builtins:

    Some common maths functions are reproduced and available to you, here's all of the supported functions. They can be used during input evaluation or variable assignation.

    Symbol Function Implementation Coverage
    abs() absolute value Trivial on ℝ and uses Euclidian distance on ℂ
    cos() cosine Taylor series
    cosh() hyperbolic cosine Taylor series
    exp() exponential Taylor series
    deg() radian to degree radian * 180 / π
    fact() factorial n! = n * (n - 1) * ... * 1
    ln() natural logarithm Taylor series +
    log() logarithm base10 Long division algorithm +
    rad() degree to radian degree * π / 180
    sin() sine Taylor series
    sinh() hyperbolic sine Taylor series
    sqrt() square root Babylonian algorithm
  • Commands:

    You also have a selection of commands that you can use to your liking during program's context.

    Command Details
    !commands Shows you details about each command.
    !config Shows current context configuration.
    !functions Shows stored Expression elements.
    !help Gives you more information about some errors that might occur at runtine.
    !history Shows you the list of previous inputs you made.
    !matrices Shows stored Matrix elements.
    !reset Wipes everything stored and set default context configuration.
    !set Allows you to tweak some options in configuration.
    !solve Built-in quadratic equation solver.

🛠️ Configuration

This program allows you to modify some options to alter or augment some behaviours. Here is the list of all available options.

Option Type Description
env.errorStackTrace Boolean Toggles tracing error display.
env.historySize Number Sets the size of the list displayed using !history command.
env.silentMode Boolean Toggles display for a lot of things. Mainly for testing purposes.
equation.graph Boolean Toggles ploting equation on a graph when using !solve command.
equation.verbose Boolean Toggles intermediate computation display when using !solve command.
function.expensionCount Number Sets the number of iterations for Taylor series.
number.fractionForm Boolean Toggles fractionnal display. Useful when 𝑥 ∈ ℚ.
number.precision Number Sets the number of computed decimals.

Every single option listed above can be configured using the !set command.

About

Maths interpreter handling complex numbers, matrix and advanced functions to list some.

Topics

Resources

License

Stars

Watchers

Forks