Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
clickSpecial(type, event) {
const _this = this,
res = document.querySelector('.result-text');
_this.flag = true;
_this.removeActive();
switch (type) {
case '1': // x 的平方
res.innerHTML = result = math.format(math.pow(result, 2), {
precision: 16
});
_this.register.ope = type;
_this.isEqual = true;
break;
case '2': // x 的立方
res.innerHTML = result = math.format(math.pow(result, 3), {
precision: 16
});
_this.register.ope = type;
_this.isEqual = true;
break;
case '3': // x 的 y 次幂
_this.events = event;
if (!event.classList.contains('active')) {
module.exports.exp = function(num1,num2) {
const num1Math = Math.bignumber(new BigNumber(num1).toString(10));
const num2Math = Math.bignumber(new BigNumber(num2).toString(10));
const result = Math.pow(num1Math,num2Math);
return new BigNumber(result.toString());
};
stateToString() {
const numAmplitudes = this.numAmplitudes();
if (!this.state || this.state.length < numAmplitudes) {
throw new Error(
'Circuit is not initialized. Please call init() or run() method',
);
}
let s = '';
for (let i = 0; i < numAmplitudes; i += 1) {
if (i) {
s += '\n';
}
const m = math.round(math.pow(math.abs(this.state[i]), 2) * 100, 2);
let bin = i.toString(2);
while (bin.length < this.nQubits) {
bin = `0${bin}`;
}
s += `${utils.formatComplex(this.state[i])}|${bin}>${m}%`;
}
return s;
}
function insertBit(input, pos, bit) {
var out = input << 1;
var m = (2 << pos) - 1;
var posBit = 1 << pos;
var out = (out ^ ((out ^ input) & m)) | posBit;
if(!bit) {
out = out ^ posBit;
}
return out;
}
var trace = [];
var unusedCount = this.numQubits - 1;
var unusedLen = math.pow(2, unusedCount);
var qpos = (this.numQubits - 1) - qubit;
for(var el = 0; el < 4; el++) {
trace.push(math.complex(0, 0));
var base = unusedLen;
while(base--) {
var col = insertBit(base, qpos, el & 1 ? 1 : 0);
var row = insertBit(base, qpos, el & 2 ? 1 : 0);
var rowVal = this.state[row];
var colVal = this.state[col];
if(rowVal && colVal) {
trace[el] = math.add(trace[el], math.multiply(rowVal, math.complex(colVal.re, colVal.im * -1.0)));
}
}
}
return [
[ trace[0], trace[1] ],
load(obj) {
this.nQubits = obj.nQubits || 1;
this.amplitudes = math.pow(2, this.nQubits);
this.clear();
this.gates = obj.gates;
this.customGates = obj.customGates;
this.state = obj.state;
}
function numericProbability(value, mean, std) {
return (1 / (std * math.sqrt(2 * math.pi))) *
math.pow(math.e,
(-(math.pow(value - mean, 2)) /
(2 * math.pow(std,2)))
);
}
QuantumCircuit.prototype.getCregValue = function(creg) {
if(!this.cregs[creg]) {
throw "Error: \"getCregBit\": unknown register \"" + creg + "\".";
}
var len = this.cregs[creg].length;
var value = 0;
for(var i = 0; i < len; i++) {
if(this.cregs[creg][i]) {
value += math.pow(2, i);
}
}
return value;
};
module.exports = (gate, qubit, nQubits, state) => {
const temp1 = math
.chain(math.eye(math.pow(2, nQubits - qubit - 1)))
.multiply(complex)
.done();
const temp2 = math
.chain(math.eye(math.pow(2, qubit)))
.multiply(complex)
.done();
const enlargeOpt = math.kron(temp1, math.kron(gate, temp2));
return math.multiply(enlargeOpt, state);
};
function numericProbability(value, mean, std) {
return (1 / (std * math.sqrt(2 * math.pi))) *
math.pow(math.e,
(-(math.pow(value - mean, 2)) /
(2 * math.pow(std,2)))
);
}