2

I try formulate some lambda expression in lambda calculus. It is similar to a code, but I have to use align environment because it contains math symbols. I wonder how I can formulate its structures better? The current one has a lot of unneeded spaces in between, although it captures some of what I want it to look like.

\begin{align*}
\text{cell} = & \text{rec} (& \lambda b.&\lambda c.  &\lambda m.&  \\
              &             & \text{if} &(\text{get?}&(m),      &  \\
              &             &           & \text{seq} &(\text{send}&(\text{contents}(m), c), & \text{ready}(b(c))), \\
              &             &           & \text{if}  &(\text{set?}&(m), & \\
              &             &           &            & \text{ready}&(b(\text{contents}(m))), & \\
              &             &           &            & \text{ready}&(b(c))))) 
\end{align*}

enter image description here

Here is what I want

enter image description here

7
  • Hi, may be You have image of what You wonna have as a result, it would be very nice Oct 17 at 20:28
  • Thanks. Question updated.
    – Ben
    Oct 17 at 20:40
  • Try replacing {align*} with {alignat*}{3} (I suppose you made the right calculation and have three alignment points).
    – Bernard
    Oct 17 at 20:48
  • Is it the last image an algorithm?
    – Sebastiano
    Oct 17 at 20:54
  • a lambda expression, using math symbol @Sebastiano
    – Ben
    Oct 17 at 20:54
4

Not quite what you want, but how about this:

\documentclass{article}
\usepackage{mathtools, amssymb}

\begin{document}

\begin{alignat*}{4}
\text{cell} ={} & \text{rec} ( & & \lambda\mathrlap{ b.\lambda c. \lambda m.} \\
               & & & \text{if} &( & \mathrlap{\text{get?}(m),} \\
               & & & & & \text{seq} &( & \text{send}(\text{contents}(m), c), \\
               & & & & & & & \text{ready}(b(c))), \\
               & & & & & \text{if}\:( & & \text{set?}(m),\\
               & & & & & & & \text{ready}(b(\text{contents}(m))), \\
               & & & & & & & \text{ready}(b(c)))))
\end{alignat*}

\end{document} 

enter image description here

2

It is a bit hard coding but easiest and enough fast (is it what You need?):

enter image description here

\documentclass{article}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{amssymb}




\begin{document}
\begin{align*}
\text{cell} =  \text{rec} (&\lambda b.\lambda c.\lambda m.\\
                           &\text{if} (\text{get?}(m), \\
                           &          \quad \text{seq} (\text{send}(\text{contents}(m), c),\\ 
                           & \qquad \quad \text{ready}(b(c))), \\
                           & \quad\text{if}  (\text{set?}(m), \\
                           &\qquad\text{ready}(b(\text{contents}(m))), \\
                           &\qquad\text{ready}(b(c))))) 
\end{align*}
\end{document}
2
  • Thanks Looks good. Why does mine fail?
    – Ben
    Oct 17 at 21:16
  • Sorry I don't understand Your question, You mean why Your code do not produse the same result as mine? or what? Oct 17 at 21:27
2

Probabily your code can be more fine if it is used lambdax package here on this link, https://ctan.org/pkg/lambdax

To work with this package you should download the lambdax.sty and keyparse.sty from your TeX distribuition (on MikTeX the answer is yes.)

Reading the explanation there is written This package provides Lambda expressions. that it is your objective.

Here there is a small example taken from https://github.com/rogard/lambdax/blob/main/testfiles/lambdax-001.lvt

\documentclass{article}
\usepackage{lambdax}
\begin{document}
\ExplSyntaxOn
\START
\box_new:N \l_tmp_box
\hbox_set:Nn \l_tmp_box{\LambdaX{(#1)}{x}}
\box_use:N \l_tmp_box
%\END
\ExplSyntaxOff
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.