
(FPCore (x y z) :precision binary64 (+ x (* y (+ z x))))
double code(double x, double y, double z) {
return x + (y * (z + x));
}
real(8) function code(x, y, z)
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]
\begin{array}{l}
\\
x + y \cdot \left(z + x\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ x (* y (+ z x))))
double code(double x, double y, double z) {
return x + (y * (z + x));
}
real(8) function code(x, y, z)
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]
\begin{array}{l}
\\
x + y \cdot \left(z + x\right)
\end{array}
(FPCore (x y z) :precision binary64 (fma y (+ x z) x))
double code(double x, double y, double z) {
return fma(y, (x + z), x);
}
function code(x, y, z) return fma(y, Float64(x + z), x) end
code[x_, y_, z_] := N[(y * N[(x + z), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x + z, x\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
fma-define100.0%
+-commutative100.0%
Simplified100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -2e+285)
(* y z)
(if (<= y -2.5e+25)
(* x y)
(if (<= y -3e-9)
(* y z)
(if (<= y 1.55e-50)
x
(if (<= y 2.3e+18)
(* y z)
(if (<= y 7.5e+68)
(* x y)
(if (<= y 7.8e+213) (* y z) (* x y)))))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2e+285) {
tmp = y * z;
} else if (y <= -2.5e+25) {
tmp = x * y;
} else if (y <= -3e-9) {
tmp = y * z;
} else if (y <= 1.55e-50) {
tmp = x;
} else if (y <= 2.3e+18) {
tmp = y * z;
} else if (y <= 7.5e+68) {
tmp = x * y;
} else if (y <= 7.8e+213) {
tmp = y * z;
} else {
tmp = x * y;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= (-2d+285)) then
tmp = y * z
else if (y <= (-2.5d+25)) then
tmp = x * y
else if (y <= (-3d-9)) then
tmp = y * z
else if (y <= 1.55d-50) then
tmp = x
else if (y <= 2.3d+18) then
tmp = y * z
else if (y <= 7.5d+68) then
tmp = x * y
else if (y <= 7.8d+213) then
tmp = y * z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2e+285) {
tmp = y * z;
} else if (y <= -2.5e+25) {
tmp = x * y;
} else if (y <= -3e-9) {
tmp = y * z;
} else if (y <= 1.55e-50) {
tmp = x;
} else if (y <= 2.3e+18) {
tmp = y * z;
} else if (y <= 7.5e+68) {
tmp = x * y;
} else if (y <= 7.8e+213) {
tmp = y * z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2e+285: tmp = y * z elif y <= -2.5e+25: tmp = x * y elif y <= -3e-9: tmp = y * z elif y <= 1.55e-50: tmp = x elif y <= 2.3e+18: tmp = y * z elif y <= 7.5e+68: tmp = x * y elif y <= 7.8e+213: tmp = y * z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2e+285) tmp = Float64(y * z); elseif (y <= -2.5e+25) tmp = Float64(x * y); elseif (y <= -3e-9) tmp = Float64(y * z); elseif (y <= 1.55e-50) tmp = x; elseif (y <= 2.3e+18) tmp = Float64(y * z); elseif (y <= 7.5e+68) tmp = Float64(x * y); elseif (y <= 7.8e+213) tmp = Float64(y * z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2e+285) tmp = y * z; elseif (y <= -2.5e+25) tmp = x * y; elseif (y <= -3e-9) tmp = y * z; elseif (y <= 1.55e-50) tmp = x; elseif (y <= 2.3e+18) tmp = y * z; elseif (y <= 7.5e+68) tmp = x * y; elseif (y <= 7.8e+213) tmp = y * z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2e+285], N[(y * z), $MachinePrecision], If[LessEqual[y, -2.5e+25], N[(x * y), $MachinePrecision], If[LessEqual[y, -3e-9], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.55e-50], x, If[LessEqual[y, 2.3e+18], N[(y * z), $MachinePrecision], If[LessEqual[y, 7.5e+68], N[(x * y), $MachinePrecision], If[LessEqual[y, 7.8e+213], N[(y * z), $MachinePrecision], N[(x * y), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{+285}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -2.5 \cdot 10^{+25}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -3 \cdot 10^{-9}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1.55 \cdot 10^{-50}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 2.3 \cdot 10^{+18}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 7.5 \cdot 10^{+68}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 7.8 \cdot 10^{+213}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -2e285 or -2.50000000000000012e25 < y < -2.99999999999999998e-9 or 1.5500000000000001e-50 < y < 2.3e18 or 7.49999999999999959e68 < y < 7.8000000000000003e213Initial program 99.9%
Taylor expanded in x around 0 75.2%
if -2e285 < y < -2.50000000000000012e25 or 2.3e18 < y < 7.49999999999999959e68 or 7.8000000000000003e213 < y Initial program 100.0%
Taylor expanded in x around inf 68.3%
Taylor expanded in y around inf 68.3%
if -2.99999999999999998e-9 < y < 1.5500000000000001e-50Initial program 100.0%
Taylor expanded in y around 0 78.2%
(FPCore (x y z) :precision binary64 (if (<= z -5.5e+72) (* y z) (if (<= z 3.1e+31) (* x (+ 1.0 y)) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -5.5e+72) {
tmp = y * z;
} else if (z <= 3.1e+31) {
tmp = x * (1.0 + y);
} else {
tmp = y * z;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (z <= (-5.5d+72)) then
tmp = y * z
else if (z <= 3.1d+31) then
tmp = x * (1.0d0 + y)
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -5.5e+72) {
tmp = y * z;
} else if (z <= 3.1e+31) {
tmp = x * (1.0 + y);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -5.5e+72: tmp = y * z elif z <= 3.1e+31: tmp = x * (1.0 + y) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -5.5e+72) tmp = Float64(y * z); elseif (z <= 3.1e+31) tmp = Float64(x * Float64(1.0 + y)); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -5.5e+72) tmp = y * z; elseif (z <= 3.1e+31) tmp = x * (1.0 + y); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -5.5e+72], N[(y * z), $MachinePrecision], If[LessEqual[z, 3.1e+31], N[(x * N[(1.0 + y), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.5 \cdot 10^{+72}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 3.1 \cdot 10^{+31}:\\
\;\;\;\;x \cdot \left(1 + y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -5.5e72 or 3.1000000000000002e31 < z Initial program 100.0%
Taylor expanded in x around 0 76.7%
if -5.5e72 < z < 3.1000000000000002e31Initial program 100.0%
Taylor expanded in x around inf 82.4%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (+ x z)))) (if (<= y -19.0) t_0 (if (<= y 1700000.0) (* x (+ 1.0 y)) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -19.0) {
tmp = t_0;
} else if (y <= 1700000.0) {
tmp = x * (1.0 + y);
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = y * (x + z)
if (y <= (-19.0d0)) then
tmp = t_0
else if (y <= 1700000.0d0) then
tmp = x * (1.0d0 + y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -19.0) {
tmp = t_0;
} else if (y <= 1700000.0) {
tmp = x * (1.0 + y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x + z) tmp = 0 if y <= -19.0: tmp = t_0 elif y <= 1700000.0: tmp = x * (1.0 + y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x + z)) tmp = 0.0 if (y <= -19.0) tmp = t_0; elseif (y <= 1700000.0) tmp = Float64(x * Float64(1.0 + y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (x + z); tmp = 0.0; if (y <= -19.0) tmp = t_0; elseif (y <= 1700000.0) tmp = x * (1.0 + y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -19.0], t$95$0, If[LessEqual[y, 1700000.0], N[(x * N[(1.0 + y), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x + z\right)\\
\mathbf{if}\;y \leq -19:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1700000:\\
\;\;\;\;x \cdot \left(1 + y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -19 or 1.7e6 < y Initial program 100.0%
Taylor expanded in y around inf 99.4%
if -19 < y < 1.7e6Initial program 100.0%
Taylor expanded in x around inf 76.6%
(FPCore (x y z) :precision binary64 (if (<= y -1.0) (* x y) (if (<= y 1.0) x (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.0) {
tmp = x * y;
} else if (y <= 1.0) {
tmp = x;
} else {
tmp = x * y;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= (-1.0d0)) then
tmp = x * y
else if (y <= 1.0d0) then
tmp = x
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.0) {
tmp = x * y;
} else if (y <= 1.0) {
tmp = x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.0: tmp = x * y elif y <= 1.0: tmp = x else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.0) tmp = Float64(x * y); elseif (y <= 1.0) tmp = x; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.0) tmp = x * y; elseif (y <= 1.0) tmp = x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.0], N[(x * y), $MachinePrecision], If[LessEqual[y, 1.0], x, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
Taylor expanded in x around inf 50.7%
Taylor expanded in y around inf 49.2%
if -1 < y < 1Initial program 100.0%
Taylor expanded in y around 0 73.8%
(FPCore (x y z) :precision binary64 (+ x (* y (+ z x))))
double code(double x, double y, double z) {
return x + (y * (z + x));
}
real(8) function code(x, y, z)
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]
\begin{array}{l}
\\
x + y \cdot \left(z + x\right)
\end{array}
Initial program 100.0%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in y around 0 37.0%
herbie shell --seed 2024034 -o generate:simplify
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))