Git Product home page Git Product logo

haskell-quantum's Introduction

haskell-quantum

Description

Implementation of the Quantum Monad, which promotes an arbitrary data type to a quantum state.

Whenever a value of type Quantum a is modified, the modification is propagated to all possible states of the underlying type. Each possible state is weighted by a complex amplitude and the individual amplitudes can interfere when the state undergoes a transformation. This allows (in theory) the simulation of any discrete quantum process.

The Quantum Monad is analogous to the Probability Monad used for probabalistic programming. The main difference is in the normalization of states: While using the L1 norm leads to probabalistic states, the L2 norm is responsible for quantum states.

Analogously, one can say that this package implements the concept of quantum programming.

Tutorial

The following code defines a Quantum Int that is in a superposition of |0> and |1>, performs a unitary variant of addition and prints the resulting measurement probabilities. Non-unitary transformations currently lead to a runtime error.

import Control.Quantum

state :: Quantum Int
state = quantize [(0, 1 / sqrt 2 ), (1, 1 / sqrt 2)]

-- All quantum transformations have to be unitary (i.e. reversible)
transform :: Quantum Int -> Quantum Int -> Quantum (Int,  Int)
transform qx qy = do
  x <- qx
  y <- qy
  return (x, x + y)

main = print $ measurements $ transform state state
-- [((0,0),0.25),((0,1),0.25),((1,1),0.25),((1,2),0.25)]

haskell-quantum's People

Contributors

ibab avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.