409 questions
3
votes
1
answer
153
views
Karatsuba Square Root implementation correctness
I'm currently trying to implement Karatsuba Sqrt for my BigInteger module in luau, though I'm having trouble with its accuracy and I don't know what I'm doing wrong.
Karatsuba function:
local function ...
4
votes
3
answers
311
views
How can I further optimize this C++ function that takes integer square roots?
In an algorithm I am using, most of the time is spent in the evaluation of square roots using the sqrt function in cmath. In my application I only need the integer part of the square root of integers, ...
-1
votes
3
answers
85
views
Using the Babylonian method to find the square root gives wrong results
I feel like I have everything right I just can't seem to get the square root right. Every time I run it the answer is off.
For example, when I plug in 100 it spits out 26 as the square root, which isn'...
-5
votes
1
answer
169
views
Haskell code for square root of negative integers
How can I use Haskell to find the square root of a negative integer?
0
votes
1
answer
142
views
How to get square root with decimal value of large integer?
My code for large integer sqrt
<?php
$y2 = gmp_init('28626386478758000000000000909090904'); // Example GMP number
$sqrt = gmp_sqrt($y2);
echo "Square root is: " . gmp_strval($sqrt) . &...
-1
votes
1
answer
109
views
How can I approximate a cubic root?
I have to do a maths exercise that requires me to frame √3 with an amplitude of 10^-5.
Using the sweep method and Python.
I'm French so I don't know if "sweep" is the right word.
Earlier in ...
1
vote
3
answers
300
views
Solving non-linear system of equations (issue with sqrt)
I am trying to solve a system of non-linear equations using Python (under-expanded jet with losses - Molkov):
I am trying to use the library Scipy and the module fsolve:
def equations10(p):
u3, ...
0
votes
1
answer
50
views
How to write the objective function that involves squart root and inverse function in cplex opl
I want to optimize a problem in which the objective contains the square root and inverse of a variable.
I tried writing like this:
using CP;
dvar int+ y;
dvar int+ z;
minimize z;
subject to{
z==4/...
1
vote
1
answer
65
views
Is there any chance that simplified forms of certain mathematical expressions throw overflow errors while complex ones dont?
I was attempting the #69 problem of leetcode, which involves finding square root of given number.
I proceeded via a binary search approach.
int mySqrt(int x) {
if (x==0 || x==1){
return x;
...
7
votes
2
answers
969
views
Time complexity of Python 3.8+'s integer square root `math.isqrt()` function
I am trying to analyze the time complexity of the default integer square root function in Python 3.8+ versions, math.isqrt()
I have tried to peruse the time complexity of this function as a function ...
1
vote
0
answers
71
views
Why is it quicker to calculate the reciprocal square root than to compute the square root? [duplicate]
On uops.info VRSQRTPS is listed as having a lower latency than VSQRTPS across all the architectures I've checked. It also has a lower throughput but perhaps there are less units that can do it on most ...
0
votes
1
answer
84
views
Finding integer square root of an integer hobby code... I'm not sure if it's actually efficient
I am very new to this and I am trying to write a program that determines whether an integer has an integer root (or not). I have combined many different ways to narrow down the search range to find ...
0
votes
2
answers
52
views
Math domain error when simplifying radicals
I am attempting to create a function in Python 3.11.4 to simplify radical expressions; the first step is to find the closest perfect square below the number. To do this, I tried making a function that ...
3
votes
1
answer
280
views
Does ARM frsqrts need to be used with extra fmul instructions for a Newton iteration?
In the documentation for the ARM instruction frsqrts, it says:
This instruction multiplies corresponding floating-point values in the vectors of the two source SIMD and FP registers, subtracts each ...
0
votes
0
answers
193
views
Square root function returning number as casted integer
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main() {
double a, b, c;
for (a = 1; a < 333; a++) {
for (c = 335; c < 998; c++) {
...
0
votes
1
answer
645
views
How to factor out perfect squares from under the square root sign?
I am trying to calculate the square root, and keep the part which could not change into integer in C++, and I found This post on Stack Overflow, but it will still have decimal.
For example, if I want ...
-1
votes
1
answer
486
views
x**-0.5: what is the - before ** performing?
while finding a square-root, we perform number**0.5, but what is the meaning of - sign before 0.5.
I was looking at a code (I was specificially looking at ViT Code, and here for scaling, they have ...
0
votes
1
answer
226
views
How to automatically calculate RMSE per group for fitting data in R?
For example, I have data like below.
genotype=rep(c("A","B","C","D","E"), each=5)
env=rep(c(10,20,30,40,50), time=5)
outcome=c(10,15,17,19,22,12,13,15,...
0
votes
1
answer
397
views
Plot of graph is not smooth in Manim (math.sqrt(1-x**2))
When I plot the graph of math.sqrt(1-x**2), the graph has unnatural bumps in it. How do I fix this? I'm very new to Manim.
Here's my code:
from manim import *
import math
class Myscene(Scene):
def ...
0
votes
0
answers
51
views
Unable to increase the precision in computing square root using bisection method [duplicate]
Tried to code bisection method to compute square root of 2, till the difference between two consecutive steps is less than some specific value, say 10^{-11}, where tolerance variable is specified as ...
1
vote
1
answer
83
views
Square Root program using Difference Equations
I made a program using difference equation initial conditions for each number, but as you can see the code didn't give me satisfying results, plus it took more loops than it's supposed to, it should ...
0
votes
2
answers
173
views
Using a BREAK statement to exit this while loop changes the value of the variable and gives incorrect answer. Need another way?
Question:
Write a program that implements Newton’s method to compute and display the square
root of a number entered by the user. The algorithm for Newton’s method follows:
Read x from the user
...
0
votes
1
answer
320
views
docplex does not support square root np.sqrt(x), please suggest an alternative solution
I have implemented docplex model with python, everything goes well: problem formulation, variables, constraints and objective function.
The problem raised when I tried to compute Euclidian distance ...
0
votes
1
answer
692
views
How do I print a square root to the console in python?
I am trying to write code that can print a square root to the console. Here is an example of some code
from math import sqrt
print("ax\N{SUPERSCRIPT TWO} + bx + c")
a = int(input("...
-3
votes
1
answer
481
views
How to calculate SquareRoot of Integer without using inbuilt function in Swift Language? I tried below code & searched but didn't get better solution
Just an exercise:
func mySqrt(_ x: Int) -> Int {
if x<2 { return x }
var y = x
var z = (y + (x/y)) / 2
while Double(abs(y - z)) >= 0.00001 {
y = z
z = (y + (...
1
vote
0
answers
141
views
Java method to calculate the square root via minuend and subtrahend and print each step
I am tasked with creating a program in java which calculates the square root of a double and goes through each step of calculating it manually. The requirements are:
split the number into number ...
0
votes
2
answers
204
views
Infinite loop in babylonian method for square roots
In some specific numbers my algorithm gets stuck. It never reaches the minimum approximation so we never get out of the while. I think I can either low my approximation requisites or use double for my ...
0
votes
1
answer
218
views
Dafny cannot prove that 'a^2<=b^2*c^2' implies 'a<=b*c' for reals greater than 0
I want to test the following property in Dafny: a^2<=b^2*c^2 implies a<=b*c. It automatically checks this for (positive) integer numbers:
lemma powersVSsquares_integers(a:int, b:int, c:int)
...
-2
votes
1
answer
497
views
Find Standard deviation for each column of array
I am to find the standard deviation. When calculating the standard deviation, my outputs are way higher than the given sample. How do I go calculating the standard deviation of each column?
Here is my ...
1
vote
2
answers
484
views
Finding square roots in surd form
I'm trying to build a program that let's you multiply two square roots and display the answer in surd form if the answer isn't an integer.
I've seen answers here and here, although I don't understand ...
-1
votes
1
answer
986
views
Is it possible to write an integer to a file without converting it to a string? [closed]
I am trying to compute the square root of 2 (up to nearly 10 million digits) with the following code
import os
os.chdir('/home/username/Desktop')
def sqroot(a, digits):
a = a * (10**(2*digits))
...
-4
votes
1
answer
191
views
how can I square the numbers between 0 and any input with extremely large numbers in python [closed]
I am in codewars and the challenge I have has one part I can't get my head around this is what I am speaking of
You are given a number "n" (n >= 0) and a digit "d" (0 <= d &...
-2
votes
2
answers
225
views
How to find out whether two numbers are powers of the same number and those powers
So say you are given the numbers 27 and 81. How would a program that tells you that the 4th root of 81 is 3 and the cubic root of 27 is three. (Both have the root of 3).
x = 16;
y = 4;
foo = ...
0
votes
1
answer
1k
views
When using a square root transformation on negatively skewed data, how do you return the original value?
I had some data that was negatively skewed in r. The transformation I used was: sqrt(max(x+1)-x) from this website: https://www.datanovia.com/en/lessons/transform-data-to-normal-distribution-in-r/. ...
5
votes
0
answers
1k
views
Why is Math.hypot so slow?
I am performing a ton of distance calculations in my code, to the point where Math.sqrt(a*a + b*b) is run hundreds of thousands of times.
I then recalled how there is a Math.hypot function that does ...
0
votes
2
answers
579
views
Javascript power and root [duplicate]
simple question
is there an operator for the root as for the power there's the "* *".
I tried to search but I couldn't find it, so I don't think there is, but if for any reason I didn't saw ...
-2
votes
1
answer
3k
views
Python- Square Root of list
Taking the square root of each number in a list.
For this problem in the sqrt_list function:
Take the square root of each item in the list,
Store each squared item in another list, and
Return this ...
0
votes
1
answer
479
views
How can I find a square root in simplest form given an integer? (Java)
I'm trying to compute the simplest form of the square root of an integer. My Java knowledge is rather limited, but I know many of the basics and such. I can't figure out how to find a simplest form ...
3
votes
1
answer
2k
views
Integer Square root of a number
It's not that I don't understand how to find the integer square root of a number. I know several ways of finding them using Python and C++.
It's just that this algorithm is really messing with my ...
0
votes
1
answer
213
views
My VDHL code runs incorrectly - square root in vhdl
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity RaccinCarreSequentielle is
generic(
N: natural:= 16
);
port(
X: unsigned(2*N-1 downto 0);
reset : in ...
3
votes
1
answer
2k
views
Square root of a u128
How can the square root of a u128 be calculated? The resulting number can be a u128 after some rounding.
f64 has a f64::sqrt function, but I dont think we should be converting u128 to f64.
0
votes
1
answer
482
views
What purpose is the lookup table serving in this code?
Below I have adapted code from William Kahan and K.C. Ng (look at the comment block on the bottom) written in 1986 to produce an approximation of 1 / sqrt(x) where x is an IEEE-754 double precision ...
0
votes
1
answer
161
views
Propagation in Python - Pandas Series TypeError
I am trying to propagate uncertainty in Python by adding two columns together of a Pandas data frame and then taking the square root. However, when I try to use Python's math.sqrt function, I receive ...
2
votes
2
answers
114
views
I made a python script to easily find a square root but I can't stop it
I made a python script to find the square root of a number and prints out the result so far, but it uses an infinite loop and I cannot stop it. Does anybody know how to stop it when it has printed out ...
-1
votes
1
answer
1k
views
Algorithm to find the square root
Playing around with formulas in C, I realized that I found a formula for calculating the square root of a number. I would like to know if such an algorithm already exists, or if it is widely known to ...
0
votes
4
answers
9k
views
Calculate root mean square deviation (RMSD) with numpy of Python
I transformed the coordinates of two atoms into an array: coord
And I must calculate the root mean squared deviation (RMSD) between the two sets of these coordinates.
For this I have:
def ...
3
votes
3
answers
291
views
How to change √243 to 9√3 in python? And how to change squared root generally? [closed]
I have a math/python question, how to change big number in squared root, to small number (but still keeping the value), for example √243 to 9√3?
And I have another question, how to use it in my code?
...
1
vote
1
answer
92
views
Algorithm to map letters to digit such that number formed is largest square possible having distinct digits
For a given string of distinct letters map each letter to a digit such that number formed is largest square possible having distinct digits.
eg:
c – 9, a – 8, r – 0, e – 1: 9801
h – 9, a – 6, b – 7, ...
0
votes
1
answer
555
views
displaying the square root of "X" in label
I have written a simple calculator program in C# which can also calculate the square root of any number.
So, I was just wondering if you could display said number in a label. Or rather display it like ...
0
votes
0
answers
69
views
Calculate a square root using the Newton method in Python [duplicate]
I have a task to calculate a square root using the Newton method using a function within a function. The user enters a number that he wants to know his root and another number that is his guess to the ...