# An algorithm with the Hadamard operator

My goal in writing this algorithm in Q# was that func would either output (1,2) or (10,20), since the output result can be either One or Zero. However, I sometimes have (1,20) or (10,2) as output. Does anyone know why this happens?

    operation func () : (Int,Int)
{
mutable res000 = Zero;
mutable int1 = 0;
mutable int2 = 0;

using (goop = Qubit[1])
{

H(goop[0]);

set res000 = M(goop[0]);

if(res000 == Zero)
{
set int1 = 1;
set int2 = 2;
}
else
{
set int1 = 10;
set int2 = 20;
}

ResetAll(goop);
}

return (int1,int2);
}


Edit:

Here's another bit of information. I also have two projection functions, and I want the projection functions to output func:

    operation Pr0 (m:Int,n:Int) : Int
{
return m;
}

operation Pr1 (m:Int,n:Int) : Int
{
return n;
}

operation func () : (Int,Int)
{
mutable res000 = Zero;
mutable int1 = 0;
mutable int2 = 0;

using (goop = Qubit[1])
{

H(goop[0]);

set res000 = M(goop[0]);

if(res000 == Zero)
{
set int1 = 1;
set int2 = 2;
}
else
{
set int1 = 10;
set int2 = 20;
}

ResetAll(goop);
}

return (int1,int2);
}

operation testPr1 () : (Int,Int)
{
return (Pr0(func()),Pr1(func()));
}


Here are the C# codes:

    class Driver
{
static void Main(string[] args)
{
using (var sim = new QuantumSimulator())
{
var res3 = testPr1.Run(sim).Result;
Console.WriteLine(res3);

}

Console.WriteLine("Press any key to continue...");
}
}

• Could you please provide more details about your environment - OS, editor, QDK version? This should not be the case and I can't reproduce this behavior on my setup. – Mariia Mykhailova Nov 26 '18 at 19:09
• @Mariia I use Visual Studio 2017 (Community Version) on Windows. The QDK version is 0.3.18.10. That phenomenon happens when I run the program several times. – qubb Nov 26 '18 at 22:10
• @qubb: Would you be willing to provide the C# code that you used to call into the Q# code above? Thanks! – Chris Granade Nov 27 '18 at 3:01
• @Mariia, Chris: Please see the edit. – qubb Nov 28 '18 at 1:07

let res = func();