// Cell 2: Problem Generator Logic & Displayproblem = { generateButton;// Listens to button clicks to re-run cellconst numBasisOptions = [1,2,2,3,4,4,4];const numBasis = numBasisOptions[Math.floor(Math.random() * numBasisOptions.length)];// Define available basis states and select 'numBasis' of them randomlyconst allBasis = ["00","01","10","11"];// Shuffle array and take the required number of basis statesconst shuffledBasis = allBasis.sort(() =>0.5-Math.random());const selectedBasis = shuffledBasis.slice(0, numBasis).sort();// Sorted for standard ordering// Helper to construct the LaTeX coefficient based on the number of basis terms and a random phaseconst getCoeff = (numBasis, phase) => {// Phases: '+1', '-1', '+i', '-i'// For numBasis = 1, magnitude is 1, so we just return the phase sign/imaginary unitif (numBasis ===1) {if (phase ==='+1') return"";if (phase ==='-1') return"-";if (phase ==='+i') return"i";if (phase ==='-i') return"-i"; }// For numBasis > 1, determine the denominatorlet denom ="";if (numBasis ===2) denom ="\\sqrt{2}";if (numBasis ===3) denom ="\\sqrt{3}";if (numBasis ===4) denom ="2";// Determine numerator and overall signlet numStr ="";let sign ="";if (phase ==='+1') { sign =""; numStr ="1"; }if (phase ==='-1') { sign ="-"; numStr ="1"; }if (phase ==='+i') { sign =""; numStr ="i"; }if (phase ==='-i') { sign ="-"; numStr ="i"; }return`${sign}\\frac{${numStr}}{${denom}}`; };const phases = ['+1','-1','+i','-i'];let terms = [];// Construct each term selectedBasis.forEach((basis, index) => {const randomPhase = phases[Math.floor(Math.random() * phases.length)];const coeff =getCoeff(numBasis, randomPhase);const ket =`|${basis}\\rangle`;let term =`${coeff}${ket}`;// Format addition/subtraction signs nicely for joiningif (index >0) {if (term.startsWith("-")) { term =` - ${term.slice(1)}`; } else { term =` + ${term}`; } } terms.push(term); });const state3 = terms.join("");returnhtml`<p>Prove either that ${tex`|\psi\rangle = ${state3}`} is entangled or that it is a product state. Your proof should use the definition of a product state/entangled state.</>`;}
Gemini was used to assist in generating the code that produces the randomized problems on this page. While AI contributed to this content, it was designed, reviewed, and approved by Prof. Shelby Kimmel.