# BernDirac
[![Wolfram Language](https://wolfr.am/NyiJ4BVJ)](https://www.wolfram.com/language/)
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
[![Platforms](https://img.shields.io/badge/Platform-Windows/MacOS/Linux-crimson)](https://github.com/bernie-wu/BernDirac)
![BernDiracLogo](Image/Logo/BernDirac_logo_v2.svg)
A [Wolfram Mathematica](https://www.wolfram.com/mathematica/) package for performing calculations involving matrices/vectors in the [Dirac notation](https://en.wikipedia.org/wiki/Bra%E2%80%93ket_notation) which is usually used in [quantum mechanics](https://en.wikipedia.org/wiki/Quantum_mechanics)/[quantum computing](https://en.wikipedia.org/wiki/Quantum_computing). It utilises the *built-in functions without predefined meanings*, namely `Ket[]`, `Bra[]`, and `CircleTimes[]`, along with their respective alias, <code>| ⟩ ↔ <kbd>esc</kbd>ket<kbd>esc</kbd></code>, <code>⟨ | ↔ <kbd>esc</kbd>bra<kbd>esc</kbd></code> and <code>⊗ ↔ <kbd>esc</kbd>c*<kbd>esc</kbd></code>.
The basis which this package works in is {|0⟩,|1⟩}, which is also known as the *computational basis* or the *Z basis*.
The package was written in Wolfram Mathematica version [12.2](https://www.wolfram.com/mathematica/quick-revision-history.html) in Windows 10 and it has zero dependencies.
## Contact
Bernard Wo - bernardwu+BernDirac@outlook.my
Project Link: [https://github.com/bernie-wu/BernDirac](https://github.com/bernie-wu/BernDirac)
# How to use?
Download [BernDirac.wl](https://github.com/bernie-wu/BernDirac/blob/main/BernDirac.wl) and place it wherever you like. Then, in your Mathematica notebook, run the following line to load the package into your current Mathematica session:
```wolframlanguage
Get[<path-to-BernDirac.wl>];
```
# Functions that this package provides
After loading [BernDirac.wl](https://github.com/bernie-wu/BernDirac/blob/main/BernDirac.wl) into your Mathematica notebook session, the following additional functions become available to use:
* [`Ket[]`](#Ket "Go-to Ket[]")
* [`Bra[]`](#Bra "Go-to Bra[]")
* [`CircleTimes[]`](#CircleTimes "Go-to CircleTimes[]")
* [`DiracForm[]`](#DiracForm "Go-to DiracForm[]")
* [`PartialTr[]`](#PartialTr "Go-to PartialTr[]")
The special quantities, namely the [**Bell states**](https://en.wikipedia.org/wiki/Bell_state) also become available to use via [`Ket[]`](#Ket "Go-to Ket[]") and [`Bra[]`](#Bra "Go-to Bra[]") (see section [Bell states](#Bell-states "Go-to Bell states")).
## Ket[]
`Ket[]` is used to denote a *column vector*. The alias `| ⟩` for `Ket[]` can be obtained with <code><kbd>esc</kbd>ket<kbd>esc</kbd></code>.
The allowed input for `Ket[]` is either `0` or `1` and the output for each case is as shown here:
>> ![In:Ket[0]](Image/Ket/ket0_in.svg "Ket[0]")
>> ![Out:{{1},{0}}](Image/Ket/ket0_out.svg "{{1},{0}}")
>
>> ![In:Ket[1]](Image/Ket/ket1_in.svg "Ket[1]")
>> ![Out:{{0},{1}}](Image/Ket/ket1_out.svg "{{0},{1}}")
`Ket[]` also supports multiple inputs, as long as they are `0` and `1`.
>> ![In:Ket[1,1,0]](Image/Ket/ket110_in.svg "Ket[1,1,0]")
>> ![Out:Ket[1,1,0]](Image/Ket/ket110_out.svg "{{0},{0},{0},{0},{0},{0},{1},{0}}")
Note that `Ket[1,1,0]` is equivalent to `Ket[1]⊗Ket[1]⊗Ket[0]` (see [`CircleTimes[]`](#CircleTimes "Go-to CircleTimes[]")).
## Bra[]
`Bra[]` is used to denote a *row vector* (i.e. `| ⟩=(⟨ |)†` where `†` denotes conjugate transpose). The alias `⟨ |` for `Bra[]` can be obtained with <code><kbd>esc</kbd>bra<kbd>esc</kbd></code>.
The allowed input for `Bra[]` is either `0` or `1` and the output for each case is as shown here:
>> ![In:Bra[0]](Image/Bra/bra0_in.svg "Bra[0]")
>> ![Out:{{1,0}}](Image/Bra/bra0_out.svg "{{1,0}}")
>
>> ![In:Bra[1]](Image/Bra/bra1_in.svg "Bra[1]")
>> ![Out:{{0,1}}](Image/Bra/bra1_out.svg "{{0,1}}")
Just like `Ket[]`, `Bra[]` also supports multiple inputs, as long as they are `0` and `1`.
>> ![In:Bra[1,1,0]](Image/Bra/bra110_in.svg "Bra[1,1,0]")
>> ![Out:Bra[1,1,0]](Image/Bra/bra110_out.svg "{{0,0,0,0,0,0,1,0}}")
Note that `Bra[1,1,0]` is equivalent to `Bra[1]⊗Bra[1]⊗Bra[0]` (see [`CircleTimes[]`](#CircleTimes "Go-to CircleTimes[]")).
## CircleTimes[]
The alias `⊗` for `CircleTimes[]`, is used to denote the [*Kronecker product*](https://en.wikipedia.org/wiki/Kronecker_product) (sometimes also called [*Tensor product*](https://en.wikipedia.org/wiki/Tensor_product)). Use <code><kbd>esc</kbd>c*<kbd>esc</kbd></code> to obtain the alias.
Below, we show that `⊗` works for multiple column vectors, row vectors, and square matrices.
**Column vector**
>> ![In:Ket[1]⊗Ket[1]⊗Ket[0]](Image/Ket/ket110_tensor_in.svg "Ket[1]⊗Ket[1]⊗Ket[0]")
>> ![Out:Ket[1]⊗Ket[1]⊗Ket[0]](Image/Ket/ket110_out.svg "{{0},{0},{0},{0},{0},{0},{1},{0}}")
**Row vector**
>> ![In:Bra[1]⊗Bra[1]⊗Bra[0]](Image/Bra/bra110_tensor_in.svg "Bra[1]⊗Bra[1]⊗Bra[0]")
>> ![Out:Bra[1,1,0]](Image/Bra/bra110_out.svg "{{0,0,0,0,0,0,1,0}}")
**Square matrix**
>> ![In:Ket[0].Bra[0]⊗Ket[1].Bra[1]](Image/BraKet/braket00_11_tensor_in.svg "Ket[0].Bra[0]⊗Ket[1].Bra[1]")
>> ![Out:Ket[0].Bra[0]⊗Ket[1].Bra[1]](Image/BraKet/braket00_11_tensor_out.svg "{{{0, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}}")
## DiracForm[]
`DiracForm[]` prints the vector or matrix using the Dirac notation. It works for column vectors, row vectors, and square matrices.
**Column vector**
>> ![In:αKet[0]⊗Ket[0]+βKet[1]⊗Ket[1]](Image/Ket/αket00_βket11_tensor_dirac_in.svg "αKet[0]⊗Ket[0]+βKet[1]⊗Ket[1]")
>> ![Out:αKet[0]⊗Ket[0]+βKet[1]⊗Ket[1]](Image/Ket/αket00_βket11_tensor_dirac_out.svg "α|0,0⟩+β|1,1⟩")
**Row vector**
>> ![In:αBra[0]⊗Bra[0]+βBra[1]⊗Bra[1]](Image/Bra/αbra00_βbra11_tensor_dirac_in.svg "αBra[0]⊗Bra[0]+βBra[1]⊗Bra[1]")
>> ![Out:αBra[0]⊗Bra[0]+βBra[1]⊗Bra[1]](Image/Bra/αbra00_βbra11_tensor_dirac_out.svg "α⟨0,0|+β⟨1,1|")
**Square matrix**
>> ![In:(αKet[0]⊗Ket[0]+βKet[1]⊗Ket[1]).(αBra[0]⊗Bra[0]+βBra[1]⊗Bra[1])](Image/BraKet/αket00_βket11_αbra00_βbra11_tensor_dirac_in.svg "(αKet[0]⊗Ket[0]+βKet[1]⊗Ket[1]).(αBra[0]⊗Bra[0]+βBra[1]⊗Bra[1])")
>> ![Out:(αKet[0]⊗Ket[0]+βKet[1]⊗Ket[1]).(αBra[0]⊗Bra[0]+βBra[1]⊗Bra[1])](Image/BraKet/αket00_βket11_αbra00_βbra11_tensor_dirac_out.svg "α²|0,0⟩.⟨0,0|+αβ|0,0⟩.⟨1,1|+αβ|1,1⟩.⟨0,0|+β²|1,1⟩.⟨1,1|")
>
>> ![In:{{a e+b g,a f+b h},{c e+d g,c f+d h}}](Image/BraKet/matrix_ketbra_in.svg "{{a e+b g,a f+b h},{c e+d g,c f+d h}}")
>> ![Out:{{a e+b g,a f+b h},{c e+d g,c f+d h}}](Image/BraKet/matrix_ketbra_out.svg "(a e+b g)|0⟩.⟨0|+(a f+b h)|0⟩.⟨1|+(c e+d g)|1⟩.⟨0|+(c f+d h)|1⟩.⟨1|")
## Bell states
By using the special letter capital dotted `Φ` and subscripts, we can access the four Bell states using [`Ket[]`](#Ket "Go-to Ket[]") and [`Bra[]`](#Ket "Go-to Ket[]"). Note that the special dotted `Φ` is known as [FormalCapitalPhi](https://reference.wolfram.com/language/ref/character/FormalCapitalPhi.html) in the documentation (for more information, see the formal letters section [here](https://reference.wolfram.com/language/tutorial/MathematicalAndOtherNotation.html)).
The dotted `Φ` alias can be accessed with <code><kbd>esc</kbd>.CapitalPhi<kbd>esc</kbd></code>, and inputting subscript(s) can be achieved with <code><kbd>ctrl</kbd>+<kbd>_</kbd></code>.
>> ![In:Ket[FormalCapitalPhi_00]](Image/Bell_states/phi00_in.svg "Ket[FormalCapitalPhi_00]")
>> ![Out:Ket[FormalCapitalPhi_00]](Image/Bell_states/phi00_out.svg "|0,0⟩/√2+|1,1⟩/√2")
>
>> ![In:Ket[FormalCapitalPhi_01]](Image/Bell_states/phi01_in.svg "Ket[FormalCapitalPhi_01]")
>> ![Out:Ket[FormalCapitalPhi_01]](Image/Bell_states/phi01_out.svg "|0,1⟩/√2+|1,0⟩/√2")
>
>> ![In:Ket[FormalCapitalPhi_10]](Image/Bell_states/phi10_in.svg "Ket[FormalCapitalPhi_10]")
>> ![Out:Ket[FormalCapitalPhi_10]](Image/Bell_states
没有合适的资源?快使用搜索试试~ 我知道了~
一个Mathematica包,用于执行涉及狄拉克符号中的.zip
共53个文件
svg:47个
md:4个
wl:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 9 浏览量
2023-04-10
23:53:07
上传
评论
收藏 375KB ZIP 举报
温馨提示
一个Mathematica包,用于执行涉及狄拉克符号中的.zip
资源推荐
资源详情
资源评论
收起资源包目录
一个Mathematica包,用于执行涉及狄拉克符号中的.zip (53个子文件)
BernDirac-main
LICENSE.md 34KB
.github
ISSUE_TEMPLATE
feature_request.md 595B
bug_report.md 834B
Example
BernDirac_examples.nb 24KB
BernDirac.wl 9KB
Image
PartialTr
partialtr1_αketbra011_βketbra110_out.svg 21KB
partialtr13_αketbra011_βketbra110_in.svg 76KB
partialtr13_αketbra011_βketbra110_out.svg 16KB
partialtr23_αketbra011_βketbra110_out.svg 18KB
partialtr23_αketbra011_βketbra110_in.svg 76KB
partialtr1_αketbra011_βketbra110_in.svg 76KB
Example
eg_postmeasurement_in.svg 85KB
eg_partialtr_bellstate_out.svg 17KB
eg_matrixexp_out.svg 64KB
eg_postmeasurement_out.svg 15KB
eg_partialtr_bellstate_in.svg 62KB
eg_bitflip_in.svg 73KB
eg_bitflip_out.svg 18KB
eg_matrixexp_in.svg 44KB
Logo
BernDirac_logo_v2.svg 26KB
Bra
bra1_out.svg 13KB
αbra00_βbra11_tensor_dirac_in.svg 28KB
αbra00_βbra11_tensor_dirac_out.svg 18KB
bra0_in.svg 20KB
bra110_tensor_in.svg 34KB
bra110_in.svg 22KB
bra110_out.svg 13KB
bra1_in.svg 18KB
bra0_out.svg 13KB
Ket
ket1_out.svg 13KB
αket00_βket11_tensor_dirac_in.svg 28KB
ket0_in.svg 20KB
ket1_in.svg 18KB
ket0_out.svg 13KB
ket110_out.svg 13KB
ket110_tensor_in.svg 34KB
αket00_βket11_tensor_dirac_out.svg 18KB
ket110_in.svg 22KB
Bell_states
phi10_in.svg 28KB
phi11_in.svg 26KB
phi00_out.svg 17KB
phi01_in.svg 28KB
phi10_out.svg 17KB
phi11_out.svg 17KB
phi00_in.svg 27KB
phi01_out.svg 17KB
BraKet
αket00_βket11_αbra00_βbra11_tensor_dirac_in.svg 34KB
braket00_11_tensor_in.svg 40KB
matrix_ketbra_in.svg 33KB
braket00_11_tensor_out.svg 14KB
αket00_βket11_αbra00_βbra11_tensor_dirac_out.svg 28KB
matrix_ketbra_out.svg 36KB
README.md 11KB
共 53 条
- 1
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9154
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功