merge Reducer

This commit is contained in:
Umur Ozkul 2022-06-23 03:36:57 +02:00
parent 7b2c16d90f
commit 95d3bf6eaa
3 changed files with 21 additions and 4 deletions

View File

@ -80,6 +80,7 @@ describe("eval on distribution functions", () => {
testEval("truncateLeft(normal(5,2), 3)", "Ok(Point Set Distribution)") testEval("truncateLeft(normal(5,2), 3)", "Ok(Point Set Distribution)")
testEval("truncateRight(normal(5,2), 3)", "Ok(Point Set Distribution)") testEval("truncateRight(normal(5,2), 3)", "Ok(Point Set Distribution)")
testEval("truncate(normal(5,2), 3, 8)", "Ok(Point Set Distribution)") testEval("truncate(normal(5,2), 3, 8)", "Ok(Point Set Distribution)")
testEval("isNormalized(truncate(normal(5,2), 3, 8))", "Ok(true)")
}) })
describe("exp", () => { describe("exp", () => {

View File

@ -2,4 +2,5 @@ module Module = Reducer_Category_Module
let internalStdLib = Module.emptyModule->SquiggleLibrary_Math.makeBindings let internalStdLib = Module.emptyModule->SquiggleLibrary_Math.makeBindings
@genType
let externalStdLib = internalStdLib->Module.toTypeScriptBindings let externalStdLib = internalStdLib->Module.toTypeScriptBindings

View File

@ -1,8 +1,23 @@
module Bindings = Reducer_Category_Module module Bindings = Reducer_Category_Module
module Module = Reducer_Category_Module module Module = Reducer_Category_Module
let m = let availableNumbers: array<(string, float)> = [
Module.emptyModule->Module.defineNumber("pi", Js.Math._PI)->Module.defineNumber("e", Js.Math._E) ("pi", Js.Math._PI),
("e", Js.Math._E),
("ln2", Js.Math._LN2),
("ln10", Js.Math._LN10),
("log2e", Js.Math._LOG2E),
("log10e", Js.Math._LOG10E),
("sqrt2", Js.Math._SQRT2),
("sqrt1_2", Js.Math._SQRT1_2),
("phi", 1.618033988749895),
("tau", 6.283185307179586),
]
let makeBindings = (previousBindings: Module.t): Module.t => let mathBindings: Bindings.t =
previousBindings->Bindings.defineModule("Math", m) availableNumbers
->E.A2.fmap(((name, v)) => (name, ReducerInterface_InternalExpressionValue.IevNumber(v)))
->Bindings.fromArray
let makeBindings = (previousBindings: Bindings.t): Bindings.t =>
previousBindings->Bindings.defineModule("Math", mathBindings)