
(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 (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%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -3.8e-64)
(* y z)
(if (<= y -2.25e-91)
x
(if (<= y -9.2e-111)
(* y z)
(if (<= y 2.6e-50) x (if (<= y 1.25e+67) (* y z) (* y x)))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.8e-64) {
tmp = y * z;
} else if (y <= -2.25e-91) {
tmp = x;
} else if (y <= -9.2e-111) {
tmp = y * z;
} else if (y <= 2.6e-50) {
tmp = x;
} else if (y <= 1.25e+67) {
tmp = y * z;
} else {
tmp = y * x;
}
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 <= (-3.8d-64)) then
tmp = y * z
else if (y <= (-2.25d-91)) then
tmp = x
else if (y <= (-9.2d-111)) then
tmp = y * z
else if (y <= 2.6d-50) then
tmp = x
else if (y <= 1.25d+67) then
tmp = y * z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -3.8e-64) {
tmp = y * z;
} else if (y <= -2.25e-91) {
tmp = x;
} else if (y <= -9.2e-111) {
tmp = y * z;
} else if (y <= 2.6e-50) {
tmp = x;
} else if (y <= 1.25e+67) {
tmp = y * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.8e-64: tmp = y * z elif y <= -2.25e-91: tmp = x elif y <= -9.2e-111: tmp = y * z elif y <= 2.6e-50: tmp = x elif y <= 1.25e+67: tmp = y * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.8e-64) tmp = Float64(y * z); elseif (y <= -2.25e-91) tmp = x; elseif (y <= -9.2e-111) tmp = Float64(y * z); elseif (y <= 2.6e-50) tmp = x; elseif (y <= 1.25e+67) tmp = Float64(y * z); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.8e-64) tmp = y * z; elseif (y <= -2.25e-91) tmp = x; elseif (y <= -9.2e-111) tmp = y * z; elseif (y <= 2.6e-50) tmp = x; elseif (y <= 1.25e+67) tmp = y * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.8e-64], N[(y * z), $MachinePrecision], If[LessEqual[y, -2.25e-91], x, If[LessEqual[y, -9.2e-111], N[(y * z), $MachinePrecision], If[LessEqual[y, 2.6e-50], x, If[LessEqual[y, 1.25e+67], N[(y * z), $MachinePrecision], N[(y * x), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.8 \cdot 10^{-64}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -2.25 \cdot 10^{-91}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq -9.2 \cdot 10^{-111}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 2.6 \cdot 10^{-50}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.25 \cdot 10^{+67}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -3.8000000000000002e-64 or -2.24999999999999988e-91 < y < -9.2e-111 or 2.6000000000000001e-50 < y < 1.24999999999999994e67Initial program 100.0%
Taylor expanded in x around 0 96.9%
fma-define98.9%
+-commutative98.9%
Simplified98.9%
Taylor expanded in x around 0 64.9%
if -3.8000000000000002e-64 < y < -2.24999999999999988e-91 or -9.2e-111 < y < 2.6000000000000001e-50Initial program 100.0%
Taylor expanded in y around 0 77.8%
if 1.24999999999999994e67 < y Initial program 100.0%
Taylor expanded in z around 0 59.3%
*-commutative59.3%
Simplified59.3%
Taylor expanded in y around inf 59.3%
*-commutative59.3%
Simplified59.3%
Final simplification69.2%
(FPCore (x y z)
:precision binary64
(if (or (<= y -4.3e-65)
(and (not (<= y -1.3e-89)) (or (<= y -6e-111) (not (<= y 1.02e-50)))))
(* y (+ x z))
x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4.3e-65) || (!(y <= -1.3e-89) && ((y <= -6e-111) || !(y <= 1.02e-50)))) {
tmp = y * (x + z);
} else {
tmp = x;
}
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.3d-65)) .or. (.not. (y <= (-1.3d-89))) .and. (y <= (-6d-111)) .or. (.not. (y <= 1.02d-50))) then
tmp = y * (x + z)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -4.3e-65) || (!(y <= -1.3e-89) && ((y <= -6e-111) || !(y <= 1.02e-50)))) {
tmp = y * (x + z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4.3e-65) or (not (y <= -1.3e-89) and ((y <= -6e-111) or not (y <= 1.02e-50))): tmp = y * (x + z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4.3e-65) || (!(y <= -1.3e-89) && ((y <= -6e-111) || !(y <= 1.02e-50)))) tmp = Float64(y * Float64(x + z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -4.3e-65) || (~((y <= -1.3e-89)) && ((y <= -6e-111) || ~((y <= 1.02e-50))))) tmp = y * (x + z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4.3e-65], And[N[Not[LessEqual[y, -1.3e-89]], $MachinePrecision], Or[LessEqual[y, -6e-111], N[Not[LessEqual[y, 1.02e-50]], $MachinePrecision]]]], N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.3 \cdot 10^{-65} \lor \neg \left(y \leq -1.3 \cdot 10^{-89}\right) \land \left(y \leq -6 \cdot 10^{-111} \lor \neg \left(y \leq 1.02 \cdot 10^{-50}\right)\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -4.30000000000000024e-65 or -1.2999999999999999e-89 < y < -6.00000000000000016e-111 or 1.0199999999999999e-50 < y Initial program 100.0%
Taylor expanded in x around 0 97.3%
fma-define98.6%
+-commutative98.6%
Simplified98.6%
Taylor expanded in y around inf 93.0%
+-commutative93.0%
Simplified93.0%
if -4.30000000000000024e-65 < y < -1.2999999999999999e-89 or -6.00000000000000016e-111 < y < 1.0199999999999999e-50Initial program 100.0%
Taylor expanded in y around 0 77.8%
Final simplification86.7%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (+ x z))))
(if (<= y -6.8e-65)
t_0
(if (<= y -1.75e-91)
(+ x (* y x))
(if (or (<= y -9.2e-111) (not (<= y 1.55e-50))) t_0 x)))))
double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -6.8e-65) {
tmp = t_0;
} else if (y <= -1.75e-91) {
tmp = x + (y * x);
} else if ((y <= -9.2e-111) || !(y <= 1.55e-50)) {
tmp = t_0;
} else {
tmp = x;
}
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 <= (-6.8d-65)) then
tmp = t_0
else if (y <= (-1.75d-91)) then
tmp = x + (y * x)
else if ((y <= (-9.2d-111)) .or. (.not. (y <= 1.55d-50))) then
tmp = t_0
else
tmp = x
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 <= -6.8e-65) {
tmp = t_0;
} else if (y <= -1.75e-91) {
tmp = x + (y * x);
} else if ((y <= -9.2e-111) || !(y <= 1.55e-50)) {
tmp = t_0;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x + z) tmp = 0 if y <= -6.8e-65: tmp = t_0 elif y <= -1.75e-91: tmp = x + (y * x) elif (y <= -9.2e-111) or not (y <= 1.55e-50): tmp = t_0 else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x + z)) tmp = 0.0 if (y <= -6.8e-65) tmp = t_0; elseif (y <= -1.75e-91) tmp = Float64(x + Float64(y * x)); elseif ((y <= -9.2e-111) || !(y <= 1.55e-50)) tmp = t_0; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (x + z); tmp = 0.0; if (y <= -6.8e-65) tmp = t_0; elseif (y <= -1.75e-91) tmp = x + (y * x); elseif ((y <= -9.2e-111) || ~((y <= 1.55e-50))) tmp = t_0; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -6.8e-65], t$95$0, If[LessEqual[y, -1.75e-91], N[(x + N[(y * x), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, -9.2e-111], N[Not[LessEqual[y, 1.55e-50]], $MachinePrecision]], t$95$0, x]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x + z\right)\\
\mathbf{if}\;y \leq -6.8 \cdot 10^{-65}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -1.75 \cdot 10^{-91}:\\
\;\;\;\;x + y \cdot x\\
\mathbf{elif}\;y \leq -9.2 \cdot 10^{-111} \lor \neg \left(y \leq 1.55 \cdot 10^{-50}\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -6.79999999999999973e-65 or -1.7499999999999999e-91 < y < -9.2e-111 or 1.5500000000000001e-50 < y Initial program 100.0%
Taylor expanded in x around 0 97.3%
fma-define98.6%
+-commutative98.6%
Simplified98.6%
Taylor expanded in y around inf 93.0%
+-commutative93.0%
Simplified93.0%
if -6.79999999999999973e-65 < y < -1.7499999999999999e-91Initial program 100.0%
Taylor expanded in z around 0 86.1%
*-commutative86.1%
Simplified86.1%
if -9.2e-111 < y < 1.5500000000000001e-50Initial program 100.0%
Taylor expanded in y around 0 77.2%
Final simplification86.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -1400000.0) (not (<= y 1.0))) (* y (+ x z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1400000.0) || !(y <= 1.0)) {
tmp = y * (x + z);
} else {
tmp = x + (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 <= (-1400000.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = y * (x + z)
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1400000.0) || !(y <= 1.0)) {
tmp = y * (x + z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1400000.0) or not (y <= 1.0): tmp = y * (x + z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1400000.0) || !(y <= 1.0)) tmp = Float64(y * Float64(x + z)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1400000.0) || ~((y <= 1.0))) tmp = y * (x + z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1400000.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1400000 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -1.4e6 or 1 < y Initial program 100.0%
Taylor expanded in x around 0 96.5%
fma-define98.3%
+-commutative98.3%
Simplified98.3%
Taylor expanded in y around inf 99.4%
+-commutative99.4%
Simplified99.4%
if -1.4e6 < y < 1Initial program 100.0%
Taylor expanded in z around inf 99.5%
Final simplification99.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.25e-9) (not (<= y 1.0))) (* y x) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.25e-9) || !(y <= 1.0)) {
tmp = y * x;
} else {
tmp = x;
}
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.25d-9)) .or. (.not. (y <= 1.0d0))) then
tmp = y * x
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.25e-9) || !(y <= 1.0)) {
tmp = y * x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.25e-9) or not (y <= 1.0): tmp = y * x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.25e-9) || !(y <= 1.0)) tmp = Float64(y * x); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.25e-9) || ~((y <= 1.0))) tmp = y * x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.25e-9], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y * x), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.25 \cdot 10^{-9} \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.25e-9 or 1 < y Initial program 100.0%
Taylor expanded in z around 0 46.9%
*-commutative46.9%
Simplified46.9%
Taylor expanded in y around inf 46.4%
*-commutative46.4%
Simplified46.4%
if -1.25e-9 < y < 1Initial program 100.0%
Taylor expanded in y around 0 68.2%
Final simplification58.0%
(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 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.6%
Final simplification37.6%
herbie shell --seed 2024095
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))