This example program doesn't actually do anything (in fact it is effectively a no-op program). These comments, however, list the Unicode characters that you can use in Diderot. With each character we give the Unicode code point and name, the LaTeX equivalent (might be useful for Diderot programs in LaTeX documents), and other comments.
Our basic philosophy behind indicating mathematical values and operators in an idiomatic and convenient way is similar to principles previously articulated by other computer scientists:
First, we want to establish the idea that a computer language is not just a way of getting a computer to perform operations but rather that it is a novel formal medium for expressing ideas about methodology. Thus, programs must be written for people to read, and only incidentally for machines to execute. -- Abelson & Sussman & Sussman, Structure and Interpretation of Computer Programs (1985)
Let us change our traditional attitude to the construction of programs: instead of imagining that our main task is to instruct a computer what to do, let us concentrate rather on explaining to humans what we want the computer to do. -- Donald Knuth, Literate Programming (1984)
These statements predate Unicode development, but that does not undermine their continued relevance for Diderot or for programming in general. See https://en.wikipedia.org/wiki/Unicode_input for information about how best to input unicode in your OS. Or, copy and paste from this file.
real rad = degrees*Ο/180;
- Unicode: U+03C0 (Greek Small Letter Pi)
- LaTeX:
\pi - This is currently the only finite real constant in Diderot.
output real out = -β;
- Unicode: U+221E (Infinity)
- LaTeX:
\infty - The above line of code is how the output of maximum-intensity projection might be intialized;
from then on subsequent use might be like
out = max(out, F(pos)).
field#2(3)[] F = bspln3 β image("img.nrrd");
- Unicode: U+229B (Circled Asterisk Operator)
- LaTeX:
\circledastis probably typical, but\varoast(with\usepackage{stmaryrd}) is slightly more legible - This commutes; you could also write
image("img.nrrd") β bspln3.
vec3 camU = normalize(camN Γ camUp);
- Unicode: U+00D7 (Multiplication Sign)
- LaTeX:
\times - As the cross-product, this is only defined for
vec3variables. It also works for the curl of a vector field; see below.
tensor[3,3] Proj = identity[3] - normβnorm
- Unicode: U+2297 (Circled Times)
- LaTeX:
\otimes. - As an operator on coordinate vectors, this is typically called the outer product. It is also used to define the Jacobian of a vector field; see below.
real ld = norm β’ lightDir;
- Unicode: U+2022 (Bullet)
- LaTeX:
\bullet, which is more consistently visible than the\cdotthat is more typical for dot products. - The meaning of
β’is really (in tensor-speak) "contract out the last index of the first argument with the first index of the second argument". Note that tensor double-dot product (which contracts out two indices in other side) is plain ASCII:.β’is also used for the divergence of a vector field; see below.
field#3(3)[] F = ...;
field#2(3)[3] gradient = βF;
field#1(3)[3,3] hessian = βββF;
field#0(3)[3,3,3] wut = βββββF;
field#2(3)[3] V = ...;
field#1(3)[3,3] jacobian = ββV;
field#1(3)[3] curl = βΓV;
field#1(3)[] divergence = ββ’V;
field#2(2)[2] U = ...;
field#1(2)[] vort = βΓU;
- Unicode: U+2207 (Nabla)
- LaTeX:
\nabla. - See above for the different uses of
β. Note thatβΓapplied to a 2D vector field gives you a scalar, butβΓapplied to a 3D vector field gives you another 3D vector field. - For consistency,
βis used even for fields on a 1-D domain, which unfortunately defies the expectation thatβsomehow generates a vector. Currently Diderot does not have a different notation for differentation over a 1-D domain.