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

Testing Number Theoretic Functions in Haskell using a recursor over natural numbers

I'm implementing some number theoretic functions as the exponentiation in Haskell using a recursor. I'm using the QuickCheck library for testing my implementation. For simplify my tests, I'm using the Natural data type from the base library,…
1
vote
2 answers

Calculating a^b^c mod 10^9+7

Problem Link - https://cses.fi/problemset/task/1712 input - 1 7 8 10 Expected Output - 928742408 My output - 989820350 point that is confusing me - Out of 100s of inputs, in only 1 or 2 test cases my code is providing wrong output, if the code is…
1
vote
1 answer

Simple matrix exponentiation in c++

So I was asked to define a matrix as: typedef vector vec; typedef vector matrix; and based on that write some functions like scalar multiplication, addition, etc. Everything but exponentiation works pretty well and I have no clue what…
Jakub Sapko
  • 304
  • 2
  • 15
1
vote
1 answer

Discrete logarithm of number of form (2ⁿ - 1)

I need to find the smallest number k for which (2n - 1)k % M equals a given X. The catch here is that n can be a very large number, with possibly 10,000 digits, and hence will be stored as a string. I know that this is a hard problem in general, but…
Shiven Sinha
  • 656
  • 5
  • 14
1
vote
1 answer

VHDL : How is this statement resolved: type foo is range -(2**30) to 2**30;?

I am having an issue processing the following type declaration: type foo is range -(2**30) to 2**30; For the exponentiation, there are two possible interpretations to consider: function "**"(universal_integer, integer) return…
1
vote
1 answer

Can this script have better performance using modular exponentiation?

def f(a, b, c): return ((a ** b)-1) // c % b Can this script be faster in some way? (I have been looking for something with modular exponentiation): pow(a, b, c) == a ** b % c but this above script doesn't seem to be improvable like that. Does…
1
vote
1 answer

How to compute a modular exponentiation in Crystal?

I want to compute 1_299_709 ** 1_300_751 % 104_729 in Crystal. In Python, the pow function allows to pass the modulo as third argument: ❯ python >>> pow(1_299_709, 1_300_751, 104_729) 90827 In Ruby, the same: ❯ irb irb(main):001:0>…
q9f
  • 11,293
  • 8
  • 57
  • 96
1
vote
2 answers

Java recursion exponentiation method making recursion more efficient

I'd like to change this exponentiation method (n is the exponent): public static double exponentiate(double x, int n) { counter++; if (n == 0) { return 1.0; } else if (n == 1) { return x; } else { return x *…
1
vote
1 answer

In 10. power / calculation / Power calculations

i am working on an apps for calculating fuel... i need to know how i can power a number in 10? the Excel code is "10^1.5"
Askapps
  • 69
  • 2
  • 12
1
vote
0 answers

Modular Exponentiation with 8 digit numbers

A Java program to find the result of raising a large number to a power over a modulus does not appear to work when the base of the exponent is 8 digits or greater. Bases that have 8 or more digits do not work (checked against online modular…
Marco Deicas
  • 53
  • 1
  • 3
1
vote
1 answer

Error while implementing matrix exponentiation

I tried to implement fast exponentiation using explanation from article on geeksforgeeks but it shows error while solving: https://www.spoj.com/problems/FIBOSUM/ Can anyone explain what’s wrong with the code? I tried by computing Fibonacci sum for…
1
vote
1 answer

JavaScript - While loop - odd numbers exponentiation

I found some problem with JavaScript exponentiation While loop code: var x = Number(prompt("X:")); var y = Number(prompt("Y:")); var count = 1; var power = 1; while(count <= y){ power = power * x; console.log (x + " to the power of " +…
Dawid
  • 11
  • 1
1
vote
2 answers

fast power function in scala

I tried to write a function for fast power in scala, but I keep getting java.lang.StackOverflowError. I think it has something to do with two slashes that use in the third line when I recursively called this function for n/2. Can someone explain why…
1
vote
2 answers

Why does Python `**` use for exponentiation instead of the `^` operator?

Why is ^ not squaring in Python? I know exponentiation is ** instead, but what exactly is ^ and why wasn't that operator used instead? For example 2^2=0, 3^2=1.
ZHU
  • 904
  • 1
  • 11
  • 25
1
vote
0 answers

converting c recursion code to mips

I am in the process of trying to convert this C code to MIPS. This is only my second project so far and I feel like I am so close. Here is the C code. //fast modular exponentiation int fme(int x, int k, int n) { int temp; int result = 1; …
Timdoozy
  • 21
  • 2