Giter Club home page Giter Club logo

eqsolver's Introduction

solver.js

By Charles Boyd <charlesboyd.me>

Portions adapted from geeksforgeeks.org/expression-evaluation

Can be used as a node.js script or included in a webpage.

For equations, use the following:
+   add
-   subtract
*   multiply
/   divide
^   raise to a power

For logcial expressions, use the following:
&   and
|   or
>   conditional
=   biconditional/equivalent
~   not
!   not

Parenthesis such as () may be used for grouping.

A value of zero (0) is assumed to be false. All others are assumed to be true. Truthy output from this script will be represented by a value of one (1).

Variables A to Z may be included for truth table printing.

For solver.evaluate(expression), all variables A to Z (except T) are assumed to have a value of zero (0) unless otherwise specified. The variable T is given a default value of one (1) and the variable F is given a default value of zero (0).

The solver.auto(expression) will evalute the experession provided (if it is valid) and print it, unless a variable besides T or F is provided, in which case it will print a truth table for the expression.

Currently, the order of operations must be specified for all logical expressions by using parenthesis: e.g. use 1 | (~0) instead of 1 | ~0.

Node.js example:
node solver.js "1+1"

TODO: Add public function descriptions, inputs, and outputs.

TODO: Add more examples

Examples:
solver.printTruthTable("(B&~1)|A");
solver.printTruthTable("A | (B & C) | H|E|L|L|O");

eqsolver's People

Contributors

charlesboyd avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.