sw-examples: qm-experiment.sw3

Raw file here.
-- a simple quantum mechanics experiment:
-- created 2021/6/22
-- updated 2021/6/23

-- let's first define a superposition, that we can measure one ket at a time:
-- (it can be any superposition, with positive coefficients)
the |superposition> => |a> + 0.2|b> + 0.5|c> + 8.1|d> + 0.01|e>


-- now define the run experiment operator:
-- each iteration it sets up a new experiment
-- and then takes a measurement of that system 
-- (which is a single ket, chosen with probability according to the coefficients in the original superposition)
-- then compares the cumulative result with the original superposition
-- then outputs the similarity results for that trial
-- over many, many trials, the result should converge towards that of the original superposition
-- note that the magnitude of the superpositions do not matter in the simm() comparison
-- it is their normalized "shape" that is compared
run-experiment |*> #=>
    unlearn[the] |result>
    for( the|k> in |1> .. |__self>):
        measure |system> !=> clean weighted-pick-elt the |superposition>
        the |result> +=> measure |system>
        the |similarity> => simm(the |result>, the |superposition>)
        print (the |k> :_ round[1] extract-value push-float 100 the |similarity>)
    end:
    the |similarity>


-- now invoke it for 500 trials:
-- run-experiment |500>


Home