4

I'd like to know how to draw these trees:

enter image description here

I really have no idea. I've taken a look but I didn't find out anything that could help me (to draw these trees in particular). So I hope you can help me.

\documentclass[a4paper]{article}
\usepackage{amsmath}

\begin{document}

\end{document}
  • 3
    Your question leaves all the effort to our community, even typing the essentials of a TeX document such as \documentclass{}...\begin{document} etc. As it is, most of our users will be very reluctant to touch your question, and you are left to the mercy of our procrastination team who are very few in number and very picky about selecting questions. You can improve your question by adding a minimal working example (MWE) that more users can copy/paste onto their systems to work on. If no hero takes the challenge we might have to close your question. – cfr Mar 26 '15 at 3:46
  • Welcome to TeX SE, by the way! There are lots of examples of trees on the site, so I'm sure you will find something to get you started. – cfr Mar 26 '15 at 3:47
  • Hello and thank you for the welcoming! I've changed the post. Is it what you were suggesting? – francolino Mar 26 '15 at 3:55
  • What are these trees for? That is, what are they meant to do or show? – cfr Mar 27 '15 at 2:16
  • In my university we're following the book "Logic and structure" by Dirk Van Dalen. If you take a look at it, you will see that they aren't proof trees. These trees are examples of functions defined by recurrence. – francolino Mar 28 '15 at 8:18
10

For example, here's a schematic of the second tree using the powerful forest package.

\documentclass[tikz, border=5pt]{standalone}
\usepackage{forest}

\begin{document}
  \begin{forest}
    for tree={
      shape=circle,
      fill=black,
      minimum width=5pt,
      inner sep=1pt,
      parent anchor=south,
      child anchor=north,
      anchor=center,
      line width=1pt
    }
    [, label={right:some label A}
      [, label={right:some label B}
        [, label={right:some label C}
          [, label={below:F}]
          [, label={right:some label D}
            [, label={below:E}]
          ]
        ]
      ]
    ]
  \end{forest}
\end{document}

schematic forest

EDIT

Here are the two trees with their formulae.

If you are learning to use proof trees in logic, DO NOT use these as examples.

These are NOT the standard trees used in logical proofs!

illogical tree 1 illogical tree 2

\documentclass[tikz, border=5pt, multi, varwidth]{standalone}
\usepackage{forest}
\standaloneenv{forest}
\begin{document}
  \forestset{
    my tree/.style={
      for tree={
        shape=circle,
        fill=black,
        minimum width=5pt,
        inner sep=1pt,
        anchor=center,
        line width=1pt,
        s sep+=25pt,
      },
    },
  }
  \begin{forest}
    my tree
    [, label={right:$(p_1 \rightarrow (\bot \vee (\lnot p_3)))$}
      [, label={below:$p_1$}]
      [, label={right:$(\bot \vee (\lnot p_3))$}
        [, label={below:$\bot$}]
        [, label={right:$(\lnot p_3)$}
          [, label={below:$p_3$}]
        ]
      ]
    ]
  \end{forest}

  \begin{forest}
    my tree
    [, label={right:$(\lnot(\lnot(p_1 \wedge (\lnot p_1))))$}
      [, label={right:$(\lnot(p_1 \wedge (\lnot p_1)))$}
        [, label={right:$(p_1 \wedge (\lnot p_1))$}
          [, label={below:$p_1$}]
          [, label={right:$(\lnot p_1)$}
            [, label={below:$p_1$}]
          ]
        ]
      ]
    ]
  \end{forest}
\end{document}
  • Thank you so much for your answer! How could I reduce the size of the object? – francolino Mar 26 '15 at 4:04
  • @francolino What object? When you use it in your paper or whatever, it will be sized based on the font size you are using and so on. Is that what you mean? – cfr Mar 26 '15 at 4:10
  • Sorry, my mistake. I just figured out that you were using "\documentclass[tikz]" when I should be using "\documentclass[a4paper]{article}". – francolino Mar 26 '15 at 4:14
  • @francolino Oh, right. Yes. standalone is just useful for creating images either while working on them or, also, for posting on this site! – cfr Mar 26 '15 at 4:18
  • 1
    I wanna thank you for your time updating this and by taking care of the question, but I did it by my own with the first example that you gave me. – francolino Mar 28 '15 at 8:19
6

Here is the pst-tree way for both trees:

\documentclass[12pt, a4paper, pdf]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fourier}
\usepackage{pst-node, pst-tree}

