Questions tagged [exponentiation]

Anything related to the exponentiation operation, i.e. the process of computing the power of a number, and the corresponding syntax, semantics, constraints and implementation in programming languages.

Exponentiation is the process of raising a number to the nth power, (xn). Mathematically, it is denoted by superscripts, where the superscripted number is the exponent - xy.

However, since many text editors do not support superscripts, an alternative notation is used in code that uses exponentiation - typically a caret (x^y) or two asterisks (x**y). Other programming languages do not support symbolic operators for exponentiation, and rely on the pow function to calculate the exponent.

Please remember that the caret notation ^ may be used for bitwise XOR instead, and some languages does not support a built-in exponentiation operator.

See more

  • : a function that performs exponentiation. Namely, pow(a, b) calculates ab.
  • : do not assume that the ^ operator represents exponentiation. Many languages treat the ^ operator as bitwise-xor instead.
  • : The function ex, base-e exponentiation.
  • : Describes a type of curve produced by an exponent. Here, the the base is constant, and the variable is the exponent - and it grows extremely fast.
  • Wikipedia article for nore information about exponents and their identities.
368 questions
9
votes
5 answers

Calculating large exponentiation in Golang

I've been trying to calculating 2^100 in Golang. I understand the limit of numeric type and tried using math/big package. Here's what I've tried but I can't figure out why it doesn't work. I've used computation by powers of two method to calculate…
Ye Lin Aung
  • 11,234
  • 8
  • 45
  • 51
8
votes
4 answers

Fast exponentiation when only first k digits are required?

This is actually for a programming contest, but I've tried really hard and haven't got even the faintest clue how to do this. Find the first and last k digits of nm where n and m can be very large ~ 10^9. For the last k digits I implemented modular…
Nikhil
  • 286
  • 3
  • 8
8
votes
3 answers

Why does MATLAB's element-wise exponentiation speed up for 512 elements?

MATLAB's power function to calculate element-wise exponential for a constant base and an array of exponents becomes noticeably faster when the size of the array becomes 512. I expected to see the computation time increase with the input size,…
devrat
  • 83
  • 4
8
votes
1 answer

JavaScript exponentiation unary operator design decision

So I was fooling around with the new exponentiation operator and I discovered you cannot put a unary operator immediately before the base number. let result = -2 ** 2; // syntax error let result = -(2 ** 2); // -4 let x = 3; let result = --x ** 2;…
8
votes
1 answer

Numpy matrix exponentiation gives negative value

I wanted to use NumPy in a Fibonacci question because of its efficiency in matrix multiplication. You know that there is a method for finding Fibonacci numbers with the matrix [[1, 1], [1, 0]]. I wrote some very simple code but after increasing n,…
Rockybilly
  • 2,938
  • 1
  • 13
  • 38
8
votes
2 answers

last digit of a^b^c

I've got stuck on this problem : Given a, b and c three natural numbers (such that 1<= a, b, c <= 10^9), you are supposed to find the last digit of the number a^b^c." What I've firstly thought was the O(log n) algorithm for raising a at power…
scummy
  • 324
  • 1
  • 11
8
votes
1 answer

Why is numpy.power slower for integer exponents?

I chose these numbers randomly, but these results seem to be consistent --- a float exponent is 25%-50% faster than an integer one. How are these handled differently? In [209]: %timeit -n 100000 -r 100 np.power(3.71242, 7) 100000 loops, best of…
DilithiumMatrix
  • 17,795
  • 22
  • 77
  • 119
8
votes
3 answers

How to calculate a^(1/n)?

I am trying to calculate a^(1/n), where ^ denotes exponentiation. However, the following: Math.pow(8, 1/3) returns 1.0 instead of returning 2.0. Why is that?
GltknBtn
  • 512
  • 6
  • 13
7
votes
4 answers

Finding integer power roots

What is the best (most efficient) algorithm for finding all integer power roots of a number? That is, given a number n, I want to find b (base) and e (exponent) such that n = be I want to obtain all the possible value pairs of b and e Ps: n b…
Gautam
  • 7,868
  • 12
  • 64
  • 105
7
votes
3 answers

Minimal addition-chain exponentiation

I know it has been proven NP-complete, and that's ok. I'm currently solving it with branch and bound where I set the initial upper limit at the number of multiplications it would take the normal binary square/multiply algorithm, and it does give the…
harold
  • 61,398
  • 6
  • 86
  • 164
7
votes
1 answer

Exponential calculation in Python

While experimenting with Euler 99, I noticed that these operations take different time: >>> 632382**518061 # never finishes.. >>> 632382**518061 > 519432**525806 # finishes in few seconds True I wonder what's the reason for this?
Eugene Yarmash
  • 142,882
  • 41
  • 325
  • 378
7
votes
3 answers

how to calculate 2^n modulo 1000000007 , n = 10^9

what is the fastest method to calculate this, i saw some people using matrices and when i searched on the internet, they talked about eigen values and eigen vectors (no idea about this stuff)...there was a question which reduced to a recursive…
manu4rhyme
  • 83
  • 1
  • 4
7
votes
3 answers

power function in prolog

What is wrong with my power function? pow(_,0,1). pow(X,Y,Z) :- pow(X,Y-1,X*Z). ?- pow(2,3,Z). ERROR: Out of global stack
TheOne
  • 10,819
  • 20
  • 81
  • 119
7
votes
4 answers

C# isPowerOf function

I have the next function: static bool isPowerOf(int num, int power) { double b = 1.0 / power; double a = Math.Pow(num, b); Console.WriteLine(a); return a == (int)a; } I inserted the print function for analysis. If I…
Novak
  • 2,760
  • 9
  • 42
  • 63
6
votes
2 answers

Exponentiation a matrix by itself N times?

I am realizing Exponentiation of a matrix using FOR: import numpy as np fl=2 cl=2 fl2=fl cl2=cl M = random.random((fl,cl)) M2 = M Result = np.zeros((fl,cl)) Temp = np.zeros((fl,cl)) itera = 2 print('Matriz A:\n',M) print('Matriz AxA:\n',M2) for i…
1 2
3
24 25