<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Kshitiz Sharma</title>
    <description>The latest articles on DEV Community by Kshitiz Sharma (@clunkier).</description>
    <link>https://dev.to/clunkier</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3651681%2Fea4cc375-b7bf-49b2-93c7-43131640c93e.jpg</url>
      <title>DEV Community: Kshitiz Sharma</title>
      <link>https://dev.to/clunkier</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/clunkier"/>
    <language>en</language>
    <item>
      <title>You have tried Maths on Computer, now try it on Quantum computer</title>
      <dc:creator>Kshitiz Sharma</dc:creator>
      <pubDate>Fri, 30 Jan 2026 14:02:53 +0000</pubDate>
      <link>https://dev.to/clunkier/you-have-tried-maths-on-computer-now-try-it-on-quantum-computer-fef</link>
      <guid>https://dev.to/clunkier/you-have-tried-maths-on-computer-now-try-it-on-quantum-computer-fef</guid>
      <description>&lt;h1&gt;
  
  
  Simulating Classical Arithmetic on Quantum Circuits with Qiskit
&lt;/h1&gt;

&lt;p&gt;Quantum computing is often introduced through complex concepts like superposition and entanglement. However, a practical way to understand quantum logic gates is to rebuild familiar classical components—like adders and multiplexers—using quantum hardware.&lt;/p&gt;

&lt;p&gt;This article demonstrates how to implement &lt;strong&gt;Half Adders&lt;/strong&gt; and &lt;strong&gt;Full Adders&lt;/strong&gt; using IBM’s &lt;strong&gt;Qiskit&lt;/strong&gt; SDK, based on the implementations found in the &lt;a href="https://github.com/clunkiersalt817/QuantumProgramming" rel="noopener noreferrer"&gt;QuantumProgramming&lt;/a&gt; repository.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Prerequisite: Qubits vs. Bits
&lt;/h2&gt;

&lt;p&gt;In this implementation, we utilize &lt;strong&gt;Qiskit&lt;/strong&gt;, an open-source SDK for working with IBM quantum processors.&lt;/p&gt;

&lt;p&gt;While classical bits are binary (0 or 1), &lt;strong&gt;qubits&lt;/strong&gt; are defined by statevectors and can exist in superpositions. However, to simulate classical arithmetic deterministic logic, we initialize these qubits to specific states (0 or 1) and use quantum gates that mimic classical logic tables:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Pauli-X Gate (&lt;code&gt;.x&lt;/code&gt;):&lt;/strong&gt; Analogous to a classical &lt;strong&gt;NOT&lt;/strong&gt; gate.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;CNOT Gate (&lt;code&gt;.cx&lt;/code&gt;):&lt;/strong&gt; Analogous to an &lt;strong&gt;XOR&lt;/strong&gt; gate (used for Sum).&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Toffoli Gate (&lt;code&gt;.ccx&lt;/code&gt;):&lt;/strong&gt; Analogous to an &lt;strong&gt;AND&lt;/strong&gt; gate (used for Carry).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  1. Implementing the Half Adder
&lt;/h2&gt;

&lt;p&gt;A Half Adder accepts two binary inputs and generates two outputs: a &lt;strong&gt;Sum&lt;/strong&gt; and a &lt;strong&gt;Carry&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Circuit Architecture
&lt;/h3&gt;

&lt;p&gt;The circuit requires 4 qubits and 2 classical bits for measurement. We initialize the input qubits to &lt;code&gt;1&lt;/code&gt; using the Pauli-X gate to test the "1 + 1" case.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Code
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;qiskit&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;qiskit.providers.aer&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;AerSimulator&lt;/span&gt;

&lt;span class="c1"&gt;# Initialize Quantum Circuit: 4 Qubits, 2 Classical Bits
&lt;/span&gt;&lt;span class="n"&gt;qc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;QuantumCircuit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Initialize inputs to '1' using the Pauli-X gate
&lt;/span&gt;&lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;x&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; 

