Compare commits
3 Commits
0b1d956ee5
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e57a1c0335 | ||
|
|
14b640b2e3 | ||
|
|
8a871e935b |
@@ -20,6 +20,7 @@
|
||||
<hgroup>
|
||||
<h1>Sieving Multiplicative Functions</h1>
|
||||
<p>Posted <time datetime="2026-04-15">April 15, 2026</time></p>
|
||||
<p>Updated <time datetime="2026-05-04">May 4, 2026</time></p>
|
||||
</hgroup>
|
||||
|
||||
<p>The
|
||||
@@ -29,7 +30,7 @@
|
||||
particular, a segmented version can be implemented to limit memory
|
||||
usage.</p>
|
||||
|
||||
Furthermore, a similar approach can be used to "sieve" the values of
|
||||
<p>Furthermore, a similar approach can be used to "sieve" the values of
|
||||
<a href="https://en.wikipedia.org/wiki/Multiplicative_function">multiplicative functions</a>.
|
||||
For instance,
|
||||
<a href="https://cp-algorithms.com/algebra/phi-function.html">this page</a>
|
||||
@@ -76,8 +77,15 @@
|
||||
<option value="mobius">Mobius</option>
|
||||
<option value="big-omega">Prime omega (with multiplicity)</option>
|
||||
<option value="little-omega">Prime omega (without multiplicity)</option>
|
||||
<option value="custom">Custom</option>
|
||||
</select>
|
||||
|
||||
<label hidden id="custom-function-label" for="custom-function">Custom function definition</label>
|
||||
<textarea hidden spellcheck=false placeholder="return Math.pow(p, k-1) * (p-1);" id="custom-function"></textarea>
|
||||
|
||||
<label hidden id="custom-function-additive-label" for="custom-function-additive">Function is additive</label>
|
||||
<input hidden type="checkbox" id="custom-function-additive" />
|
||||
|
||||
<input type="button" id="enter" value="Enter" />
|
||||
</div>
|
||||
|
||||
@@ -1125,7 +1133,8 @@ function mobius(p, k) {
|
||||
|
||||
<p>Many multiplicative and additive functions have simple formulas
|
||||
for prime powers, which makes adding a new function to sieve very
|
||||
easy with this approach.</p>
|
||||
easy with this approach. The demo even lets you write your own custom
|
||||
function to sieve - try it out!</p>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
|
||||
@@ -133,6 +133,14 @@ function sieveMultiples(p, q, l, r, y, sieve, quo, additive) {
|
||||
}
|
||||
}
|
||||
|
||||
function setCustomFunctionVisibility(e) {
|
||||
const isHidden = e.target.value !== "custom";
|
||||
document.querySelector("#custom-function-label").hidden = isHidden;
|
||||
document.querySelector("#custom-function").hidden = isHidden;
|
||||
document.querySelector("#custom-function-additive-label").hidden = isHidden;
|
||||
document.querySelector("#custom-function-additive").hidden = isHidden;
|
||||
}
|
||||
|
||||
function getFunc(func) {
|
||||
switch (func.value) {
|
||||
case "num-divisors":
|
||||
@@ -149,6 +157,11 @@ function getFunc(func) {
|
||||
return [littleOmega, true];
|
||||
case "big-omega":
|
||||
return [bigOmega, true];
|
||||
case "custom":
|
||||
const def = document.querySelector("#custom-function");
|
||||
const isAdditive = document.querySelector("#custom-function-additive");
|
||||
const f = new Function("p", "k", def.value);
|
||||
return [f, isAdditive.checked];
|
||||
default:
|
||||
throw new Error("function not implemented!");
|
||||
}
|
||||
@@ -219,4 +232,5 @@ function calculate() {
|
||||
result.appendChild(table);
|
||||
}
|
||||
|
||||
document.querySelector("#function").addEventListener("change", (e) => setCustomFunctionVisibility(e))
|
||||
document.querySelector("#enter").addEventListener("click", () => calculate())
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
overflow-y: hidden;
|
||||
}
|
||||
|
||||
figure {
|
||||
margin: 1vw;
|
||||
}
|
||||
|
||||
pre {
|
||||
overflow: auto;
|
||||
background-color: black;
|
||||
|
||||
Reference in New Issue
Block a user