QuantumBFS / ZXCalculus.jl

An implementation of ZX-calculus in Julia
http://yaoquantum.org/ZXCalculus.jl/dev/
MIT License
48 stars 7 forks source link

tensor representation of spiders. #50

Closed GiggleLiu closed 4 years ago

GiggleLiu commented 4 years ago

Might be useful in the future.

function ztensor(nleg::Int, α::T) where T<:Number
    shape = (fill(2, nleg)...,)
    factor = exp(im*α)
    out = zeros(typeof(factor), shape...)
    out[1] = one(typeof(factor))
    out[fill(2, nleg)...] = factor
    out
end

function xtensor(nleg::Int, α::T) where T<:Number
    shape = (fill(2, nleg)...,)
    reshape(reduce(kron, fill(pos, nleg)) + exp(im*α)*reduce(kron, fill(neg, nleg)), shape)
end

function htensor(nleg::Int, α::T) where T<:Number
    shape = (fill(2, nleg)...,)
    factor = exp(im*α)
    out = fill(one(typeof(factor)), shape)
    out[fill(2, nleg)...] = factor
    return out
end