ts-quantum
Version:
TypeScript library for quantum mechanics calculations and utilities
59 lines • 2.59 kB
JavaScript
;
/**
* Core quantum gates implementation
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CNOT = exports.Hadamard = exports.PauliZ = exports.PauliY = exports.PauliX = void 0;
const operator_1 = require("./operator");
const math = __importStar(require("mathjs"));
// Pauli X (bit flip) gate
exports.PauliX = new operator_1.MatrixOperator([
[math.complex(0, 0), math.complex(1, 0)],
[math.complex(1, 0), math.complex(0, 0)]
], 'unitary');
// Pauli Y gate
exports.PauliY = new operator_1.MatrixOperator([
[math.complex(0, 0), math.complex(0, -1)],
[math.complex(0, 1), math.complex(0, 0)]
], 'unitary');
// Pauli Z (phase flip) gate
exports.PauliZ = new operator_1.MatrixOperator([
[math.complex(1, 0), math.complex(0, 0)],
[math.complex(0, 0), math.complex(-1, 0)]
], 'unitary');
// Hadamard gate
exports.Hadamard = new operator_1.MatrixOperator([
[math.complex(1 / Math.sqrt(2), 0), math.complex(1 / Math.sqrt(2), 0)],
[math.complex(1 / Math.sqrt(2), 0), math.complex(-1 / Math.sqrt(2), 0)]
], 'unitary');
// CNOT (Controlled-NOT) gate for 2-qubit system
exports.CNOT = new operator_1.MatrixOperator([
[math.complex(1, 0), math.complex(0, 0), math.complex(0, 0), math.complex(0, 0)],
[math.complex(0, 0), math.complex(1, 0), math.complex(0, 0), math.complex(0, 0)],
[math.complex(0, 0), math.complex(0, 0), math.complex(0, 0), math.complex(1, 0)],
[math.complex(0, 0), math.complex(0, 0), math.complex(1, 0), math.complex(0, 0)]
], 'unitary');
//# sourceMappingURL=gates.js.map