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

How is exponentiation by squaring faster?

Suppose you want to calculate 5^65537 instead of multiplying 5 65537 times, it is recommended to do ((5^2)^16)*5. This results in 16 times squaring and one multiplication. But my question is aren't you not compensating the the number of squaring…
Ashwin
  • 12,691
  • 31
  • 118
  • 190
5
votes
2 answers

Prolog predicate - infinite loop

I need to create a Prolog predicate for power of 2, with the natural numbers. Natural numbers are: 0, s(0), s(s(0)) ans so on.. For example: ?- pow2(s(0),P). P = s(s(0)); false. ?- pow2(P,s(s(0))). P = s(0); false. This is my code: times2(X,Y) :- …
5
votes
2 answers

Exponentiation with negative base

So, the R expression and its output is as follows: > (4-7)^1.3 [1] NaN Any ideas how to solve this in R?
Andrej
  • 3,719
  • 11
  • 44
  • 73
5
votes
1 answer

Which algorithm is used to compute exponential functions the GNU C++ Standard Library?

Please consider std::exp defined in the header cmath in C++ numerics library. Now, please consider an implementation of the C++ Standard Library, say libstdc++. Considering there are various algorithms to compute the elementary functions, such as…
Herpes Free Engineer
  • 2,425
  • 2
  • 27
  • 34
5
votes
4 answers

Modular Exponentiation in Java

I need a way to calculate: (g^u * y^v) mod p in Java. I've found this algorithm for calculating (g^u) mod p: int modulo(int a,int b,int c) { long x=1 long y=a; while(b > 0){ if(b%2 == 1){ x=(x*y)%c; } …
Carl Hagen
  • 53
  • 1
  • 1
  • 5
5
votes
1 answer

How do I square a norm in CVX?

In the CVX package for Matlab, I want to minimize a function like $|Ax-b|_2^2$ . Meaning the square of a 2-norm. How do I code that in CVX? I tried both: minimize (norm(A*x-b,2)^2); and minimize (norm(A*x-b,2)*norm(A*x-b,2)); but both threw…
Leo 254
  • 181
  • 1
  • 8
5
votes
2 answers

Modulo Power function in J

If I want to compute a^b mod c then there is an efficient way of doing this, without computing a^b in full. However, when programming, if I write f g x then g(x) is computed regardless of f. J provides for composing f and g in special cases, and the…
user1202733
  • 623
  • 4
  • 10
5
votes
2 answers

Power (exponentiation) and other math function support in SPARQL

I am trying to write a SPARQL query where I want to filter on the square of something, but I am simply unable to figure out how to square a number (x2) (except by multiplying it with itself, of course). I guessed a square root function called…
Bjarke Freund-Hansen
  • 28,728
  • 25
  • 92
  • 135
5
votes
1 answer

Euclidean algorithm to solve RR' - NN' = 1. Modular exponentiation with Montgomery algorithm to implement Fermat test in python or Petite Chez scheme

This is as a personal challenge in my introductory programming class taught using Scheme, but I would be equally happy with Python examples. I've already implemented the binary method of modular exponentiation in scheme as follows: (define (pow base…
Seth
  • 51
  • 3
5
votes
1 answer

Matrix exponentiation using fermat's theorem

Like we use fermat's little theorem for modular exponentiation , I was just wondering that is there any such method for fast matrix exponentiation ? Can we use fermat's theorem for matrix exponentiation ? If no then is there any faster method than…
SlashGeek
  • 565
  • 5
  • 17
4
votes
1 answer

x87 FPU computing e powered x, maybe with a Taylor series?

I am trying to compute the function e^x (x is a single-precision float) in x87. To achieve this I am using the Taylor-series (as a reminder: e^x = 1 + (x^1)/1! + (x^2)/2! + ... + (x^n)/n!) As I'm working with the x87, I can calculate all values in…
Maru
  • 41
  • 4
4
votes
2 answers

Exponentiation of a Java BigInteger with a value lower than 1

Possible Duplicate: How to do a fractional power on BigDecimal in Java? I have a BigInteger A that I need to exponentiate with 1/b (b is an int). My problem is that A supports only A.pow(int) which is not suitable for my case. Is there any…
adrianp
  • 2,491
  • 5
  • 26
  • 44
4
votes
2 answers

How to compute -1 / (-343)^(1/3) as 1/7 in Python?

I like to incorporate Python in my exploration of functions, however I have encountered a behavior that I didn't expect or want for these assessments. >>> def h(x): ... return -1 / x**(1/3) ... >>> h(-343) (-0.07142857142857145 +…
Galen
  • 1,128
  • 1
  • 14
  • 31
4
votes
4 answers

Modular exponentiation fails for large mod in C++

This is the code I'm using for calculating (n^p)%mod. Unfortunately, it fails for large values of mod (in my case mod = 10000000000ULL) when I call it from main() method. Any idea; why? ull powMod(ull n, ull p, ull mod) { ull ans = 1; n =…
Sai Nikhil
  • 1,237
  • 2
  • 15
  • 39
4
votes
5 answers

ASP.NET CSV Response, Excel Exponential Format Issue

In my ASP.NET application, I need to write DataTable as CSV response to the customer. Everything is working fine except a column which has a numbers. Ex: 7002136138603600000 But when I open the CSV in Excel, it is showing in exponential…
Mahesh
  • 1,651
  • 5
  • 26
  • 47