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
1
vote
3 answers

Rule to calculate power of a number when the exponent is Negative in Prolog?

I have a power function pow that attempts to calculate the value of B to the power of E. So far I handle the cases- 1. exponent is 0 2. exponent is non-zero pow(B,0,1). pow(B,E,Result):- E2 is E - 1, pow(B,E2,Result2), …
Sri Kadimisetty
  • 1,804
  • 4
  • 23
  • 25
1
vote
3 answers

Recursion in prolog

I dont think I understand how recursion works in prolog The following code (a power function) pow(_,0,1). pow(X,Y,Z) :- Y1 is Y - 1 , pow(X,Y1,Z1) , Z is Z1*X . Creates the following trace: [trace] ?- pow(2,2,X). Call: (6) pow(2, 2,…
Gregorio Di Stefano
  • 1,173
  • 1
  • 15
  • 23
1
vote
0 answers

A memory efficient and fast alternative to usual `expm()` function in MATLAB or Python?

People have asked similar questions before but none has a satisfactory answer. I'm trying to solve Lindblad Master Equation and the matrix size I'm trying to simulate are of order 10000 x 10000. But the problem is with exponentiation of the matrix,…
Dev
  • 111
  • 3
1
vote
0 answers

Fast modular exponentiation algorithm in c++ (for large numbers)

For educational purpose I'm developing c++ library for operating with large numbers represented as vectors of chars (vector). Here is algorithm that I am using for modular exponentiation: BigInt modularExponentiation(BigInt base, BigInt…
1
vote
3 answers

Preperation for Class exam (C) -> n-th root with self-written functions (no math.h or something)

the objective is easy: find the geometrical middle of X1, X2, ... Xn (in my case n = 3) BUT I have to write own functions and aren't able to use pow(), exp(), log2(), etc. so I tried to calculate it with paper first, before I start coding. I used…
1
vote
1 answer

When I try to use the exponentiation operator in Rust, it gives strange results. Why?

I am trying to implement Complex-Step Differentiation in Rust. However, when raising the complex number to a power higher than 2, I get a completely different result than Julia. The algorithm works in Julia for any function but in Rust, it only…
TheBatz
  • 115
  • 2
  • 12
1
vote
1 answer

Is there a space efficient way to compute the gcd of high exponents?

Basically, I am writing a program that works with large integer values that overflow the cpp integer. I am trying to compute something like: gdc(pow(a, b), c) where a ^ b is the value overflowing the integer limit. Is there a way to do this where I…
1
vote
1 answer

Exponentiate a number N times in Python?

I want to write a function that can exponentiate a base number N times by a same exponent. For example, if I want to square a base number 2 three times, i.e. to calculate 2^2^2^2, the expected answer is 256. This seems trivial and I wrote the…
Shaun Han
  • 2,676
  • 2
  • 9
  • 29
1
vote
1 answer

Java power exponentiation method keeps returning wrong value

I am doing a small cryptography program and need a function to calculate power mod n I wrote this method: static int power(int x, int y, int p){ int res = 1; // Initialize result x = x % p; // Update x if it is more than or equal to…
1
vote
2 answers

Python's pow() function and fast exponentiation gives different answers

I am getting different answers for below two implementations in C and python. In Python print(pow(15, 47413144071, 94826288143)) Prints 1 But in C #include unsigned long Power(unsigned long A, unsigned long B, unsigned long X) { …
Shashank
  • 9
  • 5
1
vote
1 answer

How to subtract, divide, or exponentiate 3 numbers with a string user input

Ok so basically I have an assignment in my first comp sci class in high school and I was able to figure out how to do most of it. We are supposed to make a calculator that can do basic functions with the PEMDAS operators and do calculations that…
1
vote
2 answers

What's wrong with my power function which takes 2 as base, n as exponent and computes answer modulo 10^9+7?

My code: int power(int n) { int num = 1000000007; if (n == 0) return 1; if (n%2 == 1) { int storage = power((n-1)/2); return (2*storage*storage)%num; } int storage = power(n/2); return…
Aradhye Agarwal
  • 439
  • 1
  • 4
  • 9
1
vote
1 answer

What is the explanation for being able to simplify 'A^(B^C) mod prim' such that it is efficiently computable?

Prelude We want compute the modular exponentiation A(BC) mod p = ?, where A, B, C, and p are known and p is a prim number. For example: 243mod 23 = 6 If we compute it in a straightforward way, first BC = e, and then Ae = n, and finally n mod p; we…
1
vote
1 answer

Why is my algorithm about Fermat primality test so slow?

I am learning Number theory. Now, I want to write a program that perform Fermat primality test. First, I write a modular square algorithm: #modular_square.py def modular_square(a, n, m): res = 1 exp = n b = a while exp !=0 : …
Land
  • 171
  • 11
1
vote
0 answers

How to compute a/b mod P, P is a prime number?

I have been searching an answer for this question on various sites. I can understand all the basic rules of modular arithmetic until this bad guy comes in. Recently I have been suggested this page for simple understanding that…