Skip to content

Commit 30077c6

Browse files
committed
Version 0.9.196
1 parent 59a1468 commit 30077c6

File tree

5 files changed

+64
-34
lines changed

5 files changed

+64
-34
lines changed

dist/quantum-circuit.js

Lines changed: 31 additions & 16 deletions
Large diffs are not rendered by default.

dist/quantum-circuit.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/quantum-circuit.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/quantum-circuit.js

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2813,6 +2813,13 @@ QuantumCircuit.prototype.isUnitaryMatrix = function(U, precision) {
28132813
};
28142814

28152815

2816+
QuantumCircuit.prototype.isHermitianMatrix = function(H, precision) {
2817+
var diff = this.matrixDiff(H, math.ctranspose(H))
2818+
2819+
return diff <= math.pow(10, -1 * (precision || 14));
2820+
};
2821+
2822+
28162823
QuantumCircuit.prototype.matrixDiff = function(matrix1, matrix2) {
28172824
var total = 0;
28182825
var count = 0;
@@ -2827,7 +2834,7 @@ QuantumCircuit.prototype.matrixDiff = function(matrix1, matrix2) {
28272834
var i2 = (typeof item2 == "object") ? item2 : math.complex(item2);
28282835

28292836
// distance in the complex plane
2830-
var distance = math.abs(math.subtract(i1, i2)) / 2;
2837+
var distance = math.abs(math.subtract(i1, i2));
28312838

28322839
total += distance;
28332840

@@ -2987,15 +2994,19 @@ QuantumCircuit.prototype.stringifyMatrix = function(M, options) {
29872994
if(el instanceof math.Complex) {
29882995
str += self.formatComplex(el, options);
29892996
} else {
2990-
if(typeof el == "string") {
2991-
// expression
2992-
str += el;
2997+
if((typeof el == "object") && el.mathjs) {
2998+
str += formatComplex2(el.re, el.im, options);
29932999
} else {
2994-
if(forceComplex) {
2995-
str += formatComplex2(el, 0, options);
3000+
if(typeof el == "string") {
3001+
// expression
3002+
str += el;
29963003
} else {
2997-
str += formatFloat(el, options);
2998-
}
3004+
if(forceComplex) {
3005+
str += formatComplex2(el, 0, options);
3006+
} else {
3007+
str += formatFloat(el, options);
3008+
}
3009+
}
29993010
}
30003011
}
30013012
});
@@ -3004,14 +3015,18 @@ QuantumCircuit.prototype.stringifyMatrix = function(M, options) {
30043015
if(row instanceof math.Complex) {
30053016
str += self.formatComplex(row, options);
30063017
} else {
3007-
if(typeof row == "string") {
3008-
// expression
3009-
str += row;
3018+
if((typeof el == "object") && el.mathjs) {
3019+
str += formatComplex2(el.re, el.im, options);
30103020
} else {
3011-
if(forceComplex) {
3012-
str += formatComplex2(row, 0, options);
3021+
if(typeof row == "string") {
3022+
// expression
3023+
str += row;
30133024
} else {
3014-
str += formatFloat(row, options);
3025+
if(forceComplex) {
3026+
str += formatComplex2(row, 0, options);
3027+
} else {
3028+
str += formatFloat(row, options);
3029+
}
30153030
}
30163031
}
30173032
}
@@ -7378,7 +7393,7 @@ QuantumCircuit.prototype.exportToSVG = function(options) {
73787393
}
73797394

73807395
var paramVal = gate.options.params[paramName];
7381-
if(typeof paramVal == "string" && paramVal.match(/^[+-]?\d+(\.\d+)?$/)) {
7396+
if(typeof paramVal == "string" && paramVal.match(/^[\+\-]?\d*\.?\d+(?:[Ee][\+\-]?\d+)?$/)) {
73827397
paramVal = parseFloat(paramVal);
73837398
}
73847399

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "quantum-circuit",
3-
"version": "0.9.194",
3+
"version": "0.9.196",
44
"description": "Quantum Circuit Simulator",
55
"main": "lib/quantum-circuit.js",
66
"unpkg": "dist/quantum-circuit.min.js",

0 commit comments

Comments
 (0)