I want to typeset an equation for a paper. In the field of computer science we can define an equation that depends upon the form of one of it's arguments. I want to typeset this with LaTeX & amsmath
.
I might write it as follows in a program, I'm using a familiar example:
fib 0 = 1
fib 1 = 1
fib X = (fib (X - 1)) + (fib (X - 2))
This could be typeset to appear as:
fib X = { 1 if X < 2
{ (fib (X - 1)) + (fib (X - 2)) otherwise
And I know how to do this using amsmath's align and case environments. But I'd prefer the pattern match or guards to appear on the left of the equation, the same way they would in the program above. Can someone point me at how I can do this?
This is what I have so far using \begin{array}{llcl} but the spacing doesn't look right. This is the actual equation I'm trying to typeset, fibs is just a familiar example.
$$
\begin{array}{llcl}
\operatorname{prodtime}\,V & X = Y &=& 0 \\
\operatorname{prodtime}\,V & X = f(\ldots) &=& 0 \\
\operatorname{prodtime}\,V & p(X_1,\,\ldots,\,X_n) &=&
\operatorname{prodtime}\,V\,(\operatorname{body}\,p) \\
\operatorname{prodtime}\,V & V = \,f(X_1,\,\ldots,\,X_n) &=&
\operatorname{prodtime}\,V\,(\operatorname{body}\,f) \\
\operatorname{prodtime}\,V & X_0(X_1,\,\ldots,\,X_n) &=& time\_of\_call \\
\operatorname{prodtime}\,V & m(X_1,\,\ldots,\,X_n) &=& time\_of\_call \\
\operatorname{prodtime}\,V & foreign(\ldots) &=& 0 \\
\operatorname{prodtime}\,V & G_{head},\,G_{tail}
\end{array}
$$
Best Answer
Without an image of exactly how you want this typeset it is difficult to know for sure, but perhaps one of these is what you are looking for:
or perhaps:
Here is how you can modify the given MWE to obtain better spacing:
Notes:
@{}
is used to eliminate the inter column spacing{}
before the=
to get proper math spacing.$$ ... $$
with\[ ... \]
. See Why is \[ ... \] preferable to $$ ... $$? for more details.Changes as per egreg's suggestions:
\mathit{foreign}
,\mathit{time\_of\_call}
and\mathrm{head}
for better appearance of the formulas.\,
after\prodtime
, and the other uses of\operatorname
.Code: