@amilas/boolean.api v0.0.8
Presentation
This package is a library for the Amilas project, it permits you to build computation models based on the boolean algebra.
Installation
This package is compatible with npm and can be installed like this:
npm install @amilas/boolean.api
see also:
Usage
Use the following tools to build your model, you can mix them with others libraries. Once your model is built, send it to the amilas-server with the @amilas/rest.api package
boolean
A boolean
node represents à simple boolean true/false value;
import {AmilasContext} from "@amilas/core"
import AmilasBooleanApi from "@amilas/boolean.api"
const context = new AmilasContext();
const {boolean} = new AmilasBooleanApi(context);
const trueNode = boolean(true); // this node alway evals to true
const falseNode = boolean(false); // this node alway evals to false
toBoolean
A toBoolean
node allows to cast whatever node into a boolean node
import {AmilasContext} from "@amilas/core"
import AmilasBooleanApi from "@amilas/boolean.api"
import amilasStdApi from "@amilas/std.api"
const context = new AmilasContext();
const {toBoolean} = new AmilasBooleanApi(context);
const {constant} = new amilasStdApi(context);
const node1 = constant(1); // this node alway evals to 1
const castNode1 = toBoolean(node); // this node alway evals to true
const node2 = constant(0); // this node alway evals to 0
const castNode2 = toBoolean(node); // this node alway evals to false
true
A TRUE
node is an alias for boolean(true)
import {AmilasContext} from "@amilas/core"
import AmilasBooleanApi from "@amilas/boolean.api"
const context = new AmilasContext();
const {TRUE} = new AmilasBooleanApi(context);
const trueNode = TRUE(); // this node alway evals to true
false
A FALSE
node is an alias for boolean(false)
import {AmilasContext} from "@amilas/core"
import AmilasBooleanApi from "@amilas/boolean.api"
const context = new AmilasContext();
const {FALSE} = new AmilasBooleanApi(context);
const falseNode = FALSE(); // this node alway evals to false
isTrue
An isTrue
node evals to true if its child evals to true, false else
import {AmilasContext} from "@amilas/core"
import AmilasBooleanApi from "@amilas/boolean.api"
const context = new AmilasContext();
const {TRUE, isTrue} = new AmilasBooleanApi(context);
const trueNode = TRUE();
// regular call
const isTrueNode1 = isTrue(trueNode);
// chaining call
const isTrueNode2 = trueNode.isTrue();
isFalse
A isFalse
node evals to false if its child evals to false, true else
import {AmilasContext} from "@amilas/core"
import AmilasBooleanApi from "@amilas/boolean.api"
const context = new AmilasContext();
const {FALSE, isFalse} = new AmilasBooleanApi(context);
const falseNode = FALSE(); // this node alway evals to false
const isFalseNode = isFalse(falseNode); // this node alway evals to true
not
A not
node evals to true if its child evals to false, false else
import {AmilasContext} from "@amilas/core"
import AmilasBooleanApi from "@amilas/boolean.api"
const context = new AmilasContext();
const {TRUE, FALSE, not} = new AmilasBooleanApi(context);
const trueNode = TRUE();
const falseNode = FALSE();
const n1 = not(falseNode); // this node evals to true
const n2 = not(trueNode); // this node evals to false
and
An and
node evals to true if all its children evals to true, false else
import {AmilasContext} from "@amilas/core"
import AmilasBooleanApi from "@amilas/boolean.api"
const context = new AmilasContext();
const {TRUE, FALSE, and} = new AmilasBooleanApi(context);
const trueNode = TRUE();
const falseNode = FALSE();
// Here, some ways to create an and node
const n1 = and(falseNode, falseNode);
const n2 = and(trueNode, false);
const n3 = trueNode.and(falseNode);
const n4 = falseNode.and(true);
nand
import {AmilasContext} from "@amilas/core"
import AmilasBooleanApi from "@amilas/boolean.api"
const context = new AmilasContext();
const {TRUE, FALSE, nand} = new AmilasBooleanApi(context);
const trueNode = TRUE();
const falseNode = FALSE();
const n1 = nand(falseNode, falseNode); // this node evals to true
const n2 = nand(trueNode, falseNode); // this node evals to true
const n3 = nand(falseNode, trueNode); // this node evals to true
const n4 = nand(trueNode, trueNode); // this node evals to false
const n5 = nand(trueNode, trueNode, falseNode); // this node evals to true
const n6 = nand(trueNode, trueNode, trueNode); // this node evals to false
or
A or
node evals to true if at least one of its children evals to true, false else
import {AmilasContext} from "@amilas/core"
import AmilasBooleanApi from "@amilas/boolean.api"
const context = new AmilasContext();
const {TRUE, FALSE, or} = new AmilasBooleanApi(context);
const trueNode = TRUE();
const falseNode = FALSE();
const n1 = or(falseNode, falseNode); // this node evals to false
const n2 = or(trueNode, falseNode); // this node evals to true
const n3 = or(falseNode, trueNode); // this node evals to true
const n4 = or(trueNode, trueNode); // this node evals to true
const n5 = or(trueNode, falseNode, falseNode); // this node evals to true
const n6 = or(falseNode, falseNode, falseNode); // this node evals to false
nor
import {AmilasContext} from "@amilas/core"
import AmilasBooleanApi from "@amilas/boolean.api"
const context = new AmilasContext();
const {TRUE, FALSE, nor} = new AmilasBooleanApi(context);
const trueNode = TRUE();
const falseNode = FALSE();
const n1 = nor(falseNode, falseNode); // this node evals to true
const n2 = nor(trueNode, falseNode); // this node evals to false
const n3 = nor(falseNode, trueNode); // this node evals to false
const n4 = nor(trueNode, trueNode); // this node evals to false
const n5 = nor(trueNode, falseNode, falseNode); // this node evals to false
const n6 = nor(falseNode, falseNode, falseNode); // this node evals to true
xand
import {AmilasContext} from "@amilas/core"
import AmilasBooleanApi from "@amilas/boolean.api"
const context = new AmilasContext();
const {TRUE, FALSE, xand} = new AmilasBooleanApi(context);
const trueNode = TRUE();
const falseNode = FALSE();
const n1 = xand(falseNode, falseNode); // this node evals to true
const n2 = xand(trueNode, falseNode); // this node evals to false
const n3 = xand(falseNode, trueNode); // this node evals to false
const n4 = xand(trueNode, trueNode); // this node evals to true
xnand
import {AmilasContext} from "@amilas/core"
import AmilasBooleanApi from "@amilas/boolean.api"
const context = new AmilasContext();
const {TRUE, FALSE, xnand} = new AmilasBooleanApi(context);
const trueNode = TRUE();
const falseNode = FALSE();
const n1 = xnand(falseNode, falseNode); // this node evals to false
const n2 = xnand(trueNode, falseNode); // this node evals to true
const n3 = xnand(falseNode, trueNode); // this node evals to true
const n4 = xnand(trueNode, trueNode); // this node evals to false
xor
import {AmilasContext} from "@amilas/core"
import AmilasBooleanApi from "@amilas/boolean.api"
const context = new AmilasContext();
const {TRUE, FALSE, xor} = new AmilasBooleanApi(context);
const trueNode = TRUE();
const falseNode = FALSE();
const n1 = xor(falseNode, falseNode); // this node evals to false
const n2 = xor(trueNode, falseNode); // this node evals to true
const n3 = xor(falseNode, trueNode); // this node evals to true
const n4 = xor(trueNode, trueNode); // this node evals to false
xnor
import {AmilasContext} from "@amilas/core"
import AmilasBooleanApi from "@amilas/boolean.api"
const context = new AmilasContext();
const {TRUE, FALSE, xor} = new AmilasBooleanApi(context);
const trueNode = TRUE();
const falseNode = FALSE();
const n1 = xnor(falseNode, falseNode); // this node evals to true
const n2 = xnor(trueNode, falseNode); // this node evals to false
const n3 = xnor(falseNode, trueNode); // this node evals to false
const n4 = xnor(trueNode, trueNode); // this node evals to true