Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

gmp_gcdext(3) [php man page]

GMP_GCDEXT(3)								 1							     GMP_GCDEXT(3)

gmp_gcdext - Calculate GCD and multipliers

SYNOPSIS
array gmp_gcdext (GMP $a, GMP $b) DESCRIPTION
Calculates g, s, and t, such that a*s + b*t = g = gcd(a,b), where gcd is the greatest common divisor. Returns an array with respective elements g, s and t. This function can be used to solve linear Diophantine equations in two variables. These are equations that allow only integer solutions and have the form: a*x + b*y = c. For more information, go to the "Diophantine Equation" page at MathWorld PARAMETERS
o $a -Either a GMP number resource in PHP 5.5 and earlier, a GMP object in PHP 5.6 and later, or a numeric string provided that it is possible to convert the latter to a number. o $b -Either a GMP number resource in PHP 5.5 and earlier, a GMP object in PHP 5.6 and later, or a numeric string provided that it is possible to convert the latter to a number. RETURN VALUES
An array of GMP numbers. EXAMPLES
Example #1 Solving a linear Diophantine equation <?php // Solve the equation a*s + b*t = g // where a = 12, b = 21, g = gcd(12, 21) = 3 $a = gmp_init(12); $b = gmp_init(21); $g = gmp_gcd($a, $b); $r = gmp_gcdext($a, $b); $check_gcd = (gmp_strval($g) == gmp_strval($r['g'])); $eq_res = gmp_add(gmp_mul($a, $r['s']), gmp_mul($b, $r['t'])); $check_res = (gmp_strval($g) == gmp_strval($eq_res)); if ($check_gcd && $check_res) { $fmt = "Solution: %d*%d + %d*%d = %d "; printf($fmt, gmp_strval($a), gmp_strval($r['s']), gmp_strval($b), gmp_strval($r['t']), gmp_strval($r['g'])); } else { echo "Error while solving the equation "; } // output: Solution: 12*2 + 21*-1 = 3 ?> PHP Documentation Group GMP_GCDEXT(3)

Check Out this Related Man Page

GMP_HAMDIST(3)								 1							    GMP_HAMDIST(3)

gmp_hamdist - Hamming distance

SYNOPSIS
int gmp_hamdist (GMP $a, GMP $b) DESCRIPTION
Returns the hamming distance between $a and $b. Both operands should be non-negative. PARAMETERS
o $a -Either a GMP number resource in PHP 5.5 and earlier, a GMP object in PHP 5.6 and later, or a numeric string provided that it is possible to convert the latter to a number. It should be positive. o $b -Either a GMP number resource in PHP 5.5 and earlier, a GMP object in PHP 5.6 and later, or a numeric string provided that it is possible to convert the latter to a number. It should be positive. RETURN VALUES
A GMP number resource in PHP 5.5 and earlier, or a GMP object in PHP 5.6 and later. EXAMPLES
Example #1 gmp_hamdist(3) example <?php $ham1 = gmp_init("1001010011", 2); $ham2 = gmp_init("1011111100", 2); echo gmp_hamdist($ham1, $ham2) . " "; /* hamdist is equivalent to: */ echo gmp_popcount(gmp_xor($ham1, $ham2)) . " "; ?> The above example will output: 6 6 SEE ALSO
gmp_popcount(3), gmp_xor(3). PHP Documentation Group GMP_HAMDIST(3)
Man Page

7 More Discussions You Might Find Interesting

1. HP-UX

GMP multi precision math library

Hello all, I'm having trouble building the GNU Multi Precision (GMP 4.1.3) on the HP Intel Itanium 2 HP-UX 11i I'm hoping someone out there has had some experience building GMP on this platform. After running the ./configure and doing a make I get an error saying: `.rodata` is not a section ... (3 Replies)
Discussion started by: vyl
3 Replies

2. Shell Programming and Scripting

Using perl code find greatest number.

How would one go about finding the greatest number in an array of numbers using loops and if statements? For example, if you had an array like this: (4, 8, 3, 19, 6, 11) (3 Replies)
Discussion started by: DemonixX
3 Replies

3. Programming

Library linking with GMP

I am trying to set up the gnu multiple precision arithmetic library for some c++ programming I have to do. I am using a system with mac osx 10.6.3 and do NOT have root user access. I'm trying to use gmp 5.0.1. Since I don't have root user access, I had to install to a different directory Thus... (3 Replies)
Discussion started by: bluejayek
3 Replies

4. Shell Programming and Scripting

Unknown (probably) simple problem with my code

I'm relatively new to both UNIX and Linux and slightly less new at programming. But I can't figure out why this won't run properly. It's meant to calculate the GCD of two numbers (simple enough, you'd think). And I designed it myself and it looks good to me and my instructor won't respond. If... (1 Reply)
Discussion started by: Sevchenko
1 Replies

5. Homework & Coursework Questions

GCD Homework. Untraced error with an "if"

1. The problem statement, all variables and given/known data: Making a small GCD calculator. It's fully written, but i'm getting an error that i can't trace. 2. Relevant commands, code, scripts, algorithms: I'm relatively new to both UNIX and Linux and slightly less new at programming. But... (3 Replies)
Discussion started by: Sevchenko
3 Replies

6. Homework & Coursework Questions

Solving heat equation using crank-nicolsan scheme in FORTRAN

! The one-dimensional PDE for heat diffusion equation ! u_t=(D(u)u_x)_x + s where u(x,t) is the temperature, ! D(u) is the diffusivity and s(x,t) is a source term. ! Taking D(u)= 1 and s(x,t)=0 gives ! u_t= u_xx ! uniform one dimensional region |x|<1 for t>0 ! uniform mesh size delta x=0.1 !... (1 Reply)
Discussion started by: watto1
1 Replies

7. AIX

Strange error on 285 IBM intellistation

Solution found: dimm error! :mad: (2 Replies)
Discussion started by: Linusolaradm1
2 Replies