Public
Edited
Sep 4, 2024
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Plot.plot({
width: 1500,
height: 800,
color: {
type: "sequential",
scheme: "Plasma"
},
marks: [
Plot.dot(
_.range(1, 2 ** 14).map((p) => {
let primRoots = allTotients[p];
return {
p,
primRoots,
ratio: primRoots / p,
factors: allPrimeFactors[p]
};
}),
{
x: "p",
y: "ratio",
stroke: (d) => Math.log2(_.max(d.factors)),
channels: {
p: "p",
ratio: "ratio",
factors: "factors"
},
tip: {
format: {
p: true,
ratio: true,
factors: (d) => d.join(" "),
stroke: false
}
}
}
)
]
})
Insert cell
Insert cell
Plot.plot({
y: {
type: "log"
// transform: (d) => {
// let val = Math.log(d ? d : d + 0.001);
// return Math.log(val ? val : val + 0.001);
// }
},
marks: [
Plot.ruleY([0]),
Plot.lineY(primeCounts, {
x: "p",
y: (d) => d.p / Math.log(d.p),
stroke: "black"
}),
Plot.lineY(primeCounts, {
x: "p",
y: (d) => d.countTotal,
stroke: "blue"
}),
Plot.lineY(primeCounts, { x: "p", y: (d) => d.count2, stroke: "gold" }),
Plot.lineY(primeCounts, { x: "p", y: (d) => d.count3, stroke: "green" }),
Plot.lineY(primeCounts, { x: "p", y: (d) => d.count5, stroke: "red" })
]
})
Insert cell
primeCounts = {
let counts = [];
let count2 = 0;
let count3 = 0;
let count5 = 0;
let countTotal = 0;
for (let p of allPrimes) {
let factors = allPrimeFactors[p - 1];
let factorCounts = _.countBy(factors);
let uniqFactors = _.uniq(factors);
countTotal++;
if (
uniqFactors.length === 2 &&
uniqFactors[0] === 2 &&
factorCounts[uniqFactors[1]] === 1
) {
count2++;
}
if (
uniqFactors.length === 3 &&
uniqFactors[0] === 2 &&
uniqFactors[1] === 3 &&
factorCounts[uniqFactors[2]] === 2
) {
count3++;
}
if (
uniqFactors.length === 3 &&
uniqFactors[0] === 2 &&
uniqFactors[1] === 5 &&
factorCounts[uniqFactors[2]] === 2
) {
count5++;
}
counts.push({
p,
count2,
count3,
count5,
countTotal
});
}
return counts;
}
Insert cell
allPrimeFactors = primeFactors(limit)
Insert cell
allTotients = totients(limit)
Insert cell
allPrimes = getPrimes(limit)
Insert cell
limit = 2 ** 18
Insert cell
import {
primeFactors,
totients,
getPrimes,
} from "@tesseralis/math"
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