From 4793dc7d4376498fde5f1c523f8a41215518a4fb Mon Sep 17 00:00:00 2001 From: apkille Date: Wed, 26 Jun 2024 13:05:40 -0400 Subject: [PATCH] sorted_arguments for trace --- src/QSymbolicsBase/QSymbolicsBase.jl | 2 +- src/QSymbolicsBase/predefined.jl | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/QSymbolicsBase/QSymbolicsBase.jl b/src/QSymbolicsBase/QSymbolicsBase.jl index fe46613..3dd94a0 100644 --- a/src/QSymbolicsBase/QSymbolicsBase.jl +++ b/src/QSymbolicsBase/QSymbolicsBase.jl @@ -1,7 +1,7 @@ using Symbolics import Symbolics: simplify using SymbolicUtils -import SymbolicUtils: Symbolic,_isone,flatten_term,isnotflat,Chain,Fixpoint +import SymbolicUtils: Symbolic,_isone,flatten_term,isnotflat,Chain,Fixpoint,sorted_arguments using TermInterface import TermInterface: isexpr,head,iscall,children,operation,arguments,metadata diff --git a/src/QSymbolicsBase/predefined.jl b/src/QSymbolicsBase/predefined.jl index 0320022..af0fe3e 100644 --- a/src/QSymbolicsBase/predefined.jl +++ b/src/QSymbolicsBase/predefined.jl @@ -313,6 +313,7 @@ end isexpr(::STrace) = true iscall(::STrace) = true arguments(x::STrace) = [x.op] +sorted_arguments(x::STrace) = arguments(x) operation(x::STrace) = tr head(x::STrace) = :tr children(x::STrace) = [:tr, x.op] @@ -322,7 +323,7 @@ tr(x::SScaled{AbstractOperator}) = x.coeff*tr(x.obj) tr(x::SAdd{AbstractOperator}) = (+)((tr(i) for i in arguments(x))...) tr(x::SOuterKetBra) = x.bra*x.ket tr(x::SCommutator) = 0 -tr(x::STensorOperator) = (*)((tr(i) for i in arguments(x))...) # TODO add tr properties +tr(x::STensorOperator) = (*)((tr(i) for i in arguments(x))...) Base.hash(x::STrace, h::UInt) = hash((head(x), arguments(x)), h) Base.isequal(x::STrace, y::STrace) = isequal(x.op, y.op)