
(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 (+ x (* y (+ x z))))
double code(double x, double y, double z) {
return x + (y * (x + z));
}
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 * (x + z))
end function
public static double code(double x, double y, double z) {
return x + (y * (x + z));
}
def code(x, y, z): return x + (y * (x + z))
function code(x, y, z) return Float64(x + Float64(y * Float64(x + z))) end
function tmp = code(x, y, z) tmp = x + (y * (x + z)); end
code[x_, y_, z_] := N[(x + N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(x + z\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (<= y -4e-32) (* y z) (if (<= y 1.0) x (if (<= y 1.4e+202) (* x y) (* y z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4e-32) {
tmp = y * z;
} else if (y <= 1.0) {
tmp = x;
} else if (y <= 1.4e+202) {
tmp = x * 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 (y <= (-4d-32)) then
tmp = y * z
else if (y <= 1.0d0) then
tmp = x
else if (y <= 1.4d+202) then
tmp = x * y
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -4e-32) {
tmp = y * z;
} else if (y <= 1.0) {
tmp = x;
} else if (y <= 1.4e+202) {
tmp = x * y;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4e-32: tmp = y * z elif y <= 1.0: tmp = x elif y <= 1.4e+202: tmp = x * y else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4e-32) tmp = Float64(y * z); elseif (y <= 1.0) tmp = x; elseif (y <= 1.4e+202) tmp = Float64(x * y); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4e-32) tmp = y * z; elseif (y <= 1.0) tmp = x; elseif (y <= 1.4e+202) tmp = x * y; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4e-32], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.0], x, If[LessEqual[y, 1.4e+202], N[(x * y), $MachinePrecision], N[(y * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{-32}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.4 \cdot 10^{+202}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -4.00000000000000022e-32 or 1.40000000000000008e202 < y Initial program 100.0%
Taylor expanded in x around 0
*-lowering-*.f6462.1
Simplified62.1%
if -4.00000000000000022e-32 < y < 1Initial program 100.0%
Taylor expanded in y around 0
Simplified74.6%
if 1 < y < 1.40000000000000008e202Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
accelerator-lowering-fma.f6466.3
Simplified66.3%
Taylor expanded in y around inf
*-commutativeN/A
*-lowering-*.f6464.4
Simplified64.4%
Final simplification68.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (+ x z)))) (if (<= y -1.0) t_0 (if (<= y 1.0) (fma z y x) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -1.0) {
tmp = t_0;
} else if (y <= 1.0) {
tmp = fma(z, y, 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.0) tmp = t_0; elseif (y <= 1.0) tmp = fma(z, y, 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.0], t$95$0, If[LessEqual[y, 1.0], N[(z * y + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x + z\right)\\
\mathbf{if}\;y \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6498.3
Simplified98.3%
if -1 < y < 1Initial program 100.0%
Taylor expanded in z around inf
*-lowering-*.f6497.9
Simplified97.9%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6497.9
Applied egg-rr97.9%
Final simplification98.1%
(FPCore (x y z) :precision binary64 (if (<= z -1.4e-43) (fma z y x) (if (<= z 1.55e-127) (fma y x x) (fma z y x))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.4e-43) {
tmp = fma(z, y, x);
} else if (z <= 1.55e-127) {
tmp = fma(y, x, x);
} else {
tmp = fma(z, y, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -1.4e-43) tmp = fma(z, y, x); elseif (z <= 1.55e-127) tmp = fma(y, x, x); else tmp = fma(z, y, x); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -1.4e-43], N[(z * y + x), $MachinePrecision], If[LessEqual[z, 1.55e-127], N[(y * x + x), $MachinePrecision], N[(z * y + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.4 \cdot 10^{-43}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{elif}\;z \leq 1.55 \cdot 10^{-127}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\end{array}
\end{array}
if z < -1.3999999999999999e-43 or 1.55e-127 < z Initial program 100.0%
Taylor expanded in z around inf
*-lowering-*.f6482.7
Simplified82.7%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6482.7
Applied egg-rr82.7%
if -1.3999999999999999e-43 < z < 1.55e-127Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
accelerator-lowering-fma.f6496.3
Simplified96.3%
(FPCore (x y z) :precision binary64 (if (<= z -2.4e+89) (* y z) (if (<= z 1.5e+193) (fma y x x) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -2.4e+89) {
tmp = y * z;
} else if (z <= 1.5e+193) {
tmp = fma(y, x, x);
} else {
tmp = y * z;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -2.4e+89) tmp = Float64(y * z); elseif (z <= 1.5e+193) tmp = fma(y, x, x); else tmp = Float64(y * z); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -2.4e+89], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.5e+193], N[(y * x + x), $MachinePrecision], N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.4 \cdot 10^{+89}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1.5 \cdot 10^{+193}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -2.40000000000000004e89 or 1.5e193 < z Initial program 100.0%
Taylor expanded in x around 0
*-lowering-*.f6478.3
Simplified78.3%
if -2.40000000000000004e89 < z < 1.5e193Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
accelerator-lowering-fma.f6477.0
Simplified77.0%
(FPCore (x y z) :precision binary64 (if (<= y -2.5e-13) (* x y) (if (<= y 1.0) x (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.5e-13) {
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 <= (-2.5d-13)) 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 <= -2.5e-13) {
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 <= -2.5e-13: 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 <= -2.5e-13) 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 <= -2.5e-13) 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, -2.5e-13], N[(x * y), $MachinePrecision], If[LessEqual[y, 1.0], x, N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \cdot 10^{-13}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -2.49999999999999995e-13 or 1 < y Initial program 100.0%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
accelerator-lowering-fma.f6454.1
Simplified54.1%
Taylor expanded in y around inf
*-commutativeN/A
*-lowering-*.f6452.4
Simplified52.4%
if -2.49999999999999995e-13 < y < 1Initial program 100.0%
Taylor expanded in y around 0
Simplified73.4%
Final simplification62.7%
(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
Simplified37.7%
herbie shell --seed 2024204
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))