4. Math & Logic Engine

This is the most powerful and proud core driving force of MindLogic. A normal diagram is just a static picture, but in MindLogic, the graph is a living spreadsheet and a logical sandbox.

4.1 Confidence Inference

Confidence is used to process "logical probabilities" or "factual likelihoods" within the graph. When you connect multiple nodes, you can select the Junctor and configure its operator in the "Operators" section of the sidebar. The system will automatically propagate the upstream confidence to the downstream nodes based on the chosen operator:

  • Fuzzy AND (∧): Takes the minimum value of all upstream input confidences (the wooden barrel effect).
  • Fuzzy OR (∨): Takes the maximum value of all upstream input confidences.
  • Product (×): Multiplies upstream probabilities, suitable for calculating the joint probability of multiple independent continuous events.
  • Sum Probability (Σp): Calculates 1 - (1-p1)(1-p2)..., used to deduce the probability when multiple independent factors can contribute to a result.
  • Other operators include: Sum, Average, Negate, Complement, and over a dozen other mathematical operators.

Tip: The default confidence of an entity is inferred from upstream, but if you manually modify an entity's confidence, it will be "Overridden" to your specified value.

4.2 Data & Formulas

Turn nodes into spreadsheet cells, allowing underlying data to flow automatically along the edges. This is achieved through the "Attributes" panel in the sidebar.

1. Defining and Outputting Variables

In the "Defined Attributes" or "Output Expressions" sections, you can add new attributes to the current node.

  • For example, you can define a constant directly: Key: cost, Value: 100.
  • Or you can define a formula: Key: total_cost, Value: cost * 1.2.

2. Receiving Upstream Branch Data (Inputs)

If a node has multiple incoming edges, the data transmitted from these edges is automatically mounted in a hidden inputs array. For easy extraction, you can directly use the VariableName[ID] syntax to extract data from a specific branch:

  • For example, if two upstream nodes transmit a time variable, you can write the formula time[1] + time[2].

3. Using Built-in Macros

The MindLogic engine injects several powerful aggregation functions under the hood. They automatically traverse all upstream nodes to aggregate the transmitted variables:

  • SUM(cost): Adds up all cost values transmitted from upstream.
  • MIN(time) / MAX(time): Finds the minimum or maximum among all upstream time variables.
  • PRODUCT(rate): Multiplies all rate values transmitted from upstream.

4. Native JS Engine and Rich Global Functions Support

The underlying inference engine is based on a complete JSContext, and we have elevated numerous Excel-style functions and native Math functions to the global scope. You can use them directly without any prefixes, just like in Excel:

Logic & Error Handling

  • IF(condition, true_val, false_val): Conditional check.
  • AND(cond1, cond2) / OR(cond1, cond2) / NOT(cond): Basic logic.
  • IFERROR(value, fallback): Highly recommended. Safely handle missing values or divide-by-zero errors. e.g. IFERROR(A / B, 0).
  • ISBLANK(value) / ISNULL(value): Check if an upstream variable is missing.

Text Processing Functions

Useful for formatting strings to be displayed in the UI or exported:

  • CONCAT(text1, text2, ...): Merge multiple strings.
  • LEN(text): Get string length.
  • LEFT(text, n) / RIGHT(text, n): Extract substrings from the edges.
  • UPPER(text) / LOWER(text): Case conversion.
  • TRIM(text): Remove leading/trailing whitespaces.

Advanced Math & Date Functions

  • Math computations: ROUND(x), ABS(x), POW(x, y), CEIL(x), FLOOR(x), SQRT(x), MOD(num, div), PI().
  • Random generation: RAND() (0 to 1), RANDBETWEEN(min, max).
  • Date & Time: NOW(), TODAY(), YEAR(date), MONTH(date), DAY(date), DATEDIF(start, end) (Calculate day difference).

You can still fallback to native JS syntax if needed, such as Math.max(x, y).

4.3 Advanced Tips

1. Variable Name Escaping

MindLogic's calculation engine is built on top of a powerful JavaScript environment. If your variable name contains parentheses, spaces, or math operators (e.g., Order Delay (Hours)), writing it directly in a formula may be mistakenly parsed as code, resulting in a SyntaxError.

  • Solution: When using built-in aggregation functions like SUM or AVERAGE, wrap the variable name in single or double quotes.
  • Example: SUM("Order Delay (Hours)") or MAX('Delivery Time (Days)').
  • How it works: When the engine receives a string argument, it automatically searches for exact variable name matches in the data passed from all upstream nodes and aggregates them. For standard variable names containing only letters and numbers (like cost), quotes are not required, and you can just write SUM(cost).

2. Attribute Auto Pass-through

Data flowing through the network connections features an automatic pass-through and aggregation mechanism:

  1. Upstream Variable Inflow: Any custom attributes or output values calculated by formulas on upstream nodes will automatically flow along the edges into the downstream node's data pool (inputs).
  2. Smart Variable Accumulation: For standard named variables, the engine will automatically accumulate variables with the same name. For example, if three upstream nodes transmit a cost of 10, 20, and 30 respectively, you can simply write cost + 100 in the downstream node's formula (where cost is automatically summed to 60) without explicitly writing SUM(cost). This "what you connect is what you get" mechanism greatly simplifies configuring complex logic models.

4.4 Dynamic Placeholders

The most intuitive way to experience the calculation engine is through "Data Visualization". In a node's title or Markdown text description, you can use the { } syntax to insert variable names at any time.

  • How to use: Double-click the node to enter edit mode, and type Cost is: ${cost}.
  • Effect: When the graph structure changes or upstream data fluctuates, the engine instantly recalculates, and the text on the node automatically updates in real-time to Cost is: $120, without requiring any manual refresh!