File:Qcircuit ToffolifromCNOT.svg

From testwiki
Jump to navigation Jump to search
    Original file (SVG file, nominally 1,959 × 584 pixels, file size: 20 KB)

    This file is from Wikimedia Commons and may be used by other projects. The description on its file description page there is shown below.

    Summary

    Description
    English: Quantum circuit diagram constructing a Toffoli gate from single-qubit operations and six controlled NOT (CNOT) gates. This is the minimum number of CNOTs required to build a Toffoli.[1]
    Date
    Source

    Own work

    Created in LaTeX using Q-circuit
    Author Geek3
    SVG development
    InfoField
     The SVG code is valid.
     This vector image was created with LaTeX, using Q-circuit
    gate matrix:(1000000001000000001000000001000000001000000001000000000100000010)
    Source code
    InfoField

    LaTeX code

    LaTeX Qcircuit source code
    \documentclass[border=10pt]{standalone}
    \input{Qcircuit} % available on https://github.com/CQuIC/qcircuit
    \usepackage{graphicx}
    \begin{document}
    \newcommand{\multistate}[2]{*+{\hphantom{#2}} \POS[0,0].[#1,0] !C
      *{#2} \POS[0,0].[#1,0] \drop\frm{}}
    \newcommand{\ghoststate}[1]{*+{\hphantom{#1}} }
    \newcommand{\ccteqg}{\ghoststate{=}}
    \newcommand{\ccteq}[1]{\multistate{#1}{=}}
    \scalebox{5}{%
    \Qcircuit @C=0.8em {
    & \control \qw & \qw & \ccteq{2} & & \qw & \qw & \qw & \control \qw & \qw &
    \qw & \qw & \control \qw & \qw & \control \qw & \gate{T} & \control \qw & \qw \\
    & \control \qw \qwx & \qw & \ccteqg & & \qw & \control \qw & \qw & \qw \qwx &
    \qw & \control \qw & \qw & \qw \qwx & \gate{T} & \targ \qwx & \gate{T^\dagger}
    & \targ \qwx  & \qw \\
    & \targ \qw \qwx & \qw & \ccteqg & & \gate{H} & \targ \qwx & \gate{T^\dagger}
    & \targ \qwx & \gate{T} & \targ \qwx & \gate{T^\dagger} & \targ \qwx & \gate{T}
    & \qw & \gate{H} & \qw & \qw }}
    \end{document}
    

    Bash code

    postprocessing with pdf2svg, Inkscape and Scour
    x=Qcircuit_ToffolifromCNOT;
    pdflatex $x.tex;
    pdf2svg $x.pdf $x_.svg;
    inkscape --without-gui --verb=EditSelectAll --verb=SelectionUnGroup --verb=FileVacuum --verb=FileSave --verb=FileClose $x_.svg;
    scour -i $x_.svg -o $x.svg --renderer-workaround --remove-metadata --enable-id-stripping --create-groups --enable-viewboxing
    

    Mathematica code

    The following Mathematica code shows the equality:
    PauliMatrix = {{{0, 1}, {1, 0}}, {{0, -I}, {I, 0}}, {{1, 0}, {0, -1}}}[[#1]] &;
    R[x_, y_, z_] := MatrixExp[-I/2 Sum[{x, y, z}[[i]]*PauliMatrix[i], {i, 3}]];
    A_⊗B_ := KroneckerProduct[A, B];
    A_⊗B_⊗C_ := KroneckerProduct[A, B, C];
    Gn[G_, i_, n_] := Fold[#1⊗#2 &, {{1}}, ReplacePart[Table[I2, {n}], i -> G]];
    I2 = IdentityMatrix[2];
    X = R[Pi, 0, 0] I;
    Z = R[0, 0, Pi] I;
    H = {{1, 1}, {1, -1}}/Sqrt[2];
    T = Exp[I Pi/8] R[0, 0, Pi/4];
    Tdag = ConjugateTranspose[T];
    Swap = {{1, 0, 0, 0}, {0, 0, 1, 0}, {0, 1, 0, 0}, {0, 0, 0, 1}};
    CNOT = {{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 0, 1}, {0, 0, 1, 0}};
    CNOT12 = (CNOT⊗I2);
    CNOT23 = (I2⊗CNOT);
    CNOT13 = (Swap⊗I2).CNOT23.(Swap⊗I2);
    
    Toffoli = 
     CNOT12.(T⊗Tdag⊗H).CNOT12.(I2⊗T⊗T).CNOT13.Gn[Tdag, 3, 3].CNOT23.Gn[
        T, 3, 3].CNOT13.Gn[Tdag, 3, 3].CNOT23.Gn[H, 3, 3] // MatrixForm
    

    Licensing

    I, the copyright holder of this work, hereby publish it under the following license:
    w:en:Creative Commons
    attribution share alike
    This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
    You are free:
    • to share – to copy, distribute and transmit the work
    • to remix – to adapt the work
    Under the following conditions:
    • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
    • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
    1. ↑ On the CNOT-cost of TOFFOLI gates

    Captions

    Add a one-line explanation of what this file represents

    Items portrayed in this file

    depicts

    20,448 byte

    image/svg+xml

    8b4b2a4e6ab4a1f94e63efdf3e5e8a8971c6ce77

    File history

    Click on a date/time to view the file as it appeared at that time.

    Date/TimeThumbnailDimensionsUserComment
    current23:13, 9 January 2019Thumbnail for version as of 23:13, 9 January 20191,959 × 584 (20 KB)wikimediacommons>Geek3User created page with UploadWizard

    There are no pages that use this file.