aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2021-08-29 21:33:49 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2021-09-03 15:31:27 -0400
commite59d0ae5f3f6e339a8bcf131d6d68cf8c11e5ad1 (patch)
tree1d55df6518303ef4de373a06c9d0aadc3a6da71e
parent7f67a7d50ccc48e36babb7d3573ef504a5e1586d (diff)
Support trig inverses
-rw-r--r--docs/bqn.js18
1 files changed, 15 insertions, 3 deletions
diff --git a/docs/bqn.js b/docs/bqn.js
index f9fda18c..48c72f06 100644
--- a/docs/bqn.js
+++ b/docs/bqn.js
@@ -386,6 +386,11 @@ let [runtime,setPrims] = run(
,[[0,184],[4055,3],[4063,3],[4067,3],[4080,3],[4092,3],[4101,3],[4107,2],[4136,3],[4168,2],[4185,4],[4247,5],[4283,3],[4290,5],[4348,4],[4414,3],[4469,3],[4480,4],[4545,9],[4614,5],[4691,5],[4758,4],[4814,8],[4986,8],[5143,3],[5188,3],[5237,3],[5354,6],[5439,3],[5463,7],[5577,3],[5639,4],[5710,6],[5774,3],[5814,5],[5891,3],[5908,14],[6088,3],[6134,3],[6154,3],[6171,4],[6229,4],[6305,5],[6379,3],[6438,0],[6449,4],[6529,3],[6539,3],[6546,3],[6560,3],[6568,3],[6606,5],[6643,5],[6670,3],[6674,3],[6688,16],[6983,3],[7008,3],[7033,3],[7060,3],[7119,4],[7219,7],[7416,7],[7462,14],[7686,5],[7765,3],[7773,6],[7800,5],[7821,6],[7848,11],[8181,9],[8338,4],[8414,7],[8526,7],[8643,3],[8751,4],[8813,8],[8925,8],[8999,7],[9061,9],[9219,9],[9367,4],[9478,8],[9692,3],[9736,3],[9873,2],[9894,14],[10019,9],[10201,10],[10274,3],[10300,10],[10708,4],[10813,3],[10887,3],[10938,4],[11065,4],[11181,2],[11189,6],[11204,2],[11263,3],[11271,3],[11279,3],[11299,8],[11374,3],[11382,3],[11390,3],[11398,3],[11406,3],[11414,3],[11425,3],[11446,7],[11487,6],[11706,4],[11806,3],[11849,5],[11987,3],[12034,3],[12060,3],[12093,3],[12137,3],[12185,3],[12197,3],[12270,2],[12296,4],[12332,3],[12347,3],[12376,3],[12391,3],[12409,3],[12423,3],[12433,3],[12485,6],[12513,3],[12541,3],[12549,3],[12557,5],[12592,12],[12765,3],[12776,3],[12796,3],[12816,3],[12827,3],[12838,3],[12853,7],[12926,6],[12972,3],[12990,3],[12997,6],[13032,10],[13209,4],[13265,11],[13466,4],[13533,3],[13558,2],[13573,3],[13600,7],[13741,3],[13770,3],[13780,3],[13799,3],[13809,3],[13818,3],[13828,3],[13845,11],[13918,6],[14021,8],[14099,3],[14107,3],[14149,7],[14175,9],[14421,5],[14437,6],[14559,5],[14592,6],[14621,3],[14631,3],[14641,4],[14680,4],[14703,3],[14711,3],[14736,6],[14832,2],[14882,8],[15063,11],[15268,3],[15327,3],[15354,3],[15371,3],[15388,8],[15570,3],[15584,3],[15615,2],[15649,3],[15684,3],[15705,3],[15726,5],[15797,3],[15817,8],[16047,3],[16115,3],[16145,3],[16176,3],[16210,5],[16277,3],[16286,3],[16299,3],[16303,3],[16311,3],[16321,2],[16335,2],[16350,6],[16444,3],[16454,3],[16461,9],[16595,3],[16621,3],[16639,3],[16663,3],[16684,3],[16695,3],[16708,2],[16712,3],[16748,5],[16850,3],[16897,5],[16920,3],[16937,14],[17221,13],[17418,3],[17461,4],[17544,3],[17580,3],[17609,3],[17620,4],[17656,7],[17793,10],[17983,6],[18018,3],[18083,3],[18111,4],[18134,5],[18145,4],[18156,4],[18167,5],[18187,4],[18262,3],[18295,3],[18325,5],[18350,3],[18416,3],[18430,3],[18441,5],[18540,4],[18669,3],[18693,3],[18739,3],[18772,3],[18801,5],[18833,3],[18869,3],[18895,3],[18923,3],[18945,5],[18955,3],[18988,3],[19008,6],[19023,2],[19031,2],[19039,5],[19077,3],[19087,3],[19103,5],[19154,3],[19179,6],[19288,3],[19328,3],[19369,5],[19419,6],[19556,3],[19564,8],[19621,5],[19650,3],[19665,3],[19715,2],[19733,3],[19754,3],[19772,3],[19801,3],[19820,3],[19839,6],[19918,5],[19933,14],[20097,3],[20118,3],[20134,4],[20190,3],[20222,3],[20305,3],[20339,3],[20368,3],[20385,3],[20402,3]]
);
+// Allow inverses defined in JS
+let undo0 = runtime[48];
+runtime[48] = f => f.inverse || undo0(f);
+runtime[48].m = 1;
+
let rtAssert = runtime[42] = assertFn("!");
runtime.map((r,i) => { r.prim = i; });
let decompose = x => list(!isfunc(x) ? [-1,x] : has(x.prim) ? [0,x]
@@ -551,11 +556,18 @@ let primitives = dynsys(state => {
return list(gl.map((g,i) => list([g,rt[i]])));
});
+let trig = "cos cosh sin sinh tan tanh".split(" ");
+let mathns = obj2ns(Math,
+ trig.concat(trig.map(n=>"a"+n),"LN10 LN2 LOG10E LOG2E cbrt expm1 hypot log10 log1p log2 round trunc atan2".split(" ")),
+ f=>typeof f==="function"?runtime[60](f,0):f
+);
+trig.map((_,i)=>{let f=mathns[i],g=mathns[i+trig.length]; f.inverse=g; g.inverse=f;});
+
let sysvals = {
- bqn:dynsys_copy(makebqnfn("•BQN",r=>run(...r))), rebqn, primitives, js:dojs,
+ bqn:dynsys_copy(makebqnfn("•BQN",r=>run(...r))), rebqn, primitives,
type, glyph, decompose, fmt:fmt1, repr, unixtime, listkeys,
- listsys: dynsys(_ => list(Object.keys(sysvals).sort().map(str))),
- math: obj2ns(Math,("LN10 LN2 LOG10E LOG2E cbrt expm1 hypot log10 log1p log2 round trunc atan2 cos cosh sin sinh tan tanh").split(" "), f=>typeof f==="function"?runtime[60](f,0):f)
+ js:dojs, math:mathns,
+ listsys: dynsys(_ => list(Object.keys(sysvals).sort().map(str)))
};
let make_timed = tfn => {