{
  "openapi": "3.1.1",
  "info": {
    "title": "Ohmforge Logic Minimiser (multi-output, Petrick, K-map groups) API",
    "version": "1.0.0",
    "summary": "Truth table with several outputs → all minimal SOP/POS forms, grouped K-maps, gates and Verilog.",
    "description": "Every endpoint performs the same calculation as the human page and returns inputs, result, units, assumptions, sources, warnings and computedAt. MCP endpoint: /mcp."
  },
  "servers": [
    {
      "url": "https://ohmforgelogicminimizer.usefulweb.site"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Truth table with several outputs → all minimal SOP/POS forms, grouped K-maps, gates and Verilog.",
        "description": "Paste a truth table with up to 6 inputs and 8 outputs (rows with - for \"either value\", x for don't care) or a list of equations. For each output you get every minimum sum of products or product of sums (Quine–McCluskey primes and Petrick's method), the Karnaugh map with the chosen groups drawn in, the prime implicant chart, a two-level gate schematic, a Verilog module and a simulator netlist that is simulated and compared with the table. Compare mode checks whether two Boolean expressions are equivalent and lists counterexamples.\n\nMethodology:\n- Truth table: every row with - in an input stands for both values; rows not listed are 0 or don't care (your choice); a row given twice with different outputs is an error that names both lines.\n- Quine–McCluskey: for each output the 1 rows and don't cares are merged into prime implicants (the 0 rows and don't cares for the product of sums).\n- Petrick's method: \"each 1 row must be covered\" is written as a product of sums over the primes that are not essential and multiplied out with absorption (X + XY = X); every product with the fewest terms, then the fewest literals, is a minimum cover. The expansion is pruned with the cost of a branch-and-bound cover, which cannot remove a minimum; above 20,000 partial products only that one cover is returned and marked as incomplete.\n- Karnaugh maps use Gray-code order; 5 and 6 inputs are drawn as 2 or 4 maps selected by the first inputs. Each group of the chosen cover is a numbered, coloured outline (groups that wrap around the edge appear as pieces on both sides).\n- The gate schematic and the Verilog module realise the chosen cover with NOT, AND and OR gates. The same cover is written as a netlist for the logic simulator (shared inverters and terms, 1 time unit per gate), simulated for every input row and compared with the table, so the result is checked independently of the minimiser.\n- Equivalence checks evaluate both sides for every input combination (don't-care rows excluded when checking against the table).\n\nEach output is minimised on its own as a two-level circuit (terms, then literals); shared terms between outputs are reused in the netlist but not optimised for. Multi-level, XOR-based or FPGA LUT mappings can be smaller. Simulation and learning, not FPGA synthesis.",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "ohmforge_logic_minimizer",
        "x-owner-app": "ohmforge",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/OhmforgeLogicMinimizerInput"
              },
              "examples": {
                "example1": {
                  "summary": "BCD to 7-segment (a, b, c) with don't cares",
                  "value": {
                    "mode": "table",
                    "table": "# name: BCD to 7-segment (a, b, c)\nB3 B2 B1 B0 | a b c\n0 0 0 0 | 1 1 1\n0 0 0 1 | 0 1 1\n0 0 1 0 | 1 1 0\n0 0 1 1 | 1 1 1\n0 1 0 0 | 0 1 1\n0 1 0 1 | 1 0 1\n0 1 1 0 | 1 0 1\n0 1 1 1 | 1 1 1\n1 0 0 0 | 1 1 1\n1 0 0 1 | 1 1 1\n1 0 1 - | x x x\n1 1 - - | x x x\n"
                  }
                },
                "example2": {
                  "summary": "Cyclic function: two minimum covers (Petrick)",
                  "value": {
                    "mode": "table",
                    "table": "# name: Cyclic core (Petrick)\nA B C | F\n0 0 0 | 1\n0 0 1 | 1\n0 1 0 | 1\n0 1 1 | 0\n1 0 0 | 0\n1 0 1 | 1\n1 1 0 | 1\n1 1 1 | 1\n"
                  }
                },
                "example3": {
                  "summary": "Full adder from equations as product of sums",
                  "value": {
                    "mode": "equations",
                    "equations": "S = A ^ B ^ C\nCo = AB + AC + BC",
                    "form": "pos"
                  }
                },
                "example4": {
                  "summary": "Is A'B + AB' the same as (A + B)(AB)'?",
                  "value": {
                    "mode": "compare",
                    "left": "A'B + AB'",
                    "right": "(A + B)(AB)'"
                  }
                },
                "example5": {
                  "summary": "Check a hand-made solution (one row wrong)",
                  "value": {
                    "mode": "table",
                    "table": "# name: Cyclic core (Petrick)\nA B C | F\n0 0 0 | 1\n0 0 1 | 1\n0 1 0 | 1\n0 1 1 | 0\n1 0 0 | 0\n1 0 1 | 1\n1 1 0 | 1\n1 1 1 | 1\n",
                    "check": "F = A'B' + AC + B"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OhmforgeLogicMinimizerResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed JSON body.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Invalid input (see errors[]).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded (see Retry-After).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/tool": {
      "get": {
        "operationId": "getToolDefinition",
        "summary": "Inputs, output schema and examples for this tool",
        "responses": {
          "200": {
            "description": "Tool definition.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Problem": {
        "type": "object",
        "description": "RFC 9457 problem details. 422 responses include per-field `errors`.",
        "required": [
          "type",
          "title",
          "status",
          "detail"
        ],
        "properties": {
          "type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "field",
                "message"
              ],
              "properties": {
                "field": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "OhmforgeLogicMinimizerInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "mode": {
            "title": "Input",
            "type": "string",
            "enum": [
              "table",
              "equations",
              "compare"
            ],
            "default": "table"
          },
          "table": {
            "title": "Truth table",
            "description": "Header \"A B C | F G\" (inputs | outputs), then one row per line: \"0 1 1 | 1 0\" (spaces optional). - in the inputs covers 0 and 1; x or - in the outputs is a don't care. Up to 6 inputs (a letter with an optional number) and 8 outputs. # starts a comment.",
            "type": "string",
            "maxLength": 100000,
            "default": "# name: BCD to 7-segment (a, b, c)\nB3 B2 B1 B0 | a b c\n0 0 0 0 | 1 1 1\n0 0 0 1 | 0 1 1\n0 0 1 0 | 1 1 0\n0 0 1 1 | 1 1 1\n0 1 0 0 | 0 1 1\n0 1 0 1 | 1 0 1\n0 1 1 0 | 1 0 1\n0 1 1 1 | 1 1 1\n1 0 0 0 | 1 1 1\n1 0 0 1 | 1 1 1\n1 0 1 - | x x x\n1 1 - - | x x x\n"
          },
          "unlisted": {
            "title": "Rows not listed",
            "type": "string",
            "enum": [
              "0",
              "x"
            ],
            "default": "0"
          },
          "equations": {
            "title": "Equations",
            "description": "For \"Equations\": one per line, e.g. \"S = A xor B xor C\" and \"Co = AB + AC + BC\". Same operators as the truth-table tool (' or ! NOT, · \u0026 or nothing AND, + | OR, ^ XOR).",
            "type": "string",
            "maxLength": 8000,
            "default": ""
          },
          "form": {
            "title": "Minimal form",
            "type": "string",
            "enum": [
              "sop",
              "pos"
            ],
            "default": "sop"
          },
          "check": {
            "title": "Check against (optional)",
            "description": "Your own solution per output, e.g. \"a = B3 + B1 + B2B0 + B2'B0'\": each is compared with the table (don't-care rows ignored) and mismatching rows are listed.",
            "type": "string",
            "maxLength": 4000,
            "default": ""
          },
          "left": {
            "title": "Expression 1",
            "description": "For \"Compare two expressions\", up to 16 variables.",
            "type": "string",
            "maxLength": 1000,
            "default": ""
          },
          "right": {
            "title": "Expression 2",
            "type": "string",
            "maxLength": 1000,
            "default": ""
          }
        },
        "required": []
      },
      "OhmforgeLogicMinimizerResult": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "schemaVersion",
          "tool",
          "computedAt",
          "inputs",
          "summary",
          "result",
          "units",
          "assumptions",
          "sources",
          "warnings",
          "presentation",
          "links"
        ],
        "properties": {
          "schemaVersion": {
            "type": "string",
            "const": "1.0"
          },
          "tool": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "name",
              "version"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "version": {
                "type": "string"
              }
            }
          },
          "computedAt": {
            "type": "string",
            "format": "date-time"
          },
          "inputs": {
            "type": "object",
            "description": "Normalised inputs actually used, including applied defaults."
          },
          "summary": {
            "type": "string"
          },
          "result": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "mode"
            ],
            "properties": {
              "mode": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "inputs": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "outputs": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "form": {
                "type": "string"
              },
              "functions": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "output": {
                      "type": "string"
                    },
                    "minterms": {
                      "type": "array",
                      "items": {
                        "type": "integer"
                      }
                    },
                    "dontCares": {
                      "type": "array",
                      "items": {
                        "type": "integer"
                      }
                    },
                    "expression": {
                      "type": "string",
                      "description": "Chosen minimal cover (solution 1 unless the function has several)."
                    },
                    "verilog": {
                      "type": "string"
                    },
                    "minimalSolutions": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      },
                      "description": "Every minimum cover found by Petrick's method (max 24 listed)."
                    },
                    "solutionCount": {
                      "type": "integer"
                    },
                    "complete": {
                      "type": "boolean",
                      "description": "False when Petrick's expansion hit its limit; then only one minimal cover is listed."
                    },
                    "terms": {
                      "type": "integer"
                    },
                    "literals": {
                      "type": "integer"
                    },
                    "primeImplicants": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "additionalProperties": false,
                        "properties": {
                          "term": {
                            "type": "string"
                          },
                          "cube": {
                            "type": "string"
                          },
                          "essential": {
                            "type": "boolean"
                          }
                        }
                      }
                    },
                    "check": {
                      "type": [
                        "object",
                        "null"
                      ],
                      "additionalProperties": false,
                      "properties": {
                        "expression": {
                          "type": "string"
                        },
                        "equivalent": {
                          "type": "boolean"
                        },
                        "compared": {
                          "type": "integer"
                        },
                        "mismatchCount": {
                          "type": "integer"
                        },
                        "mismatches": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "additionalProperties": false,
                            "properties": {
                              "row": {
                                "type": "integer"
                              },
                              "inputs": {
                                "type": "string"
                              },
                              "expected": {
                                "type": "string"
                              },
                              "actual": {
                                "type": "string"
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              },
              "gates": {
                "type": "integer"
              },
              "simulation": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "rows": {
                    "type": "integer"
                  },
                  "mismatches": {
                    "type": "integer"
                  }
                }
              },
              "verilog": {
                "type": "string"
              },
              "netlist": {
                "type": "string",
                "description": "Netlist for the ohmforge-logic-simulator tool."
              },
              "truthTable": {
                "type": "string",
                "description": "Full truth table in the text format (re-importable)."
              },
              "equivalence": {
                "type": [
                  "object",
                  "null"
                ],
                "additionalProperties": false,
                "properties": {
                  "left": {
                    "type": "string"
                  },
                  "right": {
                    "type": "string"
                  },
                  "variables": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "equivalent": {
                    "type": "boolean"
                  },
                  "compared": {
                    "type": "integer"
                  },
                  "mismatchCount": {
                    "type": "integer"
                  },
                  "mismatches": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "additionalProperties": false,
                      "properties": {
                        "row": {
                          "type": "integer"
                        },
                        "inputs": {
                          "type": "string"
                        },
                        "left": {
                          "type": "string"
                        },
                        "right": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "units": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "assumptions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "title"
              ],
              "properties": {
                "title": {
                  "type": "string"
                },
                "url": {
                  "type": "string"
                },
                "publisher": {
                  "type": "string"
                },
                "retrievedAt": {
                  "type": "string"
                },
                "note": {
                  "type": "string"
                }
              }
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "presentation": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "Display blocks used by the human page (same data)."
          },
          "links": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "human",
              "api",
              "openapi",
              "methodology"
            ],
            "properties": {
              "human": {
                "type": "string",
                "format": "uri"
              },
              "api": {
                "type": "string",
                "format": "uri"
              },
              "openapi": {
                "type": "string",
                "format": "uri"
              },
              "methodology": {
                "type": "string",
                "format": "uri"
              }
            }
          }
        }
      }
    }
  }
}