\renewcommand\psedge{\ncline[arrows =-]}

\begin{document}
\psset{levelsep=1.5cm, treesep=3cm, dotsize =5pt}

\pstree
{\Tdot[dotsize =5pt] \nput{45}{\pssucc}{$ (p_1\to(\bot ∨ (\neg p_3)))$}}%
{%
    \Tdot\nput{-90}{\pssucc}{$p_1$}
    \pstree{\Tdot\nput{45}{\pssucc}{$(\bot ∨ (\neg p_3)) $}}%
    {\Tdot\nput{-90}{\pssucc}{$\bot $}%
        \pstree{\Tdot\nput{45}{\pssucc}{$(\neg p_3)$}}
        {\Tdot\nput{-90}{\pssucc}{$p_3$}}
    }
}
\hfill
\raisebox{-1.5cm}{%
    \pstree%
    {\Tdot[dotsize =5pt] \nput{45}{\pssucc}{$ (\neg(\neg(p_1 ∧ (\neg p_1))))$}}%
    {\pstree%
        {\Tdot \nput{45}{\pssucc}{$ (\neg(p_1 ∧ (\neg p_1)))$}}%
        {\pstree%
            {\Tdot \nput{45}{\pssucc}{$ (p_1 ∧ (\neg p_1)) $}}%
            {\Tdot\nput{-90}{\pssucc}{$p_1$}%
                \pstree%
                {\Tdot \nput{45}{\pssucc}{$(\neg p_1)$}}%
                {\Tdot\nput{-90}{\pssucc}{$p_1$}}
            }
        }
    }
}%
\end{document} 

enter image description here

  • Since you've repeated the odd logic, I guess I can too. Do you have any idea what these are for? They seem to fly in the face of logic itself.... – cfr Mar 27 '15 at 2:18
  • @cfr: No, I only slavishly copied the formulae. I don't know what $\bot$ means for a logician! – Bernard Mar 27 '15 at 2:45
  • Oh, that bit is OK. Semantically, it is a truth-function which always has the value false. I just can't figure out what these trees are meant to be for. They aren't proof trees.... – cfr Mar 27 '15 at 3:05
6

It can also be done with MetaPost, e.g. with the help of the MetaObj package.

A tree is one of the ‘‘objects’’ that MetaObj handles, and is defined recursively, as those in this program are:

t := _T(TCs)(TCs, _T(TCs)(TCs, _T(TCs)(TCs)));
...
t := _T(TCs)(_T(TCs)(_T(TCs)(TCs, _T(TCs)(TCs))));

_T is a shortcut for the new_Tree command, which create a (sub)tree, and TCs another shortcut for putting a filled circle at the current node.

\documentclass{article}
\usepackage{luamplib}
  \everymplib{verbatimtex \leavevmode etex; 
    input metaobj
      setCurveDefaultOption("arrows")("draw");
      setObjectDefaultOption("Tree")("treenodehsize")(0);
      setObjectDefaultOption("Tree")("hbsep")(1.6cm);
      setObjectDefaultOption("Tree")("vsep")(.7cm);
      labeloffset := 2bp;
    beginfig(1);}
  \everyendmplib{endfig;}
\begin{document}
  \emph{Examples.}
  \begin{minipage}[t]{0.36\linewidth}
    \centering
    $T\big((p_1 \to (\perp \vee \neg (p_3)))\big)$;
    \par\bigskip
    \begin{mplibcode}
      t := _T(TCs)(TCs, _T(TCs)(TCs, _T(TCs)(TCs)));
      Obj(t).n = origin;
      ObjLabel.treeroot(Obj(t))(1)(btex $p_1$ etex) "labdir(bot)";
      ObjLabel.treeroot(Obj(t))(2,1)(btex $\perp$ etex) "labdir(bot)";
      ObjLabel.treeroot(Obj(t))(2,2,1)(btex $p_3$ etex) "labdir(bot)";
      ObjLabel.treeroot(Obj(t))(2,2)(btex $(\neg p_3)$ etex) "labdir(urt)";
      ObjLabel.treeroot(Obj(t))(2)(btex $(\perp \vee (\neg p_3))$ etex) "labdir(urt)";
      label.urt(btex $(p_1 \to (\perp \vee (\neg p_3)))$ etex, origin);
      draw_Obj(t);
    \end{mplibcode}
  \end{minipage}
  %
  \begin{minipage}[t]{0.36\linewidth}
    \centering
    $T\big(\neg(\neg(p_1 \wedge (\neg p_1))) \big)$
    \par\bigskip
    \begin{mplibcode}
      t := _T(TCs)(_T(TCs)(_T(TCs)(TCs, _T(TCs)(TCs))));
      Obj(t).n = origin shifted (5cm, 0);
      label.urt(btex $(\neg(\neg(p_1 \wedge (\neg p_1))))$ etex, Obj(t).n);
      ObjLabel.treeroot(Obj(t))(1)(btex $(\neg(p_1 \wedge (\neg p_1)))$ etex) "labdir(urt)";
      ObjLabel.treeroot(Obj(t))(1,1)(btex $(p_1 \wedge (\neg p_1))$ etex) "labdir(urt)";
      ObjLabel.treeroot(Obj(t))(1,1,1)(btex $p_1$ etex) "labdir(bot)";
      ObjLabel.treeroot(Obj(t))(1,1,2)(btex $(\neg p_1)$ etex) "labdir(urt)";
      ObjLabel.treeroot(Obj(t))(1,1,2,1)(btex $p_1$ etex) "labdir(bot)";
      draw_Obj(t);
    \end{mplibcode}
  \end{minipage}
