
(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 8 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 -4.2e+119)
(* y z)
(if (<= y -2.95e+44)
(* x y)
(if (<= y -5e-58) (* y z) (if (<= y 5.2e-88) x (* y z))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4.2e+119) {
tmp = y * z;
} else if (y <= -2.95e+44) {
tmp = x * y;
} else if (y <= -5e-58) {
tmp = y * z;
} else if (y <= 5.2e-88) {
tmp = x;
} 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 <= (-4.2d+119)) then
tmp = y * z
else if (y <= (-2.95d+44)) then
tmp = x * y
else if (y <= (-5d-58)) then
tmp = y * z
else if (y <= 5.2d-88) then
tmp = x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -4.2e+119) {
tmp = y * z;
} else if (y <= -2.95e+44) {
tmp = x * y;
} else if (y <= -5e-58) {
tmp = y * z;
} else if (y <= 5.2e-88) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4.2e+119: tmp = y * z elif y <= -2.95e+44: tmp = x * y elif y <= -5e-58: tmp = y * z elif y <= 5.2e-88: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4.2e+119) tmp = Float64(y * z); elseif (y <= -2.95e+44) tmp = Float64(x * y); elseif (y <= -5e-58) tmp = Float64(y * z); elseif (y <= 5.2e-88) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -4.2e+119) tmp = y * z; elseif (y <= -2.95e+44) tmp = x * y; elseif (y <= -5e-58) tmp = y * z; elseif (y <= 5.2e-88) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4.2e+119], N[(y * z), $MachinePrecision], If[LessEqual[y, -2.95e+44], N[(x * y), $MachinePrecision], If[LessEqual[y, -5e-58], N[(y * z), $MachinePrecision], If[LessEqual[y, 5.2e-88], x, N[(y * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.2 \cdot 10^{+119}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -2.95 \cdot 10^{+44}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -5 \cdot 10^{-58}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{-88}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -4.19999999999999966e119 or -2.94999999999999982e44 < y < -4.99999999999999977e-58 or 5.20000000000000027e-88 < y Initial program 100.0%
Taylor expanded in x around 0
*-lowering-*.f6460.1%
Simplified60.1%
if -4.19999999999999966e119 < y < -2.94999999999999982e44Initial program 99.9%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6474.1%
Simplified74.1%
Taylor expanded in y around inf
*-commutativeN/A
*-lowering-*.f6474.1%
Simplified74.1%
if -4.99999999999999977e-58 < y < 5.20000000000000027e-88Initial program 100.0%
Taylor expanded in y around 0
Simplified76.5%
Final simplification67.1%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (+ x z)))) (if (<= y -1.0) t_0 (if (<= y 1.0) (+ x (* y z)) 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 = x + (y * z);
} 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 <= (-1.0d0)) then
tmp = t_0
else if (y <= 1.0d0) then
tmp = x + (y * z)
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 <= -1.0) {
tmp = t_0;
} else if (y <= 1.0) {
tmp = x + (y * z);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x + z) tmp = 0 if y <= -1.0: tmp = t_0 elif y <= 1.0: tmp = x + (y * z) 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 = Float64(x + Float64(y * z)); 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 <= -1.0) tmp = t_0; elseif (y <= 1.0) tmp = x + (y * z); 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, -1.0], t$95$0, If[LessEqual[y, 1.0], N[(x + N[(y * z), $MachinePrecision]), $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:\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 99.9%
Taylor expanded in y around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6498.9%
Simplified98.9%
if -1 < y < 1Initial program 100.0%
Taylor expanded in z around inf
*-lowering-*.f6497.1%
Simplified97.1%
Final simplification98.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (+ x z)))) (if (<= y -2.6) t_0 (if (<= y 1.12e-88) (+ x (* x y)) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -2.6) {
tmp = t_0;
} else if (y <= 1.12e-88) {
tmp = x + (x * 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 <= (-2.6d0)) then
tmp = t_0
else if (y <= 1.12d-88) then
tmp = x + (x * 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 <= -2.6) {
tmp = t_0;
} else if (y <= 1.12e-88) {
tmp = x + (x * y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x + z) tmp = 0 if y <= -2.6: tmp = t_0 elif y <= 1.12e-88: tmp = x + (x * y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x + z)) tmp = 0.0 if (y <= -2.6) tmp = t_0; elseif (y <= 1.12e-88) tmp = Float64(x + Float64(x * 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 <= -2.6) tmp = t_0; elseif (y <= 1.12e-88) tmp = x + (x * 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, -2.6], t$95$0, If[LessEqual[y, 1.12e-88], N[(x + N[(x * y), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x + z\right)\\
\mathbf{if}\;y \leq -2.6:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.12 \cdot 10^{-88}:\\
\;\;\;\;x + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.60000000000000009 or 1.12e-88 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6492.9%
Simplified92.9%
if -2.60000000000000009 < y < 1.12e-88Initial program 100.0%
Taylor expanded in z around 0
*-commutativeN/A
*-lowering-*.f6473.6%
Simplified73.6%
Final simplification84.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* y (+ x z)))) (if (<= y -2.6) t_0 (if (<= y 2.1e-89) (* x (+ y 1.0)) t_0))))
double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -2.6) {
tmp = t_0;
} else if (y <= 2.1e-89) {
tmp = x * (y + 1.0);
} 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 <= (-2.6d0)) then
tmp = t_0
else if (y <= 2.1d-89) then
tmp = x * (y + 1.0d0)
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 <= -2.6) {
tmp = t_0;
} else if (y <= 2.1e-89) {
tmp = x * (y + 1.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x + z) tmp = 0 if y <= -2.6: tmp = t_0 elif y <= 2.1e-89: tmp = x * (y + 1.0) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x + z)) tmp = 0.0 if (y <= -2.6) tmp = t_0; elseif (y <= 2.1e-89) tmp = Float64(x * Float64(y + 1.0)); 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 <= -2.6) tmp = t_0; elseif (y <= 2.1e-89) tmp = x * (y + 1.0); 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, -2.6], t$95$0, If[LessEqual[y, 2.1e-89], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x + z\right)\\
\mathbf{if}\;y \leq -2.6:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 2.1 \cdot 10^{-89}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.60000000000000009 or 2.1000000000000001e-89 < y Initial program 100.0%
Taylor expanded in y around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6492.9%
Simplified92.9%
if -2.60000000000000009 < y < 2.1000000000000001e-89Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6473.5%
Simplified73.5%
Final simplification84.6%
(FPCore (x y z) :precision binary64 (if (<= z -8.5e-6) (* y z) (if (<= z 7.5e+96) (* x (+ y 1.0)) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -8.5e-6) {
tmp = y * z;
} else if (z <= 7.5e+96) {
tmp = x * (y + 1.0);
} 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 <= (-8.5d-6)) then
tmp = y * z
else if (z <= 7.5d+96) then
tmp = x * (y + 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 (z <= -8.5e-6) {
tmp = y * z;
} else if (z <= 7.5e+96) {
tmp = x * (y + 1.0);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -8.5e-6: tmp = y * z elif z <= 7.5e+96: tmp = x * (y + 1.0) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -8.5e-6) tmp = Float64(y * z); elseif (z <= 7.5e+96) tmp = Float64(x * Float64(y + 1.0)); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -8.5e-6) tmp = y * z; elseif (z <= 7.5e+96) tmp = x * (y + 1.0); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -8.5e-6], N[(y * z), $MachinePrecision], If[LessEqual[z, 7.5e+96], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.5 \cdot 10^{-6}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 7.5 \cdot 10^{+96}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -8.4999999999999999e-6 or 7.4999999999999996e96 < z Initial program 100.0%
Taylor expanded in x around 0
*-lowering-*.f6476.9%
Simplified76.9%
if -8.4999999999999999e-6 < z < 7.4999999999999996e96Initial program 100.0%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6480.5%
Simplified80.5%
(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 99.9%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-commutativeN/A
+-lowering-+.f6446.5%
Simplified46.5%
Taylor expanded in y around inf
*-commutativeN/A
*-lowering-*.f6445.4%
Simplified45.4%
if -1 < y < 1Initial program 100.0%
Taylor expanded in y around 0
Simplified65.8%
Final simplification56.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
Simplified35.5%
herbie shell --seed 2024150
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))