public override string ToString() { string s = ""; int n = Stuff.Log2(this.Vector.ColumnCount); double min = 1.0f; Debug.Log("Min : " + min); for (int i = 0; i < this.Vector.ColumnCount; i++) { double p = (this.Vector[0, i] * this.Vector[0, i]).Real; if (p > 0) { if (p < min) { min = p; } } } string working_string = ""; for (int i = 0; i < this.Vector.ColumnCount; i++) { double p = (this.Vector[0, i] * this.Vector[0, i]).Real; if (p > 0) { if (string.Format("{0:N2}", (this.Vector[0, i]).Real)[0].Equals('-')) { working_string += "-"; } for (double j = 0.0f; j < min; j += (this.Vector[0, i] * this.Vector[0, i]).Real) // 2*min? { string binary_string = Convert.ToString(i, 2).PadLeft(n, '0') + ", "; for (int k = 0; k < binary_string.Length; k++) { working_string += binary_string[k]; } } } } s += working_string.Substring(0, working_string.Length - 2); // Ancien format /*s += "\n"; * for (int i = 0; i < this.Vector.ColumnCount; i++) * { * double p = (this.Vector[0, i] * this.Vector[0, i]).Real; * if (p > 0) * { * s += string.Format("{0:N2}", (this.Vector[0, i]).Real) + " |" + Convert.ToString(i, 2).PadLeft(n, '0') + "> " + "\n"; * } * }*/ return(s); }
public IEnumerable <Possibility> EnumeratePossibilities() { int n = Stuff.Log2(this.Vector.ColumnCount); for (int i = 0; i < this.Vector.ColumnCount; i++) { double p = (this.Vector[0, i] * this.Vector[0, i]).Real; bool[] values = new bool[n]; for (int j = 0; j < n; j++) { values[j] = (i & (1 << j)) == 1; } yield return(new Possibility(p, values)); } }
/// <summary> /// Fonction qui permet de display les résultats sous forme de boules à la manière du livre QisForQuantum il suffit de remplacer ToString() qui est appelée dans ShowResult.cs pour avoir cet affichage /// </summary> public string ToStringBalls() { string s = ""; string seq = ""; int n = Stuff.Log2(this.Vector.ColumnCount); for (int i = 0; i < this.Vector.ColumnCount; i++) { double p = (this.Vector[0, i] * this.Vector[0, i]).Real; double amp = this.Vector[0, i].Real; if (p > 0) { //s += String.Format("{0:0.00}", Math.Sqrt(p)) + ".|" + Convert.ToString(i, 2).PadLeft(n, '0') + "> " + " + "; s += "|" + Convert.ToString(i, 2).PadLeft(n, '0') + ">" + " , "; seq += Convert.ToString(i, 2).PadLeft(n, '0'); } } UnityEngine.Debug.Log(" " + s); s = s.Substring(0, s.Length - 2); return(s); }