Published
Edited
Jun 12, 2019
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function deduce (...ts) {
ts = ts.map(t => (t._proof || t.nodeName) ? t : html`<div>${t}</div>`);
const proof = html`<div class="proof"
style="display: inline-flex;
flex-direction: column;">
<div class="premises"
style="display: inline-flex;
flex-wrap: nowrap;
align-items: flex-end;
justify-content: center;
border-bottom: 2px solid #000;">
</div>
<div class="conclusion"
style="display: inline-flex;
margin-bottom: -2px;">
<div class="le" style="flex-grow: 1;"></div>
<div class="ct" style="margin-bottom: 2px;"></div>
<div class="ri" style="flex-grow: 1;"></div>
</div>
</div>`;
// add conclusion
// '.proof > .conclusion > .ct'
const conclusion = ts.pop();
proof.children[1].children[1].appendChild(conclusion);
// add premises
const prem = proof.children[0];
ts.forEach((t, i) => {
// add premiss
prem.appendChild(t);
// if the premiss is a sub-tree, white-out parts of the horizontal bar for aesthetic reasons
if (t._proof) {
if (i == 0) {
// '.proof > .conclusion > .le'
t.children[1].children[0].style['border-bottom'] = '2px solid #fff';
} else if (i+1 == ts.length) {
// '.proof > .conclusion > .ri'
t.children[1].children[2].style['border-bottom'] = '2px solid #fff';
}
}
// add a bit of spacing between premises
if (i + 1 < ts.length) {
prem.appendChild(html`<div class="premiss space" style="width: 2em;"></div>`);
}
});
// so that future runs of this function can check that the node is a proof tree
proof._proof = true;
return proof;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more