Comments (12)
Try this:
/\^\s*((?:\d{5,}(?:\.\d*)?)|(?:\d{5,}?(?:\.\d*)))/g
from algebrite.
Sounds good. I wonder whether this approximation should only happen with float() (or when a float appears in the expression, which triggers numeric evaluation too). Once that happens though, since floats are "toxic", all results would be numeric from then on, we'd need a way to promote a float into a non-float in case one wants to use the result in non-numeric ways. There is a routine I'm working on to guess a symbolic form for a float, could use that.
from algebrite.
@davidedc do you know of the PSLQ Algorithm? That is very powerful way to "guess" the float -> exact conversion eg (sqrt(2)+1)/2, pi^2+1
http://mathworld.wolfram.com/PSLQAlgorithm.html
from algebrite.
yes eventually that's the ambition. For step 1, there is a surprising lot that can be guessed with quick and un-elegant trial and error routines. If anyone wants to take on PSLQ though...
from algebrite.
in fact approxratio(7.9488357 * 10^328927)
already works (gives 24236/3049*10^328927
). Works in zeno branch, I don't think it works in master yet. (In fact I think Michael @murkle gave me pointers to approxratio routine).
from algebrite.
This does not need to be a float, since 10^(fractional part) eg. 10^(0.8542786512636754831467...) can be done very fast, even as a bignumber. Does Algebrite currently support choosing the precision for logs and exponentiation?
from algebrite.
Something like this works for me right now...
const Algebrite = require("Algebrite");
const exp = "90000000^8000000";
let result = "";
if (exp.search(/\^\d\d\d\d\d/) > -1) { //if the exponent is bigger than 9999.
//matches any string that contains ^nnnnn
console.log("Infinite precision arithmethic would take too long, falling back to approximation.")
const base = exp.slice(0, exp.indexOf("^"));
const exponent = exp.slice(exp.indexOf("^")+1, exp.length);
const exponentb10 = Math.log10(base) * exponent;
const significand = Math.pow(10, exponentb10%1); //This part can allow choosing precision by using bignumber
const base10 = Math.floor(exponentb10);
result = significand + "e" + base10;
} else {
result = Algebrite.run(exp).toString();
}
console.log(result); //Outputs 1.1899113297459072e63633940
from algebrite.
@bloc97 nice, I'll use this under MIT and credit if it's OK.
Yes sorry by float I mean: Algebrite goes into "numeric" mode (using JS Numbers) only when the expression contains a float() call or contains a number with a decimal point plus a few other cases such as when using nroots. Otherwise, it returns symbolic results (which are expression trees containing rationals as long-integer num/denom pairs, constants such as PI and E and all the operations such as SQRT etc.).
So I'm thinking this approximation should probably only kick-in when doing something like float(90000000^8000000)
or 90000000.0^8000000.0
or analogous, and left as-is (unevalled) otherwise.
No there is no arbitrary precision in numerical calculations (yet), floats are just JS Numbers at the moment (i.e. the 64 bits floats sometimes called doubles).
from algebrite.
Sure, but the regex was hacked in and not really robust, if someone typed in 500 ^ 60000 it wouldn't work, and it would also break if someone did 500^500^500000, so it would be best to parse the input and simplify it as one single operation before doing regex.
Perhaps you already have a solution to this within Algebrite itself?
from algebrite.
ah yes sure. I think that a check when evalling the exponential operator should be enough, I'll try something.
from algebrite.
just to give a heads up: while the regex solution works great for the routine above that lives "outside" of the Algebrite core, the solution from "within" the Algebrite core will just check the size of the two numbers with the available bigint comparison operators (or the existing rational number comparison operators)
from algebrite.
Even better :)
from algebrite.
Related Issues (20)
- Returning numerical values
- nroots and roots do not work for polynomials with non-integer coefficients
- Solving Boolean expressions
- Solving systems of equations
- Absolute value syntax errors
- Solving equations involving fractions
- Simplify
- GUI for user to edit/enter the equation in HTML
- Testing equivalance could be more smart, easily
- Update NPM version
- cann't simpifay apk
- the order of the powers of the polynomial is reversed HOT 1
- How to solve equations? HOT 2
- How to identify if an expression given by a human is in its simplified form HOT 4
- Is there some kind of AST ? HOT 1
- draw function is needed HOT 1
- Can't return numerical results < 1e-6. Can't substitute variables with scientific notation
- Infinite loop when try to inverse a 1x1 matrix
- Computation of binomial
- Display order of polynomial monomials
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from algebrite.