Welcome to TiddlyWiki created by Jeremy Ruston, Copyright © 2007 UnaMesa Association
I am a researcher in quantum information theory based at Royal holloway, University of London. I have worked in applied mathematics, quantum information theory, and condensed matter physics for the past eight years or so.
Inspired by the recent discussions (see, eg., Michael Nielsen’s blog postings) surrounding open science I have decided to make my research notes open. This TiddlyWiki is one attempt to make my notes accessible to a wider audience, and it is hoped that it can be as current a snapshot of my research notes as possible. The content is a little sparse at the moment, but I hope to add more as time passes.
If you make any progress on the ideas or open problems discussed on this site then please let me know: I am more than happy for anything here to become a joint project, the more the merrier! (After all, it might be easier to write a joint paper with the collaborators on this site rather than rewriting everything yourself…)
If you want to look at any of my notes which include many formulae then I'd strongly suggest installing the jsMath [[fonts|http://www.math.union.edu/~dpvc/jsMath/download/jsMath-fonts.html]] (they are 4 ttf files).
The central place to find out about my current research is my [[blog|http://tjoresearchnotes.wordpress.com/]]. You can find links to the rss updates from my twitter and del.icio.us accounts and from this TiddlyWiki there.
Draft posts can be found [[here|Draft blog posts]].
[[The simulation problem]]
!Introduction
One thing I'm beginning to understand in practising open science in the web 2.0 age is that it is all about getting //content// from A to B. Also, what seems to be becoming clear, is that the //format// of the content is becoming increasingly less well-defined: news articles blend with blog posts blend with music videos blend with scientific data. It used to be that the format dictated the content (eg. via the file extension), but now this distinction is much less clear.
However, what isn't working so well (at least to my inexperienced mind) is content //synchronisation// between services.
!Introduction
The Davidenko equation is a system of differential equations which track the zeros of a parameter-dependent system of polynomials.
!Simple example
Let $p_t(x) = \sum_{j=0}^d a_j(t) x^j$ be a parameter-dependent polynomial of degree $d$ in the variable $x$. Write $z_j(t)$, $j = 1, 2, \ldots, d$ for the (possibly compex) zeroes of $p_t(x)$. We want to set up a system of ordinary differential equations for the parameter-dependent zeros of $p_t(x)$. This can be done in several ways. One way is to suppose that we know $z_j(t)$, $j = 1, 2, \ldots, d$ at a time $t$ and to consider a small change in $H(x,t) = p_t(x)$:
$$
dH(x,t) = \frac{\partial H(x,t)}{\partial x} dx + \frac{\partial H(x,t)}{\partial t} dt.
$$
Now, substituting $x = z_j(t)$ we obtain
$$
dH(z_j(t),t) = \frac{\partial H(z_j(t),t)}{\partial x} dz_j(t) + \frac{\partial H(z_j(t),t)}{\partial t} dt.
$$
Now, because $z_j(t)$ is supposed to be a zero of $p_t(x)$ for all time we must have that
$$
0 = \frac{\partial H(z_j(t),t)}{\partial x} dz_j(t) + \frac{\partial H(z_j(t),t)}{\partial t} dt
$$
so that
$$
\frac{dz_j(t)}{dt} = - \left(\frac{\partial H(z_j(t),t)}{\partial x}\right)^{-1} \frac{\partial H(z_j(t),t)}{\partial t}.
$$
This is the basic Davidenko equation.
!!A small example polynomial
Suppose that
$$
p_t(x) = x^2 + (1+t)x - 1.
$$
In this case the Davidenko equation becomes
$$
\frac{dz_j(t)}{dt} = - \frac{z_j(t)}{2z_j(t) + t - 1}, \quad j = 1, 2.
$$
!Full derivation
[[Discrete phase space]]
[[Random QSAT]]
[[Toward efficient quantum circuits for the Laughlin wavefunction]]
[[On open science]]
[[Hamiltonian complexity]]
[[What is a quantum phase transition?]]
In the (now foundational) paper quant-ph/9707038 Lo and Popescu describe protocols involving [[local operations and classical communication|Local operations and classical communication]] on quantum bipartite entangled states. There are several tricks that one can play with entangled states in this setting and I just want to note down some of the more basic and fundamental results. All of the results here pertain to two $d$-dimensional quantum systems (qudits).
Write $|\Psi^+\rangle = \frac{1}{\sqrt{d}}\sum_{j=1}^d |jj\rangle$. Then we have the following
<<<
''Lemma 1''. Let $M$ be a $d\times d$ matrix. Then
$$
M\otimes \mathbb{I}|\Psi^+\rangle = \mathbb{I}\otimes M^T|\Psi^+\rangle.
$$
<<<
<<<
//Proof//.
$$
M\otimes \mathbb{I}|\Psi^+\rangle = \frac{1}{\sqrt{d}}\sum_{j,k=1}^d m_{k,j} |kj\rangle = \frac{1}{\sqrt{d}}\sum_{j,k=1}^d m_{j,k} |jk\rangle = \mathbb{I}\otimes M^T|\Psi^+\rangle.
$$
<<<
The second result tells us how to prepare essentially //any// two-qudit state from $|\Psi^+\rangle$ via a local rotation and a post-selected measurement on just //one// half of $|\Psi^+\rangle$. This is the //remote-control of entanglement// trick. It is also known as the Reeh-Schlieder theorem in algebraic quantum field theory (where it applies in a vastly more general setting) which is also called the //Taj-Mahal theorem// (because someone could create the Taj-Mahal on the other side of the universe by simply measuring one half of a sufficiently entangled state and post selecting). The precise result is
<<<
''Proposition 1''. Let $|\phi\rangle = \sum_{j=1}^d \sqrt{p_j}|u_jv_j\rangle$ be the Schmidt decomposition of an arbitrary pure state of two qudits. Suppose that $p_j>0$. Then
$$
|\phi\rangle = A\otimes \mathbb{I}|\Psi^+\rangle,
$$
where $A = MUV^T$ with $U|j\rangle = |u_j\rangle$, $V|j\rangle = |v_j\rangle$, and $M|j\rangle = \sqrt{dp_j}|j\rangle$.
<<<
<<<
//Proof//. Follows directly after applying Lemma 1.
<<<
In this note I will describe how to construct all of the ground states for a class of interacting quantum spin systems. The systems considered here pertain to $n$ qudits (with local dimension $d$) arranged in a line, and have the following form (they are a subclass of the family of [[quantum satisfiability|Quantum satisfiability]] instances).
$$
\sum_{j=1}^{n-1} |\phi_{j,j+1}\rangle\langle\phi_{j,j+1}|\otimes \mathbb{I}_{[n]\setminus\{j,j+1\}},
$$
where the pure states $|\phi_{j,j+1}\rangle$ have [[Schmidt decomposition]]
$$
|\phi_{j,j+1}\rangle = \sum_{k=1}^d\sqrt{q_k^{(j)}}|u_kv_k\rangle,
$$
with $q_j>0$. The pure states $|\phi_{j,j+1}\rangle$ are otherwise arbitrary.
The way to solve these systems is to exploit [[Proposition 1|Entanglement remote-control]]: we first write
$$
|\phi_{j,j+1}\rangle = A_j\otimes \mathbb{I}_{j+1}|\Psi^+\rangle,
$$
where $|\Psi^+\rangle = \frac{1}{\sqrt{d}}\sum_{j=1}^d |jj\rangle$. The next step is to take a ground state $|\Omega\rangle$ of
$$
K = \sum_{j=1}^{n-1} |\Psi_{j,j+1}^+\rangle\langle\Psi_{j,j+1}^+|\otimes \mathbb{I}_{[n]\setminus\{j,j+1\}}.
$$
and construct
$$
|\Gamma\rangle = T_1\otimes T_2\otimes \cdots \otimes T_{n-1}\otimes \mathbb{I}_n|\Omega\rangle,
$$
where, for $j$ even (need to check these formulae!),
$$
T_{n-j} = (A_{j-1}^\dagger A_{j-2}^*\cdots A_2^* A_1^\dagger)^{-1},
$$
and for $j$ odd,
$$
T_{n-j} = (A_{j-1}^* A_{j-2}^\dagger\cdots A_2^* A_1^\dagger)^{-1}.
$$
We now have the following
<<<
''Proposition 1''. $|\Gamma\rangle$ is a ground state of $H$.
<<<
<<<
//Proof//.
<<<
[[Stochastic Davidenko equation]]
From Oded Regev's lecture [[notes|http://www.cs.tau.ac.il/~odedr/teaching/quantum_fall_2005/ln/qma.pdf]]:
<<<
As we all know, for any two lines in $\mathbb{R}^n$ that go through the origin (i.e., one-dimensional subspaces), one can define the angle between them. If we take a line and a plane, we can again define the angle between them in a natural way. But what happens if we take two planes? Here our three-dimensional intuition is no longer good enough. Indeed, in three-dimensions, two two-dimensional subspaces always intersect in a line, and orthogonal to that line we find the angle between the two subspaces. This is no longer true in higher dimensions: Starting from four dimensions, two two-dimensional subspaces generally have a trivial intersection, and instead of forming an angle, they form two angles!
In more generality, the question we consider in this section is how two subspaces interact. This question turns out to have a very elegant answer, as we shall soon see. This answer, which was first given in a remarkable paper of C. Jordan in 1875, was since rediscovered many times by mathematicians, statisticians, physicists, and computer scientists. In addition to being a crucial component in witness-preserving amplification of QMA, this question also plays an important role in many recent results in quantum computation, often in an implicit way... This topic is also covered in Chapter VII of the [[book|http://books.google.co.uk/books?id=eay3HALl620C&dq=bhatia+matrix+analysis&printsec=frontcover&source=bn&hl=en&ei=_2zfSYeQCNqD-AaHj6yFCQ&sa=X&oi=book_result&ct=result&resnum=4]] by
Bhatia.
<<<
The lemma itself is as follows.
<<<
''Lemma 1'' (Jordan, 1875). For any two Hermitian projectors $\Pi_0$ and $\Pi_1$, there exists an orthogonal decomposition of the Hilbert space into one dimensional and two dimensional subspaces that are invariant under both $\Pi_0$ and $\Pi_1$. Moreover, inside each two-dimensional subspace, $\Pi_0$ and $\Pi_1$ are rank-one projectors. (In other words, inside each two-dimensional subspace there are two unit vectors $|v\rangle$ and $|w\rangle$ suchthat $\Pi_0$ projects on $|v\rangle$ and $\Pi_1$ projects on $|w\rangle$.)
<<<
The proof of this lemma is actually elementary:
<<<
//Proof//. The idea is to look at the hermitian matrix $H = \Pi_0 + \Pi_1$. It turns out that the eigenvectors of $H$ can be partitioned into sets of size one or two, and these sets in fact span the subspaces mentioned in the lemma.
Let $|\phi\rangle$ be an eigenvector of $H$, of unit length. Let $\lambda$ be the corresponding eigenvalue. Then
$$
\Pi_0|\phi\rangle + \Pi_1|\phi\rangle = \lambda|\phi\rangle.
$$
Assume first that $\Pi_0|\phi\rangle$ lies in the subspace spanned by $|\phi\rangle$. By the eigenvector equation above, we have that $\Pi_1|\phi\rangle$ lies in the same subspace. This means that the subspace spanned by $|\phi\rangle$ is invariant under $\Pi_0$ and $\Pi_1$, hence it is an eigenvector of both projectors. Hence $\Pi_0|\phi\rangle$ is $0$ or $|\phi\rangle$, and similarly for $\Pi_1$.
So we now assume that $\Pi_0|\phi\rangle$ is not in the subspace spanned by $|\phi\rangle$. So consider, instead, the two-dimensional subspace $S$ spanned by $|\phi\rangle$ and $\Pi_0|\phi\rangle$. Evidently $S$ is invariant under $\phi_0$ because
$$
\Pi_0(\alpha |\phi\rangle + \beta\Pi_0|\phi) = (\alpha+\beta)\Pi_0|\phi\rangle \in S.
$$
It is also invariant under $\Pi_1$ thanks to the eigenvector equation:
$$
\Pi_1|\phi\rangle = \lambda|\phi\rangle - \Pi_0|\phi\rangle \in S
$$
so that
$$
\Pi_1\Pi_0|\phi\rangle = \Pi_1(\lambda|\phi\rangle - \Pi_1|\phi\rangle) = (\lambda-1)\Pi_1|\phi\rangle \in S.
$$
Because $S$ is invariant under both $\Pi_0$ and $\Pi_1$ it is invariant under $H$. Hence, the vector orthogonal to $|\phi\rangle$ in $S$ is actually another eigenvector of $H$, and so $S$ is actually spanned by a pair of eigenvectors of $H$, as claimed. To conclude, note that inside $S$ the operators $\Pi_0$ and $\Pi_1$ are rank-one projectors.
<<<
/***
|''Name:''|LoadRemoteFileThroughProxy (previous LoadRemoteFileHijack)|
|''Description:''|When the TiddlyWiki file is located on the web (view over http) the content of [[SiteProxy]] tiddler is added in front of the file url. If [[SiteProxy]] does not exist "/proxy/" is added. |
|''Version:''|1.1.0|
|''Date:''|mar 17, 2007|
|''Source:''|http://tiddlywiki.bidix.info/#LoadRemoteFileHijack|
|''Author:''|BidiX (BidiX (at) bidix (dot) info)|
|''License:''|[[BSD open source license|http://tiddlywiki.bidix.info/#%5B%5BBSD%20open%20source%20license%5D%5D ]]|
|''~CoreVersion:''|2.2.0|
***/
//{{{
version.extensions.LoadRemoteFileThroughProxy = {
major: 1, minor: 1, revision: 0,
date: new Date("mar 17, 2007"),
source: "http://tiddlywiki.bidix.info/#LoadRemoteFileThroughProxy"};
if (!window.bidix) window.bidix = {}; // bidix namespace
if (!bidix.core) bidix.core = {};
bidix.core.loadRemoteFile = loadRemoteFile;
loadRemoteFile = function(url,callback,params)
{
if ((document.location.toString().substr(0,4) == "http") && (url.substr(0,4) == "http")){
url = store.getTiddlerText("SiteProxy", "/proxy/") + url;
}
return bidix.core.loadRemoteFile(url,callback,params);
}
//}}}
[[About]]
[[Blog]]
[[Ideas]]
[[Problems]]
[[Notes]]
[[Talks]]
[[Courses]]
!Title of talk: Hamiltonian Complexity
These are notes for a talk to be given at the 2009 IMA [[conference|http://www.ima.org.uk/Conferences/quantum_computing_programme.html]] on quantum computing and complexity of simulation.
The idea of the talk is to give a very gentle introduction to results about the computational complexity of simulating physical systems.
!Outline
* Title slide
* Outline
* Physical systems
** Hilbert space
** Hamiltonians
** States
** Observables
*** //Physically// measurable observables are //local//
* Simulation
** Want to be able to //predict//
** What problems? Want to predict local observables.
*** Equilibrium:
**** Zero temp.
**** Non-zero temp.
*** Non-equilibrium: dynamical observables.
** Efficiency: scaling with $n$, $d$, $\|h\|$, and $\mbox{supp}(A)$ is crucial
* Hardness
** What does //hard// mean?
*** Physical predictions impossible if hard!
*** But maybe system can never enter //hard// states?
** Review of //hardness// results (see other talks)
*** QMA etc.
* Efficient simulation
** Describe [[QSAT|Quantum satisfiability]]
*** Review of //easiness// results
*** Describe partial results toward extending alphabet; relate to 3-[[colouring]].
*** Describe entanglement remote-control solution.
** Describe //dynamics//
*** Describe the [[Lieb-Robinson bound]].
*** Describe how Lieb-Robinson can be used to provide approximate QCA description of propagator.
** Describe //adiabatic continuation//.
*** Quote results on efficient simulation of gapped adiabatic evolution for 2D systems.
/***
|''Name:''|PasswordOptionPlugin|
|''Description:''|Extends TiddlyWiki options with non encrypted password option.|
|''Version:''|1.0.2|
|''Date:''|Apr 19, 2007|
|''Source:''|http://tiddlywiki.bidix.info/#PasswordOptionPlugin|
|''Author:''|BidiX (BidiX (at) bidix (dot) info)|
|''License:''|[[BSD open source license|http://tiddlywiki.bidix.info/#%5B%5BBSD%20open%20source%20license%5D%5D ]]|
|''~CoreVersion:''|2.2.0 (Beta 5)|
***/
//{{{
version.extensions.PasswordOptionPlugin = {
major: 1, minor: 0, revision: 2,
date: new Date("Apr 19, 2007"),
source: 'http://tiddlywiki.bidix.info/#PasswordOptionPlugin',
author: 'BidiX (BidiX (at) bidix (dot) info',
license: '[[BSD open source license|http://tiddlywiki.bidix.info/#%5B%5BBSD%20open%20source%20license%5D%5D]]',
coreVersion: '2.2.0 (Beta 5)'
};
config.macros.option.passwordCheckboxLabel = "Save this password on this computer";
config.macros.option.passwordInputType = "password"; // password | text
setStylesheet(".pasOptionInput {width: 11em;}\n","passwordInputTypeStyle");
merge(config.macros.option.types, {
'pas': {
elementType: "input",
valueField: "value",
eventName: "onkeyup",
className: "pasOptionInput",
typeValue: config.macros.option.passwordInputType,
create: function(place,type,opt,className,desc) {
// password field
config.macros.option.genericCreate(place,'pas',opt,className,desc);
// checkbox linked with this password "save this password on this computer"
config.macros.option.genericCreate(place,'chk','chk'+opt,className,desc);
// text savePasswordCheckboxLabel
place.appendChild(document.createTextNode(config.macros.option.passwordCheckboxLabel));
},
onChange: config.macros.option.genericOnChange
}
});
merge(config.optionHandlers['chk'], {
get: function(name) {
// is there an option linked with this chk ?
var opt = name.substr(3);
if (config.options[opt])
saveOptionCookie(opt);
return config.options[name] ? "true" : "false";
}
});
merge(config.optionHandlers, {
'pas': {
get: function(name) {
if (config.options["chk"+name]) {
return encodeCookie(config.options[name].toString());
} else {
return "";
}
},
set: function(name,value) {config.options[name] = decodeCookie(value);}
}
});
// need to reload options to load passwordOptions
loadOptionsCookie();
/*
if (!config.options['pasPassword'])
config.options['pasPassword'] = '';
merge(config.optionsDesc,{
pasPassword: "Test password"
});
*/
//}}}
[[Solving a simple QSAT instance]]
[[Quantum circuits for the Laughlin wavefunction]]
/***
|Name|Plugin: Scientific Notation|
|Created by|BobMcElrath|
|Email|my first name at my last name dot org|
|Location|http://bob.mcelrath.org/tiddlyjsmath-2.0.3.html|
|Version|1.0|
|Requires|[[TiddlyWiki|http://www.tiddlywiki.com]] ≥ 2.0.3, [[jsMath|http://www.math.union.edu/~dpvc/jsMath/]] ≥ 3.0, [[Plugin: jsMath]]|
!Description
This plugin will render numbers expressed in scientific notation, such as {{{3.5483e12}}} using the jsMath plugin to display it in an intuitive way such as 3.5483e12. You may customize the number of significant figures displayed, as well as "normalize" numbers so that {{{47392.387e9}}} is displayed as 47392.387e9.
!Installation
Install the Requirements, above, add this tiddler to your tiddlywiki, and give it the {{{systemConfig}}} tag.
!History
* 1-Feb-06, version 1.0, Initial release
!Code
***/
//{{{
config.formatters.push({
name: "scientificNotation",
match: "\\b[0-9]+\\.[0-9]+[eE][+-]?[0-9]+\\b",
element: "span",
className: "math",
normalize: true, // set to 'true' to convert numbers to X.XXX \times 10^{y}
sigfigs: 3, // with this many digits in the mantissa
handler: function(w) {
var snRegExp = new RegExp("\\b([0-9]+(?:\\.[0-9]+)?)[eE]([-0-9+]+)\\b");
var mymatch = snRegExp.exec(w.matchText);
var mantissa = mymatch[1];
var exponent = parseInt(mymatch[2]);
// normalize the number.
if(this.normalize) {
mantissa = parseFloat(mantissa);
while(mantissa > 10.0) {
mantissa = mantissa / 10.0;
exponent++;
}
while(mantissa < 1.0) {
mantissa = mantissa * 10.0;
exponent--;
}
var sigfigsleft = this.sigfigs;
mantissa = parseInt(mantissa) + "." + (Math.round(Math.pow(10,this.sigfigs-1)*mantissa)+"").substr(1,this.sigfigs-1);
}
var e = document.createElement(this.element);
e.className = this.className;
if(exponent == 0) {
e.appendChild(document.createTextNode(mantissa));
} else {
e.appendChild(document.createTextNode(mantissa + "\\times 10^{" + exponent + "}"));
}
w.output.appendChild(e);
}
});
//}}}
/***
|Name|Plugin: arXiv Links|
|Created by|BobMcElrath|
|Email|my first name at my last name dot org|
|Location|http://bob.mcelrath.org/tiddlyjsmath-2.0.3.html|
|Version|1.0|
|Requires|[[TiddlyWiki|http://www.tiddlywiki.com]] ≥ 2.0.3|
!Description
This formatting plugin will render links to the [[arXiv|http://www.arxiv.org]] preprint system. If you type a paper reference such as hep-ph/0509024, it will be rendered as an external link to the abstract of that paper.
!Installation
Add this tiddler to your tiddlywiki, and give it the {{{systemConfig}}} tag.
!History
* 1-Feb-06, version 1.0, Initial release
!Code
***/
//{{{
config.formatters.push({
name: "arXivLinks",
match: "\\b(?:astro-ph|cond-mat|hep-ph|hep-th|hep-lat|gr-qc|nucl-ex|nucl-th|quant-ph|(?:cs|math|nlin|physics|q-bio)(?:\\.[A-Z]{2})?)/[0-9]{7}\\b",
element: "a",
handler: function(w) {
var e = createExternalLink(w.output, "http://arxiv.org/abs/"+w.matchText);
e.target = "_blank"; // open in new window
w.outputText(e,w.matchStart,w.nextMatch);
}
});
//}}}
/***
|Name|Plugin: jsMath|
|Created by|BobMcElrath|
|Email|my first name at my last name dot org|
|Location|http://bob.mcelrath.org/tiddlyjsmath.html|
|Version|1.5.1|
|Requires|[[TiddlyWiki|http://www.tiddlywiki.com]] ≥ 2.0.3, [[jsMath|http://www.math.union.edu/~dpvc/jsMath/]] ≥ 3.0|
!Description
LaTeX is the world standard for specifying, typesetting, and communicating mathematics among scientists, engineers, and mathematicians. For more information about LaTeX itself, visit the [[LaTeX Project|http://www.latex-project.org/]]. This plugin typesets math using [[jsMath|http://www.math.union.edu/~dpvc/jsMath/]], which is an implementation of the TeX math rules and typesetting in javascript, for your browser. Notice the small button in the lower right corner which opens its control panel.
!Installation
In addition to this plugin, you must also [[install jsMath|http://www.math.union.edu/~dpvc/jsMath/download/jsMath.html]] on the same server as your TiddlyWiki html file. If you're using TiddlyWiki without a web server, then the jsMath directory must be placed in the same location as the TiddlyWiki html file.
I also recommend modifying your StyleSheet use serif fonts that are slightly larger than normal, so that the math matches surrounding text, and \\small fonts are not unreadable (as in exponents and subscripts).
{{{
.viewer {
line-height: 125%;
font-family: serif;
font-size: 12pt;
}
}}}
If you had used a previous version of [[Plugin: jsMath]], it is no longer necessary to edit the main tiddlywiki.html file to add the jsMath <script> tag. [[Plugin: jsMath]] now uses ajax to load jsMath.
!History
* 11-Nov-05, version 1.0, Initial release
* 22-Jan-06, version 1.1, updated for ~TW2.0, tested with jsMath 3.1, editing tiddlywiki.html by hand is no longer necessary.
* 24-Jan-06, version 1.2, fixes for Safari, Konqueror
* 27-Jan-06, version 1.3, improved error handling, detect if ajax was already defined (used by ZiddlyWiki)
* 12-Jul-06, version 1.4, fixed problem with not finding image fonts
* 26-Feb-07, version 1.5, fixed problem with Mozilla "unterminated character class".
* 27-Feb-07, version 1.5.1, Runs compatibly with TW 2.1.0+, by Bram Chen
!Examples
|!Source|!Output|h
|{{{The variable $x$ is real.}}}|The variable $x$ is real.|
|{{{The variable \(y\) is complex.}}}|The variable \(y\) is complex.|
|{{{This \[\int_a^b x = \frac{1}{2}(b^2-a^2)\] is an easy integral.}}}|This \[\int_a^b x = \frac{1}{2}(b^2-a^2)\] is an easy integral.|
|{{{This $$\int_a^b \sin x = -(\cos b - \cos a)$$ is another easy integral.}}}|This $$\int_a^b \sin x = -(\cos b - \cos a)$$ is another easy integral.|
|{{{Block formatted equations may also use the 'equation' environment \begin{equation} \int \tan x = -\ln \cos x \end{equation} }}}|Block formatted equations may also use the 'equation' environment \begin{equation} \int \tan x = -\ln \cos x \end{equation}|
|{{{Equation arrays are also supported \begin{eqnarray} a &=& b \\ c &=& d \end{eqnarray} }}}|Equation arrays are also supported \begin{eqnarray} a &=& b \\ c &=& d \end{eqnarray} |
|{{{I spent \$7.38 on lunch.}}}|I spent \$7.38 on lunch.|
|{{{I had to insert a backslash (\\) into my document}}}|I had to insert a backslash (\\) into my document|
!Code
***/
//{{{
// AJAX code adapted from http://timmorgan.org/mini
// This is already loaded by ziddlywiki...
if(typeof(window["ajax"]) == "undefined") {
ajax = {
x: function(){try{return new ActiveXObject('Msxml2.XMLHTTP')}catch(e){try{return new ActiveXObject('Microsoft.XMLHTTP')}catch(e){return new XMLHttpRequest()}}},
gets: function(url){var x=ajax.x();x.open('GET',url,false);x.send(null);return x.responseText}
}
}
// Load jsMath
jsMath = {
Setup: {inited: 1}, // don't run jsMath.Setup.Body() yet
Autoload: {root: new String(document.location).replace(/[^\/]*$/,'jsMath/')} // URL to jsMath directory, change if necessary
};
var jsMathstr;
try {
jsMathstr = ajax.gets(jsMath.Autoload.root+"jsMath.js");
} catch(e) {
alert("jsMath was not found: you must place the 'jsMath' directory in the same place as this file. "
+"The error was:\n"+e.name+": "+e.message);
throw(e); // abort eval
}
try {
window.eval(jsMathstr);
} catch(e) {
alert("jsMath failed to load. The error was:\n"+e.name + ": " + e.message + " on line " + e.lineNumber);
}
jsMath.Setup.inited=0; // allow jsMath.Setup.Body() to run again
// Define wikifers for latex
config.formatterHelpers.mathFormatHelper = function(w) {
var e = document.createElement(this.element);
e.className = this.className;
var endRegExp = new RegExp(this.terminator, "mg");
endRegExp.lastIndex = w.matchStart+w.matchLength;
var matched = endRegExp.exec(w.source);
if(matched) {
var txt = w.source.substr(w.matchStart+w.matchLength,
matched.index-w.matchStart-w.matchLength);
if(this.keepdelim) {
txt = w.source.substr(w.matchStart, matched.index+matched[0].length-w.matchStart);
}
e.appendChild(document.createTextNode(txt));
w.output.appendChild(e);
w.nextMatch = endRegExp.lastIndex;
}
}
config.formatters.push({
name: "displayMath1",
match: "\\\$\\\$",
terminator: "\\\$\\\$\\n?", // 2.0 compatability
termRegExp: "\\\$\\\$\\n?",
element: "div",
className: "math",
handler: config.formatterHelpers.mathFormatHelper
});
config.formatters.push({
name: "inlineMath1",
match: "\\\$",
terminator: "\\\$", // 2.0 compatability
termRegExp: "\\\$",
element: "span",
className: "math",
handler: config.formatterHelpers.mathFormatHelper
});
var backslashformatters = new Array(0);
backslashformatters.push({
name: "inlineMath2",
match: "\\\\\\\(",
terminator: "\\\\\\\)", // 2.0 compatability
termRegExp: "\\\\\\\)",
element: "span",
className: "math",
handler: config.formatterHelpers.mathFormatHelper
});
backslashformatters.push({
name: "displayMath2",
match: "\\\\\\\[",
terminator: "\\\\\\\]\\n?", // 2.0 compatability
termRegExp: "\\\\\\\]\\n?",
element: "div",
className: "math",
handler: config.formatterHelpers.mathFormatHelper
});
backslashformatters.push({
name: "displayMath3",
match: "\\\\begin\\{equation\\}",
terminator: "\\\\end\\{equation\\}\\n?", // 2.0 compatability
termRegExp: "\\\\end\\{equation\\}\\n?",
element: "div",
className: "math",
handler: config.formatterHelpers.mathFormatHelper
});
// These can be nested. e.g. \begin{equation} \begin{array}{ccc} \begin{array}{ccc} ...
backslashformatters.push({
name: "displayMath4",
match: "\\\\begin\\{eqnarray\\}",
terminator: "\\\\end\\{eqnarray\\}\\n?", // 2.0 compatability
termRegExp: "\\\\end\\{eqnarray\\}\\n?",
element: "div",
className: "math",
keepdelim: true,
handler: config.formatterHelpers.mathFormatHelper
});
// The escape must come between backslash formatters and regular ones.
// So any latex-like \commands must be added to the beginning of
// backslashformatters here.
backslashformatters.push({
name: "escape",
match: "\\\\.",
handler: function(w) {
w.output.appendChild(document.createTextNode(w.source.substr(w.matchStart+1,1)));
w.nextMatch = w.matchStart+2;
}
});
config.formatters=backslashformatters.concat(config.formatters);
window.wikify = function(source,output,highlightRegExp,tiddler)
{
if(source && source != "") {
if(version.major == 2 && version.minor > 0) {
var wikifier = new Wikifier(source,getParser(tiddler),highlightRegExp,tiddler);
wikifier.subWikifyUnterm(output);
} else {
var wikifier = new Wikifier(source,formatter,highlightRegExp,tiddler);
wikifier.subWikify(output,null);
}
jsMath.ProcessBeforeShowing();
}
}
//}}}
[[Computer science problems]]
[[Mathematics problems]]
[[Physics problems]]
[[Miscellaneous problems]]
!Introduction
In a recent paper [[arXiv:0902.4797|http://arxiv.org/abs/0902.4797]] Riera, Pico, and Latorre describe a quantum circuit which efficiently prepares a quantum register in the integer quantum Hall effect ground state.
An open problem from this paper is to describe quantum circuits which efficiently prepare the Laughlin wavefunction for the fractional quantum Hall effect. This problem is significantly more complicated than the integer quantum Hall effect case because there are delicate cancellations that can occur and must be accounted for.
!Sequential generation
One might hope to build a quantum circuit for the Laughlin wavefunction //sequentially//. To do this one needs to have some kind of recursion relation.
!!Representing the Laughlin function in a quantum register
The way we represent a multiparticle wavefunction in a quantum register is to use a basis where a monomial multiplied by a gaussian weighting:
$$
z_1^{d_1}z_2^{d_2}\cdots z_n^{d_n} e^{-\frac12\sum_{j=1}^n |z_j|^2}
$$
is represented as
$$
|d_1d_2\cdots d_n\rangle.
$$
Because the gaussian weighting is the same for all terms in the wavefunctions we wish to represent we typically drop it from now on and just speak of the //monomial// $z_1^{d_1}z_2^{d_2}\cdots z_n^{d_n}$ as being represented by $|d_1d_2\cdots d_n\rangle$.
!!A simple recursion relation for the Vandermonde determinant
A nice recursion relation is described in the [[paper|http://arxiv.org/abs/cond-mat/9306022]] of Dunne, who notes the following properties of the Vandermonde determinant: let
$$
V_n(z_1, z_2, \ldots, z_n) = \prod_{1\le j<k}^n(z_j-z_k).
$$
Note that
$$
V_n(z_1, z_2, \ldots, z_n) = V_{n-1}(z_2, z_3, \ldots, z_n)\prod_{j=2}^n(z_1-z_j).
$$
We now write
$$
\prod_{j=2}^n(z_1-z_j) = \sum_{k=0}^{n-1} (-1)^kz^{n-1-k}e_k,
$$
where $e_0 = 1$, $e_1 = \sum_{k=2}^n z_k$, $\ldots$, $e_{n-1} = z_2z_3\cdots z_{n}$, i.e., $e_l$ is the sum of all products of $l$ distinct variables $z_2, z_3, \ldots, z_n$.
This observation now allows us to write out the desired recursion:
$$
(V_n(z_1, z_2, \ldots, z_n))^{2m+1} = \left(\sum_{k=0}^{n-1} (-1)^kz^{n-1-k}e_k\right)^{2m+1}(V_{n-1}(z_2, z_3, \ldots, z_n))^{2m+1}.
$$
!!An example for $m=1$
Let's consider the simplest case, namely $V_2(z_1, z_2)$: this is represented as
$$
V_2(z_1, z_2) = (z_1-z_2) \mapsto \frac{1}{\sqrt{2}}(|10\rangle-|01\rangle).
$$
Now the Laughlin wavefunction with $m=1$ is represented as
$$
(V_2(z_1, z_2))^3 = (z_1-z_2)^3 \mapsto \frac{1}{\sqrt{20}}(|30\rangle - 3|21\rangle + 3|12\rangle - |03\rangle).
$$
Introducing the linear operator
$$
L_{j,k}|x_1x_2\cdots x_n\rangle = |x_1x_2\cdots x_{j-1} (x_j+k) x_{j+1} \cdots x_n\rangle
$$
allows us to also write
$$
(V_2(z_1, z_2))^3 \mapsto (L_{1,2} - 2L_{1,1}L_{2,1} + L_{2,2}) \times \frac{1}{\sqrt{2}}(|10\rangle-|01\rangle).
$$
It is convenient to adopt a multi-index notation and define
$$
L_{\mu}|x_1x_2\cdots x_n\rangle = |(x_1+\mu_1)(x_2+\mu_2)\cdots(x_n+\mu_n)\rangle
$$
where $\mu = (\mu_1, \mu_2, \ldots, \mu_n)$. Thus
$$
(V_2(z_1, z_2))^3 \mapsto (L_{(2,0)} - 2L_{(1,1)} + L_{(0,2)}) \times \frac{1}{\sqrt{2}}(|10\rangle-|01\rangle).
$$
!!A nonunitary(!) quantum circuit for the Laughline wavefunction
The recursion relation for the Vandermonde determinant can now be represented, in quantum notation, as
$$
|V_n\rangle = \sum_{k=0}^{n-1} (-1)^k|n-1-k\rangle E_k|V_{n-1}\rangle,
$$
where
$$
|V_n\rangle = \frac{1}{\sqrt{n!}} \sum_{\pi\in S_n} \epsilon(\pi)|\pi^{-1}(0)\pi^{-1}(1)\cdots \pi^{-1}(n-1)\rangle
$$
is the quantum representation of the Vandermonde determinant, and
$$
E_k = \sum_{\mu\subset \{0,1,\ldots, n-1\}, |\mu| = k} L_\mu
$$
Cubing this recursion in the obvious way gives a //nonunitary// circuit for the $m=1$ Laughlin wavefunction. Unfortunately the operators $E_k$ aren't unitary, so this is why the problem is hard.
In the paper quant-ph/0602108 Sergey Bravyi introduced a class of systems which are aimed at generalising the [[satisfiability|http://en.wikipedia.org/wiki/Boolean_satisfiability_problem]] problem.
The idea is to replace a $k$-SAT instance, by a quantum hamiltonian
$$
H = -\sum_{e\in E} h_e,
$$
where each of $h_e$ is a //projector// onto some subspace whose [[support]] is bounded by $k$.
non-linear notes on my research
Tobias J. Osborne's research notes
The [[approach|Entanglement remote-control and deciding QSAT]] to deciding [[QSAT|Quantum satisfiability]] instances via [[entanglement remote-control|Entanglement remote-control]] reduces the problem of first finding the ground-eigenspace of hamiltonians of the form
$$
H = \sum_{e\in E} |\Psi^{+}\rangle_e\langle \Psi^{+}|\otimes \mathbb{I}_{[n]\setminus e},
$$
where $|\Psi^+\rangle = \frac{1}{\sqrt{d}}\sum_{j=1}^d |jj\rangle$ and $E$ is the edge set of some finite //tree//-graph $G = (V=[n], E)$ with $[n]=\{1,2,\ldots, n\}$. The second step is to add in extra constraints to form loops.
I'll focus on solving the first problem. In fact, I'll just try and describe the ground eigenspace for the simplest possible example, namely, the following hamiltonian on 3 qudits
$$
H = |\Psi^{+}\rangle_{12}\langle \Psi^{+}|\otimes \mathbb{I}_3 + \mathbb{I}_1\otimes |\Psi^{+}\rangle_{23}\langle \Psi^{+}|.
$$
It's pretty easy to find quite a lot of states in the ground eigenspace: any state of the form $|jkl\rangle$ with $j\not=k$ and $k\not=l$, $j,k,l \in [d]$ will do. How many of these are there? Well, there are $d^3-2d^2+d$ such states. Are these all the ground states? Well, no, there are a couple more, namely, any state of the form
$$
|\eta(k)\rangle = \frac{1}{\sqrt{d}}\sum_{j=1}^d e^{\frac{2\pi i}{d}jk} |jjj\rangle,
$$
with $k\in [d-1]$ is also a ground state. There are $d-1$ such states. Thus there are at least $d^3-2d^2+1$ orthogonal ground states. Is this all of them? There should be more because the smallest the ground eigenspace can be is $d^3-2d$-dimensional.
!Introduction
The [[Davidenko equation]] is a system of differential equations which track the zeros of parameter-dependent system of polynomials. This note is aimed at understanding what happens when the polynomials depend on one or more [[continuous-time martingales|Continuous-time martingale]], such as simple [[brownian motions|Brownian motion]].
!Simple example
(This needs to be fixed: the second order terms aren't correct yet!)
To understand what I'm talking about let's derive the stochastic Davidenko equation in the case of a parameter-dependent polynomial in one variable. Note that this discussion is at the level of [[physical rigour]].
Let $p(x) = \sum_{j=0}^d a_j(B_t, t) x^j$ be a polynomial of degree $d$ whose coefficients $a_j$ are functions of $B_t$ and $t$, where $B_t$ is a [[Wiener process]], i.e., a standard [[Brownian motion]]. We want to understand the zeros $z_l(B_t, t)$, $l = 1, 2, \ldots, d$ of $p(x)$. To do this we mimic the derivation of the [[Davidenko equation]] and set up a set of [[Stochastic differential equations|Stochastic differential equation]] for $z_l(B_t,t)$. As with the [[Davidenko equation]] this can be done in a variety of ways.
Consider a small change in $p(x)$:
$$
dp(x) = \sum_{j=0}^d da_j(B_t,t) x^j + ja_j(B_t,t)x^{j-1} dx + jx^{j-1}da_j(B_t,t)dx + j(j-1)a_j(B_t,t)x^{j-2}(dx)^2.
$$
(Here we are foreshadowing the use of [[ItĹŤ's rule]].)
Now use [[ItĹŤ's rule]] to write
$$
da_j(B_t,t) = \frac{\partial a_j(y,t)}{\partial t}\Bigg|_{y=B_t} dt + \frac{\partial a_j(y,t)}{\partial y}\Bigg|_{y=B_t} dB_t + \frac12\frac{\partial^2 a_j(y,t)}{\partial^2 y}\Bigg|_{y=B_t}dt
$$
for the SDE satisfied by $a_j(B_t,t)$. Then we have that
$$
dp(x) = \sum_{j=0}^d \left(\frac{\partial a_j(y,t)}{\partial t}\Bigg|_{y=B_t} dt + \frac{\partial a_j(y,t)}{\partial y}\Bigg|_{y=B_t} dB_t + \frac12\frac{\partial^2 a_j(y,t)}{\partial^2 y}\Bigg|_{y=B_t}dt\right) x^j + ja_j(B_t,t)x^{j-1} dx + j(j-1)a_j(B_t,t)x^{j-2}(dx)^2.
$$
Now if $z_l(B_t, t)$ is a zero of $p(x)$ then we must have that $0 = dp(z_l(B_t, t))$, i.e.,
$$
0= \sum_{j=0}^d \left(\frac{\partial a_j(y,t)}{\partial t}\Bigg|_{y=B_t} dt + \frac{\partial a_j(y,t)}{\partial y}\Bigg|_{y=B_t} dB_t + \frac12\frac{\partial^2 a_j(y,t)}{\partial^2 y}\Bigg|_{y=B_t}dt\right) z_l(B_t, t)^j + ja_j(B_t,t)z_l(B_t, t)^{j-1} dz_l(B_t, t) + j(j-1)a_j(B_t,t)z_l(B_t,t)^{j-2}(dz_l(B_t,t))^2.
$$
This is the stochastic Davidenko equation.
!!A small example polynomial
Suppose that
$$
p(x) = x^2+B_tx-1.
$$
Thus, $a_0 = -1$, $a_1 = B_t$, and $a_2 = 1$. In this case the stochastic Davidenko equation becomes
$$
z_l(B_t,t)dB_t + (2z_l(B_t,t) + B_t)dz_l(B_t,t) = 0,
$$
or
$$
dz_l(B_t,t) = - \frac{z_l(B_t,t)}{2z_l(B_t,t) + B_t} dB_t.
$$
!2009
[[Notes on talk for IMA conference at IMS]]
The simulation problem aims to formalise in a concrete way what a theoretical physicist does when they make a prediction about a physical system. I would argue that the simulation problem is the central problem of the newly emerging field of [[hamiltonian complexity]].
I am a lecturer in the [[department of mathematics|http://www.ma.rhul.ac.uk/]] at Royal Holloway, University of London.
I am currently exploring the possibilities offered by [[open science|http://en.wikipedia.org/wiki/Open_notebook_science]] via this TiddlyWiki and my [[blog|http://tjoresearchnotes.wordpress.com/]].
/***
Description: Contains the stuff you need to use Tiddlyspot
Note, you also need UploadPlugin, PasswordOptionPlugin and LoadRemoteFileThroughProxy
from http://tiddlywiki.bidix.info for a complete working Tiddlyspot site.
***/
//{{{
// edit this if you are migrating sites or retrofitting an existing TW
config.tiddlyspotSiteId = 'tjoresearchnotes';
// make it so you can by default see edit controls via http
config.options.chkHttpReadOnly = false;
window.readOnly = false; // make sure of it (for tw 2.2)
window.showBackstage = true; // show backstage too
// disable autosave in d3
if (window.location.protocol != "file:")
config.options.chkGTDLazyAutoSave = false;
// tweak shadow tiddlers to add upload button, password entry box etc
with (config.shadowTiddlers) {
SiteUrl = 'http://'+config.tiddlyspotSiteId+'.tiddlyspot.com';
SideBarOptions = SideBarOptions.replace(/(<<saveChanges>>)/,"$1<<tiddler TspotSidebar>>");
OptionsPanel = OptionsPanel.replace(/^/,"<<tiddler TspotOptions>>");
DefaultTiddlers = DefaultTiddlers.replace(/^/,"[[WelcomeToTiddlyspot]] ");
MainMenu = MainMenu.replace(/^/,"[[WelcomeToTiddlyspot]] ");
}
// create some shadow tiddler content
merge(config.shadowTiddlers,{
'WelcomeToTiddlyspot':[
"This document is a ~TiddlyWiki from tiddlyspot.com. A ~TiddlyWiki is an electronic notebook that is great for managing todo lists, personal information, and all sorts of things.",
"",
"@@font-weight:bold;font-size:1.3em;color:#444; //What now?// @@ Before you can save any changes, you need to enter your password in the form below. Then configure privacy and other site settings at your [[control panel|http://" + config.tiddlyspotSiteId + ".tiddlyspot.com/controlpanel]] (your control panel username is //" + config.tiddlyspotSiteId + "//).",
"<<tiddler TspotControls>>",
"See also GettingStarted.",
"",
"@@font-weight:bold;font-size:1.3em;color:#444; //Working online// @@ You can edit this ~TiddlyWiki right now, and save your changes using the \"save to web\" button in the column on the right.",
"",
"@@font-weight:bold;font-size:1.3em;color:#444; //Working offline// @@ A fully functioning copy of this ~TiddlyWiki can be saved onto your hard drive or USB stick. You can make changes and save them locally without being connected to the Internet. When you're ready to sync up again, just click \"upload\" and your ~TiddlyWiki will be saved back to tiddlyspot.com.",
"",
"@@font-weight:bold;font-size:1.3em;color:#444; //Help!// @@ Find out more about ~TiddlyWiki at [[TiddlyWiki.com|http://tiddlywiki.com]]. Also visit [[TiddlyWiki.org|http://tiddlywiki.org]] for documentation on learning and using ~TiddlyWiki. New users are especially welcome on the [[TiddlyWiki mailing list|http://groups.google.com/group/TiddlyWiki]], which is an excellent place to ask questions and get help. If you have a tiddlyspot related problem email [[tiddlyspot support|mailto:support@tiddlyspot.com]].",
"",
"@@font-weight:bold;font-size:1.3em;color:#444; //Enjoy :)// @@ We hope you like using your tiddlyspot.com site. Please email [[feedback@tiddlyspot.com|mailto:feedback@tiddlyspot.com]] with any comments or suggestions."
].join("\n"),
'TspotControls':[
"| tiddlyspot password:|<<option pasUploadPassword>>|",
"| site management:|<<upload http://" + config.tiddlyspotSiteId + ".tiddlyspot.com/store.cgi index.html . . " + config.tiddlyspotSiteId + ">>//(requires tiddlyspot password)//<br>[[control panel|http://" + config.tiddlyspotSiteId + ".tiddlyspot.com/controlpanel]], [[download (go offline)|http://" + config.tiddlyspotSiteId + ".tiddlyspot.com/download]]|",
"| links:|[[tiddlyspot.com|http://tiddlyspot.com/]], [[FAQs|http://faq.tiddlyspot.com/]], [[blog|http://tiddlyspot.blogspot.com/]], email [[support|mailto:support@tiddlyspot.com]] & [[feedback|mailto:feedback@tiddlyspot.com]], [[donate|http://tiddlyspot.com/?page=donate]]|"
].join("\n"),
'TspotSidebar':[
"<<upload http://" + config.tiddlyspotSiteId + ".tiddlyspot.com/store.cgi index.html . . " + config.tiddlyspotSiteId + ">><html><a href='http://" + config.tiddlyspotSiteId + ".tiddlyspot.com/download' class='button'>download</a></html>"
].join("\n"),
'TspotOptions':[
"tiddlyspot password:",
"<<option pasUploadPassword>>",
""
].join("\n")
});
//}}}
| !date | !user | !location | !storeUrl | !uploadDir | !toFilename | !backupdir | !origin |
| 10/04/2009 17:04:38 | Tobias J. Osborne | [[/|http://tjoresearchnotes.tiddlyspot.com/]] | [[store.cgi|http://tjoresearchnotes.tiddlyspot.com/store.cgi]] | . | [[index.html | http://tjoresearchnotes.tiddlyspot.com/index.html]] | . |
| 10/04/2009 18:11:56 | Tobias J. Osborne | [[/|http://tjoresearchnotes.tiddlyspot.com/]] | [[store.cgi|http://tjoresearchnotes.tiddlyspot.com/store.cgi]] | . | [[index.html | http://tjoresearchnotes.tiddlyspot.com/index.html]] | . |
| 13/04/2009 23:22:27 | Tobias J. Osborne | [[/|http://tjoresearchnotes.tiddlyspot.com/]] | [[store.cgi|http://tjoresearchnotes.tiddlyspot.com/store.cgi]] | . | [[index.html | http://tjoresearchnotes.tiddlyspot.com/index.html]] | . |
| 14/04/2009 07:05:26 | Tobias J. Osborne | [[/|http://tjoresearchnotes.tiddlyspot.com/]] | [[store.cgi|http://tjoresearchnotes.tiddlyspot.com/store.cgi]] | . | [[index.html | http://tjoresearchnotes.tiddlyspot.com/index.html]] | . |
| 14/04/2009 17:13:10 | Tobias J. Osborne | [[/|http://tjoresearchnotes.tiddlyspot.com/]] | [[store.cgi|http://tjoresearchnotes.tiddlyspot.com/store.cgi]] | . | [[index.html | http://tjoresearchnotes.tiddlyspot.com/index.html]] | . | ok |
| 14/04/2009 17:13:38 | Tobias J. Osborne | [[/|http://tjoresearchnotes.tiddlyspot.com/]] | [[store.cgi|http://tjoresearchnotes.tiddlyspot.com/store.cgi]] | . | [[index.html | http://tjoresearchnotes.tiddlyspot.com/index.html]] | . |
| 17/04/2009 15:59:48 | Tobias J. Osborne | [[/|http://tjoresearchnotes.tiddlyspot.com/]] | [[store.cgi|http://tjoresearchnotes.tiddlyspot.com/store.cgi]] | . | [[index.html | http://tjoresearchnotes.tiddlyspot.com/index.html]] | . | ok |
| 17/04/2009 16:14:04 | Tobias J. Osborne | [[/|http://tjoresearchnotes.tiddlyspot.com/]] | [[store.cgi|http://tjoresearchnotes.tiddlyspot.com/store.cgi]] | . | [[index.html | http://tjoresearchnotes.tiddlyspot.com/index.html]] | . | ok |
| 17/04/2009 16:27:34 | Tobias J. Osborne | [[/|http://tjoresearchnotes.tiddlyspot.com/]] | [[store.cgi|http://tjoresearchnotes.tiddlyspot.com/store.cgi]] | . | [[index.html | http://tjoresearchnotes.tiddlyspot.com/index.html]] | . |
| 27/04/2009 15:43:06 | Tobias J. Osborne | [[/|http://tjoresearchnotes.tiddlyspot.com/]] | [[store.cgi|http://tjoresearchnotes.tiddlyspot.com/store.cgi]] | . | [[index.html | http://tjoresearchnotes.tiddlyspot.com/index.html]] | . |
/***
|''Name:''|UploadPlugin|
|''Description:''|Save to web a TiddlyWiki|
|''Version:''|4.1.3|
|''Date:''|Feb 24, 2008|
|''Source:''|http://tiddlywiki.bidix.info/#UploadPlugin|
|''Documentation:''|http://tiddlywiki.bidix.info/#UploadPluginDoc|
|''Author:''|BidiX (BidiX (at) bidix (dot) info)|
|''License:''|[[BSD open source license|http://tiddlywiki.bidix.info/#%5B%5BBSD%20open%20source%20license%5D%5D ]]|
|''~CoreVersion:''|2.2.0|
|''Requires:''|PasswordOptionPlugin|
***/
//{{{
version.extensions.UploadPlugin = {
major: 4, minor: 1, revision: 3,
date: new Date("Feb 24, 2008"),
source: 'http://tiddlywiki.bidix.info/#UploadPlugin',
author: 'BidiX (BidiX (at) bidix (dot) info',
coreVersion: '2.2.0'
};
//
// Environment
//
if (!window.bidix) window.bidix = {}; // bidix namespace
bidix.debugMode = false; // true to activate both in Plugin and UploadService
//
// Upload Macro
//
config.macros.upload = {
// default values
defaultBackupDir: '', //no backup
defaultStoreScript: "store.php",
defaultToFilename: "index.html",
defaultUploadDir: ".",
authenticateUser: true // UploadService Authenticate User
};
config.macros.upload.label = {
promptOption: "Save and Upload this TiddlyWiki with UploadOptions",
promptParamMacro: "Save and Upload this TiddlyWiki in %0",
saveLabel: "save to web",
saveToDisk: "save to disk",
uploadLabel: "upload"
};
config.macros.upload.messages = {
noStoreUrl: "No store URL in parmeters or options",
usernameOrPasswordMissing: "Username or password missing"
};
config.macros.upload.handler = function(place,macroName,params) {
if (readOnly)
return;
var label;
if (document.location.toString().substr(0,4) == "http")
label = this.label.saveLabel;
else
label = this.label.uploadLabel;
var prompt;
if (params[0]) {
prompt = this.label.promptParamMacro.toString().format([this.destFile(params[0],
(params[1] ? params[1]:bidix.basename(window.location.toString())), params[3])]);
} else {
prompt = this.label.promptOption;
}
createTiddlyButton(place, label, prompt, function() {config.macros.upload.action(params);}, null, null, this.accessKey);
};
config.macros.upload.action = function(params)
{
// for missing macro parameter set value from options
if (!params) params = {};
var storeUrl = params[0] ? params[0] : config.options.txtUploadStoreUrl;
var toFilename = params[1] ? params[1] : config.options.txtUploadFilename;
var backupDir = params[2] ? params[2] : config.options.txtUploadBackupDir;
var uploadDir = params[3] ? params[3] : config.options.txtUploadDir;
var username = params[4] ? params[4] : config.options.txtUploadUserName;
var password = config.options.pasUploadPassword; // for security reason no password as macro parameter
// for still missing parameter set default value
if ((!storeUrl) && (document.location.toString().substr(0,4) == "http"))
storeUrl = bidix.dirname(document.location.toString())+'/'+config.macros.upload.defaultStoreScript;
if (storeUrl.substr(0,4) != "http")
storeUrl = bidix.dirname(document.location.toString()) +'/'+ storeUrl;
if (!toFilename)
toFilename = bidix.basename(window.location.toString());
if (!toFilename)
toFilename = config.macros.upload.defaultToFilename;
if (!uploadDir)
uploadDir = config.macros.upload.defaultUploadDir;
if (!backupDir)
backupDir = config.macros.upload.defaultBackupDir;
// report error if still missing
if (!storeUrl) {
alert(config.macros.upload.messages.noStoreUrl);
clearMessage();
return false;
}
if (config.macros.upload.authenticateUser && (!username || !password)) {
alert(config.macros.upload.messages.usernameOrPasswordMissing);
clearMessage();
return false;
}
bidix.upload.uploadChanges(false,null,storeUrl, toFilename, uploadDir, backupDir, username, password);
return false;
};
config.macros.upload.destFile = function(storeUrl, toFilename, uploadDir)
{
if (!storeUrl)
return null;
var dest = bidix.dirname(storeUrl);
if (uploadDir && uploadDir != '.')
dest = dest + '/' + uploadDir;
dest = dest + '/' + toFilename;
return dest;
};
//
// uploadOptions Macro
//
config.macros.uploadOptions = {
handler: function(place,macroName,params) {
var wizard = new Wizard();
wizard.createWizard(place,this.wizardTitle);
wizard.addStep(this.step1Title,this.step1Html);
var markList = wizard.getElement("markList");
var listWrapper = document.createElement("div");
markList.parentNode.insertBefore(listWrapper,markList);
wizard.setValue("listWrapper",listWrapper);
this.refreshOptions(listWrapper,false);
var uploadCaption;
if (document.location.toString().substr(0,4) == "http")
uploadCaption = config.macros.upload.label.saveLabel;
else
uploadCaption = config.macros.upload.label.uploadLabel;
wizard.setButtons([
{caption: uploadCaption, tooltip: config.macros.upload.label.promptOption,
onClick: config.macros.upload.action},
{caption: this.cancelButton, tooltip: this.cancelButtonPrompt, onClick: this.onCancel}
]);
},
options: [
"txtUploadUserName",
"pasUploadPassword",
"txtUploadStoreUrl",
"txtUploadDir",
"txtUploadFilename",
"txtUploadBackupDir",
"chkUploadLog",
"txtUploadLogMaxLine"
],
refreshOptions: function(listWrapper) {
var opts = [];
for(i=0; i<this.options.length; i++) {
var opt = {};
opts.push();
opt.option = "";
n = this.options[i];
opt.name = n;
opt.lowlight = !config.optionsDesc[n];
opt.description = opt.lowlight ? this.unknownDescription : config.optionsDesc[n];
opts.push(opt);
}
var listview = ListView.create(listWrapper,opts,this.listViewTemplate);
for(n=0; n<opts.length; n++) {
var type = opts[n].name.substr(0,3);
var h = config.macros.option.types[type];
if (h && h.create) {
h.create(opts[n].colElements['option'],type,opts[n].name,opts[n].name,"no");
}
}
},
onCancel: function(e)
{
backstage.switchTab(null);
return false;
},
wizardTitle: "Upload with options",
step1Title: "These options are saved in cookies in your browser",
step1Html: "<input type='hidden' name='markList'></input><br>",
cancelButton: "Cancel",
cancelButtonPrompt: "Cancel prompt",
listViewTemplate: {
columns: [
{name: 'Description', field: 'description', title: "Description", type: 'WikiText'},
{name: 'Option', field: 'option', title: "Option", type: 'String'},
{name: 'Name', field: 'name', title: "Name", type: 'String'}
],
rowClasses: [
{className: 'lowlight', field: 'lowlight'}
]}
};
//
// upload functions
//
if (!bidix.upload) bidix.upload = {};
if (!bidix.upload.messages) bidix.upload.messages = {
//from saving
invalidFileError: "The original file '%0' does not appear to be a valid TiddlyWiki",
backupSaved: "Backup saved",
backupFailed: "Failed to upload backup file",
rssSaved: "RSS feed uploaded",
rssFailed: "Failed to upload RSS feed file",
emptySaved: "Empty template uploaded",
emptyFailed: "Failed to upload empty template file",
mainSaved: "Main TiddlyWiki file uploaded",
mainFailed: "Failed to upload main TiddlyWiki file. Your changes have not been saved",
//specific upload
loadOriginalHttpPostError: "Can't get original file",
aboutToSaveOnHttpPost: 'About to upload on %0 ...',
storePhpNotFound: "The store script '%0' was not found."
};
bidix.upload.uploadChanges = function(onlyIfDirty,tiddlers,storeUrl,toFilename,uploadDir,backupDir,username,password)
{
var callback = function(status,uploadParams,original,url,xhr) {
if (!status) {
displayMessage(bidix.upload.messages.loadOriginalHttpPostError);
return;
}
if (bidix.debugMode)
alert(original.substr(0,500)+"\n...");
// Locate the storeArea div's
var posDiv = locateStoreArea(original);
if((posDiv[0] == -1) || (posDiv[1] == -1)) {
alert(config.messages.invalidFileError.format([localPath]));
return;
}
bidix.upload.uploadRss(uploadParams,original,posDiv);
};
if(onlyIfDirty && !store.isDirty())
return;
clearMessage();
// save on localdisk ?
if (document.location.toString().substr(0,4) == "file") {
var path = document.location.toString();
var localPath = getLocalPath(path);
saveChanges();
}
// get original
var uploadParams = new Array(storeUrl,toFilename,uploadDir,backupDir,username,password);
var originalPath = document.location.toString();
// If url is a directory : add index.html
if (originalPath.charAt(originalPath.length-1) == "/")
originalPath = originalPath + "index.html";
var dest = config.macros.upload.destFile(storeUrl,toFilename,uploadDir);
var log = new bidix.UploadLog();
log.startUpload(storeUrl, dest, uploadDir, backupDir);
displayMessage(bidix.upload.messages.aboutToSaveOnHttpPost.format([dest]));
if (bidix.debugMode)
alert("about to execute Http - GET on "+originalPath);
var r = doHttp("GET",originalPath,null,null,username,password,callback,uploadParams,null);
if (typeof r == "string")
displayMessage(r);
return r;
};
bidix.upload.uploadRss = function(uploadParams,original,posDiv)
{
var callback = function(status,params,responseText,url,xhr) {
if(status) {
var destfile = responseText.substring(responseText.indexOf("destfile:")+9,responseText.indexOf("\n", responseText.indexOf("destfile:")));
displayMessage(bidix.upload.messages.rssSaved,bidix.dirname(url)+'/'+destfile);
bidix.upload.uploadMain(params[0],params[1],params[2]);
} else {
displayMessage(bidix.upload.messages.rssFailed);
}
};
// do uploadRss
if(config.options.chkGenerateAnRssFeed) {
var rssPath = uploadParams[1].substr(0,uploadParams[1].lastIndexOf(".")) + ".xml";
var rssUploadParams = new Array(uploadParams[0],rssPath,uploadParams[2],'',uploadParams[4],uploadParams[5]);
var rssString = generateRss();
// no UnicodeToUTF8 conversion needed when location is "file" !!!
if (document.location.toString().substr(0,4) != "file")
rssString = convertUnicodeToUTF8(rssString);
bidix.upload.httpUpload(rssUploadParams,rssString,callback,Array(uploadParams,original,posDiv));
} else {
bidix.upload.uploadMain(uploadParams,original,posDiv);
}
};
bidix.upload.uploadMain = function(uploadParams,original,posDiv)
{
var callback = function(status,params,responseText,url,xhr) {
var log = new bidix.UploadLog();
if(status) {
// if backupDir specified
if ((params[3]) && (responseText.indexOf("backupfile:") > -1)) {
var backupfile = responseText.substring(responseText.indexOf("backupfile:")+11,responseText.indexOf("\n", responseText.indexOf("backupfile:")));
displayMessage(bidix.upload.messages.backupSaved,bidix.dirname(url)+'/'+backupfile);
}
var destfile = responseText.substring(responseText.indexOf("destfile:")+9,responseText.indexOf("\n", responseText.indexOf("destfile:")));
displayMessage(bidix.upload.messages.mainSaved,bidix.dirname(url)+'/'+destfile);
store.setDirty(false);
log.endUpload("ok");
} else {
alert(bidix.upload.messages.mainFailed);
displayMessage(bidix.upload.messages.mainFailed);
log.endUpload("failed");
}
};
// do uploadMain
var revised = bidix.upload.updateOriginal(original,posDiv);
bidix.upload.httpUpload(uploadParams,revised,callback,uploadParams);
};
bidix.upload.httpUpload = function(uploadParams,data,callback,params)
{
var localCallback = function(status,params,responseText,url,xhr) {
url = (url.indexOf("nocache=") < 0 ? url : url.substring(0,url.indexOf("nocache=")-1));
if (xhr.status == 404)
alert(bidix.upload.messages.storePhpNotFound.format([url]));
if ((bidix.debugMode) || (responseText.indexOf("Debug mode") >= 0 )) {
alert(responseText);
if (responseText.indexOf("Debug mode") >= 0 )
responseText = responseText.substring(responseText.indexOf("\n\n")+2);
} else if (responseText.charAt(0) != '0')
alert(responseText);
if (responseText.charAt(0) != '0')
status = null;
callback(status,params,responseText,url,xhr);
};
// do httpUpload
var boundary = "---------------------------"+"AaB03x";
var uploadFormName = "UploadPlugin";
// compose headers data
var sheader = "";
sheader += "--" + boundary + "\r\nContent-disposition: form-data; name=\"";
sheader += uploadFormName +"\"\r\n\r\n";
sheader += "backupDir="+uploadParams[3] +
";user=" + uploadParams[4] +
";password=" + uploadParams[5] +
";uploaddir=" + uploadParams[2];
if (bidix.debugMode)
sheader += ";debug=1";
sheader += ";;\r\n";
sheader += "\r\n" + "--" + boundary + "\r\n";
sheader += "Content-disposition: form-data; name=\"userfile\"; filename=\""+uploadParams[1]+"\"\r\n";
sheader += "Content-Type: text/html;charset=UTF-8" + "\r\n";
sheader += "Content-Length: " + data.length + "\r\n\r\n";
// compose trailer data
var strailer = new String();
strailer = "\r\n--" + boundary + "--\r\n";
data = sheader + data + strailer;
if (bidix.debugMode) alert("about to execute Http - POST on "+uploadParams[0]+"\n with \n"+data.substr(0,500)+ " ... ");
var r = doHttp("POST",uploadParams[0],data,"multipart/form-data; ;charset=UTF-8; boundary="+boundary,uploadParams[4],uploadParams[5],localCallback,params,null);
if (typeof r == "string")
displayMessage(r);
return r;
};
// same as Saving's updateOriginal but without convertUnicodeToUTF8 calls
bidix.upload.updateOriginal = function(original, posDiv)
{
if (!posDiv)
posDiv = locateStoreArea(original);
if((posDiv[0] == -1) || (posDiv[1] == -1)) {
alert(config.messages.invalidFileError.format([localPath]));
return;
}
var revised = original.substr(0,posDiv[0] + startSaveArea.length) + "\n" +
store.allTiddlersAsHtml() + "\n" +
original.substr(posDiv[1]);
var newSiteTitle = getPageTitle().htmlEncode();
revised = revised.replaceChunk("<title"+">","</title"+">"," " + newSiteTitle + " ");
revised = updateMarkupBlock(revised,"PRE-HEAD","MarkupPreHead");
revised = updateMarkupBlock(revised,"POST-HEAD","MarkupPostHead");
revised = updateMarkupBlock(revised,"PRE-BODY","MarkupPreBody");
revised = updateMarkupBlock(revised,"POST-SCRIPT","MarkupPostBody");
return revised;
};
//
// UploadLog
//
// config.options.chkUploadLog :
// false : no logging
// true : logging
// config.options.txtUploadLogMaxLine :
// -1 : no limit
// 0 : no Log lines but UploadLog is still in place
// n : the last n lines are only kept
// NaN : no limit (-1)
bidix.UploadLog = function() {
if (!config.options.chkUploadLog)
return; // this.tiddler = null
this.tiddler = store.getTiddler("UploadLog");
if (!this.tiddler) {
this.tiddler = new Tiddler();
this.tiddler.title = "UploadLog";
this.tiddler.text = "| !date | !user | !location | !storeUrl | !uploadDir | !toFilename | !backupdir | !origin |";
this.tiddler.created = new Date();
this.tiddler.modifier = config.options.txtUserName;
this.tiddler.modified = new Date();
store.addTiddler(this.tiddler);
}
return this;
};
bidix.UploadLog.prototype.addText = function(text) {
if (!this.tiddler)
return;
// retrieve maxLine when we need it
var maxLine = parseInt(config.options.txtUploadLogMaxLine,10);
if (isNaN(maxLine))
maxLine = -1;
// add text
if (maxLine != 0)
this.tiddler.text = this.tiddler.text + text;
// Trunck to maxLine
if (maxLine >= 0) {
var textArray = this.tiddler.text.split('\n');
if (textArray.length > maxLine + 1)
textArray.splice(1,textArray.length-1-maxLine);
this.tiddler.text = textArray.join('\n');
}
// update tiddler fields
this.tiddler.modifier = config.options.txtUserName;
this.tiddler.modified = new Date();
store.addTiddler(this.tiddler);
// refresh and notifiy for immediate update
story.refreshTiddler(this.tiddler.title);
store.notify(this.tiddler.title, true);
};
bidix.UploadLog.prototype.startUpload = function(storeUrl, toFilename, uploadDir, backupDir) {
if (!this.tiddler)
return;
var now = new Date();
var text = "\n| ";
var filename = bidix.basename(document.location.toString());
if (!filename) filename = '/';
text += now.formatString("0DD/0MM/YYYY 0hh:0mm:0ss") +" | ";
text += config.options.txtUserName + " | ";
text += "[["+filename+"|"+location + "]] |";
text += " [[" + bidix.basename(storeUrl) + "|" + storeUrl + "]] | ";
text += uploadDir + " | ";
text += "[[" + bidix.basename(toFilename) + " | " +toFilename + "]] | ";
text += backupDir + " |";
this.addText(text);
};
bidix.UploadLog.prototype.endUpload = function(status) {
if (!this.tiddler)
return;
this.addText(" "+status+" |");
};
//
// Utilities
//
bidix.checkPlugin = function(plugin, major, minor, revision) {
var ext = version.extensions[plugin];
if (!
(ext &&
((ext.major > major) ||
((ext.major == major) && (ext.minor > minor)) ||
((ext.major == major) && (ext.minor == minor) && (ext.revision >= revision))))) {
// write error in PluginManager
if (pluginInfo)
pluginInfo.log.push("Requires " + plugin + " " + major + "." + minor + "." + revision);
eval(plugin); // generate an error : "Error: ReferenceError: xxxx is not defined"
}
};
bidix.dirname = function(filePath) {
if (!filePath)
return;
var lastpos;
if ((lastpos = filePath.lastIndexOf("/")) != -1) {
return filePath.substring(0, lastpos);
} else {
return filePath.substring(0, filePath.lastIndexOf("\\"));
}
};
bidix.basename = function(filePath) {
if (!filePath)
return;
var lastpos;
if ((lastpos = filePath.lastIndexOf("#")) != -1)
filePath = filePath.substring(0, lastpos);
if ((lastpos = filePath.lastIndexOf("/")) != -1) {
return filePath.substring(lastpos + 1);
} else
return filePath.substring(filePath.lastIndexOf("\\")+1);
};
bidix.initOption = function(name,value) {
if (!config.options[name])
config.options[name] = value;
};
//
// Initializations
//
// require PasswordOptionPlugin 1.0.1 or better
bidix.checkPlugin("PasswordOptionPlugin", 1, 0, 1);
// styleSheet
setStylesheet('.txtUploadStoreUrl, .txtUploadBackupDir, .txtUploadDir {width: 22em;}',"uploadPluginStyles");
//optionsDesc
merge(config.optionsDesc,{
txtUploadStoreUrl: "Url of the UploadService script (default: store.php)",
txtUploadFilename: "Filename of the uploaded file (default: in index.html)",
txtUploadDir: "Relative Directory where to store the file (default: . (downloadService directory))",
txtUploadBackupDir: "Relative Directory where to backup the file. If empty no backup. (default: ''(empty))",
txtUploadUserName: "Upload Username",
pasUploadPassword: "Upload Password",
chkUploadLog: "do Logging in UploadLog (default: true)",
txtUploadLogMaxLine: "Maximum of lines in UploadLog (default: 10)"
});
// Options Initializations
bidix.initOption('txtUploadStoreUrl','');
bidix.initOption('txtUploadFilename','');
bidix.initOption('txtUploadDir','');
bidix.initOption('txtUploadBackupDir','');
bidix.initOption('txtUploadUserName','');
bidix.initOption('pasUploadPassword','');
bidix.initOption('chkUploadLog',true);
bidix.initOption('txtUploadLogMaxLine','10');
// Backstage
merge(config.tasks,{
uploadOptions: {text: "upload", tooltip: "Change UploadOptions and Upload", content: '<<uploadOptions>>'}
});
config.backstageTasks.push("uploadOptions");
//}}}