-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
43 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package operator | ||
|
||
import util.* | ||
import kotlin.math.pow | ||
|
||
/** | ||
* Created by DEDZTBH on 2020/09/22. | ||
* Project KuantumCircuitSim | ||
*/ | ||
|
||
fun allStates(n: Int) = | ||
Array(2.0.pow(n).toInt()) { | ||
IntArray(n) { i -> (it shr i) and 1 }.apply { reverse() } | ||
} | ||
|
||
|
||
class AllInit(N: Int) : TFinder(N) { | ||
override fun printResult() { | ||
super.printResult() | ||
println("\nFinal states: ") | ||
allStates(N).forEach { arr -> | ||
println("Init |${arr.joinToString("")}>") | ||
var jointState = I1 | ||
arr.forEach { i -> | ||
jointState = (if (i == 0) KET0 else KET1) kron jointState | ||
} | ||
(opMatrix * jointState).print() | ||
println() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters