# Quantum boolean [closed]

## Background

Have you ever dream of quantum state? If that's true for you, you are probably weird...

Anyway, I came up with an idea: what if we make a quantum in code?

Create a data type, function, or class, anything that can be put in a condition.

You can redefine anything as long as it’s infront of the other code( or the testcase I mean)

or you can make another file, and take the code as input, output the run result, but that will count as compiler/transpiler

What should it do:

(def your thing here, I'll name it "X" for now, you can also
redefine “if”, or anything else, as long as it’s in this part of
code and it doesn’t change the text of code(which count as transpiler i suppose))

if X:
part a
else:
part b


part a and b should both be executed, although the chance of which being first should be 50/50.


if X:
a=5
else:
a=10
b=5


a should have 50% chance to be 5, 50% 10, but b will always be 5

x can be different everytime mention, or always the same on parallel universe

if X:
part a
else if X:
part b
else:
part c


Could be:

execute a,b,c with a 50% being first execute,b,c 25% each.(second X and first X both being quantum)

In this case a will never be the second one executed.

possible case:

a,b,c
a,c,b
b,c,a
c,b,a

     / a True 50%
init           / b True 25%
\ a False
\ b False - c 25%
First X     Second X


Or:

X True for a

X False for c

b will never be executed.

     / X True - a
init
\ X False - c


you code should not work on non-quantum condition.

if True:
if X:
part a
else:
part b
else:
part c


c should never be executed no matter what

# Example

X as your submit

if X: # or X()
print(1)
else:
print(2)


return

1
2


or

2
1


the X can even just be a marker for your function to indicate where it need to rerun or change. as long as you specify your variable name( please don't inject whole code into it)

# Extra

You can specific to always have else after if, since doing nothing in else will make it identical to normal if.

A whole compiler/transpiler (changing code to fit in quantum state) is allowed, but will compete on it's own(with other compiler style anwser).

# Rule

• Standard rules.

# Goal

golf your quantum as smaller as possible!

• Are you aware of any languages in which this is actually possible? Nov 26 at 2:23
• @Unmitigated Mathematica. Try it online! Nov 26 at 7:33
• @alephalpha That just defines a new if, which is doable in most any language but isn't the challenge. This is however possible in some logical programming languages like curry that already allow superpositions (e.g. True?False in curry), the only hitch is that they need to be random. Nov 26 at 9:36
• @GrainGhost The Mathematica code does not define a new if, but defines a value x such that If has a special definition for it. I don't think this is doable in many other languages. Nov 28 at 23:55