Skip to content

Instantly share code, notes, and snippets.

View lucainnocenti's full-sized avatar

Luca Innocenti lucainnocenti

  • University of Palermo
  • Palermo
View GitHub Profile
@lucainnocenti
lucainnocenti / bibitem-sorter.py
Last active December 13, 2023 06:17
Python script to sort the bibitem entries according to the citation order in the text. Useful when one has for some reason to not use bibtex and .bib files. Usage is as `python bibitem-sorter.py file.tex sorted_file.tex`
import argparse
import os
import sys
import re
def printBold(msg):
HEADER = '\033[95m'
BOLD = '\033[1m'
print(HEADER + BOLD + msg + '\x1b[0m')
@lucainnocenti
lucainnocenti / scramblingDynamics.m
Last active July 28, 2022 09:40
Examples of scrambling (cit) dynamics
(* this one gives maximally negative tripartite *)
superScrambling2qutritsUnitary := Table[
Normal @ Flatten @ KroneckerProduct[
SparseArray[{Mod[i + j, 3] + 1 -> 1}, 3],
SparseArray[{Mod[i - j, 3] + 1 -> 1}, 3]
],
{i, {0, 1, 2}}, {j, {0, 1, 2}}
] // ArrayReshape[#, {9, 9}] & // Transpose;
(* unitary changing local bases to Fourier bases *)
generatePair[pauliIndices_List, tuple_List] := {
BitXor[
ReplaceAll[
pauliIndices, {3 -> 0, 2 -> 1}
],
tuple
],
(-1)^Total@tuple[[Flatten@Position[pauliIndices, 2 | 3]]]
};
@lucainnocenti
lucainnocenti / shannonEntropy.m
Created November 15, 2021 02:44
Two-dimensional visualisation of Shannon entropy
ShannonEntropy[probs_] := -Total[# * Log @ #] & @ DeleteCases[probs, _?PossibleZeroQ];
par[t_, s_] = {1, 0, 0} + t / Sqrt@2 {-1, 1, 0} + s/Sqrt[3/2] {-1/2, -1/2, 1} // Simplify;
par[pars_List] := par @@ pars;
ContourPlot[
ShannonEntropy@par[t, s], {t, 0, Sqrt@2}, {s, 0, Sqrt[3/2]},
PlotRange -> All,
ColorFunction -> "TemperatureMap", PlotRangePadding -> None,
Contours -> 10,
FrameStyle -> Directive[Large, Black, FontFamily -> "Latin Modern Math"],
FrameLabel -> (MaTeX[#, Magnification -> 2] & /@ {"t", "s"}),
@lucainnocenti
lucainnocenti / visualiseDualFrames.m
Last active November 11, 2021 16:53
Dynamically visualise dual and parseval frames
getDualBasis[vecs_List] := With[{
sMatrix = Total[KroneckerProduct[#, Conjugate@#] & /@ vecs]
},
Dot[Inverse@sMatrix, #] & /@ vecs
];
getParsevalFrame[vecs_List] := With[{
sMatrix = Total[KroneckerProduct[#, Conjugate@#] & /@ vecs]
},
Dot[MatrixFunction[Sqrt, Inverse@sMatrix], #] & /@ vecs
];
@lucainnocenti
lucainnocenti / dynamicStereographicProjectionIn3D.m
Created August 8, 2021 23:29
Dynamic visualisation of stereographic projection of the sphere
stereoTo3D[x_, y_] := 1/(1 + x^2 + y^2) {2 x, 2 y, 1 - x^2 - y^2};
DynamicModule[
{pt = {0, 0}},
Row @ {
LocatorPane[Dynamic @ pt,
Graphics[{Gray, Disk[]}, Frame -> True, ImageSize -> 200]
],
Graphics3D[
{
@lucainnocenti
lucainnocenti / euclideanAlgorithm.m
Created April 29, 2021 17:38
Perform and visualise Euclidean algorithm on a pair of integers
euclideanAlgorithmList[a_Integer, b_Integer] := NestWhileList[
With[{newSortedPair = {Max@# - Floor[Max@#/Min@#] Min@#, Min@#}},
If[#[[1]] > #[[2]], newSortedPair, Reverse@newSortedPair]
] &,
{a, b},
Min @ # > 1 &
];
DynamicModule[{a = 17, b = 10},
EventHandler[
@lucainnocenti
lucainnocenti / pointPlanesDualityInR2.m
Last active August 29, 2020 22:03
Dynamic visualisation of point-plane duality in convex geometry
DynamicModule[{pts={{1,1}}, activePoint=None},
EventHandler[
Dynamic @ Show[
Graphics[{
PointSize@0.04,Dynamic@Point@pts,
Circle[],
If[activePoint =!= None,
{Blue, Point @ pts[[activePoint]]}, {}
],
InfiniteLine[# / Norm[#]^2, Cross @ #] & /@ pts // Dynamic
@lucainnocenti
lucainnocenti / interpolationLinearApprox.m
Created July 31, 2020 12:34
linear approximation of function in MMA
xMax = 1.4;
numPartitions = 10; dx = xMax/numPartitions;
pointsAndLines[pts_] := {Point@pts, Line@pts};
fun[x_] := x^2;
Plot[fun@x, {x, 0, xMax},
PlotRange -> All, PlotStyle -> Directive[Thick], Frame -> True,
GridLines -> Automatic,
FrameStyle -> Directive[Black, Thick, Large],
PlotLegends -> "Expressions",
ImageSize -> 500
@lucainnocenti
lucainnocenti / distribute.m
Last active May 17, 2020 20:18
Replacement rules implementing a noncommutative algebra, and functions to show how expressions are written in terms of nested commutators
<< MaTeX`
distribute[args_] := (args //. {
HoldPattern[nc[l___, Plus[m__], r___]] :> Total[nc[l, #, r] & /@ {m}],
nc[l___, c_*nc[m__], r___] :> c nc[l, m, r],
nc[l___, nc[m__], r___] :> nc[l, m, r],
nc[-a_, b_] :> -nc[a, b],
nc[a_, -b_] :> -nc[a, b],
nc[nc[l : __], r_] :> nc[l, r], nc[l_, nc[r : __]] :> nc[l, r],
nc[a_] :> a