diff --git a/packages/squiggle-lang/src/rescript/Distributions/DistributionTypes.res b/packages/squiggle-lang/src/rescript/Distributions/DistributionTypes.res index 98c49a21..3a256ea0 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/DistributionTypes.res +++ b/packages/squiggle-lang/src/rescript/Distributions/DistributionTypes.res @@ -14,6 +14,7 @@ type error = | OperationError(Operation.Error.t) | PointSetConversionError(SampleSetDist.pointsetConversionError) | SparklineError(PointSetTypes.sparklineError) // This type of error is for when we find a sparkline of a discrete distribution. This should probably at some point be actually implemented + | RequestedModeInvalidError | OtherError(string) @genType @@ -33,6 +34,7 @@ module Error = { | OperationError(err) => Operation.Error.toString(err) | PointSetConversionError(err) => SampleSetDist.pointsetConversionErrorToString(err) | SparklineError(err) => PointSetTypes.sparklineErrorToString(err) + | RequestedModeInvalidError => `Requested mode invalid` | OtherError(s) => s } diff --git a/packages/squiggle-lang/src/rescript/Distributions/GenericDist/GenericDist.res b/packages/squiggle-lang/src/rescript/Distributions/GenericDist/GenericDist.res index 47fb2c01..d91db41e 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/GenericDist/GenericDist.res +++ b/packages/squiggle-lang/src/rescript/Distributions/GenericDist/GenericDist.res @@ -5,6 +5,7 @@ type toPointSetFn = t => result type toSampleSetFn = t => result type scaleMultiplyFn = (t, float) => result type pointwiseAddFn = (t, t) => result +type asMode = AsSymbolic | AsMontecarlo | AsConvolution let sampleN = (t: t, n) => switch t { @@ -215,7 +216,7 @@ module AlgebraicCombination = { : Convolution(convOp) } - let run = ( + let run' = ( t1: t, ~toPointSetFn: toPointSetFn, ~toSampleSetFn: toSampleSetFn, @@ -233,6 +234,21 @@ module AlgebraicCombination = { } } } + + let run = ( + ~mode: option=?, + t1: t, + ~toPointSetFn: toPointSetFn, + ~toSampleSetFn: toSampleSetFn, + ~arithmeticOperation, + ~t2: t, + ): result => { + let algebraicResult = run'(t1, ~toPointSetFn, ~toSampleSetFn, ~arithmeticOperation, ~t2) + switch mode { + | Some(_) => algebraicResult + | None => Error(RequestedModeInvalidError) + } + } } let algebraicCombination = AlgebraicCombination.run diff --git a/packages/squiggle-lang/src/rescript/Distributions/GenericDist/GenericDist.resi b/packages/squiggle-lang/src/rescript/Distributions/GenericDist/GenericDist.resi index ce32a39b..ccb9a5c6 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/GenericDist/GenericDist.resi +++ b/packages/squiggle-lang/src/rescript/Distributions/GenericDist/GenericDist.resi @@ -4,6 +4,7 @@ type toPointSetFn = t => result type toSampleSetFn = t => result type scaleMultiplyFn = (t, float) => result type pointwiseAddFn = (t, t) => result +type asMode = AsSymbolic | AsMontecarlo | AsConvolution let sampleN: (t, int) => array @@ -42,6 +43,7 @@ let truncate: ( ) => result let algebraicCombination: ( + ~mode: asMode=?, t, ~toPointSetFn: toPointSetFn, ~toSampleSetFn: toSampleSetFn,