
(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-def100.0%
+-commutative100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -2.8e+128)
(* y x)
(if (<= y -3.3e-7)
(* y z)
(if (<= y -5e-103)
x
(if (<= y -3.1e-121)
(* y z)
(if (<= y 2.3e-145)
x
(if (<= y 4.3e-128)
(* y z)
(if (<= y 1.8e-20)
x
(if (or (<= y 3.4e+81)
(and (not (<= y 3.2e+126)) (<= y 1.2e+156)))
(* y z)
(* y x))))))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.8e+128) {
tmp = y * x;
} else if (y <= -3.3e-7) {
tmp = y * z;
} else if (y <= -5e-103) {
tmp = x;
} else if (y <= -3.1e-121) {
tmp = y * z;
} else if (y <= 2.3e-145) {
tmp = x;
} else if (y <= 4.3e-128) {
tmp = y * z;
} else if (y <= 1.8e-20) {
tmp = x;
} else if ((y <= 3.4e+81) || (!(y <= 3.2e+126) && (y <= 1.2e+156))) {
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 <= (-2.8d+128)) then
tmp = y * x
else if (y <= (-3.3d-7)) then
tmp = y * z
else if (y <= (-5d-103)) then
tmp = x
else if (y <= (-3.1d-121)) then
tmp = y * z
else if (y <= 2.3d-145) then
tmp = x
else if (y <= 4.3d-128) then
tmp = y * z
else if (y <= 1.8d-20) then
tmp = x
else if ((y <= 3.4d+81) .or. (.not. (y <= 3.2d+126)) .and. (y <= 1.2d+156)) 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 <= -2.8e+128) {
tmp = y * x;
} else if (y <= -3.3e-7) {
tmp = y * z;
} else if (y <= -5e-103) {
tmp = x;
} else if (y <= -3.1e-121) {
tmp = y * z;
} else if (y <= 2.3e-145) {
tmp = x;
} else if (y <= 4.3e-128) {
tmp = y * z;
} else if (y <= 1.8e-20) {
tmp = x;
} else if ((y <= 3.4e+81) || (!(y <= 3.2e+126) && (y <= 1.2e+156))) {
tmp = y * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.8e+128: tmp = y * x elif y <= -3.3e-7: tmp = y * z elif y <= -5e-103: tmp = x elif y <= -3.1e-121: tmp = y * z elif y <= 2.3e-145: tmp = x elif y <= 4.3e-128: tmp = y * z elif y <= 1.8e-20: tmp = x elif (y <= 3.4e+81) or (not (y <= 3.2e+126) and (y <= 1.2e+156)): tmp = y * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.8e+128) tmp = Float64(y * x); elseif (y <= -3.3e-7) tmp = Float64(y * z); elseif (y <= -5e-103) tmp = x; elseif (y <= -3.1e-121) tmp = Float64(y * z); elseif (y <= 2.3e-145) tmp = x; elseif (y <= 4.3e-128) tmp = Float64(y * z); elseif (y <= 1.8e-20) tmp = x; elseif ((y <= 3.4e+81) || (!(y <= 3.2e+126) && (y <= 1.2e+156))) 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 <= -2.8e+128) tmp = y * x; elseif (y <= -3.3e-7) tmp = y * z; elseif (y <= -5e-103) tmp = x; elseif (y <= -3.1e-121) tmp = y * z; elseif (y <= 2.3e-145) tmp = x; elseif (y <= 4.3e-128) tmp = y * z; elseif (y <= 1.8e-20) tmp = x; elseif ((y <= 3.4e+81) || (~((y <= 3.2e+126)) && (y <= 1.2e+156))) tmp = y * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.8e+128], N[(y * x), $MachinePrecision], If[LessEqual[y, -3.3e-7], N[(y * z), $MachinePrecision], If[LessEqual[y, -5e-103], x, If[LessEqual[y, -3.1e-121], N[(y * z), $MachinePrecision], If[LessEqual[y, 2.3e-145], x, If[LessEqual[y, 4.3e-128], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.8e-20], x, If[Or[LessEqual[y, 3.4e+81], And[N[Not[LessEqual[y, 3.2e+126]], $MachinePrecision], LessEqual[y, 1.2e+156]]], N[(y * z), $MachinePrecision], N[(y * x), $MachinePrecision]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.8 \cdot 10^{+128}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -3.3 \cdot 10^{-7}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -5 \cdot 10^{-103}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq -3.1 \cdot 10^{-121}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 2.3 \cdot 10^{-145}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 4.3 \cdot 10^{-128}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1.8 \cdot 10^{-20}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 3.4 \cdot 10^{+81} \lor \neg \left(y \leq 3.2 \cdot 10^{+126}\right) \land y \leq 1.2 \cdot 10^{+156}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -2.79999999999999983e128 or 3.40000000000000003e81 < y < 3.1999999999999998e126 or 1.2000000000000001e156 < y Initial program 100.0%
Taylor expanded in z around 0 67.7%
*-commutative67.7%
Simplified67.7%
Taylor expanded in y around inf 67.7%
if -2.79999999999999983e128 < y < -3.3000000000000002e-7 or -4.99999999999999966e-103 < y < -3.0999999999999998e-121 or 2.30000000000000007e-145 < y < 4.29999999999999994e-128 or 1.79999999999999987e-20 < y < 3.40000000000000003e81 or 3.1999999999999998e126 < y < 1.2000000000000001e156Initial program 100.0%
Taylor expanded in z around inf 77.6%
Taylor expanded in x around 0 75.5%
if -3.3000000000000002e-7 < y < -4.99999999999999966e-103 or -3.0999999999999998e-121 < y < 2.30000000000000007e-145 or 4.29999999999999994e-128 < y < 1.79999999999999987e-20Initial program 100.0%
Taylor expanded in y around 0 75.1%
Final simplification72.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -7.2e-63) (not (<= x 8e-70))) (+ x (* y x)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7.2e-63) || !(x <= 8e-70)) {
tmp = x + (y * 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 ((x <= (-7.2d-63)) .or. (.not. (x <= 8d-70))) then
tmp = x + (y * x)
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -7.2e-63) || !(x <= 8e-70)) {
tmp = x + (y * x);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7.2e-63) or not (x <= 8e-70): tmp = x + (y * x) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7.2e-63) || !(x <= 8e-70)) tmp = Float64(x + Float64(y * x)); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -7.2e-63) || ~((x <= 8e-70))) tmp = x + (y * x); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7.2e-63], N[Not[LessEqual[x, 8e-70]], $MachinePrecision]], N[(x + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.2 \cdot 10^{-63} \lor \neg \left(x \leq 8 \cdot 10^{-70}\right):\\
\;\;\;\;x + y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -7.20000000000000016e-63 or 7.99999999999999997e-70 < x Initial program 100.0%
Taylor expanded in z around 0 86.1%
*-commutative86.1%
Simplified86.1%
if -7.20000000000000016e-63 < x < 7.99999999999999997e-70Initial program 100.0%
Taylor expanded in z around inf 90.7%
Taylor expanded in x around 0 77.6%
Final simplification82.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.6e-45) (not (<= z 1.2e-37))) (+ x (* y z)) (+ x (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.6e-45) || !(z <= 1.2e-37)) {
tmp = x + (y * z);
} else {
tmp = x + (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 ((z <= (-2.6d-45)) .or. (.not. (z <= 1.2d-37))) then
tmp = x + (y * z)
else
tmp = x + (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2.6e-45) || !(z <= 1.2e-37)) {
tmp = x + (y * z);
} else {
tmp = x + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.6e-45) or not (z <= 1.2e-37): tmp = x + (y * z) else: tmp = x + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.6e-45) || !(z <= 1.2e-37)) tmp = Float64(x + Float64(y * z)); else tmp = Float64(x + Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.6e-45) || ~((z <= 1.2e-37))) tmp = x + (y * z); else tmp = x + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.6e-45], N[Not[LessEqual[z, 1.2e-37]], $MachinePrecision]], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.6 \cdot 10^{-45} \lor \neg \left(z \leq 1.2 \cdot 10^{-37}\right):\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot x\\
\end{array}
\end{array}
if z < -2.59999999999999987e-45 or 1.19999999999999995e-37 < z Initial program 100.0%
Taylor expanded in z around inf 87.5%
if -2.59999999999999987e-45 < z < 1.19999999999999995e-37Initial program 100.0%
Taylor expanded in z around 0 92.0%
*-commutative92.0%
Simplified92.0%
Final simplification89.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 5.0))) (* y x) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 5.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.0d0)) .or. (.not. (y <= 5.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.0) || !(y <= 5.0)) {
tmp = y * x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.0) or not (y <= 5.0): tmp = y * x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 5.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.0) || ~((y <= 5.0))) tmp = y * x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 5.0]], $MachinePrecision]], N[(y * x), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 5\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1 or 5 < y Initial program 100.0%
Taylor expanded in z around 0 56.1%
*-commutative56.1%
Simplified56.1%
Taylor expanded in y around inf 55.3%
if -1 < y < 5Initial program 100.0%
Taylor expanded in y around 0 67.4%
Final simplification61.5%
(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 36.1%
Final simplification36.1%
herbie shell --seed 2024017
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))