
(FPCore (x y z) :precision binary64 :pre TRUE (+ x (* y (+ z x))))
double code(double x, double y, double z) {
return x + (y * (z + x));
}
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (y * (z + x))
end function
public static double code(double x, double y, double z) {
return x + (y * (z + x));
}
def code(x, y, z): return x + (y * (z + x))
function code(x, y, z) return Float64(x + Float64(y * Float64(z + x))) end
function tmp = code(x, y, z) tmp = x + (y * (z + x)); end
code[x_, y_, z_] := N[(x + N[(y * N[(z + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = x + (y * (z + x)) END code
x + y \cdot \left(z + x\right)
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 :pre TRUE (+ x (* y (+ z x))))
double code(double x, double y, double z) {
return x + (y * (z + x));
}
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (y * (z + x))
end function
public static double code(double x, double y, double z) {
return x + (y * (z + x));
}
def code(x, y, z): return x + (y * (z + x))
function code(x, y, z) return Float64(x + Float64(y * Float64(z + x))) end
function tmp = code(x, y, z) tmp = x + (y * (z + x)); end
code[x_, y_, z_] := N[(x + N[(y * N[(z + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = x + (y * (z + x)) END code
x + y \cdot \left(z + x\right)
(FPCore (x y z) :precision binary64 :pre TRUE (fma y (+ z x) x))
double code(double x, double y, double z) {
return fma(y, (z + x), x);
}
function code(x, y, z) return fma(y, Float64(z + x), x) end
code[x_, y_, z_] := N[(y * N[(z + x), $MachinePrecision] + x), $MachinePrecision]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = (y * (z + x)) + x END code
\mathsf{fma}\left(y, z + x, x\right)
Initial program 100.0%
Applied rewrites100.0%
(FPCore (x y z)
:precision binary64
:pre TRUE
(let* ((t_0 (* y (+ x z))))
(if (<= y -1.3910059451961023)
t_0
(if (<= y 0.0036597640836557375) (fma y z x) t_0))))double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -1.3910059451961023) {
tmp = t_0;
} else if (y <= 0.0036597640836557375) {
tmp = fma(y, z, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(y * Float64(x + z)) tmp = 0.0 if (y <= -1.3910059451961023) tmp = t_0; elseif (y <= 0.0036597640836557375) tmp = fma(y, z, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.3910059451961023], t$95$0, If[LessEqual[y, 0.0036597640836557375], N[(y * z + x), $MachinePrecision], t$95$0]]]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = LET t_0 = (y * (x + z)) IN LET tmp_1 = IF (y <= (36597640836557375314253004461306773009710013866424560546875e-61)) THEN ((y * z) + x) ELSE t_0 ENDIF IN LET tmp = IF (y <= (-13910059451961023224697555633611045777797698974609375e-52)) THEN t_0 ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
t_0 := y \cdot \left(x + z\right)\\
\mathbf{if}\;y \leq -1.3910059451961023:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.0036597640836557375:\\
\;\;\;\;\mathsf{fma}\left(y, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if y < -1.3910059451961023 or 0.0036597640836557375 < y Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites62.1%
Applied rewrites62.1%
Taylor expanded in y around inf
Applied rewrites64.3%
if -1.3910059451961023 < y < 0.0036597640836557375Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites76.4%
Applied rewrites76.4%
(FPCore (x y z) :precision binary64 :pre TRUE (if (<= x -4.420245809256181e-50) (fma y x x) (if (<= x 456191841.59206736) (fma y z x) (fma y x x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.420245809256181e-50) {
tmp = fma(y, x, x);
} else if (x <= 456191841.59206736) {
tmp = fma(y, z, x);
} else {
tmp = fma(y, x, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -4.420245809256181e-50) tmp = fma(y, x, x); elseif (x <= 456191841.59206736) tmp = fma(y, z, x); else tmp = fma(y, x, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -4.420245809256181e-50], N[(y * x + x), $MachinePrecision], If[LessEqual[x, 456191841.59206736], N[(y * z + x), $MachinePrecision], N[(y * x + x), $MachinePrecision]]]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = LET tmp_1 = IF (x <= (45619184159206736087799072265625e-23)) THEN ((y * z) + x) ELSE ((y * x) + x) ENDIF IN LET tmp = IF (x <= (-44202458092561807173146183805990310442416852708706562951185861630934021423055811815087956022190442979509568437286867776620587384972527189574975636787712574005126953125e-216)) THEN ((y * x) + x) ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;x \leq -4.420245809256181 \cdot 10^{-50}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{elif}\;x \leq 456191841.59206736:\\
\;\;\;\;\mathsf{fma}\left(y, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\end{array}
if x < -4.4202458092561807e-50 or 456191841.59206736 < x Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites62.1%
Applied rewrites62.1%
if -4.4202458092561807e-50 < x < 456191841.59206736Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites76.4%
Applied rewrites76.4%
(FPCore (x y z) :precision binary64 :pre TRUE (if (<= x -1.2014353339475216e-53) (fma y x x) (if (<= x 1.3907246641268288e-133) (* y z) (fma y x x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.2014353339475216e-53) {
tmp = fma(y, x, x);
} else if (x <= 1.3907246641268288e-133) {
tmp = y * z;
} else {
tmp = fma(y, x, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -1.2014353339475216e-53) tmp = fma(y, x, x); elseif (x <= 1.3907246641268288e-133) tmp = Float64(y * z); else tmp = fma(y, x, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -1.2014353339475216e-53], N[(y * x + x), $MachinePrecision], If[LessEqual[x, 1.3907246641268288e-133], N[(y * z), $MachinePrecision], N[(y * x + x), $MachinePrecision]]]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = LET tmp_1 = IF (x <= (13907246641268287719553288589367698732274009277678938853341083963550402305825730272558285284260707557226592286720658421468340914383077588215032524302117800378662076704866440675793204111827833749549383931163536547600078549247750976353053708772891633938598045310131695191357079148094045872458853184477607279647119117250357415993544663024295005016028881072998046875e-494)) THEN (y * z) ELSE ((y * x) + x) ENDIF IN LET tmp = IF (x <= (-1201435333947521567179383940228922831410793169252770766996959593329040310462231836384689301534482831918011668944531164721304996863097958037513990348088555037975311279296875e-224)) THEN ((y * x) + x) ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;x \leq -1.2014353339475216 \cdot 10^{-53}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{elif}\;x \leq 1.3907246641268288 \cdot 10^{-133}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\end{array}
if x < -1.2014353339475216e-53 or 1.3907246641268288e-133 < x Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites62.1%
Applied rewrites62.1%
if -1.2014353339475216e-53 < x < 1.3907246641268288e-133Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites62.1%
Applied rewrites62.1%
Taylor expanded in x around 0
Applied rewrites41.4%
(FPCore (x y z)
:precision binary64
:pre TRUE
(if (<= y -1.7369450345442874e+177)
(* y z)
(if (<= y -1.6957869950355719e+109)
(* x y)
(if (<= y -1.9567418453105813e-16)
(* y z)
(if (<= y 2.3080107308185876e-32) (* x 1.0) (* y z))))))double code(double x, double y, double z) {
double tmp;
if (y <= -1.7369450345442874e+177) {
tmp = y * z;
} else if (y <= -1.6957869950355719e+109) {
tmp = x * y;
} else if (y <= -1.9567418453105813e-16) {
tmp = y * z;
} else if (y <= 2.3080107308185876e-32) {
tmp = x * 1.0;
} else {
tmp = y * z;
}
return tmp;
}
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= (-1.7369450345442874d+177)) then
tmp = y * z
else if (y <= (-1.6957869950355719d+109)) then
tmp = x * y
else if (y <= (-1.9567418453105813d-16)) then
tmp = y * z
else if (y <= 2.3080107308185876d-32) then
tmp = x * 1.0d0
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.7369450345442874e+177) {
tmp = y * z;
} else if (y <= -1.6957869950355719e+109) {
tmp = x * y;
} else if (y <= -1.9567418453105813e-16) {
tmp = y * z;
} else if (y <= 2.3080107308185876e-32) {
tmp = x * 1.0;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.7369450345442874e+177: tmp = y * z elif y <= -1.6957869950355719e+109: tmp = x * y elif y <= -1.9567418453105813e-16: tmp = y * z elif y <= 2.3080107308185876e-32: tmp = x * 1.0 else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.7369450345442874e+177) tmp = Float64(y * z); elseif (y <= -1.6957869950355719e+109) tmp = Float64(x * y); elseif (y <= -1.9567418453105813e-16) tmp = Float64(y * z); elseif (y <= 2.3080107308185876e-32) tmp = Float64(x * 1.0); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.7369450345442874e+177) tmp = y * z; elseif (y <= -1.6957869950355719e+109) tmp = x * y; elseif (y <= -1.9567418453105813e-16) tmp = y * z; elseif (y <= 2.3080107308185876e-32) tmp = x * 1.0; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.7369450345442874e+177], N[(y * z), $MachinePrecision], If[LessEqual[y, -1.6957869950355719e+109], N[(x * y), $MachinePrecision], If[LessEqual[y, -1.9567418453105813e-16], N[(y * z), $MachinePrecision], If[LessEqual[y, 2.3080107308185876e-32], N[(x * 1.0), $MachinePrecision], N[(y * z), $MachinePrecision]]]]]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = LET tmp_3 = IF (y <= (2308010730818587590762110147375810142062287416606639275854782999805688643013554654814280253649627638878882862627506256103515625e-158)) THEN (x * (1)) ELSE (y * z) ENDIF IN LET tmp_2 = IF (y <= (-195674184531058127709734167246648549435989266850367818140199460685835219919681549072265625e-105)) THEN (y * z) ELSE tmp_3 ENDIF IN LET tmp_1 = IF (y <= (-16957869950355718931465531247763550139979082796806578673657974316572747102086548313566244811727926991247114240)) THEN (x * y) ELSE tmp_2 ENDIF IN LET tmp = IF (y <= (-1736945034544287412347033863073873456965503088732749302439491853026289663537555191881741523762841739547105102182173562149034075232772331190135807316162207859763136650384978739200)) THEN (y * z) ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;y \leq -1.7369450345442874 \cdot 10^{+177}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -1.6957869950355719 \cdot 10^{+109}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -1.9567418453105813 \cdot 10^{-16}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 2.3080107308185876 \cdot 10^{-32}:\\
\;\;\;\;x \cdot 1\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
if y < -1.7369450345442874e177 or -1.6957869950355719e109 < y < -1.9567418453105813e-16 or 2.3080107308185876e-32 < y Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites62.1%
Applied rewrites62.1%
Taylor expanded in x around 0
Applied rewrites41.4%
if -1.7369450345442874e177 < y < -1.6957869950355719e109Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites62.1%
Applied rewrites62.1%
Taylor expanded in y around inf
Applied rewrites27.2%
if -1.9567418453105813e-16 < y < 2.3080107308185876e-32Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites62.1%
Taylor expanded in y around 0
Applied rewrites37.3%
(FPCore (x y z) :precision binary64 :pre TRUE (if (<= y -1.3910059451961023) (* x y) (if (<= y 0.0036597640836557375) (* x 1.0) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.3910059451961023) {
tmp = x * y;
} else if (y <= 0.0036597640836557375) {
tmp = x * 1.0;
} else {
tmp = x * y;
}
return tmp;
}
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= (-1.3910059451961023d0)) then
tmp = x * y
else if (y <= 0.0036597640836557375d0) then
tmp = x * 1.0d0
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.3910059451961023) {
tmp = x * y;
} else if (y <= 0.0036597640836557375) {
tmp = x * 1.0;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.3910059451961023: tmp = x * y elif y <= 0.0036597640836557375: tmp = x * 1.0 else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.3910059451961023) tmp = Float64(x * y); elseif (y <= 0.0036597640836557375) tmp = Float64(x * 1.0); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.3910059451961023) tmp = x * y; elseif (y <= 0.0036597640836557375) tmp = x * 1.0; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.3910059451961023], N[(x * y), $MachinePrecision], If[LessEqual[y, 0.0036597640836557375], N[(x * 1.0), $MachinePrecision], N[(x * y), $MachinePrecision]]]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = LET tmp_1 = IF (y <= (36597640836557375314253004461306773009710013866424560546875e-61)) THEN (x * (1)) ELSE (x * y) ENDIF IN LET tmp = IF (y <= (-13910059451961023224697555633611045777797698974609375e-52)) THEN (x * y) ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;y \leq -1.3910059451961023:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 0.0036597640836557375:\\
\;\;\;\;x \cdot 1\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
if y < -1.3910059451961023 or 0.0036597640836557375 < y Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites62.1%
Applied rewrites62.1%
Taylor expanded in y around inf
Applied rewrites27.2%
if -1.3910059451961023 < y < 0.0036597640836557375Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites62.1%
Taylor expanded in y around 0
Applied rewrites37.3%
(FPCore (x y z) :precision binary64 :pre TRUE (* x 1.0))
double code(double x, double y, double z) {
return x * 1.0;
}
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * 1.0d0
end function
public static double code(double x, double y, double z) {
return x * 1.0;
}
def code(x, y, z): return x * 1.0
function code(x, y, z) return Float64(x * 1.0) end
function tmp = code(x, y, z) tmp = x * 1.0; end
code[x_, y_, z_] := N[(x * 1.0), $MachinePrecision]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = x * (1) END code
x \cdot 1
Initial program 100.0%
Taylor expanded in x around inf
Applied rewrites62.1%
Taylor expanded in y around 0
Applied rewrites37.3%
herbie shell --seed 2026092
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))