Questions tagged [complex-numbers]

This challenge involves the manipulation of complex numbers, including parsing and printing them as well as performing complex arithmetic. This tag also encompasses generalised complex numbers like quaternions.

Filter by
Sorted by
Tagged with
10 votes
13 answers
1k views

Convert a Gaussian integer to its positive form

We already have a challenge for computing the GCD of two Gaussian integers, but that challenge explicitly allows to choose any of the four possible values. Your task now is to bring the Gaussian ...
bsoelch's user avatar
  • 5,677
11 votes
19 answers
1k views

The rectangle spanned by two numbers

One way to generalize the concept of a range from the integers to the Gaussian integers (complex numbers with integer real and imaginary part) is taking all numbers contained in the rectangle enclosed ...
bsoelch's user avatar
  • 5,677
25 votes
16 answers
3k views

Convert to base i - 1

Given \$ i = \sqrt{-1} \$, a base-\$ (i - 1) \$ binary number \$ N \$ with \$ n \$ binary digits from \$ d_{0} \$ to \$ d_{n - 1} \$ satisfies the following equation. $$ N = d_{n - 1} (i - 1) ^ {n - 1}...
xiver77's user avatar
  • 2,325
11 votes
2 answers
465 views

Greatest Common Gaussian Divisor

Gaussian integers are complex numbers \$x+yi\$ such that \$x\$ and \$y\$ are both integers, and \$i^2 = -1\$. The norm of a Gaussian integer \$N(x+yi)\$ is defined as \$x^2 + y^2 = |x+yi|^2\$. It is ...
caird coinheringaahin g's user avatar
45 votes
27 answers
3k views

Simplify ijk-string

Related: Multiply Quaternions Challenge Given a string made of ijk, interpret it as the product of imaginary units of quaternion and simplify it into one of the ...
Bubbler's user avatar
  • 73.8k
25 votes
10 answers
2k views

Floor of complex number

Background Complex floor is a domain extension of the mathematical floor function for complex numbers. This is used in some APL languages to implement floor , ...
Bubbler's user avatar
  • 73.8k
20 votes
15 answers
3k views

Complex Fibonacci numbers

The Binet formula is a closed form expression for the \$n\$'th Fibonacci number: $$F_n = \frac {\phi^n - (1-\phi)^n} {\sqrt 5}$$ where \$\phi = \frac {1 + \sqrt 5} 2\$ is the golden ratio. This ...
caird coinheringaahin g's user avatar
10 votes
10 answers
333 views

Counting shortest paths on a triangular grid

Background An Eisenstein integer is a complex number of the form \$ z = a + b\omega \$ where \$a, b\$ are integers and \$\omega\$ is the third root of unity \$\frac{1-\sqrt3i}{2}\$. The Eisenstein ...
Bubbler's user avatar
  • 73.8k
3 votes
1 answer
450 views

Gaussian integer division reminder [closed]

Gaussian integer is a complex number in the form \$x+yi\$, where \$x,y\$ are integer and \$i^2=-1\$. The task is to perform such operation for Gaussian integers \$a,b\$, that \$a=q \cdot b+r\$ and \$|...
Alexey Burdin's user avatar
33 votes
10 answers
3k views

The qvolume of an integer

It is ancient knowledge that every non-negative integer can be rewritten as the sum of four squared integers. For example the number 1 can be expressed as \$0^2+0^2+0^2+1^2\$. Or, in general, for any ...
don bright's user avatar
  • 1,305
11 votes
11 answers
3k views

Quaternion square root

Background Quaternion is a number system that extends complex numbers. A quaternion has the following form $$ a + bi + cj + dk $$ where \$ a,b,c,d \$ are real numbers and \$ i,j,k \$ are three ...
Bubbler's user avatar
  • 73.8k
19 votes
20 answers
3k views

Hermitian matrix?

