diff --git a/packages/squiggle-lang/__tests__/ReducerInterface/ReducerInterface_Distribution_test.res b/packages/squiggle-lang/__tests__/ReducerInterface/ReducerInterface_Distribution_test.res index 9e25f7e2..1b5f8bfd 100644 --- a/packages/squiggle-lang/__tests__/ReducerInterface/ReducerInterface_Distribution_test.res +++ b/packages/squiggle-lang/__tests__/ReducerInterface/ReducerInterface_Distribution_test.res @@ -63,8 +63,8 @@ describe("eval on distribution functions", () => { testEval("lognormal(5, 2) * 2", "Ok(Lognormal(5.693147180559945,2))") }) describe("division", () => { - testEval("lognormal(5,2) / lognormal(10,2)", "Ok(Lognormal(-5,4))") - testEval("lognormal(10,2) / lognormal(5,2)", "Ok(Lognormal(5,4))") + testEval("lognormal(5,2) / lognormal(10,2)", "Ok(Lognormal(-5,2.8284271247461903))") + testEval("lognormal(10,2) / lognormal(5,2)", "Ok(Lognormal(5,2.8284271247461903))") testEval("lognormal(5, 2) / 2", "Ok(Lognormal(4.306852819440055,2))") testEval("2 / lognormal(5, 2)", "Ok(Lognormal(-4.306852819440055,2))") testEval("2 / normal(10, 2)", "Ok(Point Set Distribution)") diff --git a/packages/squiggle-lang/src/rescript/Distributions/SymbolicDist/SymbolicDist.res b/packages/squiggle-lang/src/rescript/Distributions/SymbolicDist/SymbolicDist.res index afd35800..da722036 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/SymbolicDist/SymbolicDist.res +++ b/packages/squiggle-lang/src/rescript/Distributions/SymbolicDist/SymbolicDist.res @@ -160,14 +160,14 @@ module Lognormal = { let multiply = (l1, l2) => { // https://wikiless.org/wiki/Log-normal_distribution?lang=en#Multiplication_and_division_of_independent,_log-normal_random_variables let mu = l1.mu +. l2.mu - let sigma = Js.Math.sqrt(l1.sigma ** 2. +. l2.sigma ** 2.) // m + let sigma = Js.Math.sqrt(l1.sigma ** 2. +. l2.sigma ** 2.) #Lognormal({mu: mu, sigma: sigma}) } let divide = (l1, l2) => { let mu = l1.mu -. l2.mu // We believe the ratiands will have covariance zero. // See here https://stats.stackexchange.com/questions/21735/what-are-the-mean-and-variance-of-the-ratio-of-two-lognormal-variables for details - let sigma = l1.sigma +. l2.sigma + let sigma = Js.Math.sqrt(l1.sigma ** 2. +. l2.sigma ** 2.) #Lognormal({mu: mu, sigma: sigma}) } let operate = (operation: Operation.Algebraic.t, n1: t, n2: t) =>