{"id":32168635,"url":"https://github.com/ash-project/crux","last_synced_at":"2025-10-29T06:19:26.339Z","repository":{"id":318774208,"uuid":"1076527941","full_name":"ash-project/crux","owner":"ash-project","description":"Library for boolean satisfiability solving and expression manipulation.","archived":false,"fork":false,"pushed_at":"2025-10-18T16:26:25.000Z","size":101,"stargazers_count":6,"open_issues_count":1,"forks_count":2,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-21T15:59:57.402Z","etag":null,"topics":["elixir","sat-solver"],"latest_commit_sha":null,"homepage":"https://hex.pm/packages/crux","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ash-project.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSES/MIT.txt","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":["zachdaniel","jimsynz"]}},"created_at":"2025-10-15T01:50:59.000Z","updated_at":"2025-10-18T16:26:29.000Z","dependencies_parsed_at":"2025-10-15T15:05:22.623Z","dependency_job_id":"011382aa-fe55-4df4-bfc7-86704a506064","html_url":"https://github.com/ash-project/crux","commit_stats":null,"previous_names":["ash-project/crux"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/ash-project/crux","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ash-project%2Fcrux","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ash-project%2Fcrux/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ash-project%2Fcrux/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ash-project%2Fcrux/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ash-project","download_url":"https://codeload.github.com/ash-project/crux/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ash-project%2Fcrux/sbom","scorecard":{"id":1238815,"data":{"date":"2025-10-16T00:53:49Z","repo":{"name":"github.com/ash-project/crux","commit":"08cdeb48065682245849f9b8c516c894971567c4"},"scorecard":{"version":"v5.3.0","commit":"c22063e786c11f9dd714d777a687ff7c4599b600"},"score":7.1,"checks":[{"name":"Maintained","score":0,"reason":"project was created within the last 90 days. Please review its contents carefully","details":["Warn: Repository was created within the last 90 days."],"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/c22063e786c11f9dd714d777a687ff7c4599b600/docs/checks.md#maintained"}},{"name":"Dependency-Update-Tool","score":10,"reason":"update tool detected","details":["Info: detected update tool: Dependabot: .github/dependabot.yml:1"],"documentation":{"short":"Determines if the project uses a dependency update tool.","url":"https://github.com/ossf/scorecard/blob/c22063e786c11f9dd714d777a687ff7c4599b600/docs/checks.md#dependency-update-tool"}},{"name":"Code-Review","score":3,"reason":"Found 3/9 approved changesets -- score normalized to 3","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/c22063e786c11f9dd714d777a687ff7c4599b600/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/c22063e786c11f9dd714d777a687ff7c4599b600/docs/checks.md#packaging"}},{"name":"Pinned-Dependencies","score":5,"reason":"dependency not pinned by hash detected -- score normalized to 5","details":["Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/ash-project/crux/ci.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/scorecard.yml:80: update your workflow using https://app.stepsecurity.io/secureworkflow/ash-project/crux/scorecard.yml/main?enable=pin","Info:   2 out of   3 GitHub-owned GitHubAction dependencies pinned","Info:   1 out of   2 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/c22063e786c11f9dd714d777a687ff7c4599b600/docs/checks.md#pinned-dependencies"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/c22063e786c11f9dd714d777a687ff7c4599b600/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/c22063e786c11f9dd714d777a687ff7c4599b600/docs/checks.md#binary-artifacts"}},{"name":"Token-Permissions","score":10,"reason":"GitHub workflow tokens follow principle of least privilege","details":["Warn: jobLevel 'contents' permission set to 'write': .github/workflows/ci.yml:22","Warn: jobLevel 'security-events' permission set to 'write': .github/workflows/ci.yml:25","Info: topLevel 'contents' permission set to 'read': .github/workflows/ci.yml:15","Info: topLevel permissions set to 'read-all': .github/workflows/scorecard.yml:22"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/c22063e786c11f9dd714d777a687ff7c4599b600/docs/checks.md#token-permissions"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/c22063e786c11f9dd714d777a687ff7c4599b600/docs/checks.md#vulnerabilities"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/c22063e786c11f9dd714d777a687ff7c4599b600/docs/checks.md#signed-releases"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/c22063e786c11f9dd714d777a687ff7c4599b600/docs/checks.md#cii-best-practices"}},{"name":"Fuzzing","score":10,"reason":"project is fuzzed","details":["Info: ElixirPropertyBasedTesting integration found: test/crux/expression/rewrite_rule/absorption_law_test.exs:7","Info: ElixirPropertyBasedTesting integration found: test/crux/expression/rewrite_rule/annihilator_law_test.exs:7","Info: ElixirPropertyBasedTesting integration found: test/crux/expression/rewrite_rule/associativity_law_test.exs:7","Info: ElixirPropertyBasedTesting integration found: test/crux/expression/rewrite_rule/commutativity_law_test.exs:8","Info: ElixirPropertyBasedTesting integration found: test/crux/expression/rewrite_rule/complement_law_test.exs:7","Info: ElixirPropertyBasedTesting integration found: test/crux/expression/rewrite_rule/consensus_theorem_test.exs:7","Info: ElixirPropertyBasedTesting integration found: test/crux/expression/rewrite_rule/de_morgans_law_test.exs:7","Info: ElixirPropertyBasedTesting integration found: test/crux/expression/rewrite_rule/distributive_law_test.exs:7","Info: ElixirPropertyBasedTesting integration found: test/crux/expression/rewrite_rule/distributivity_based_simplification_law_test.exs:7","Info: ElixirPropertyBasedTesting integration found: test/crux/expression/rewrite_rule/idempotent_law_test.exs:8","Info: ElixirPropertyBasedTesting integration found: test/crux/expression/rewrite_rule/identity_law_test.exs:8","Info: ElixirPropertyBasedTesting integration found: test/crux/expression/rewrite_rule/negation_law_test.exs:8","Info: ElixirPropertyBasedTesting integration found: test/crux/expression/rewrite_rule/tautology_law_test.exs:7","Info: ElixirPropertyBasedTesting integration found: test/crux/expression/rewrite_rule/unit_resolution_test.exs:7","Info: ElixirPropertyBasedTesting integration found: test/crux/expression/rewrite_rule_test.exs:7","Info: ElixirPropertyBasedTesting integration found: test/crux/expression_test.exs:8","Info: ElixirPropertyBasedTesting integration found: test/crux/formula_test.exs:7","Info: ElixirPropertyBasedTesting integration found: test/crux_test.exs:10"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/c22063e786c11f9dd714d777a687ff7c4599b600/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSES/MIT.txt:0","Info: FSF or OSI recognized license: MIT License: LICENSES/MIT.txt:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/c22063e786c11f9dd714d777a687ff7c4599b600/docs/checks.md#license"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'main'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/c22063e786c11f9dd714d777a687ff7c4599b600/docs/checks.md#branch-protection"}},{"name":"SAST","score":10,"reason":"SAST tool is run on all commits","details":["Info: all commits (3) are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/c22063e786c11f9dd714d777a687ff7c4599b600/docs/checks.md#sast"}},{"name":"Security-Policy","score":10,"reason":"security policy file detected","details":["Info: security policy file detected: github.com/ash-project/.github/SECURITY.md:1","Info: Found linked content: github.com/ash-project/.github/SECURITY.md:1","Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/ash-project/.github/SECURITY.md:1","Info: Found text in security policy: github.com/ash-project/.github/SECURITY.md:1"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/c22063e786c11f9dd714d777a687ff7c4599b600/docs/checks.md#security-policy"}},{"name":"Contributors","score":6,"reason":"project has 2 contributing companies or organizations -- score normalized to 6","details":["Info: found contributions from: betterlifehealth, spandex-project"],"documentation":{"short":"Determines if the project has a set of contributors from multiple organizations (e.g., companies).","url":"https://github.com/ossf/scorecard/blob/c22063e786c11f9dd714d777a687ff7c4599b600/docs/checks.md#contributors"}},{"name":"CI-Tests","score":6,"reason":"2 out of 3 merged PRs checked by a CI test -- score normalized to 6","details":null,"documentation":{"short":"Determines if the project runs tests before pull requests are merged.","url":"https://github.com/ossf/scorecard/blob/c22063e786c11f9dd714d777a687ff7c4599b600/docs/checks.md#ci-tests"}}]},"last_synced_at":"2025-10-16T06:49:54.991Z","repository_id":318774208,"created_at":"2025-10-16T06:49:54.991Z","updated_at":"2025-10-16T06:49:54.991Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281139058,"owners_count":26450137,"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","status":"online","status_checked_at":"2025-10-26T02:00:06.575Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["elixir","sat-solver"],"created_at":"2025-10-21T15:59:11.052Z","updated_at":"2025-10-29T06:19:26.309Z","avatar_url":"https://github.com/ash-project.png","language":"Elixir","funding_links":["https://github.com/sponsors/zachdaniel","https://github.com/sponsors/jimsynz"],"categories":[],"sub_categories":[],"readme":"\u003c!--\n  SPDX-FileCopyrightText: 2025 crux contributors \u003chttps://github.com/ash-project/crux/graphs.contributors\u003e\n  SPDX-License-Identifier: MIT\n--\u003e\n\n\u003c!-- ex_doc_ignore_start --\u003e\n# Crux\n\u003c!-- ex_doc_ignore_end --\u003e\n\n![Elixir CI](https://github.com/ash-project/crux/workflows/Ash%20CI/badge.svg)\n[![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/ash-project/crux/badge)](https://scorecard.dev/viewer/?uri=github.com/ash-project/crux)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Hex version badge](https://img.shields.io/hexpm/v/crux.svg)](https://hex.pm/packages/crux)\n[![Hexdocs badge](https://img.shields.io/badge/docs-hexdocs-purple)](https://hexdocs.pm/crux)\n[![REUSE status](https://api.reuse.software/badge/github.com/ash-project/crux)](https://api.reuse.software/info/github.com/ash-project/crux)\n[![Crux DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/ash-project/crux)\n\nCrux is a powerful Elixir library for boolean satisfiability (SAT) solving,\nboolean expression manipulation, and constraint satisfaction. It provides an\nintuitive DSL for creating boolean expressions and a comprehensive toolkit for\nworking with satisfiability problems.\n\n## Features\n\n- **Boolean Expression DSL** - Intuitive macro for creating complex boolean\n  expressions\n- **SAT Solving** - Solve satisfiability problems with multiple backend solvers\n- **Expression Manipulation** - Simplify, evaluate, and transform boolean\n  expressions\n- **CNF Conversion** - Convert expressions to Conjunctive Normal Form for SAT\n  solving\n- **Decision Trees** - Build binary decision trees for exploring satisfying\n  assignments\n- **Constraint Helpers** - Built-in functions for common constraint patterns\n- **Multiple Backends** - Support for PicoSAT (fast NIF) and SimpleSAT (pure\n  Elixir)\n\n## Installation\n\nAdd `crux` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:crux, \"~\u003e 0.1.2\"},\n    # Choose one SAT solver backend:\n    {:picosat_elixir, \"~\u003e 0.2\"}, # Recommended: Fast NIF-based solver\n    # OR\n    {:simple_sat, \"~\u003e 0.1\"}      # Pure Elixir alternative\n  ]\nend\n```\n\n## Quick Start\n\n### Creating Boolean Expressions\n\nUse the `b/1` macro to create boolean expressions with an intuitive syntax:\n\n```elixir\nimport Crux.Expression\n\n# Basic boolean operations\nexpr = b(:user_logged_in and (:is_admin or :is_moderator))\n\n# Advanced boolean operators\nexpr = b(xor(:payment_cash, :payment_card))  # exactly one payment method\nexpr = b(implies(:is_student, :gets_discount)) # if student then discount\n```\n\n### Solving Satisfiability Problems\n\nConvert expressions to formulas and solve them:\n\n```elixir\nalias Crux.{Expression, Formula}\n\n# Create and solve a formula\nexpression = Expression.b(:a and (:b or :c))\nformula = Formula.from_expression(expression)\n\ncase Crux.solve(formula) do\n  {:ok, solution} -\u003e\n    IO.inspect(solution) # %{a: true, b: true, c: false}\n  {:error, :unsatisfiable} -\u003e\n    IO.puts(\"No solution exists\")\nend\n```\n\n### Expression Manipulation\n\n```elixir\nimport Crux.Expression\n\n# Simplify expressions\ncomplex_expr = b((:a and true) or (false and :b))\nsimple_expr = Expression.simplify(complex_expr)  # :a\n\n# Evaluate with variable assignments\nresult = Expression.run(b(:a and :b), fn\n  :a -\u003e true\n  :b -\u003e false\nend)  # false\n\n# Convert to Conjunctive Normal Form\ncnf_expr = Expression.to_cnf(b(:a or (:b and :c)))\n```\n\n## Core Concepts\n\n### Expressions\n\nBoolean expressions are the foundation of Crux. They support:\n- Variables (atoms like `:user`, `:admin`)\n- Constants (`true`, `false`)\n- Basic operators (`and`, `or`, `not`)\n- Advanced operators (`xor`, `nand`, `nor`, `implies`, `implied_by`, `xnor`)\n\n### Formulas\n\nFormulas are expressions converted to Conjunctive Normal Form (CNF) for SAT solving:\n\n```elixir\nformula = Formula.from_expression(Expression.b(:a and :b))\n# %Formula{\n#   cnf: [[1], [2]],\n#   bindings: %{1 =\u003e :a, 2 =\u003e :b},\n#   reverse_bindings: %{a: 1, b: 2}\n# }\n```\n\n### SAT Solving\n\nCrux can determine if boolean formulas are satisfiable and find satisfying assignments:\n\n```elixir\n# Check satisfiability\nCrux.satisfiable?(formula)  # true/false\n\n# Find all satisfying scenarios\nCrux.satisfying_scenarios(formula)  # [%{a: true, b: true}]\n\n# Build decision trees\ntree = Crux.decision_tree(formula)  # {:a, false, {:b, false, true}}\n```\n\n## API Overview\n\n### Core Modules\n\n- **`Crux`** - Main SAT solving functions (`solve/1`, `satisfiable?/1`, `decision_tree/2`)\n- **`Crux.Expression`** - Boolean expression creation and manipulation\n- **`Crux.Formula`** - CNF formula representation and conversion\n\n### Expression Functions\n\n```elixir\n# Creation\nExpression.b(:a and :b)\n\n# Manipulation\nExpression.simplify/1      # Simplify expressions\nExpression.to_cnf/1        # Convert to CNF\nExpression.balance/1       # Normalize operand order\n\n# Evaluation\nExpression.run/2           # Evaluate with variable bindings\nExpression.expand/2        # Expand with custom callbacks\n\n# Traversal\nExpression.prewalk/2       # Pre-order traversal\nExpression.postwalk/2      # Post-order traversal\n\n# Constraint helpers\nExpression.at_most_one/1   # At most one variable true\nExpression.exactly_one/1   # Exactly one variable true\nExpression.all_or_none/1   # All variables same value\n```\n\n## SAT Solver Backends\n\nCrux supports multiple SAT solver backends:\n\n### PicoSAT (Recommended)\n\n```elixir\n{:picosat_elixir, \"~\u003e 0.2\"}\n```\n- Fast NIF-based solver\n- Production-ready and battle-tested\n- Best performance for large problems\n\n### SimpleSAT\n\n```elixir\n{:simple_sat, \"~\u003e 0.1\"}\n```\n- Pure Elixir implementation\n- No NIF dependencies\n- Suitable for smaller problems or when avoiding NIFs\n\n## Advanced Features\n\n### Decision Trees\n\nBuild binary decision trees to explore all satisfying assignments:\n\n```elixir\nformula = Formula.from_expression(Expression.b(:a and :b))\ntree = Crux.decision_tree(formula, sorter: \u0026\u003c=/2)\n# {:a, false, {:b, false, true}}\n```\n\n### Constraint Patterns\n\nCrux provides helpers for common constraint satisfaction patterns:\n\n```elixir\nimport Crux.Expression\n\n# User can have at most one role\nroles = [:admin, :moderator, :user]\nat_most_one_role = at_most_one(roles)\n\n# Payment methods - exactly one must be selected\npayment_methods = [:cash, :card, :paypal]\npayment_constraint = exactly_one(payment_methods)\n\n# Feature flags - all related features synchronized\nrelated_features = [:dark_mode_ui, :dark_mode_api]\nsync_constraint = all_or_none(related_features)\n```\n\n### Domain Knowledge Integration\n\nProvide custom conflict and implication rules for domain-specific validation:\n\n```elixir\nopts = [\n  conflicts?: fn\n    :admin, :guest -\u003e true    # admin and guest roles conflict\n    _, _ -\u003e false\n  end,\n  implies?: fn\n    :admin, :can_delete -\u003e true  # admin implies delete permission\n    _, _ -\u003e false\n  end\n]\n\nscenarios = Crux.satisfying_scenarios(formula, opts)\n```\n\n## Use Cases\n\n### Authorization Policies\n\nModel complex authorization rules:\n\n```elixir\nimport Crux.Expression\n\n# User access policy\npolicy = b(\n  (:is_owner or :is_admin) and\n  not :is_suspended and\n  (:has_subscription or :is_trial_user)\n)\n\n# Check if a specific user satisfies the policy\nuser_context = %{\n  is_owner: false,\n  is_admin: true,\n  is_suspended: false,\n  has_subscription: true,\n  is_trial_user: false\n}\n\nresult = Expression.run(policy, fn var -\u003e Map.get(user_context, var, false) end)\n\ncase result do\n  true -\u003e :access_granted\n  false -\u003e :access_denied\nend\n```\n\n### Resource Scheduling\n\nModel resource allocation constraints:\n\n```elixir\n# Meeting room scheduling\nrooms = [:room_a, :room_b, :room_c]\ntime_slots = [:slot_1, :slot_2, :slot_3]\n\nconstraints = for room \u003c- rooms do\n  # Each room can be booked at most once per time slot\n  at_most_one(for slot \u003c- time_slots, do: :\"#{room}_#{slot}\")\nend\n```\n\n\u003c!-- ex_doc_ignore_start --\u003e\n## License\n\nThis project is licensed under the MIT License - see the [LICENSES](LICENSES)\ndirectory for details.\n\u003c!-- ex_doc_ignore_end --\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fash-project%2Fcrux","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fash-project%2Fcrux","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fash-project%2Fcrux/lists"}