Skip to content

Commit

Permalink
updated sneg
Browse files Browse the repository at this point in the history
  • Loading branch information
rokzitko committed Apr 19, 2022
1 parent f17c130 commit 3fe6424
Showing 1 changed file with 44 additions and 31 deletions.
75 changes: 44 additions & 31 deletions nrginit/sneg.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
SNEG - Mathematica package for calculations with non-commuting
operators of the second quantization algebra
Copyright (C) 2002-2019 Rok Zitko
Copyright (C) 2002-2022 Rok Zitko
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -31,8 +31,8 @@

BeginPackage["Sneg`"];

snegidstring = "sneg.m 1.251 20 Mar 2019";
snegcopyright = "Copyright (C) 2002-2019 Rok Zitko";
snegidstring = "sneg.m 2.0.0 April 2022";
snegcopyright = "Copyright (C) 2002-2022 Rok Zitko";

$SnegVersion = Module[{pos, p1, p2},
pos = StringPosition[snegidstring, " "];
Expand Down Expand Up @@ -560,7 +560,7 @@ spin projection quantum numbers (Q,S_z) in occupation number representation.",
operators corresponding to the levels described by the opreators
a,b,... Here N is the number of pairs."];
UsageWithMore[maskOp,
"maskOp[op, args] calls function op while all constants declared to
"maskOp[op, margs] calls function op while all constants declared to
sneg are masked. This prevents some interferences between sneg and
certain Mathematica functions."];
UsageWithMore[quickISObasis,
Expand Down Expand Up @@ -760,10 +760,6 @@ of operator H in the given basis (in the creation operator representation).
ScriptBaselineShifts -> {1, 1}]
]
];

(* Avoid superfluous parenthesis *)
(* MakeBoxes[a_ * x[i_, j___, sigma_], fmt:(StandardForm|TraditionalForm)] :=
RowBox[{MakeBoxes[a, fmt], MakeBoxes[x[i, j, sigma], fmt]}]; *)
];

(* Convert x to a string in the TeX format *)
Expand Down Expand Up @@ -860,10 +856,6 @@ of operator H in the given basis (in the creation operator representation).
ScriptBaselineShifts -> {1, 1}]
]
];

(* Avoid superfluous parenthesis *)
(* MakeBoxes[a_ * x[i_, j___], fmt:(StandardForm|TraditionalForm)] :=
RowBox[{MakeBoxes[a, fmt], MakeBoxes[x[i, j, sigma], fmt]}]; *)
];


