{"id":20364308,"url":"https://github.com/rvanasa/funqy","last_synced_at":"2025-04-12T04:36:32.991Z","repository":{"id":85027336,"uuid":"121702118","full_name":"rvanasa/funqy","owner":"rvanasa","description":"FunQy - A high-level hybrid quantum programming language","archived":false,"fork":false,"pushed_at":"2020-11-09T17:59:12.000Z","size":27653,"stargazers_count":33,"open_issues_count":0,"forks_count":3,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-26T00:11:10.447Z","etag":null,"topics":["functional-programming","language","library","programming-language","quantum","quantum-computing","quantum-programming-language","simulator"],"latest_commit_sha":null,"homepage":"","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/rvanasa.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":"2018-02-16T00:59:34.000Z","updated_at":"2024-05-22T11:54:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"d0f8ed2e-0b13-4615-9f68-842feaf3893e","html_url":"https://github.com/rvanasa/funqy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rvanasa%2Ffunqy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rvanasa%2Ffunqy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rvanasa%2Ffunqy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rvanasa%2Ffunqy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rvanasa","download_url":"https://codeload.github.com/rvanasa/funqy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248518329,"owners_count":21117637,"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":["functional-programming","language","library","programming-language","quantum","quantum-computing","quantum-programming-language","simulator"],"created_at":"2024-11-15T00:11:06.144Z","updated_at":"2025-04-12T04:36:32.974Z","avatar_url":"https://github.com/rvanasa.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"## FunQy: A Next-Generation Quantum Programming Language\n\nFunQy is a novel functional quantum/classical hybrid programming language. \nInstead of describing algorithms in terms of quantum [logic gates](https://en.wikipedia.org/wiki/Quantum_logic_gate), registers, and [qubits](https://en.wikipedia.org/wiki/Qubit),\nFunQy operates purely in terms of functions, values, and states using what we call _pattern extraction_.\n\nPattern extraction is a bidirectional analog to pattern matching from classical functional programming, \nwith the additional quantum capability of executing all paths simultaneously. \nThis abstraction provides a clear understanding of the logic and quantum performance benefits of a particular program—instead\nof executing one path at a time, pattern extraction can execute arbitrary combinations of possible inputs. \nThis tends to be vastly more intuitive and scalable than the prevalent [circuit-based algorithm](https://arxiv.org/abs/1804.03719) conventions. \n\nMost of the existing \"high-level\" quantum programming languages are just preprocessors for defining these quantum circuits.\nFunQy exposes powerful layers of abstraction that are fully independent of the underlying architecture.\n\n---\n\nHere are a few interesting outcomes of this paradigm:\n- Funqy looks and feels like a high-level programming language, **useful for classical software engineers** unfamiliar with quantum gates and registers.\n- All states and values are immutable and thus **purely functional**. This declarative basis for quantum computation is more intuitive, more optimizable, and more powerful than the quantum circuit paradigm. \n- The language is fully **architecture-agnostic**; qubits and gates are completely invisible to the language unless otherwise desired.\n- **Classical and quantum algorithms are defined simultaneously**; in other words, the compiler will use the classical version of a function if the input value is correspondingly classical. In effect, only operations which would actually benefit from quantum speed-up are performed on a quantum register.\n- By organizing code in terms of functions and extractions, scripts tend to **semantically convey their underlying purpose and logic**. \n- On top of \"product\" space (entanglement/tuples), FunQy unlocks the **\"sum\" space (matrix/vector indices)** of a quantum system.\n- It is possible to define **non-unitary mappings** (i.e. non-square and/or non-reversible matrices), which compile using auxillary qubits as needed.\n- State initializations, repeated measurements, and dynamically adjusted circuits are all implicit to FunQy's semantics. For instance, reusing a state object will automatically reconstruct the state to circumvent the no-cloning principle. \n- FunQy's type system provides the **scalability and expressiveness** needed to design and reason about algorithms for future (100+ qubit) quantum computers. \n- `extract` blocks **visually demonstrate quantum algorithm speed-up** by always having the same time complexity regardless of input value. \n\n---\n\n### Build Requirements\n\n- [Nightly Rust](https://doc.rust-lang.org/1.15.1/book/nightly-rust.html) `\u003e= 1.28.0`\n\nThe following command will install the latest version of Rust:\n```sh\n$ curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain=nightly\n```\n\n### Usage Examples\n\nEvaluate a FunQy script:\n```sh\n$ funqy eval path/to/ScriptFile.fqy [-o output_file.txt] [--watch]\n$ funqy eval https://some.cdn/file/ScriptFile.fqy [...]\n$ funqy eval \"raw: measure(sup(1,2,3))\" [...]\n```\n\nStart an interactive REPL session:\n```sh\n$ funqy repl [-h history_file.txt]\n```\n\nView all available commands:\n```sh\n$ funqy --help\n```\n\n### Qubit Gate Analogy\n\n```\n\ndata Qubit = F | T\t\t//\tDefine |0⟩ as `F` and |1⟩ as `T`\n\nlet (^) = sup\t\t\t//\tDefine superposition operator\nlet (~) = phf\t\t\t//\tDefine phase flip operator\nlet (#) = measure\t\t//\tDefine measurement operator\n\n// identity (no change)\nfn id = {\n    F =\u003e F,\t\t\t//\t|0⟩ =\u003e |0⟩\n    T =\u003e T,\t\t\t//\t|1⟩ =\u003e |1⟩\n}\n\n// Pauli-X rotation (NOT gate)\nfn px = {\n    F =\u003e T,\t\t\t//\t|0⟩ =\u003e |1⟩\n    T =\u003e F,\t\t\t//\t|1⟩ =\u003e |0⟩\n}\nlet not = px\nlet (!) = px\n\n// Pauli-Y rotation\nfn py = {\n    F =\u003e @[1/2] T,\t\t//\t|0⟩ =\u003e |i⟩\n    T =\u003e @[-1/2] F,\t\t//\t|1⟩ =\u003e -|i⟩\n}\n\n// Pauli-Z rotation\nfn pz = {\n    F =\u003e F,\t\t\t//\t|0⟩ =\u003e |0⟩\n    T =\u003e ~T,\t\t//\t|1⟩ =\u003e -|1⟩\n}\n\n// Hadamard gate\nfn hadamard = {\n    F =\u003e F ^ T, \t\t//\t|0⟩ =\u003e (|0⟩ + |1⟩) / sqrt(2)\n    T =\u003e F ^ ~T,\t\t//\t|1⟩ =\u003e (|0⟩ - |1⟩) / sqrt(2)\n}\n\n// SWAP gate\nfn swap = {\n    (F, T) =\u003e (T, F), \t//\t|01⟩ =\u003e |10⟩\n    (T, F) =\u003e (F, T),\t//\t|10⟩ =\u003e |01⟩\n}\n\n// sqrt(NOT) gate\nlet sqrt_not = @[1/2] not\n\n// sqrt(SWAP) gate\nlet sqrt_swap = @[1/2] swap\n\n// Controlled gate\nfn c(gate)(ctrl, tgt) = {\n    let out = extract ctrl {\n        F =\u003e tgt,\t//\t|0⟩ ⊗ tgt =\u003e |0⟩ ⊗ tgt \n        T =\u003e gate(tgt),\t//\t|1⟩ ⊗ tgt =\u003e |1⟩ ⊗ gate(tgt)\n    }\n    (ctrl, out)\n}\n\n// Controlled NOT gate\nfn cnot(ctrl, tgt) = c(not)(ctrl, tgt)\n\n// Bell state preparation (implemented via gates)\nfn bell_as_circuit(q1, q2) = cnot(hadamard(q1), q2)\n\n// Bell state preparation (implemented via extraction)\nfn bell_as_extract = {\n    (F, F) =\u003e (F, F) ^ (T, T),\n    (F, T) =\u003e (F, T) ^ (T, F),\n    (T, F) =\u003e (F, F) ^ ~(T, T),\n    (T, T) =\u003e (F, T) ^ ~(T, F),\n}\n\nassert bell_as_circuit == bell_as_extract\n\nlet inv_bell = inv(bell_as_circuit)\nassert inv(inv_bell) == bell_as_circuit\n\n```\n\n_Note that FunQy is very early in development; this syntax may be subject to change._\n\nThe above example demonstrates the crossover between FunQy and traditional quantum computing languages. \nHowever, the pattern extraction paradigm gains its advantage from combining different quantum object dimensionalities. \n\n### Higher-Order Gate Analogy\n\nHere is an interesting outcome of using both 2D (qubit) and 3D (qutrit) values in a function:\n\n```\n\ndata Axis3 = X | Y | Z\n\nfn rotate(r)(s) = extract r {\n    X =\u003e px(s)\n    Y =\u003e py(s)\n    Z =\u003e pz(s)\n}\n\nassert rotate(X) == px\nassert rotate(Y) == py\nassert rotate(Z) == pz\nassert rotate(X ^ Z) == hadamard\t// it's back\n\n// assert rotate(^(X, ~Y, @[1/2] Z)) == ...\n\n```\n\nFor more documentation and examples, please check out the [tests](https://github.com/rvanasa/funqy/tree/master/tests) folder. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frvanasa%2Ffunqy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frvanasa%2Ffunqy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frvanasa%2Ffunqy/lists"}