{"id":18016989,"url":"https://github.com/fitzgen/synth-loop-free-prog","last_synced_at":"2025-07-17T06:37:43.447Z","repository":{"id":66008136,"uuid":"214911402","full_name":"fitzgen/synth-loop-free-prog","owner":"fitzgen","description":"Synthesis of Loop-free Programs in Rust","archived":false,"fork":false,"pushed_at":"2020-02-27T21:48:11.000Z","size":91,"stargazers_count":66,"open_issues_count":0,"forks_count":7,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-07-15T05:47:13.846Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://fitzgeraldnick.com/2020/01/13/synthesizing-loop-free-programs.html","language":"Rust","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/fitzgen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2019-10-13T23:53:34.000Z","updated_at":"2025-06-25T23:55:54.000Z","dependencies_parsed_at":"2023-04-24T08:37:12.960Z","dependency_job_id":null,"html_url":"https://github.com/fitzgen/synth-loop-free-prog","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fitzgen/synth-loop-free-prog","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fitzgen%2Fsynth-loop-free-prog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fitzgen%2Fsynth-loop-free-prog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fitzgen%2Fsynth-loop-free-prog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fitzgen%2Fsynth-loop-free-prog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fitzgen","download_url":"https://codeload.github.com/fitzgen/synth-loop-free-prog/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fitzgen%2Fsynth-loop-free-prog/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265573815,"owners_count":23790514,"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":[],"created_at":"2024-10-30T04:19:52.325Z","updated_at":"2025-07-17T06:37:43.431Z","avatar_url":"https://github.com/fitzgen.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `synth-loop-free-prog`\n\nImplementing [*Synthesis of Loop-free Programs* by Gulwani et\nal](https://www.microsoft.com/en-us/research/wp-content/uploads/2016/12/pldi11-loopfree-synthesis.pdf)\nin Rust, using the [Z3][] solver.\n\nI explain the paper and walk through this implementation in my blog post\n[*Synthesizing Loop-Free Programs with Rust and Z3*](https://fitzgeraldnick.com/2020/01/13/synthesizing-loop-free-programs.html).\n\n## Example\n\n```rust\nuse synth_loop_free_prog::*;\n\nlet mut builder = ProgramBuilder::new();\n// ...build an unoptimized program...\nlet spec_program = builder.finish();\n\n// Define a library of components that the synthesized program can use.\nlet library = Library {\n    components: vec![\n        component::add(),\n        component::sub(),\n        component::xor(),\n        component::shl(),\n        // etc...\n    ],\n};\n\nlet config = z3::Config::new();\nlet context = z3::Context::new(\u0026config);\n\n// Synthesize an optimized program!\nlet optimized_program = Synthesizer::new(\u0026context, \u0026library, \u0026spec_program)\n    // One hour timeout.\n    .set_timeout(60 * 60 * 1000)\n    // Synthesize optimally small programs.\n    .should_synthesize_minimal_programs(true)\n    // Start synthesis!\n    .synthesize()?;\n\nprintln!(\"Synthesized program:\\n\\n{}\", optimized_program);\n```\n\n## Build\n\nFirst, ensure that you have [Z3][] installed on your system:\n\n```shell\n# Something like this, depending on your OS.\n$ sudo apt install libz3-dev\n```\n\nThen run\n\n```shell\n$ cargo build\n```\n\n## Testing\n\n```shell\n$ cargo test\n```\n\n## Running the Example Benchmarks\n\nRun the all 25 benchmark programs from the paper (originally taken from\n[Hacker's Delight](https://www.goodreads.com/book/show/276079.Hacker_s_Delight))\nlike this:\n\n```shell\n$ cargo run --example brahma\n```\n\nYou can also run only the ones that finish pretty quickly like this:\n\n```shell\n$ cargo run --example brahma -- --only-fast\n```\n\nYou can see a full listing of the available options with:\n\n```shell\n$ cargo run --example brahma -- --help\n```\n\n## Logging\n\nLogging requires incoking `cargo` with `--features log` when building, running,\nor testing.\n\nAt the `debug` log level, information about the progress of synthesis, the bit\nwidth we're synthesizing at, and the example inputs is logged:\n\n```shell\n$ export RUST_LOG=synth_loop_free_prog=debug\n```\n\nAt the `trace` level, every SMT query is additionally logged:\n\n```shell\n$ export RUST_LOG=synth_loop_free_prog=trace\n```\n\n[Z3]: https://github.com/Z3Prover/z3\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffitzgen%2Fsynth-loop-free-prog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffitzgen%2Fsynth-loop-free-prog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffitzgen%2Fsynth-loop-free-prog/lists"}