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
4
votes
1 answer

Fast Exponentiation when only k digits are required - continued

Where I need help... What I want to do now is translate this solution, which calculates the mantissaof a number to c++: n^m = exp10(m log10(n)) = exp(q (m log(n)/q)) where q = log(10) Finding the first n digits from the result can be done like…
Jonathan
  • 1,126
  • 10
  • 19
4
votes
2 answers

prolog unification resolution

Why does this work: power(_,0,1) :- !. power(X,Y,Z) :- Y1 is Y - 1, power(X,Y1,Z1), Z is X * Z1. And this gives a stack overflow exception? power(_,0,1) :- !. power(X,Y,Z) :- power(X,Y - 1,Z1), Z is X * Z1.
TheOne
  • 10,819
  • 20
  • 81
  • 119
4
votes
2 answers

Fast exponentiation: real^real (C++ MinGW, Code::Blocks)

I am writing an application where in a certain block I need to exponentiate reals around 3*500*500 times. When I use the exp(y*log(x)) algorithm, the program noticeably lags. It is significantly faster if I use another algorithm based on playing…
Artemiy
  • 482
  • 1
  • 3
  • 13
4
votes
1 answer

Large multiplication output coming out negative in Ruby

I wrote some code that is supposed to sum n^n for 1 <= n <= 1000. Here's the code: sum = 0 (1..1000).each do |n| sum += n**n puts "n = #{n}, sum = #{sum}" end For some reason, the output is coming out negative after number 28: n = 29, sum =…
user100051
4
votes
1 answer

Exponentiation of polynomials, RR and ZZ in NTL library

I am using the NTL library for a RSA cryptanalysis implementation. But I am running into some problems frequently regarding type mismatch/incompatibility. Eg- I need RR type value of n^((h-1.0)/(h*k-1.0)) where n is type ZZ, and h and k are int.…
Sapta
  • 41
  • 2
4
votes
1 answer

Fast Exponentiation for galois fields

I want to be able to compute g^x = g * g * g * ... * g (x times) where g is in a finite field GF(2^m). Here m is rather large, m = 256, 384, 512, etc. so lookup tables are not the solution. I know that there are really fast algorithms for a…
3
votes
3 answers

Efficient Exponentiation For HUGE Numbers (I'm Talking Googols)

I am in the midst of solving a simple combination problem whose solution is 2^(n-1). The only problem is 1 <= n <= 2^31 -1 (max value for signed 32 bit integer) I tried using Java's BigInteger class but It times out for numbers 2^31/10^4 and…
Jimmy Huch
  • 4,400
  • 7
  • 29
  • 34
3
votes
2 answers

Why is the BigInteger.ModPow function in C# much slower than that in Java?

I have found that the BigInteger.ModPow function in C# is very slow compared to the BigInteger.modPow function in Java. This makes me reluctant to use C# to implement functions that perform modular exponentiation. I have written a test program to…
Quicksilver
  • 136
  • 8
3
votes
4 answers

Python: speed up pow(base,exp,mod) for fixed exp and mod, or with vectorization

The bottleneck of my code is the repeated calling of pow(base,exponent,modulus) for very large integers (numpy does not support such large integers, about 100 to 256 bits). However, my exponent and modulus is always the same. Could I somehow utilize…
torpedo
  • 283
  • 2
  • 15
3
votes
1 answer

BigInteger exponentiation with BigInteger number: ArithmeticException, would overflow supported range

I'm building the DSA algorithm. But I had a problem when ranking BigInteger numbers with other BigInteger numbers. This is the formula I want to use: v = ((g^u1 * y^u2) mod p) mod q This is the code I made: BigInteger v =…
adhiskara
  • 81
  • 7
3
votes
2 answers

Mathematically, why does this SICP algorithm for the exponent of a number modulo another number work?

Section 1.2.6 of SICP gives the following procedure: (define (expmod base exp m) (cond ((= exp 0) 1) ((even? exp) (remainder (square (expmod base (/ exp 2) m)) m)) (else (remainder (* base…
J. Mini
  • 1,868
  • 1
  • 9
  • 38
3
votes
2 answers

How to check which is greater: a**b or b**a for big numbers?

Say I have two numbers, a and bsuch that 1 <= a, b <= 10**9 How can I quickly check which is greater: a^b or b^a? Calculating a**b directly in Python is too slow.
planetp
  • 14,248
  • 20
  • 86
  • 160
3
votes
1 answer

Time complexity of a loop with value increasing in powers of 2

for(i=1;i<=n;i=pow(2,i)) { print i } What will be the time complexity of this? Approximate kth term for value of i will be pow(2,(pow(2,pow(2,pow(2, pow(2,pow(2,...... k times))))))) How can the above value, let's say kth value of i < n be solved…
Gaurav Kumar
  • 1,091
  • 13
  • 31
3
votes
3 answers

math.pow of a very large integer in Python is wrong

I am trying to print a very large number by calculating very large powers of an integer. Although my code is correct, i am not observing the desired output. Generally, python interpreter can print very large integer as much as the system memory…
csvraju
  • 105
  • 1
  • 1
  • 6
3
votes
2 answers

Handling numpy.exp overflow when using function on 2d-array

I've got a 2d numpy array on which I want to use my function sigmoid(x) which is: def sigmoid(x): return 1 / (1 + np.exp(-x)) My problem is that I have inputs that are too big like 3000 and I get this warning: RuntimeWarning: overflow…
Markus S
  • 33
  • 4