Note that this challenge requires no handling or understanding of complex numbers. Given a non-empty square matrix where every element is a two-element (Re,Im) integer list, determine (giving any ...
Adám's user avatar
  • 29.9k
11 votes
8 answers
2k views

Eigenvalues of a Matrix

Given a square matrix, output the matrix's eigenvalues. Each eigenvalue should be repeated a number of times equal to its algebraic multiplicity. The eigenvalues of a matrix ...
user avatar
11 votes
23 answers
2k views

Exponent of complex numbers

Given two integers, which may be negative, zero, or positive, \$a\$ and \$b\$ (taken in any reasonable format, including inputting a plain complex number), convert it to \$a + bi\$ where \$i\$ is the ...
Okx's user avatar
  • 16.4k
22 votes
6 answers
677 views

Factorize a Gaussian integer

A Gaussian integer is a complex number whose real and imaginary parts are integers. Gaussian integers, like ordinary integers, can be represented as a product of Gaussian primes, in a unique manner. ...
anatolyg's user avatar
  • 13.1k
9 votes
15 answers
1k views

Compute a complex power

The Rundown Given any input x and y, perform a complex operation, and print a corresponding result. How your program should work Given an input x and y in the form z = x+yi, find zi-z If the ...
Graviton's user avatar
  • 2,791
36 votes
21 answers
6k views

Draw a graph of \$y=(-n)^x\$

Challenge Given an input of an integer, \$n\$ (where \$0<n<50\$), output the graph of \$y=\mathrm{Re}((-n)^x)\$ from \$x = -3\$ to \$x = 3\$ inclusive. Where \$\mathrm{Re}(p)\$ is the real part ...
Beta Decay's user avatar
  • 23.3k
9 votes
3 answers
318 views

Imaginary Parts of Non-Trivial Riemann Zeroes

Introduction According to the Riemann Hypothesis, all zeroes of the Riemann zeta function are either negative even integers (called trivial zeroes) or complex numbers of the form ...
user avatar
35 votes
25 answers
3k views

Complex Binary Numbers

Let's create a simple, surjective mapping from positive integers to Gaussian integers, which are complex numbers where the real and imaginary parts are integers. Given a positive integer, for example ...
Calvin's Hobbies's user avatar
20 votes
13 answers
3k views

Codegolf the permanent

The challenge is to write codegolf for the permanent of a matrix. The permanent of an \$n\times n\$ matrix \$A = a_{i,j}\$) is defined as $$\text{perm}(A) = \sum_{\sigma \in S_n} \prod^n_{i=1} a_{i,\...
user avatar
17 votes
7 answers
871 views

Gauss to Eisenstein

Given a Gaussian integer \$a+bi\$ where \$a\$,\$b\$ are integers and \$i = \exp\left(\pi i/2\right)\$ is the imaginary unit, return the closest (w.r.t to the Euclidean distance) Eisenstein integer \$k+...
flawr's user avatar
  • 43.7k
8 votes
3 answers
586 views

Counting Eisenstein primes

Introduction Eisenstein integers are complex numbers of the form a+bω Where a,b are integers, and ...
Meow Mix's user avatar
  • 913
26 votes
10 answers
2k views

Parse a Quaternion

If you don't know already, a quaternion is basically a 4-part number. For the purposes of this challenge, it has a real component and three imaginary components. The imaginary components are ...
GamrCorps's user avatar
  • 7,502
67 votes
9 answers
5k views

Addition in base -1+i

Gaussian integers are complex numbers of the form a+bi where a and b are both integers. In ...
Sp3000's user avatar
  • 61.7k
11 votes
3 answers
3k views

Evaluate the Riemann Zeta Function at a Complex Number

Introduction I found this question that was closed because it was unclear, yet it was a nice idea. I'll do my best to make this into a clear challenge. The Riemann Zeta function is a special function ...
Jens Renders's user avatar
  • 1,568
11 votes
8 answers
603 views

Primitive Roots of Unity

Let z be a complex number. z is an nth primitive root of unity if for a certain positive integer ...
a spaghetto's user avatar
  • 11.2k
17 votes
2 answers
634 views

Output quater-imaginary base numbers in binary

Write a function or program that outputs Quater-imaginary base displayed as binary digits. The number base is 2i, where i is the square root of -1. See Complex Number for more details on i. Each digit ...
CJ Dennis's user avatar
  • 4,288
16 votes
5 answers
460 views

Add and multiply perplexing numbers

The split-complex numbers, also known as "perplex numbers" are similar to the complex numbers. Instead of i^2 = -1, however, we have ...
PhiNotPi's user avatar
  • 29k
17 votes
5 answers
969 views

What's the voltage over each component?

The picture below shows a RLC circuit. A RLC circuit is an electrical circuit consisting of a resistor (R), an inductor (L), and a capacitor (C), connected in series or in parallel. (1) In order to ...
Stewie Griffin's user avatar
12 votes
4 answers
682 views

Multiply Pauli Matrices

The Pauli matrices are a set of 2x2 matrices which appear very commonly in quantum physics (no, you don't need to know any quantum physics for this challenge). If we include the identity in the set, ...
Martin Ender's user avatar
15 votes
4 answers
2k views

Solve a 2x2 Eigensystem

For those with a little linear algebra background, the challenge is as simple as this: determine the eigenvalues and eigenvectors of a given complex 2x2 matrix. You may skip ahead to The Challenge for ...
Martin Ender's user avatar
7 votes
11 answers
2k views

Wait, but what's e^N?

Objective: The objective is to calculate e^N for some real or imaginary N (e.g. 2, -3i, 0.7, 2.5i, but not 3+2i). This is code golf, so, shortest code (in bytes) wins. So, for example: N = 3, e^N =...
mmk's user avatar
  • 253
30 votes
57 answers
5k views

Find i^n, given n

The Challenge In as few characters as possible, find the value of \$i^n\$, given \$n\$, a positive integer greater than 0. This should be outputted as a String. For those that don't know, \$i\$ is ...
Kezz's user avatar
  • 435
16 votes
13 answers
2k views

Multiply Quaternions

Write a named function or program that computes the quaternion product of two quaternions. Use as few bytes as possible. Quaternions Quaternions are an extension of the real numbers that further ...
xnor's user avatar
  • 144k
23 votes
16 answers
2k views

is_gaussian_prime(z)?

Task Write a function that accepts two integers \$a,b\$ that represent the Gaussian integer \$z = a+bi\$ (complex number). The program must return true or false depending on whether \$a+bi\$ is a ...
flawr's user avatar
  • 43.7k
48 votes
14 answers
4k views

Too Fast, Too Fourier: FFT Code Golf

Implement the Fast Fourier Transform in the fewest possible characters. Rules: Shortest solution wins It can be assumed that the input is a 1D array whose length is a power of two. You may use the ...
jakevdp's user avatar
  • 747
2 votes
6 answers
562 views

Perform basic operations on complex numbers in a language without native support for complex numbers

Your code has to provide the following functions: read(x) Reads a complex number from the standard input. It has to accept and evaluate something in the form ...
vsz's user avatar
  • 8,117
3 votes
7 answers
861 views

Resolve quadratic equation

Challenge: Write the smallest program (in characters) that resolves quadratic equations i.e. ax² + bx + c = 0 Rules: Given 3 numbers in R comma-delimited on ...
Toto's user avatar
  • 967
24 votes
3 answers
7k views

Generate Newton fractals

You all know the Newton method to approximate the roots of a function, don't you? My goal in this task is to introduce you into an interesting aspect of this algorithm. Newton's algorithm converges ...
FUZxxl's user avatar
  • 10.1k