&lt;span class="c1"&gt;# Logic Implementation
&lt;/span&gt;&lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cx&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;       &lt;span class="c1"&gt;# XOR gate (Sum calculation)
&lt;/span&gt;&lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cx&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;       &lt;span class="c1"&gt;# XOR gate (Sum calculation)
&lt;/span&gt;&lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ccx&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="c1"&gt;# Toffoli gate (Carry calculation)
&lt;/span&gt;
&lt;span class="c1"&gt;# Measure results to classical bits
&lt;/span&gt;&lt;span class="n"&gt;qc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;measure&lt;/span&gt;&lt;span class="p"&gt;(,)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Execution and Output
&lt;/h3&gt;

&lt;p&gt;When running this circuit on a simulator (like &lt;code&gt;AerSimulator&lt;/code&gt;), the output for inputs &lt;code&gt;1&lt;/code&gt; and &lt;code&gt;1&lt;/code&gt; results in a count of &lt;code&gt;{ '10': 1024 }&lt;/code&gt;. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Binary &lt;code&gt;10&lt;/code&gt;&lt;/strong&gt; corresponds to decimal &lt;strong&gt;2&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;  This confirms the Half Adder logic: &lt;strong&gt;1 + 1 = 0 (Sum) with a Carry of 1&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. Scaling to a Full Adder
&lt;/h2&gt;

&lt;p&gt;To handle a carry-in bit, we scale up to a &lt;strong&gt;Full Adder&lt;/strong&gt;. This requires a larger circuit setup to manage three inputs (&lt;code&gt;q0&lt;/code&gt;, &lt;code&gt;q1&lt;/code&gt;, &lt;code&gt;q2&lt;/code&gt;).&lt;/p&gt;

&lt;h3&gt;
  
  
  Circuit Architecture
&lt;/h3&gt;

&lt;p&gt;The implementation uses 5 qubits and 4 classical bits. In the repository example, all three inputs are initialized to &lt;code&gt;1&lt;/code&gt; to test the maximum addition case (1 + 1 + 1).&lt;/p&gt;

&lt;h3&gt;
  
  
  The Code
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;qfa&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;QuantumCircuit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Initialize all three inputs to '1'
&lt;/span&gt;&lt;span class="n"&gt;qfa&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;x&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="c1"&gt;# XOR gates for Sum logic (CNOT)
&lt;/span&gt;&lt;span class="n"&gt;qfa&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cx&lt;/span&gt;&lt;span class="p"&gt;(,)&lt;/span&gt;

&lt;span class="c1"&gt;# Toffoli gates for Carry logic
&lt;/span&gt;&lt;span class="n"&gt;qfa&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ccx&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;qfa&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ccx&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;qfa&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ccx&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Measure the results
&lt;/span&gt;&lt;span class="n"&gt;qfa&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;measure&lt;/span&gt;&lt;span class="p"&gt;(,)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Execution and Output
&lt;/h3&gt;

&lt;p&gt;The simulator returns &lt;code&gt;{ '0011': 1024 }&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  The binary result &lt;code&gt;11&lt;/code&gt; equals decimal &lt;strong&gt;3&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;  This validates the logic: &lt;strong&gt;1 + 1 + 1 = 1 (Sum) with a Carry of 1&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion and Resources
&lt;/h2&gt;

&lt;p&gt;Translating classical logic into quantum circuits is an excellent way to familiarize yourself with Qiskit's syntax and gate operations. The repository also explores control logic, including a &lt;strong&gt;2x1 Multiplexer&lt;/strong&gt; implementation.&lt;/p&gt;

&lt;p&gt;For the full source code and Jupyter Notebooks, you can view the repository here:&lt;br&gt;
&lt;strong&gt;GitHub: &lt;a href="https://github.com/clunkiersalt817/QuantumProgramming" rel="noopener noreferrer"&gt;clunkiersalt817/QuantumProgramming&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>computerscience</category>
      <category>python</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
