How it works: Because you can never observe a scenario in which fail
has been called (since it destroys the universe), you will necessarily observe a “fortuitous” timeline in which the values returned by choice
cause your program to complete without ever calling fail
. Be careful to ensure that such a timeline exists!
Do not run a program that calls fail() unconditionally or in every timeline. Such a program destroys every universe in which it runs correctly, so the only observable outcome is one in which an extremely unlikely (and potentially dangerous) event prevents it from completing.
When there are multiple possible (non-fail
ing) executions of a quantum program, we consistently end up observing the lexicographically smallest one with respect to the iteration order of sequences passed to choice
. This phenomenon remains unexplained.
https://github.com/karldray/quantum