{"id":13749191,"url":"https://github.com/night-crawler/nnf","last_synced_at":"2026-06-04T16:31:02.418Z","repository":{"id":65516140,"uuid":"582436713","full_name":"night-crawler/nnf","owner":"night-crawler","description":"Negation Normal Form manipulation library","archived":false,"fork":false,"pushed_at":"2023-04-19T11:50:05.000Z","size":31,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-05-22T21:34:42.836Z","etag":null,"topics":["cnf","nnf","tseitin-transformation"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/night-crawler.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-26T20:40:56.000Z","updated_at":"2024-08-03T07:03:06.384Z","dependencies_parsed_at":"2024-08-03T07:13:04.006Z","dependency_job_id":null,"html_url":"https://github.com/night-crawler/nnf","commit_stats":{"total_commits":10,"total_committers":1,"mean_commits":10.0,"dds":0.0,"last_synced_commit":"2f53e52722add11b59ed4f63aa935d568b937b5d"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/night-crawler%2Fnnf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/night-crawler%2Fnnf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/night-crawler%2Fnnf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/night-crawler%2Fnnf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/night-crawler","download_url":"https://codeload.github.com/night-crawler/nnf/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240236230,"owners_count":19769573,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cnf","nnf","tseitin-transformation"],"created_at":"2024-08-03T07:00:56.742Z","updated_at":"2026-06-04T16:31:02.405Z","avatar_url":"https://github.com/night-crawler.png","language":"Rust","funding_links":[],"categories":["Projects"],"sub_categories":["Libraries"],"readme":"# nnf\n\n[![crates.io](https://img.shields.io/crates/v/nnf.svg)](https://crates.io/crates/nnf)\n[![Rust](https://github.com/night-crawler/nnf/actions/workflows/rust.yml/badge.svg?branch=main)](https://github.com/night-crawler/nnf/actions/workflows/rust.yml)\n[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)\n\nNegation Normal Form manipulation library\n\n### Macro \u0026 bit operations\n\n```rust\nfn sample() {\n    let a = Nnf::Var(\"a\", true);\n    let b = var!(\"b\", false);\n    let or = or!(a.clone(), b.clone());\n}\n\n```\n\n### Simple operations optimization\n\n```rust\nassert_eq!(and!(\"a\") \u0026 and!(\"b\"), and!(\"a\", \"b\"));\nassert_eq!(and!(\"a\") | and!(\"b\"), or!(\"a\", \"b\"));\n```\n\n### Tseitin Transform (NNF -\u003e CNF)\n\n```rust\nfn transform(sentence: Nnf\u003c\u0026'static str\u003e) -\u003e Nnf\u003c\u0026'static str\u003e {\n    let mut counter = 0;\n    let transformer = TseitinTransform::new(|_| {\n        let name: \u0026'static str = Box::leak(Box::new(format!(\"aux_{}\", counter)));\n        counter += 1;\n        var!(name)\n    });\n\n    transformer.transform(sentence)\n}\n\nfn test() {\n    let sentence = or!(\n        and!(\n            var!(\"a\"),\n            and!(\"b\", \"c\")\n        ),\n        and!(\n            or!(\"!d\", \"e\"),\n            and!(\"f\", \"!g\")\n        )\n    );\n    assert!(!sentence.is_cnf(), \"Expression is not a cnf yet\");\n\n    let sentence = transform(sentence);\n    assert!(sentence.is_cnf(), \"Expression must be in the cnf form after transformation\");\n\n    assert_eq!(\n        sentence,\n        and!(\n            or!(\"a\", \"!aux_1\"),\n            or!(\"aux_0\", \"!aux_1\"),\n            or!(\"aux_1\", \"aux_4\"),\n            or!(\"aux_2\", \"!aux_4\"),\n            or!(\"aux_3\", \"!aux_4\"),\n            or!(\"!aux_0\", \"b\"),\n            or!(\"!aux_0\", \"c\"),\n            or!(\"aux_3\", \"d\"),\n            or!(\"aux_3\", \"!e\"),\n            or!(\"!aux_2\", \"f\"),\n            or!(\"!aux_2\", \"!g\"),\n            or!(\"!a\", \"!aux_0\", \"aux_1\"),\n            or!(\"!aux_2\", \"!aux_3\", \"aux_4\"),\n            or!(\"aux_0\", \"!b\", \"!c\"),\n            or!(\"!aux_3\", \"!d\", \"e\"),\n            or!(\"aux_2\", \"!f\", \"g\")\n        )\n    );\n}\n```\n\n## Parse Tree\n\n### Macro support\n\n```rust\nfn test() {\n    let root = ExpressionNode::Not(\n        ExpressionNode::And(\n            ExpressionNode::Or(\n                ExpressionNode::Leaf(1).into(),\n                ExpressionNode::Leaf(2).into(),\n            ).into(),\n            ExpressionNode::And(\n                ExpressionNode::Leaf(3).into(),\n                ExpressionNode::Leaf(4).into(),\n            ).into(),\n        ).into());\n\n    let root = e_not!(\n    e_and!(\n        e_or!(\n            e_leaf!(1),\n            e_leaf!(2)\n        ),\n        e_and!(\n            e_leaf!(3),\n            e_leaf!(4)\n        )\n    )\n);\n}\n```\n\n### Expression Tree to NNF conversion (De Morgan's Law, double negation, etc.)\n\n```rust\nassert_eq!(\n    e_not!(e_leaf!(true) \u0026 e_leaf!(true)).to_nnf(),\n    e_or!(e_leaf!(false), e_leaf!(false))\n);\n\nassert_eq!(\n    e_not!(e_leaf!(true) | e_leaf!(true)).to_nnf(),\n    e_and!(e_leaf!(false), e_leaf!(false))\n);\n\nassert_eq!(\n    !ExpressionNode::Not(e_or!(e_leaf!(true), e_leaf!(true)).into()),\n    e_or!(e_leaf!(true), e_leaf!(true))\n);\n```\n\n## (Optional) Render / Graphviz\n\n```rust\nfn test() {\n    let sentence = or!(\n            and!(\n                var!(\"a\"),\n                and!(\"b\", \"c\")\n            ),\n            and!(\n                or!(\"!d\", \"e\"),\n                and!(\"f\", \"!g\")\n            )\n        );\n    assert!(!sentence.render().is_empty());\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnight-crawler%2Fnnf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnight-crawler%2Fnnf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnight-crawler%2Fnnf/lists"}