-
-
Notifications
You must be signed in to change notification settings - Fork 30
API
Arthur Guiot edited this page Feb 20, 2018
·
3 revisions
This a temporary document. ( A lot of functions are missing, check out our test file or our code to have a better idea of TheoremJS)
const t = require("theorems.js")
/* List of functions */
/* Array Manipulation */
// Flatten
t.flatten([
[1, 2],
[3, 4], 5
]) // => [1, 2, 3, 4, 5]
// Linspace
t.linspace(0, 100, 10) // => [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
// Range
t.range(10) // => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
// Reshape
t.reshape(t.range(10), 2) /* => [
[0, 1],
[2, 3],
[4, 5],
[6, 7],
[8, 9],
[10]
]) */
/* Math */
/* Algebra */
// Function
t.f("x", "2*x+1") // => TheoremJS function object
// Run
t.run(f, x) // = f(x)
// Polynomial
t.polynomial(2, 1) // f(x) = 2x + 1
t.polynomial(3, 2, 1) // f(x) = 3x^2 + 2x + 1
// Find Roots
t.findRoots(t.polynomial(1, -1, -1)) // => ['(1 + Math.sqrt(5)) / 2', '(1 - Math.sqrt(5)) / 2']
// Numeral Solve
t.numeralSolve(t.f("x", "2*x+1"), 0) // => ['-0.5', 0] , Returns -0.5 with 0 error rate
// Y-Intercept
t.y_intercept(t.f("x", "2*x+1")) // => 1
/* Math Basic functions */
// Factorial (returns a BigNumber object)
t.factorial(5).toNumber() // => 120
// Pow (returns a BigNumber object)
t.pow(2, 8).toNumber() // => 256
// Root (returns a BigNumber object)
t.root(256, 8).toNumber() // => 2
// Sqrt (returns a BigNumber object)
t.sqrt(4).toNumber() // => 2
// Sigmoid (returns a BigNumber object)
t.sigmoid(0).toNumber() // => 0.5
/* Number Theory */
// Pi (returns a BigNumber object)
t.pi().toNumber() // => 3.14159265358979
// e (returns a BigNumber object)
t.e().toNumber() // => 2.71828182845905
// Golden Ratio (returns a BigNumber object)
t.goldenRatio().toNumber() // => 1.61803398874989
// Constants (returns a BigNumber object)
t.c("pi") // => 3.14159265358979
t.c("e") // => 2.71828182845905
t.c("goldenRatio") // => 1.61803398874989
t.c("sqrt(2)") // => 1.4142135623730951
t.c("EulerGamma") // => 0.577215664901533
t.c("UltimateAnswer") // => 42
// isPrime
t.isPrime(31013) // => true
// Round
t.round(3.1415926535897, 2) // => 3.14
/* Other */
// Apply
t.apply(2, x => 2 * x) // => 4
// Min, Max & Sort
t.min(1, 3, 2) // => 1
t.max(1, 3, 2) // => 3
t.sort(1, 3, 2) // => [1, 2, 3]
// Product (returns a BigNumber object)
t.product(1, 3, 2).toNumber() // => 6
// Sum (returns a BigNumber object)
t.sum(1, 3, 3).toNumber() // => 7
Any questions? Don't hesitate to create an issue and tell me about your problem 😊.
Copyright © 2017-2018 Arthur Guiot