Published
Edited
Nov 10, 2020
4 stars
Insert cell
Insert cell
Insert cell
a = 8
Insert cell
html`<b>${a*7}`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
circuitShow(c=> {
const nand_out = c.nand(c.input('b'), c.input('a'))
c.output('and_out', c.not(nand_out))
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
dob = new Date('December 16, 1997')
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
sequenceParts = [[year, 4], [month, 4], [fixed, 3], [day, 5]]
.map(([nr, places])=> toBinaryString(nr, places))
Insert cell
Insert cell
Insert cell
table(truthTable(sequence), {head: ['(q3, q2, q1, q0)', 'YDOB'], code: true})
Insert cell
code(truthTable16ToKMap(sequence))
Insert cell
Insert cell
// verify
sequence === sequenceFromF16Str( (q0, q1, q2, q3)=> q1 ? q3*(q0 ? !q2 : 1) : q2 )
Insert cell
sequence
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
dobCircuitBuilder1 = ({input, output, high, not, mux, and, nand})=> {
const [q0, q1, q2, q3] = ['q0', 'q1', 'q2', 'q3'].map(input),
HIGH = high(),
d = not(q2),
b = mux(q0, HIGH, d),
a = and(q3, b),
YDOB = mux(q1, q2, a)
output('YDOB', YDOB)
}
Insert cell
Insert cell
Insert cell
Insert cell
// -> 2*mux + 3*nand
dobCircuitBuilder = ({input, output, high, not, mux, and, nand})=> {
const [q0, q1, q2, q3] = ['q0', 'q1', 'q2', 'q3'].map(input),
HIGH = high(),
d = nand(q2, q2),
b = mux(q0, HIGH, d),
a1 = nand(q3, b),
a = nand(a1, a1),
YDOB = mux(q1, q2, a)
output('YDOB', YDOB)
}
Insert cell
// verify
sequence === sequenceFromF16Str((...input)=> circuitRunDigital(dobCircuitBuilder, input)[0])
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
drawFSM(fsm_transitions)
Insert cell
dot`digraph lol { a->b; }`
Insert cell
Insert cell
fsm_truth_table = truthTableFromFsmTransitions(fsm_transitions, ['b', 'a'])
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// verify
sequenceFromF16Str((a, b, q0, q1)=> a ? q0 : (q1 ? b : !!(!q0*!b))) == fsm_sequence_q[1]
Insert cell
Insert cell
// verify
sequenceFromF16Str((a, b, q0, q1)=> a ? (q1 ? b : !(b*!(q0*b)) ) : 0) == fsm_sequence_q[0]
Insert cell
// using de morgans law;
sequenceFromFStr((a, b)=> a+b, 4) == sequenceFromFStr((a, b)=> !(!a*!b), 4)
Insert cell
Insert cell
Insert cell
Insert cell
// q1 + q0 circuit combined into one
fsm_circuit_builder = ({input, nand, and, not, mux, output, high, low})=> {
const [a, b, q0, q1] = 'a, b, q0, q1'.split(', ').map(input),
LOW = low(),
n_b = nand(b, b),
n_q0 = nand(q0, q0),

_6 = nand(q0, b),
_5 = nand(b, _6),

_3 = nand(n_q0, n_b),
_2 = nand(_3, _3),

_4 = mux(q1, _5, b),
_1 = mux(q1, _2, b),

q0next = mux(a, LOW, _4),
q1next = mux(a, _1, q0)
output('q0next', q0next)
output('q1next', q1next)
}
Insert cell
circuitShow(fsm_circuit_builder)
Insert cell
// verify
fsm_sequence_q.map((s, i)=> s == sequenceFromF16Str(
(...input)=> circuitRunDigital(fsm_circuit_builder, input)[i]))
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
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
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// dot is used to visualize graph structures
dot = require("@observablehq/graphviz@0.2")
Insert cell
Insert cell
Insert cell
Insert cell
circuitBuild_node_types = [...circuitBuild_node_types_netlist, ...circuitBuild_node_types_own]
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