Skip to content
davidbkemp edited this page Nov 24, 2012 · 2 revisions

Determine the value of f(0) + f(1) mod 2 with a single invocation of f (where f maps {0,1} to {0,1}).

var deutsch = function(f) {
   return jsqubits('|01>').hadamard(jsqubits.ALL).applyFunction(1, 0, f).hadamard(jsqubits.ALL).measure(1).result;
};

//var f = function(x) {return 1;};
//var f = function(x) {return 0;};
//var f = function(x) {return x;};
var f = function(x) {return (x + 1) % 2;};

deutsch(f)
Clone this wiki locally