import Tests.Parsingimport Determinize.Checking.FiniteDistributionimport Determinize.Proof.Primitives.DiscreteLawsnamespace Determinize.Testsopen Checkingexample : (finiteDistribution [1 / 6, 1 / 3, 1 / 2]).map (·.probabilities) = .ok [1 / 6, 1 / 3, 1 / 2] := by decide +kernelexample : (finiteDistribution [0, 1, 0]).map (·.mean) = .ok 1 := by decide +kernelexample : (bernoulliDistribution (1 / 4)).map (·.mean) = .ok (1 / 4) := by decide +kernelexample (p : ℝ) (h : 0 ≤ p ∧ p ≤ 1) : (∫ x, x ∂Spec.Paper.bernoulliFiber (.sample .G) p) = p := Proof.DiscreteLaws.integral_id_bernoulliFiber (.sample .G) p h#print axioms Proof.DiscreteLaws.integral_id_discreteFiber#print axioms Proof.DiscreteLaws.integral_id_bernoulliFiberexample : (remainderDistribution [1 / 6, 1 / 3]).map (·.probabilities) = .ok [1 / 6, 1 / 3, 1 / 2] := by decide +kernelexample : (remainderDistribution []).map (·.probabilities) = .ok [1] := by decide +kerneldef finiteDistributions : IO Unit := do for probabilities in [[(-1 : Rat)], [3 / 4, 1 / 2]] do check (!(remainderDistribution probabilities).isOk) "invalid remainder probabilities accepted" for weights in [[], [0], [0, 0], [-1, 2], [2, -1], [1, 2, 3], [1 / 4, 1 / 4]] do check (!(finiteDistribution weights).isOk) s!"invalid weights accepted: {weights}" for p in [(-1 : Rat), 2] do check (!(bernoulliDistribution p).isOk) "invalid Bernoulli probability accepted" for p in [(0 : Rat), 1 / 4, 1] do let d ← IO.ofExcept (bernoulliDistribution p) check (d.mean == p) s!"wrong Bernoulli mean at {p}" check (d.probabilities == [1 - p, p]) "Bernoulli outcomes reordered" let d ← IO.ofExcept (finiteDistribution [0, 1, 0]) check (d.probabilities == [0, 1, 0]) "zero weights changed outcome indices" let a ← IO.ofExcept (finiteDistribution [1 / 6, 1 / 3, 1 / 2]) check (a.probabilities == [1 / 6, 1 / 3, 1 / 2]) "probabilities changed" check (a.mean == 4 / 3) "wrong categorical mean"end Determinize.Tests