diff --git a/packages/squiggle-lang/__tests__/Distributions/AlgebraicShapeCombination_test.res b/packages/squiggle-lang/__tests__/Distributions/AlgebraicShapeCombination_test.res index 702b67a4..552799ac 100644 --- a/packages/squiggle-lang/__tests__/Distributions/AlgebraicShapeCombination_test.res +++ b/packages/squiggle-lang/__tests__/Distributions/AlgebraicShapeCombination_test.res @@ -14,4 +14,16 @@ describe("Combining Continuous and Discrete Distributions", () => { ), // Multiply distribution by -1 true, ) + makeTest( + "keep order of xs when first number is discrete and adding", + AlgebraicShapeCombination.isOrdered( + AlgebraicShapeCombination.combineShapesContinuousDiscrete( + #Add, + {xs: [0., 1.], ys: [1., 1.]}, + {xs: [1.], ys: [1.]}, + ~discretePosition=First, + ), + ), // 1 + distribution + true, + ) }) diff --git a/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/AlgebraicShapeCombination.res b/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/AlgebraicShapeCombination.res index a51de00d..2508e3df 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/AlgebraicShapeCombination.res +++ b/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/AlgebraicShapeCombination.res @@ -214,7 +214,7 @@ let combineShapesContinuousDiscrete = ( // When this operation is flipped (like 1 - normal(5, 2)) then the // x axis coordinates would all come out the wrong order. So we need // to fill them out in the opposite direction - let index = discretePosition == First ? t1n - 1 - i : i + let index = discretePosition == First && op == #Subtract ? t1n - 1 - i : i Belt.Array.set( dxyShape, index,