diff --git a/packages/components/.prettierignore b/packages/components/.prettierignore new file mode 100644 index 00000000..5e03c80e --- /dev/null +++ b/packages/components/.prettierignore @@ -0,0 +1,2 @@ +dist/ +storybook-static diff --git a/packages/components/src/components/SquiggleChart.tsx b/packages/components/src/components/SquiggleChart.tsx index 9553d329..534d164d 100644 --- a/packages/components/src/components/SquiggleChart.tsx +++ b/packages/components/src/components/SquiggleChart.tsx @@ -131,7 +131,7 @@ export interface SquiggleChartProps { /** variables declared before this expression */ environment?: unknown; /** When the environment changes */ - onEnvChange?(env: unknown): void; + onChange?(expr: squiggleExpression): void; /** CSS width of the element */ width?: number; height?: number; @@ -141,8 +141,7 @@ export const SquiggleChart: React.FC = ({ squiggleString = "", sampleCount = 1000, outputXYPoints = 1000, - environment = [], - onEnvChange = () => {}, + onChange = () => {}, height = 60, width = NaN, }: SquiggleChartProps) => { @@ -158,8 +157,8 @@ export const SquiggleChart: React.FC = ({ let expressionResult = run(squiggleString, samplingInputs); let internal: JSX.Element; if (expressionResult.tag === "Ok") { - onEnvChange(environment); let expression = expressionResult.value; + onChange(expression); internal = ( ); diff --git a/packages/components/src/components/SquiggleEditor.tsx b/packages/components/src/components/SquiggleEditor.tsx index 4ede7891..580db580 100644 --- a/packages/components/src/components/SquiggleEditor.tsx +++ b/packages/components/src/components/SquiggleEditor.tsx @@ -3,6 +3,7 @@ import * as ReactDOM from "react-dom"; import { SquiggleChart } from "./SquiggleChart"; import { CodeEditor } from "./CodeEditor"; import styled from "styled-components"; +import type { squiggleExpression } from "@quri/squiggle-lang"; export interface SquiggleEditorProps { /** The input string for squiggle */ @@ -22,7 +23,7 @@ export interface SquiggleEditorProps { /** The environment, other variables that were already declared */ environment?: unknown; /** when the environment changes. Used again for notebook magic*/ - onEnvChange?(env: unknown): void; + onChange?(expr: squiggleExpression): void; /** The width of the element */ width: number; } @@ -43,7 +44,7 @@ export let SquiggleEditor: React.FC = ({ diagramStart, diagramStop, diagramCount, - onEnvChange, + onChange, environment, }: SquiggleEditorProps) => { let [expression, setExpression] = React.useState(initialSquiggleString); @@ -69,7 +70,7 @@ export let SquiggleEditor: React.FC = ({ diagramStop={diagramStop} diagramCount={diagramCount} environment={environment} - onEnvChange={onEnvChange} + onChange={onChange} /> ); @@ -80,7 +81,7 @@ export function renderSquiggleEditorToDom(props: SquiggleEditorProps) { ReactDOM.render( { + onChange={(expr) => { // Typescript complains on two levels here. // - Div elements don't have a value property // - Even if it did (like it was an input element), it would have to @@ -96,10 +97,10 @@ export function renderSquiggleEditorToDom(props: SquiggleEditorProps) { // viewof env = cell('normal(0,1)') // to work // @ts-ignore - parent.value = env; + parent.value = expr; parent.dispatchEvent(new CustomEvent("input")); - if (props.onEnvChange) props.onEnvChange(env); + if (props.onChange) props.onChange(expr); }} />, parent diff --git a/packages/squiggle-lang/__tests__/ReducerInterface/ReducerInterface_Distribution_test.res b/packages/squiggle-lang/__tests__/ReducerInterface/ReducerInterface_Distribution_test.res index d4199f89..605797b9 100644 --- a/packages/squiggle-lang/__tests__/ReducerInterface/ReducerInterface_Distribution_test.res +++ b/packages/squiggle-lang/__tests__/ReducerInterface/ReducerInterface_Distribution_test.res @@ -20,6 +20,7 @@ describe("eval on distribution functions", () => { }) describe("unaryMinus", () => { testEval("mean(-normal(5,2))", "Ok(-5)") + testEval("-normal(5,2)", "Ok(Normal(-5,2))") }) describe("to", () => { testEval("5 to 2", "Error(Math Error: Low value must be less than high value.)") diff --git a/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/AlgebraicShapeCombination.res b/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/AlgebraicShapeCombination.res index d68a9623..39d68e6a 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/AlgebraicShapeCombination.res +++ b/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/AlgebraicShapeCombination.res @@ -232,13 +232,12 @@ let combineShapesContinuousDiscrete = ( i, ( fn(continuousShape.xs[i], discreteShape.xs[j]), - continuousShape.ys[i] *. discreteShape.ys[j] /. discreteShape.xs[j], + continuousShape.ys[i] *. discreteShape.ys[j] /. Js.Math.abs_float(discreteShape.xs[j]), ), ) |> ignore () } Belt.Array.set(outXYShapes, j, dxyShape) |> ignore - () } } @@ -246,12 +245,11 @@ let combineShapesContinuousDiscrete = ( |> E.A.fmap(XYShape.T.fromZippedArray) |> E.A.fold_left( (acc, x) => - XYShape.PointwiseCombination.combine( - (a, b) => Ok(a +. b), + XYShape.PointwiseCombination.addCombine( XYShape.XtoY.continuousInterpolator(#Linear, #UseZero), acc, x, - )->E.R.toExn("Error, unexpected failure", _), + ), XYShape.T.empty, ) } diff --git a/packages/squiggle-lang/src/rescript/Distributions/SymbolicDist/SymbolicDist.res b/packages/squiggle-lang/src/rescript/Distributions/SymbolicDist/SymbolicDist.res index 7ce95721..92249eae 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/SymbolicDist/SymbolicDist.res +++ b/packages/squiggle-lang/src/rescript/Distributions/SymbolicDist/SymbolicDist.res @@ -52,7 +52,7 @@ module Normal = { switch operation { | #Add => Some(#Normal({mean: n1 +. n2.mean, stdev: n2.stdev})) | #Subtract => Some(#Normal({mean: n1 -. n2.mean, stdev: n2.stdev})) - | #Multiply => Some(#Normal({mean: n1 *. n2.mean, stdev: n1 *. n2.stdev})) + | #Multiply => Some(#Normal({mean: n1 *. n2.mean, stdev: Js.Math.abs_float(n1) *. n2.stdev})) | _ => None } @@ -60,8 +60,8 @@ module Normal = { switch operation { | #Add => Some(#Normal({mean: n1.mean +. n2, stdev: n1.stdev})) | #Subtract => Some(#Normal({mean: n1.mean -. n2, stdev: n1.stdev})) - | #Multiply => Some(#Normal({mean: n1.mean *. n2, stdev: n1.stdev *. n2})) - | #Divide => Some(#Normal({mean: n1.mean /. n2, stdev: n1.stdev /. n2})) + | #Multiply => Some(#Normal({mean: n1.mean *. n2, stdev: n1.stdev *. Js.Math.abs_float(n2)})) + | #Divide => Some(#Normal({mean: n1.mean /. n2, stdev: n1.stdev /. Js.Math.abs_float(n2)})) | _ => None } }