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
3
votes
3 answers

Fast exponentiation implementation

Could someone please point out a site where I can find an algorithm to efficiently calculate integer exponentiation to large powers using C#? eg. I want to calculate 2^60000 or 3^12345
Hugo
  • 140
  • 2
  • 7
3
votes
2 answers

Transforming recursion into tail recursion?

I am trying to write a predicate that recursively finds the nth power of some number [A^n = A * A^(n-1)] and uses the shortcut A^(2n) = A^n * A^n. Here is the solution so far. p(_,0,1):-!. p(A,N,R):-N mod…
ivt
  • 301
  • 3
  • 9
3
votes
2 answers

How do variables in pattern matching allow parameter omission?

I'm doing some homework but I've been stuck for hours on something. I'm sure it's really trivial but I still can't wrap my head around it after digging through the all documentation available. Can anybody give me a hand? Basically, the exercise in…
3
votes
5 answers

Raising to power in PHP

Well, i need to do some calculations in PHP script. And i have one expression that behaves wrong. echo 10^(-.01); Outputs 10 echo 1 / (10^(.01)); Outputs 0 echo bcpow('10', '-0.01') . '
'; Outputs 1 echo bcdiv('1', bcpow('10',…
Kuroki Kaze
  • 8,161
  • 4
  • 36
  • 48
3
votes
2 answers

Exponentiation of negative real

Can somebody explain why I'm getting a positive result in the first case and a negative in the second. auto r1 = -3.0L; auto r2 = 2.0L; writeln(typeid(r1)); // real writeln(typeid(r2)); // real writeln(typeid(r1 ^^ r2)); // real writeln(r1 ^^…
fwend
  • 1,813
  • 2
  • 15
  • 17
2
votes
1 answer

Prolog Functor - Computing x^y

I am new to prolog and trying out to learn how to program. I want to know how to compute x^y in Prolog both being integers. I know for a fact that it goes something like this: % exp(y,x,z) <- z is x**y
Amjad
  • 1,627
  • 5
  • 21
  • 41
2
votes
1 answer

What are the differences between a**b and pow(a,b), in symbolic calculation

EDIT: added assert as suggested by Wrzlprmft, which does not raise any exception. I have to write code with many expressions of type a**b, under the following circumstances import sympy as sp a, b = sp.symbols('a,b', real=True, positive=True) expr1…
2
votes
2 answers

Why is exponentiation not atomic?

In calculating the efficiency of algorithms, I have read that the exponentiation operation is not considered to be an atomic operation (like multiplication). Is it because exponentiation is the same as the multiplication operation repeated several…
Ali Haider
  • 378
  • 2
  • 13
2
votes
0 answers

Efficient exponentiation with division

I need to calculate to compute a repeated application of a linear transform under a modulus. ((a ** p - 1) // (a - 1)) % m == ((pow(a, p, x) - 1) // (a - 1)) % m How could I figure an x that would work given a, p, and m? Could it just be x = ((a -…
YoungCoder5
  • 845
  • 1
  • 7
  • 14
2
votes
2 answers

overflow in mpz type using gmp mpz_pow_ui

I am getting an overflow error when calling mpz_pow_ui from gmp, with the maximum unsigned long int value. According to the signature here, this is supposed to work, shouldn’t it? What am I missing? Example: example.cpp: #include #include…
Yoni Zohar
  • 301
  • 2
  • 6
2
votes
1 answer

How to find out Boltzmann weight or partition function at low temperature?

In statistical physics, we often try to find out the partition function which is expressed as Z=\sum_i e^(-\beta E_i) where \beta is inverse temperature. e^(-\beta E_i), the term under the summation is called the Boltzmann weight. Now at low…
hbaromega
  • 2,317
  • 2
  • 24
  • 32
2
votes
1 answer

Fractional Exponentiation in Forth

I'm trying to write a function that fits a value to a model. I have a measurement from a pressure sensor and using a calibrated model I have to convert the value into the final pressure management. Doing so involves raising the measurement to a…
Fuzzy_Bunnys
  • 193
  • 8
2
votes
1 answer

Implement solution of differential equations system using exponential matrix in Julia

I try to reproduce the example, in Julia, that I show in the figure and taken from Matrix Exponentiation I show you how far I have managed to reproduce the exercise in Julia. But I don't know how to introduce the vector t, for a range of interest,…
HerClau
  • 161
  • 2
  • 15
2
votes
1 answer

Why is gmpy2 so slow at complex exponentiation?

I was using complex numbers in gmpy2 and noticed that it was slow. I narrowed it down the exponentiation operator. At first I thought it was just because it was complex. But then I compared it to mpmath which uses gmpy2 and it was so much faster: #…
Status
  • 912
  • 1
  • 12
  • 23
2
votes
1 answer

m to the power of 0 in Church’s Numerals

A topic on undergraduate level computer science. I came upon a bothering problem about (0 m) in terms of exponentiation of church’s numerals in lambda calculus when reviewing the theory. As far as I know, (0 m) when reduced results in λx. x, which…