/// <summary> /// Adds a binary XOR gate to the circuit. /// </summary> /// <param name="leftInput">Left input wire.</param> /// <param name="rightInput">Right input wire.</param> /// <returns>A wire representing the logical XOR of both inputs.</returns> public Wire Xor(Wire leftInput, Wire rightInput) { if (leftInput == Wire.Zero) { return(rightInput); } if (rightInput == Wire.Zero) { return(leftInput); } if (leftInput == Wire.One) { return(Not(rightInput)); } if (rightInput == Wire.One) { return(Not(leftInput)); } _numberOfXorGates++; return(Wire.FromGate(new XorGate(_nextGateId++, leftInput.Gate, rightInput.Gate))); }
/// <summary> /// Adds a unary NOT gate to the circuit. /// </summary> /// <param name="input">Input wire to negate.</param> /// <returns>A wire representing the logical negation of the input.</returns> public Wire Not(Wire input) { if (input == Wire.Zero) { return(Wire.One); } if (input == Wire.One) { return(Wire.Zero); } return(Wire.FromGate(new NotGate(RequestGateContext(ref _nextNotGateId), input.Gate))); }
/// <summary> /// Adds a unary NOT gate to the circuit. /// </summary> /// <param name="input">Input wire to negate.</param> /// <returns>A wire representing the logical negation of the input.</returns> public Wire Not(Wire input) { if (input == Wire.Zero) { return(Wire.One); } if (input == Wire.One) { return(Wire.Zero); } _numberOfNotGates++; return(Wire.FromGate(new NotGate(_nextGateId++, input.Gate))); }
/// <summary> /// Adds a binary AND gate to the circuit. /// </summary> /// <param name="leftInput">Left input wire.</param> /// <param name="rightInput">Right input wire.</param> /// <returns>A wire representing the logical AND of both inputs.</returns> public Wire And(Wire leftInput, Wire rightInput) { if (leftInput == Wire.Zero || rightInput == Wire.Zero) { return(Wire.Zero); } if (leftInput == Wire.One) { return(rightInput); } if (rightInput == Wire.One) { return(leftInput); } return(Wire.FromGate(new AndGate(RequestGateContext(ref _nextAndGateId), leftInput.Gate, rightInput.Gate))); }
/// <summary> /// Adds a binary AND gate to the circuit. /// </summary> /// <param name="leftInput">Left input wire.</param> /// <param name="rightInput">Right input wire.</param> /// <returns>A wire representing the logical AND of both inputs.</returns> public Wire And(Wire leftInput, Wire rightInput) { if (leftInput == Wire.Zero || rightInput == Wire.Zero) { return(Wire.Zero); } if (leftInput == Wire.One) { return(rightInput); } if (rightInput == Wire.One) { return(leftInput); } _numberOfAndGates++; return(Wire.FromGate(new AndGate(_nextGateId++, leftInput.Gate, rightInput.Gate))); }
/// <summary> /// Adds a binary XOR gate to the circuit. /// </summary> /// <param name="leftInput">Left input wire.</param> /// <param name="rightInput">Right input wire.</param> /// <returns>A wire representing the logical XOR of both inputs.</returns> public Wire Xor(Wire leftInput, Wire rightInput) { if (leftInput == Wire.Zero) { return(rightInput); } if (rightInput == Wire.Zero) { return(leftInput); } if (leftInput == Wire.One) { return(Not(rightInput)); } if (rightInput == Wire.One) { return(Not(leftInput)); } return(Wire.FromGate(new XorGate(RequestGateContext(ref _nextXorGateId), leftInput.Gate, rightInput.Gate))); }
/// <summary> /// Adds a new input wire to the circuit. /// </summary> /// <returns>Input wire.</returns> public Wire Input() { return(Wire.FromGate(new InputGate(RequestGateContext(ref _nextInputGateId)))); }
/// <summary> /// Adds a new input wire to the circuit. /// </summary> /// <returns>Input wire.</returns> public Wire Input() { return(Wire.FromGate(new InputGate(_nextGateId++, _nextInputIndex++))); }