davidedc / algebrite Goto Github PK
View Code? Open in Web Editor NEWComputer Algebra System in Javascript (Typescript)
Home Page: http://algebrite.org
License: MIT License
Computer Algebra System in Javascript (Typescript)
Home Page: http://algebrite.org
License: MIT License
simplify(sqrt(x*y))
gives x^(1/2) y^(1/2)
(incorrect: counterexample x = -1 and y = -1)
simplify(sqrt(1/x))
gives 1 / x^(1/2)
(incorrect: counterexample x = -1)
simplify(sqrt(x^y))
gives x^(1/2 y)
(incorrect: counterexample x = -1)
the last case includes the example: simplify(sqrt(x^2))
which gives x
instead of abs(x)
see https://en.wikipedia.org/wiki/Square_root#Principal_square_root_of_a_complex_number
Currently doing 50000^100000 or 30000! will cause the CAS to hang, but if exponentiation approximation by logarithms and Stirling's factorial approximation are implemented, the CAS should be able to handle those big numbers.
x^y ~= 10^(y * log10(x))
if y * log10(x) is a non-integer number, we can approximate the number by
10^(fractional part) * 10^floor(y*log10(x))
The exponential part can then be expressed symbolically.
eg. 50000^70000 could then be displayed as ~= 7.9488357 * 10^328927
Algebrite.run("integral(x^2/(a+b*x))")
"-a x / b + 1/2 x^2 - 3 a^2 / (2 b^2) + a^2 log(b x + a) / (b^2)"
A possible correct answer (from GeoGebra) is
(((1 / 2 * b) * x^(2)) - (a * x)) / b^(2) + (a^(2) * log(abs((b * x) + a)) / b^(3))
which differentiates to the correct expression (also has log(abs()))
Algebrites answer has an extra factor of b when differentiated
(b * x^(2) / (a + (b * x)))
http://www.wolframalpha.com/input/?i=derivative+of+-a+x+%2F+b+%2B+1%2F2+x%5E2+-+3+a%5E2+%2F+(2+b%5E2)+%2B+a%5E2+log(b+x+%2B+a)+%2F+(b%5E2)
(bug found by running list of Algebrite's standard integrals through GeoGebra/Giac and comparing, I can share the script once I've debugged it a bit 😄 )
On the algebrite.org site, if I enter (using the Arbitrary-precision arithmetic box):
log(1.99999999)
log(2.0)
log(2)
log(2.00000001)
log(3)
sin(0)
then I get
0.693147
0.693147
log(2)
0.693147
log(3)
0
I get the same effect if I construct the equation programmaticly in JS. Looks like log isn't recognising 2 as a number?
Hi,
I'm probably being very silly somewhere but I can't figure out how to multiply 2 matrices. I tried this :
Algebrite.run('A=[[a,b],[c,d]]');
Algebrite.run('C=[[x],[y]]');
Algebrite.run('A*C')
and got this:
[[x],[y]] [[a,b],[c,d]]
That looks like the two different matrices have been output?
Also, it would be super if the documentation could reflect the current version on Github!
Thanks and Regards
Anurup
Algebrite.run("integral(1/x^3*1/sqrt(x^2-4))")
"1/16 arcsec(1/2 x) + (x^2 - 4)^(1/2) / (8 x^2)"
arcsec isn't defined in Algebrite. Also arcsec is a pretty rare/unusual function so an answer in terms of atan() might be more useful eg
sqrt(-a+x^2)/2/a/(-a+x^2+a)+1/a/2/sqrt(a)*atan(sqrt(-a+x^2)/sqrt(a))
and there are a couple of other integrals that use arcsec.
Hey
I am using this library included from src not with node js or anything.
I am trying to figure out how to use the method printlatex but as here I alwayse get "nil":
console.log(Algebrite.printlatex('a+b=c').toString());
How to use this function?
Best
Markus
subst( u, (x*y*z + x*y), (x*y*z + x*y) + x )
returns x y z + x y + x
I'd expect it to return x + u
With algebrite 1.0.0, this evaluates to 0
and(([1,2])==([3,4]),1)
Now it evaluates to 1.
Looks like it broke with ce4220a
Hey there I just want to ask how to write an own function?
What I did is:
I wrote my own coffeescript: string2array.coffee:
string2array = (hal)->
console.log hal
console.log JSON.parse(hal)
JSON.parse(hal)
In the runtime/defs.coffee: (I added:)
string2array = counter++
In the runtime/init.coffee: (I added:)
std_symbol("size", string2array)
In the runtime/zombocom.coffee (I added:)
builtin_fns = ["string2array"]
Now I tried to build it (npm run build):
[email protected] build /home/markus/Desktop/Algebrite-master
cat runtime/defs.coffee sources/*.coffee runtime/alloc.coffee runtime/find.coffee runtime/init.coffee runtime/mcmp.coffee runtime/otherCFunctions.coffee runtime/count.coffee runtime/run.coffee runtime/stack.coffee runtime/symbol.coffee runtime/zombocom.coffee runtime/lrucache.coffee runtime/freeze.coffee | coffee -sc > dist/algebrite.js[stdin]:23406:17: error: unexpected
Substitute new expr for old expr in expr.Input: push expr
push old expr push new expr
Output: Result on stack
JSON.parse(hal)###
^^^
npm ERR! code ELIFECYCLE
npm ERR! errno 1
[...]
Getting the above error.
Any ideas how to solve this?
I would use the Algebrite libray and understand more of it. Would appreciate if sb could explain how to add new coffee scripts
Algebrite.run("(integral(arccos(x)))")
"(-x^2 + 1)^(1/2) + x arccos(x)"
Should be
-sqrt(-x² + 1) + x arccos(x)
Hi!
I've not found this information in the doc files: how to compare two numbers, for instance, 1/2 and 1/3?
Thanks!
User functions deleted after a “Stop” in “integral” function
In the next example, the function "testFunction" is woirking until the Stop message.
----- INPUT ----
testFunction(a,b)=a+b
testFunction(8,9)
integral(x)
testFunction(8,9)
integral(1/(x^6+b^6))
testFunction(8,9)
----- OUTPUT ----
17
1/2 x^2
17
Stop: integral: sorry, could not find a solution
testFunction(8,9)
I tested the same input in Eigenmath and the result was:
----- OUTPUT ----
17
1/2*x^2
17
Stop: integral: sorry, could not find a solution
17
Thanks,
Hey There i wonder if its is possible to set and get a vector within a matrix with algebrite
I just found getting an entry within a matrix with cofactor.....
what I want is something like: getRowVectorofMatrix(Matrix,Row) and the same for Columns
a getter and a setter this would be a really nice feature for me.
Best
Markus
Algebrite.run("integral(x^(-1))")
"log(x)"
Algebrite.run("integral(1/x)")
"log(x)"
There is some weird things going on with getting the floating point value of cos and sin, for example float(sin(2)) = 0. I tried to debug this, but the source is hard to read.
simplify((x^2-x*y)/(x*y-y^2))
outputs x (x - y) / (-y^2 + x y)
while it should probably be x/y
. However if we factor the numerator with factor((x^2-x*y))
we obtain x (x - y)
, which is fine.
What am I doing wrong?
Thank you,
Pedro
Greetings Davide -
First, I want to thank you for Algebrite. It is brilliant.
Second, I want to introduce you to a project I am developing which is leveraging Algebrite called the GEOMETOR Explorer - a browser-based graphics and animation engine for exploring classical constructive geometry and documenting instances of Golden Sections with algebraic proofs.
It's all on Github right here: https://github.com/i-am-phi/geometor-explorer
A fairly descriptive readme is developing in the project so I won't reproduce that here.
I am hoping to gain your interest at whatever level you desire. I see from your website that you are an artist as well as an engineer. I am an architect - not a mathematician - but also a solution developer. I think we would have some very interesting conversations.
Algebrite is working incredibly well - but it seems that some values are not simplifying correctly when the constructions get more complex. I have an additional file in the project - Root 3 B - where the last line (12) is getting munged from the points.
I am using ALgebrite to create line and circle equations from the points, then subtracting/substituting these equations from each other to determine the intersection points. Your insight on how to best approach this scenario would be tremendous.
I am preparing to host this on Geometor.com along with a tremendous amount of content I have been developing over the years.
I hope to hear from you.
In the docs to derive a function you have to use Algebrite.d(...)
. The thing is that in practice what actually works is Algebrite.derivative(...)
. Point me in the right direction and I can send in a Pull Request.
Hello, don't know if this is an issue with the latex expressions generated, butI havn't found a workaround (I'm using the latest bundle-for-browser js):
let's say I have: 2/x
and I want to obtain this at the power of 3
so in the end I want latex for (2/x)^3
(I'm making it a two step operation beacause I need to substitute first, it's not really necessary for the issue a hand, you can replicate it with a single string)
I run this in my script:
Algebrite.run("printlatex("+A+")")
but I end up with an unnecessary parenthesis:
It's possible to get rid of the extra parentheses? It isn't much, and it doesn't affect the algebra, but it's a bit annoying to see and aesthetic is paramoount in my project.
But there's more: I'm not the first to have problems with the fact that blocking simplification when parsing to latex isn't so easy (I've found some posts, but only a few... maybe I'm not the first but surely one of the few). With the former example, what if I'd like to obtain the fraction inside \left( and \right) (latex-y speaking)? Hoping the image upload will work, something like this:
Any help much apreciated, and thanks for the great library! Calcolus and other features are really great for my project
I'm trying to generate an isosurface, and right now I'm running the same expression, with replaced variables 15000+ times. Is there any way to optimize this call:
Algebrite.eval(eq, "a", a, "b", b)
Thanks for all your work.
numerically solve expression by assigning values to symbols: we can now pass additional expressions to eval() or run() to do that:
Algebrite.run('x^2+y^2', 'x=2', 'y=3') // => 13
It'll be great if it can be done also like math.js do:
Algebrite.run('x^2+y^2', { x: 2, y: 3 })
Hi
I am creating an application using Algebrite and I want to save the scope containing the declared variables and functions. The problem is that I can’t find that object.
When someone runs something like ‘x=10’ in Algebrite, in which object is stored?
Thank you, Algebrite is great.
The latest version isn't on NPM (last version 5 months ago). Took me a while to realize why toLatexString() didn't work.
A=[[0],[1]]
B=[[-4 / (-2 - 5 s + s^2) + s / (-2 - 5 s + s^2),2 / (-2 - 5 s + s^2)],[3 / (-2 - 5 s + s^2),-1 / (-2 - 5 s + s^2) + s / (-2 - 5 s + s^2)]]
B*A
Gives me:
[[0],[1]] [[-4 / (-2 - 5 s + s^2) + s / (-2 - 5 s + s^2),2 / (-2 - 5 s + s^2)],[3 / (-2 - 5 s + s^2),-1 / (-2 - 5 s + s^2) + s / (-2 - 5 s + s^2)]]
Actually this is NOT what I expected.....
I just tested this example on http://algebrite.org/#Matrices,%20tensors
Hope someone can help me - what do I wrong?
How to use Algebrite to multiplicate matrices and vectors?
A more simple example:
C=[[0,1]]
B=[[0],[1]]
C*B
[[0,1]] [[0],[1]]
Hi Davide,
There is some problem below:
a=require('algebrite');
s = "3x/(x^2+2) - 2/(x-1) - 4";
a.denominator(s) // works.
s = "(2x-5)*(3x-3)*(x+4) / (x^2-5) + (x-5)*(2x-3)*(2x+5) / (x^2+3x-2) + 2x - 3";
a.denominator(s) // doesn't work.
Hi Davide,
I'm from Brazil.
Great job! Symbolic integral is so cool.
I'm kind of novice in Node.js, therefore I apologize in advance for my probably silly question
I'm trying to use Algebrite in the browser without success. I would not like to depend on tools like Browserify and use the Algebrite functions only within that file. I would like to directly use Algebrite functions in external code without having to transpile. In short, I would like to use Algebrite as a black box. I've been able to do this with some Node.js modules, such as Math.js and Poly-roots.js, but looking at algebrite.js or _algebrite.bundle-for-browser.js, I cannot have a clue how use the functions like numerator, etc.
This doesn't work:
Algebrite.run("expand((sin(x)+1)^2)")
"Stop: divide by zero"
Minimal test case:
Algebrite.run("expand(sin(x))")
"Stop: divide by zero"
I'm trying to do the following: have an input box where a user can enter a string to be evaluated. When the user presses enter, the user's string will be parsed to LaTeX, followed by an equal sign, followed by the Algebrite evaluation of the string. (For example, if the user enters x*x then the output would be x \cdot x = x^2.)
The evaluated part is easy with the printlatex() function. I'm having trouble with the left-hand side of the equation. I'm currently using Alegbrite.run(`printlatex(quote(${inp}))`) which works well for many cases, but doesn't quite do what I'd expect in others. For example, entering [[1,2],[3,4]]^2 does not make the LHS of the equality a 2x2 matrix with a superscript-2. Is there a ready-made API function that I could use to essentially just parse a user input string without evaluating it first? (E.g., a sister to printlatex but without evaluation.)
Algebrite input = integral(x*sqrt((-9)-x^2))
Algebrite output = -1/3 (-x^6 - 27 x^4 - 243 x^2 - 729)^(1/2)
js giac input:evalfa(regroup(integrate((x)*(sqrt((-(9))-((x)^(2)))),x)))
js giac output:-1/3*sqrt(-x^2-9)*(-x^2-9)+c_24
Algebrite's answer differentiates to
((-x) * sqrt((-x^(2)) - 9))
rather than
(x * sqrt((-x^(2)) - 9))
(I think... please check 😄 )
The sum
function is listed in the Algebrite function reference, but doesn't appear to have an implementation yet.
The function reference says:
sum(i,j,k,f)
For i equals j through k evaluate f. Returns the sum of all f.
But when I execute the following code in nodejs
var Algebrite = require('algebrite');
Algebrite.run('sum(n,1,6,x^n)');
I get the error message
'Eval_sum is not defined'
By contrast, if I execute the same expression in eigenmath, I get the following results:
$ ./math
> sum(n,1,6,x^n)
6 5 4 3 2
x + x + x + x + x + x
My goal is to be able to evaluate even more complicated expressions such as
sum(k,2,12,coeff((sum(n,1,6,x^n))^2,x,k))
which should return 36.
Thanks!
Algebrite chokes on parsing any expression with a unicode greek letter. EG: 3*γ
npm installed a few days ago
var a=require('algebrite') ;
e=a.parse('(x+1)*(x+2)')
U {
cons:
{ car: U { cons: [Object], q: rational {}, k: 5, printname: 'multiply' },
cdr: U { cons: [Object], q: rational {}, k: 0 } },
q: rational {},
k: 0 }
a.expand(e)
ReferenceError: isone is not defined
at expand (/home/mike/solver/client/node_modules/algebrite/dist/algebrite.js:5756:9)
at expand (/home/mike/solver/client/node_modules/algebrite/dist/algebrite.js:5739:9)
at Eval_expand (/home/mike/solver/client/node_modules/algebrite/dist/algebrite.js:5721:12)
at Eval_cons (/home/mike/solver/client/node_modules/algebrite/dist/algebrite.js:5205:16)
at Eval (/home/mike/solver/client/node_modules/algebrite/dist/algebrite.js:5061:9)
at fixed_top_level_eval (/home/mike/solver/client/node_modules/algebrite/dist/algebrite.js:16620:5)
at exec (/home/mike/solver/client/node_modules/algebrite/dist/algebrite.js:16591:7)
at repl:1:3
at REPLServer.defaultEval (repl.js:262:27)
at bound (domain.js:287:14)
I cloned the repo, I notice that in algebrite.bundle-for-browser.js there is:
.... isnpi, isnum, isone, isoneover, ....
in the var list near the beggining, while in dist/algebrite.js is:
.... isnpi, isnum, isoneover, ....
ie., isone is missing
Hey,
Algebrite.dot("[[2,2],[2,2]]","[[0],[1]]").toString() gives:
Error: Stop: inverse of singular matrix
So this is actually not correct!
any ideas how to solve that?
Best
Markus
1111 * 1111.0 = 1234320.0
In javascript the result is 1234321. What's going on here?
I can't find the documentation of the functions in the Algebrite
object, I mean the ones that are not available in the scripting language and therefore already documented in the functions reference here. Maybe is somewhere I can't find.
For example, run()
, eval()
and clear()
functions are not documented. I guessed that run()
is equivalent to eval(...).toString()
, and I found myself the existence of the clear()
function, which is pretty needful I think.
More, it is not documented if there's a way to numerically solve expression by assigning values to symbols, and I accidentally found that I can pass additional expressions to eval()
or run()
to do that:
Algebrite.run('x^2+y^2', 'x=2', 'y=3') // => 13
It'll be great if it can be done also like math.js do:
Algebrite.run('x^2+y^2', { x: 2, y: 3 })
Is it possible to do a partial fraction expansion with Algebrite?
e.g.:
2 / (394 - 50 s + s^2 ) = A/(s+s_1) + B/(s+s_2)
and A,B, s1, s2 should be calculated of course.
Markus
Algebrite.run("derivative(integral(arctanh(x)))")
"Stop: integral: sorry, could not find a solution"
Algebrite.run("derivative(integral(arcsinh(x)))")
"Stop: integral: sorry, could not find a solution"
Algebrite.run("derivative(integral(arccosh(x)))")
"Stop: integral: sorry, could not find a solution"
I am trying to turn the result of Algebrite.simplify('x+x+x')
into a string. I thought Algebrite.print()
might do that, but it fails, throwing the exception "ReferenceError: Eval_display is not defined".
Some background:
What I am actually trying to accomplish is testing whether two expressions (this could be equations, too) are equivalent to each other. I was using Algebrite.run(expr1) == Algebrite.run(expr2)
, but this has side effects and does not work for equations or inequalities. I thought simplify
might be the better way to go.
see jiggzson/nerdamer#219 . Very much worth adding the examples that work OK in the test suit.
Hi Davide,
Look at the lines below:
var a=require('algebrite');
var expr="(2x-5)*(3x-3)*(x+4)";
var exprS = a.simplify(expr).toString();
console.log(exprS); // display 3 (2 x^3 + x^2 - 23 x + 20)
console.log(a.expand(exprS).toString()); // display nil
exprS = exprS.charAt(0) + "*" + exprS.slice(1); // put a "*" between 3 and the rest
console.log(a.expand(exprS).toString()); // display 6 x^3 + 3 x^2 - 69 x + 60
Simplify produces a expression with implicit multiplication ("*") but expand does not accept it.
I believe that the best approach would be expand come around to accepting implicit multiplication.
Hi,
I could not see any obvious (read straight-forward) method to create an augmented matrix - either by adding a block of rows OR a block of columns.
This would be invaluable.
Thanks and Regards
Anurup
Please allow execution in expression editors with Shift+Enter like in Messengers.
thanks for the useful software.
Enter "roots(2^x - y, y)" into the sandbox and it hangs. This doesn't occur in the desktop Eigenmath.
e.g. roots(x+0.2x^2=0) -> will not work (Error: Stop: roots: 1st argument is not a polynomial)
however roots(5x+x^2=0) works.[-5,0]
algebrite seems to sort function calls and variables alphabetically, e.g.
a log(x) + sin(x) y
instead of
a log(x) + y sin(x)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.