Questions tagged [rational-number]

A rational is a number that can be expressed as the ratio of two integers.

In mathematics, a rational number is any number that can be expressed as the quotient or fraction p/q of two integers, p and q, with the denominator q not equal to zero. Since q may be equal to 1, every integer is a rational number. The set of all rational numbers is usually denoted by a boldface Q (or blackboard bold (\mathbb{Q} in LaTeX), Unicode ℚ); it was thus denoted in 1895 by Peano after quoziente, Italian for "quotient".

110 questions
2
votes
1 answer

Factorization of univariate polynomials over some number field with Sympy

I am working on factoring multivariate polynomials over some extension fields, using Sympy. If I can factor univariate polynomials over the reals, I think I would have a working code. For my code this bring me down to factoring a univariate…
Robert
  • 43
  • 4
2
votes
2 answers

why does Ruby's Rational class treat string arguments differently from numeric arguments?

I'm using ruby's Rational library to convert the width & height of images to aspect ratios. I've noticed that string arguments are treated differently than numeric arguments. >> Rational('1.91','1') => (191/100) >> Rational(1.91,1) =>…
Alex
  • 258
  • 1
  • 10
2
votes
1 answer

Haskell readsPrec rational functions

I got a problem with the implementation of the readsPrec to parse an input for following datastructure: data Term = Monom Int Int          | Addition Term Term          | Subtraction Term Term          | Multiplication Term Term          |…
RodrigoDela
  • 1,706
  • 12
  • 26
2
votes
3 answers

comparing intervals using integers

First off, I know there are many different easier/reliable ways to perform what I am about to ask, but that is not the point of my question. I am attempting to compare two sets of integers as if they were fractions. What I mean by this is suppose I…
Jason M.
  • 692
  • 2
  • 8
  • 24
1
vote
1 answer

Finding the root of an equation of 1.75th order

I have found the yield of a crop (Y) as a function of its nitrogen offtake (U) i.e., Y(U). The rest of the values for this particular crop are: Y_crit U_crit Q p U_max Y 12327.9 123.2790 57.14286 0.75 198.38 14170 I want to solve for…
1
vote
1 answer

sympy solve() and complex rational numbers

The following code: from sympy import * a, b = symbols("a b") eqs = [ a + b - 3j, a - b - 2 ] print(solve(eqs, [a, b])) prints: {a: 1.0 + 1.5*I, b: -1.0 + 1.5*I} I'd like the results to be returned as complex rational numbers not floating point…
ErikR
  • 51,541
  • 9
  • 73
  • 124
1
vote
2 answers

Simplifying Fractions With java

Hey guys I am working on a SW here I am kinda in need of help, you see we need to make a method where we are gonna simplify fractions. any idea how? here's my code as of now (don't mind the dvalue Method it is already finsih all I need is the…
user759630
  • 679
  • 2
  • 8
  • 11
1
vote
0 answers

How to convert floating point number to ratio of integers in python with high accuracy?

QUESTION: I would like to convert floats into a ratio of integers in simplest form. (Not a duplicate of this question, see "EDIT" below). For example, 0.1 = 1, 10, 0.66666... = 2, 3, etc. In the code snippet below, I try doing this for x = 0.1, 0.2,…
1
vote
1 answer

Why type-casting don't properly work with $. in Ruby?

I have a Ruby code as shown below, Try it online! loop{p$.+=1r} and another one, in which I just divide the 1r by 2 as shown below, Try it online! loop{p$.+=1r/2} As far as I can guess, the type-casting isn't working properly with $.. In the first…
vrintle
  • 5,501
  • 2
  • 16
  • 46
1
vote
1 answer

Convert a decimal number to a fraction AS3

I'm trying to get to convert the decimals to a fraction so for example, I had written something such as var _pow:int = Math.pow(base,i) and if i turned out to be a negative number it would give out a decimal (example: 3 ^ -2) and I'm currently stuck…
1
vote
1 answer

How to sort an array of rational numbers in C++?

I want to sort an array of rational numbers of type integers. I have used the Bubble Sort algorithm. I am dividing numerator with denominator and then comparing two rational numbers on the basis of their float quotient value. But, I am not getting…
Junaid
  • 941
  • 2
  • 14
  • 38
1
vote
2 answers

Binary splitting in Pari/GP

While trying to implement a sine-function without a FPU I recognized that all of the input is already rational, so I decided to try an all-rational approach. Probably slower but: why not? The series is linearly convergent and hence has a chance for…
deamentiaemundi
  • 5,502
  • 2
  • 12
  • 20
1
vote
1 answer

How to make algebraic manipulations in Coq easier?

I'm experimenting with Coq's standard libraries for integers and rationals. So far my proofs are very time-consuming and look terrible. I guess I miss some important proof techniques. Such simple lemmas shouldn't be so long to prove. Any hints? Here…
Dmitry Vyal
  • 2,347
  • 2
  • 24
  • 24
1
vote
1 answer

How should I specify that Rationals should be displayed in decimal notation in Ruby?

If I decide to use Rationals in Ruby for a console application, but don't want them displayed as a fraction, is there an idiomatic way to specify they should be displayed in decimal notation? Options I know about include: fraction = Rational(1, 2) …
Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
1
vote
1 answer

Convert an array of integers into a SymPy matrix of their ratios

I'd like to change a 3D array of integers into a SymPy matrix of rationals. I know that I should use Sympy (Rational and Matrix) but I don't know how to do it. For example, [[[2, 1], [1, 3], [3, 2]], [[4, 3], [5, 2], [0, 1]]] should become 2 1/3…
LOL
  • 29
  • 6