-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fractions #84
Comments
Yes, very nice. Working with ratios is one way to maintain arbitrary precision. Like Ratio.js. |
This would be very nice, I would see rational as another type i.e. like complex, matrix. We have big numbers and having rationals will mean we cover any (pretty much, except VERY BIG numbers) rational number. What could one want more for complete happiness? |
Binary, hexadecimal, octal numbers :D |
Algebraic numbers! That is, a way to recognize that 1,41421… = √2 "Simpler" version: Recognizing only numbers that satisfy a^n = m and (where n and m are integers), and rewriting these numbers to the format ∛42 (or whatever) More difficult (and complete) version: Recognizing numbers that could also be 2 + √5 – ∛42, or so. (That is, all numbers that satisfy a polynomial equations P(x) = 0, and express these as radicals to an arbitrary power.) The more complete version is, I think, very difficult to achieve – even from a math theory perspective. I also think that the simpler version covers 99% of the use cases. |
Another note: I don't think the complexity of Ratio.js is necessary here. As far as I'm concerned, I only need to know if a decimal number equals a reasonable simple fraction, or a reasonably simple radical. No need to maintain extreme precision in calculations. (In this case, "reasonable simple fraction" could be interpreted as a fraction where the denominator is less than 1000, and a "reasonable simple radical" could be up to the 10th root. Or so.) |
Yes, support for symbolic computation would be great. |
I would strongly agree with Itangalo, a basic fractions component to math.js would significantly improve math.js :) |
I think the best way to implement this is to add another type for fractions( ratios), like we do with complex numbers. Then we could another type for symbolic computation. This way these types will maintain closed ecosystems for all the supported operations within and also bridges will allow cross type computation. Something similar we have for bignumber and standard numbers currently |
I agree with you @husayt Before we introduce more data types, I would love to introduce a modular approach to data types. I want to split functions in separate, decoupled sub-functions, each handling one data type, and make an easy way to describe relations and conversion rules to deal with cross type computations. We should be able to split math.js in standalone packages for Matrix, BigNumber, Unit, etc. |
As usual, whenever I think I came with good idea, Jos just comes with even Looking forward. Thanks
|
Ha ha. That's not really true, you and others bring up a lot of good ideas, like this symbolic computation, which will be really cool. Without you guys this library would be far from as good as it is right now, and there is still tons of good ideas waiting to be implemented :). Regarding a modular structure: see also #71 |
Meanwhile, this might be a useful addition to math.js.
This function prints any decimal number in its simplified fraction format.
to test input this method into http://www.numerics.info/scripts and try in calculator. Also, very useful simplify fractions method:
the code is:
|
Thanks, these are some nice, little functions. The function names should not collide of course with future functionality. |
Hi Jos, congratulations with recent launch of 1.0 version. Now that work is going towards 2.0 I was wondering if there are any plans for fractions. Would be good to know your thinking on this. Thanks |
Thanks Huseyn :) See my comment here regarding number base conversions, same holds for fractions, which would be great to have. |
Jos, I was thinking about implementing this myself and it's not as simple as it seems. The easiest part is to convert number to fraction, the difficulty start is when you want to use these fractions in expressions. It appears we need another type (like bignumber, complex number), call it fraction or rationalNumber. If expression has a fraction in it then result of operations and should be also a fraction. Only then we would get exact right answer for the following simple expression and alike: Do you have any hints, if I want to introduce this type? Thanks |
yes indeed. I think we can integrate Ratio.js similarly as Decimal.js is integrated right now for bignumber support. |
What about fractions with BigIinteger numerators/denominators or may be even with polynomials in numerator/denominator - http://en.wikipedia.org/wiki/Rational_function ? |
That would be great. I too want to implement BigNumber support for Unit, that would be similar to BigNumbers in Fractions. |
I've implemented support for fractions in the docs: https://github.com/josdejong/mathjs/blob/v2/docs/datatypes/fractions.md There is one thing I'm not yet certain about: what should be the default notation when formatting a fraction using var a = math.fraction(2, 3);
console.log(math.format(a)); // Fraction, 2/3
console.log(math.format(a, {fraction: 'ratio'})); // Fraction, 2/3
console.log(math.format(a, {fraction: 'decimal'})); // Fraction, 0.(6) Which value should be the default for option |
THIS IS AMAZING NEWS. My most missing feature is not missing anymore. Thank you Jos. I think ratio notation should be default, as not everything can be expressed as decimal. |
:) It was cool to implement, it's now very easy in I agree with you that |
This is so nice, I can't wait to v2 release. We will be integrating it into numerics straigthaway. Just need to figure out best way of putting this in calculator. Before our calculator was working in bigNumber mode by default and it was ok. But now I am not sure. On one side I want Also, here are some issues/questions
|
Jos, shall I put issues above into different card? or is it ok to leave here? |
Please create a new issue for them, thanks! |
The just released v2 has support for fractions, powered by https://github.com/infusion/Fraction.js/ |
A way to convert decimal numbers into their fraction form i.e.
0.25 = 1/4
.Operations on fractions:
1/4+2/4=3/4
1/4*2/4=3/4
The text was updated successfully, but these errors were encountered: