import { renderLatex } from "@ofb/katex"; import { createMemo, createSignal, For } from "solid-js"; function DotRow(props: { count: number; class?: string }) { return (
{() => }
); } function CommutativeDemo() { const [mode, setMode] = createSignal<"add" | "mul">("add"); const [left, setLeft] = createSignal(3); const [right, setRight] = createSignal(5); const [swapped, setSwapped] = createSignal(false); const first = createMemo(() => (swapped() ? right() : left())); const second = createMemo(() => (swapped() ? left() : right())); const product = createMemo(() => left() * right()); const equationHtml = createMemo(() => { if (mode() === "add") { return renderLatex(`${first()} + ${second()} = ${first() + second()}`); } return renderLatex(`${first()} \\times ${second()} = ${product()}`); }); const compareHtml = createMemo(() => { if (mode() === "add") { return renderLatex(`${left()} + ${right()} = ${right()} + ${left()} = ${left() + right()}`); } return renderLatex(`${left()} \\times ${right()} = ${right()} \\times ${left()} = ${product()}`); }); return (

Commutative property

setLeft(Number(e.currentTarget.value))} />
setRight(Number(e.currentTarget.value))} />

{mode() === "add" ? (
{first()}
{second()}
{first() + second()}
) : ( )}

Swapping the order does not change the total. Commutative means you can commute (move) the numbers.

); } export default CommutativeDemo;