Pre-processing large mathematical expressions for gmp?

Brian Gladman brg at
Tue Jun 15 08:57:59 CEST 2010

From: "Jim Skea" <jimskea at>
Sent: Tuesday, June 15, 2010 1:32 AM
To: <gmp-discuss at>
Subject: Pre-processing large mathematical expressions for gmp?

> Does anyone know of a pre-processor that would take a long mathematical
> expression and convert it into the equivalent set of gmp function calls,
> creating any temporary variables as necessary?
> Something that would take, as a small example
> y = y + h6*(k1+2*k2+2*k3+k4)
> and produce
> mpf_mul_ui(t0, k3, 2);
> mpf_mul_ui(t1, k2, 2);
> mpf_add(t2,t0,t1);
> mpf_add(t3,t2,k1);
> mpf_add(t4,t3,k4);
> mpf_mul(t5,t4,h6);
> mpf_add(y, y, t5);
> Failing that, any idea about how to do this (using yacc? bison?) other 
> than
> writing a dedicated program?

The obvious solution is to use the GMP C++ interface as this effectively 
does this for you.

If you need C source code output there are quite a few C++ to C translators 
around that might do what you want if you represent your starting formulae 
in C++.

     Brian Gladman

More information about the gmp-discuss mailing list