\end{document}

To be typeset with LuaLaTeX. Output:

enter image description here

5

This is a raw MWE with Asymptote:

enter image description here

The trees looks like syntactic trees for some kind of logical expressions with operators $\to$, $\vee$, $\wedge$, $\neg$ and operands $p_1$, $p_3$ and $\perp$.

In the example file testoptree.asy the tree is defined recursively by manual analysis of the expression and separating operator (as a string) and its left and right subexpression (subtree). The string labels at the non-terminal nodes are formed automatically.

//
// testoptree.asy 
//
import optree;
real w=9cm, h=0.618w; size(w,h);
string p1="p_1", p3="p_3", to="\to", perp="\perp", vee="\vee", neg="\neg", wedge="\wedge";

opTree T1=
opTree(
  opTree(p1),to,
  opTree(
    opTree(perp), vee,
    opTree(
      neg, opTree(p3)
    )
  )
);

opTree T2=
opTree(
  neg,
  opTree(
  neg,
    opTree(
      opTree(p1), wedge,
      opTree(
        neg, opTree(p1)
      )         
    ) 
  ) 
);

void drawNode(pair c){
  fill(circle(c,0.07),white);
  fill(circle(c,0.06),orange);
}

draw(T1,darkblue+1.2bp,drawNode);
draw(shift(4,0)*T2,darkblue+1.2bp,drawNode);

This MWE uses a module optree.asy shown below.

struct opTree{
  string sr;
  opTree left, right;
  pair root;
  void operator init(opTree left=null, string sr, opTree right=null){
    this.left=left;
    this.sr=sr;
    this.right=right;
  }
}

string operator cast(opTree T){
  if(T==null)return "";
  if(T.left==null && T.right==null){
    return " "+T.sr+" ";
  }else{  
    return "("+T.left+T.sr+T.right+")";
  }
}

opTree operator*(transform t,opTree T){
  if(T!=null){
    T.root=t*T.root;
    T.left=t*T.left;
    T.right=t*T.right;
  }
  return T;
}

typedef void DrawFunc(pair);

void draw(opTree T,pen linepen=currentpen, DrawFunc drawNode=null){
  real dx=0.5, dy=sqrt(3)/2;
  if(T!=null){
    if(T.left!=null && T.right!=null){ 
      T.left.root =T.root+(-dx,-dy); 
      T.right.root=T.root+( dx,-dy);
      draw(T.right.root--T.root--T.left.root,linepen);
    }
    if(T.left==null && T.right!=null ){ 
      T.right.root=T.root+(0,-dy);
      draw(T.root--T.right.root,linepen);
    }
    if(T.left!=null && T.right==null ){ 
      T.left.root =T.root+(0,-dy); 
      draw(T.root--T.left.root,linepen);
    }

    if(drawNode!=null) drawNode(T.root);

    if(T.left==null && T.right==null){
      label("$"+T.sr+"$",T.root,plain.S);
    }else{
      label("$"+T+"$",T.root,plain.NE);      
    }
    draw(T.left ,linepen,drawNode);
    draw(T.right,linepen,drawNode);
  }
}

To get a standalone testoptree.pdf, run:

asy -f pdf testoptree.asy

provided that optree.asy is in the same folder (or it is some of standard folders where the asy is looking for files).

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.