
(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 -5e+110)
(* y x)
(if (<= y -8.2e-32)
(* y z)
(if (<= y 6.8e-11)
x
(if (or (<= y 2.5e+35) (and (not (<= y 1.4e+182)) (<= y 1.35e+208)))
(* y z)
(* y x))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -5e+110) {
tmp = y * x;
} else if (y <= -8.2e-32) {
tmp = y * z;
} else if (y <= 6.8e-11) {
tmp = x;
} else if ((y <= 2.5e+35) || (!(y <= 1.4e+182) && (y <= 1.35e+208))) {
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 <= (-5d+110)) then
tmp = y * x
else if (y <= (-8.2d-32)) then
tmp = y * z
else if (y <= 6.8d-11) then
tmp = x
else if ((y <= 2.5d+35) .or. (.not. (y <= 1.4d+182)) .and. (y <= 1.35d+208)) 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 <= -5e+110) {
tmp = y * x;
} else if (y <= -8.2e-32) {
tmp = y * z;
} else if (y <= 6.8e-11) {
tmp = x;
} else if ((y <= 2.5e+35) || (!(y <= 1.4e+182) && (y <= 1.35e+208))) {
tmp = y * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5e+110: tmp = y * x elif y <= -8.2e-32: tmp = y * z elif y <= 6.8e-11: tmp = x elif (y <= 2.5e+35) or (not (y <= 1.4e+182) and (y <= 1.35e+208)): tmp = y * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5e+110) tmp = Float64(y * x); elseif (y <= -8.2e-32) tmp = Float64(y * z); elseif (y <= 6.8e-11) tmp = x; elseif ((y <= 2.5e+35) || (!(y <= 1.4e+182) && (y <= 1.35e+208))) 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 <= -5e+110) tmp = y * x; elseif (y <= -8.2e-32) tmp = y * z; elseif (y <= 6.8e-11) tmp = x; elseif ((y <= 2.5e+35) || (~((y <= 1.4e+182)) && (y <= 1.35e+208))) tmp = y * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5e+110], N[(y * x), $MachinePrecision], If[LessEqual[y, -8.2e-32], N[(y * z), $MachinePrecision], If[LessEqual[y, 6.8e-11], x, If[Or[LessEqual[y, 2.5e+35], And[N[Not[LessEqual[y, 1.4e+182]], $MachinePrecision], LessEqual[y, 1.35e+208]]], N[(y * z), $MachinePrecision], N[(y * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{+110}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -8.2 \cdot 10^{-32}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 6.8 \cdot 10^{-11}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 2.5 \cdot 10^{+35} \lor \neg \left(y \leq 1.4 \cdot 10^{+182}\right) \land y \leq 1.35 \cdot 10^{+208}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -4.99999999999999978e110 or 2.50000000000000011e35 < y < 1.40000000000000003e182 or 1.35e208 < y Initial program 100.0%
Taylor expanded in x around inf 71.7%
+-commutative71.7%
Simplified71.7%
Taylor expanded in y around inf 71.7%
if -4.99999999999999978e110 < y < -8.1999999999999995e-32 or 6.7999999999999998e-11 < y < 2.50000000000000011e35 or 1.40000000000000003e182 < y < 1.35e208Initial program 99.9%
Taylor expanded in x around 0 67.2%
if -8.1999999999999995e-32 < y < 6.7999999999999998e-11Initial program 100.0%
Taylor expanded in y around 0 77.1%
Final simplification73.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.48e+153) (not (<= z 3.1e+40))) (* y z) (* x (+ y 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.48e+153) || !(z <= 3.1e+40)) {
tmp = y * z;
} else {
tmp = x * (y + 1.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) :: tmp
if ((z <= (-1.48d+153)) .or. (.not. (z <= 3.1d+40))) then
tmp = y * z
else
tmp = x * (y + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.48e+153) || !(z <= 3.1e+40)) {
tmp = y * z;
} else {
tmp = x * (y + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.48e+153) or not (z <= 3.1e+40): tmp = y * z else: tmp = x * (y + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.48e+153) || !(z <= 3.1e+40)) tmp = Float64(y * z); else tmp = Float64(x * Float64(y + 1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.48e+153) || ~((z <= 3.1e+40))) tmp = y * z; else tmp = x * (y + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.48e+153], N[Not[LessEqual[z, 3.1e+40]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.48 \cdot 10^{+153} \lor \neg \left(z \leq 3.1 \cdot 10^{+40}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\end{array}
\end{array}
if z < -1.47999999999999998e153 or 3.0999999999999998e40 < z Initial program 100.0%
Taylor expanded in x around 0 77.6%
if -1.47999999999999998e153 < z < 3.0999999999999998e40Initial program 100.0%
Taylor expanded in x around inf 84.3%
+-commutative84.3%
Simplified84.3%
Final simplification82.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.5e-32) (not (<= y 6.4e-9))) (* y (+ x z)) (* x (+ y 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.5e-32) || !(y <= 6.4e-9)) {
tmp = y * (x + z);
} else {
tmp = x * (y + 1.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) :: tmp
if ((y <= (-5.5d-32)) .or. (.not. (y <= 6.4d-9))) then
tmp = y * (x + z)
else
tmp = x * (y + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -5.5e-32) || !(y <= 6.4e-9)) {
tmp = y * (x + z);
} else {
tmp = x * (y + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.5e-32) or not (y <= 6.4e-9): tmp = y * (x + z) else: tmp = x * (y + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.5e-32) || !(y <= 6.4e-9)) tmp = Float64(y * Float64(x + z)); else tmp = Float64(x * Float64(y + 1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -5.5e-32) || ~((y <= 6.4e-9))) tmp = y * (x + z); else tmp = x * (y + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.5e-32], N[Not[LessEqual[y, 6.4e-9]], $MachinePrecision]], N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.5 \cdot 10^{-32} \lor \neg \left(y \leq 6.4 \cdot 10^{-9}\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\end{array}
\end{array}
if y < -5.50000000000000024e-32 or 6.40000000000000023e-9 < y Initial program 100.0%
Taylor expanded in y around inf 96.4%
+-commutative96.4%
Simplified96.4%
if -5.50000000000000024e-32 < y < 6.40000000000000023e-9Initial program 100.0%
Taylor expanded in x around inf 77.2%
+-commutative77.2%
Simplified77.2%
Final simplification88.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.023) (not (<= y 1.0))) (* y x) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.023) || !(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 <= (-0.023d0)) .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 <= -0.023) || !(y <= 1.0)) {
tmp = y * x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.023) or not (y <= 1.0): tmp = y * x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.023) || !(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 <= -0.023) || ~((y <= 1.0))) tmp = y * x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.023], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y * x), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.023 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -0.023 or 1 < y Initial program 100.0%
Taylor expanded in x around inf 62.6%
+-commutative62.6%
Simplified62.6%
Taylor expanded in y around inf 61.2%
if -0.023 < y < 1Initial program 100.0%
Taylor expanded in y around 0 72.9%
Final simplification66.8%
(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.2%
Final simplification36.2%
herbie shell --seed 2023318
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))