Expand All @@ -887,6 +879,12 @@ of operator H in the given basis (in the creation operator representation).
snegnonopQ[#] ^= True;
Conjugate[#] ^= #;
addto[listrealconstants, #];
}&, {l}];

snegpositiveconstants[l__] := Scan[
{ snegnonopQ[#] ^= True;
Conjugate[#] ^= #;
addto[listrealconstants, #];

Unprotect[Power];
Power[Power[#, n_], 1/2] /; (EvenQ[n]) := Power[#,n/2];
Expand Down Expand Up @@ -938,11 +936,6 @@ of operator H in the given basis (in the creation operator representation).
ScriptSizeMultipliers -> 1,
ScriptBaselineShifts -> {1, 1}]
];


(* Avoid superfluous parenthesis *)
(* MakeBoxes[a_ * x[i_, j___], fmt:(StandardForm|TraditionalForm)] :=
RowBox[{MakeBoxes[a, fmt], MakeBoxes[x[i, j], fmt]}]; *)
];

snegspinoperators[l__] := Scan[
Expand Down Expand Up @@ -1469,6 +1462,9 @@ of operator H in the given basis (in the creation operator representation).
supercommutator[a___] := superkomutator[a];
superanticommutator[a___] := superantikomutator[a];

(* Other helper functions *)
extracteps[a_, b_, H_] := anticommutator[a, commutator[H, conj[b]]] // Expand;

(* (Manual) normal ordering *)
SetAttributes[normalorder, Listable];
normalorder[a_] := a - vev[a];
Expand Down Expand Up @@ -2165,6 +2161,15 @@ operator corresponding to an (operator) expression g. g must be a
nambu[op_?fermionQ[j___], n_:0] := {op[CR, j, UP], (-1)^n op[AN, j, DO]};
nambu[op_?AtomQ, n___] := nambu[op[], n];

(* BCS pairing operator *)
bcs[op_?fermionQ[j1__], Phi_] :=
Exp[ I Phi] nc[op[CR, j1, UP], op[CR, j1, DO]] +
Exp[-I Phi] nc[op[AN, j1, DO], op[AN, j1, UP]]

bcs[Delta_, op_?fermionQ[j1__]] :=
Delta nc[op[CR, j1, UP], op[CR, j1, DO]] +
Conjugate[Delta] nc[op[AN, j1, DO], op[AN, j1, UP]]

(* X, Y and Z componentes of the isospin operator. *)

SetAttributes[{isospinxyz, isospin, isospinx, isospiny, isospinz,
Expand Down Expand Up @@ -2270,13 +2275,21 @@ operator corresponding to an (operator) expression g. g must be a
hop[fn1_Function, op2_?fermionQ[j2___]] := hop[fn1, op2[#1, j2, #2]&];
hop[op1_?fermionQ[j1___], fn2_Function] := hop[op1[#1, j1, #2]&, fn2];

(* Generic hopping with a complex-valued parameter t *)
genhop[t_, op1_?fermionQ[j1___], op2_?fermionQ[j2___], sigma_] :=
t op1[CR, j1, sigma]~nc~op2[AN, j2, sigma] +
Conjugate[t] op2[CR, j2, sigma]~nc~op1[AN, j1, sigma];

genhop[t_, op1_?fermionQ[j1___], op2_?fermionQ[j2___]] /; (spinof[op1] == spinof[op2] == 1/2) :=
genhop[t, op1[j1], op2[j2], UP] + genhop[t, op1[j1], op2[j2], DO];

(* Hopping with spin-flip *)
SetAttributes[spinfliphop, Listable];
spinfliphop[op1_?fermionQ[j1___], op2_?fermionQ[j2___]] := Sum[
op1[CR, j1, sigma] ~ nc ~ op2[AN, j2, 1-sigma] +
op2[CR, j2, sigma] ~ nc ~ op1[AN, j1, 1-sigma],
{sigma, DO, UP} ];
{sigma, DO, UP} ];

(* Hopping with hole operators:
c^\dag_{k,\sigma} f_\sigma} + f^\dag_\sigma c_{k\sigma}
\to
Expand Down Expand Up @@ -2309,10 +2322,10 @@ operator corresponding to an (operator) expression g. g must be a

(* Hopping with spin-flip and phase change *)
SetAttributes[spinfliphopphi, Listable];
spinfliphopphi[op1_?fermionQ[j1___], op2_?fermionQ[j2___], phi_] :=
Sum[Exp[I phi] op1[CR, j1, sigma]~nc~op2[AN, j2, 1 - sigma] +
Exp[-I phi] op2[CR, j2, sigma]~nc~op1[AN, j1, 1 - sigma],
{sigma, DO, UP}];
spinfliphopphi[op1_?fermionQ[j1___], op2_?fermionQ[j2___], phi_] :=
Sum[Exp[I phi] op1[CR, j1, sigma]~nc~op2[AN, j2, 1 - sigma] +
Exp[-I phi] op2[CR, j2, sigma]~nc~op1[AN, j1, 1 - sigma],
{sigma, DO, UP}];

(* Current operator *)
(*
Expand Down Expand Up @@ -2630,8 +2643,8 @@ representations of the SU(2) group (i.e. S=1 representation instead of
buildop[op_String, type_] := With[{x = ToExpression[op]},
x[type] /; (x =!= $Failed && operatorQ[x])];

buildop[op_String, type_, args_String] :=
With[{x = ToExpression[op], arglist = removecommas[args]},
buildop[op_String, type_, margs_String] :=
With[{x = ToExpression[op], arglist = removecommas[margs]},
x @@ Prepend[arglist, type] /; (x =!= $Failed && operatorQ[x])];

buildket[n_String] := ket @@ removecommas[n];
Expand All @@ -2640,11 +2653,11 @@ representations of the SU(2) group (i.e. S=1 representation instead of

snegstringparse[s_String] := StringCases[s, {
(op : Except[Characters["|<>()+"]] ..) ~~
"+(" ~~ (args : Except[Characters[")"]] ...) ~~ ")" :>
buildop[op, CR, args],
"+(" ~~ (margs : Except[Characters[")"]] ...) ~~ ")" :>
buildop[op, CR, margs],
(op : Except[Characters["|<>()+"]] ..) ~~
"(" ~~ (args : Except[Characters[")"]] ...) ~~ ")" :>
buildop[op, AN, args],
"(" ~~ (margs : Except[Characters[")"]] ...) ~~ ")" :>
buildop[op, AN, margs],
"|" ~~ (ndx : Except[Characters["|<>()"]] ...) ~~ ">" :>
buildket[ndx],
"<" ~~ (ndx : Except[Characters["|<>()"]] ...) ~~ "|" :>
Expand Down Expand Up @@ -3823,9 +3836,9 @@ the conventional (anti)commutation rules. Of course, this only works
(* Sometimes arguments needs to be evaluated before being passed to
a function. *)

maskOp[op_, args__] := Module[{map, invmap, tmp, res},
maskOp[op_, margs__] := Module[{map, invmap, tmp, res},
{map, invmap} = maskconstants[];
tmp = {args} /. map;
tmp = {margs} /. map;
res = ReleaseHold[op] @@ tmp;
res /. invmap
];
Expand Down

0 comments on commit 3fe6424

Please sign in to comment.