
(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-def100.0%
+-commutative100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -8e+151)
(* y z)
(if (<= y -6.6e+128)
(* y x)
(if (<= y -3.3e+63)
(* y z)
(if (<= y -3.45e+46)
(* y x)
(if (<= y -1.9e-64)
(* y z)
(if (<= y 4.2e-23)
x
(if (<= y 6.4e+28)
(* y z)
(if (or (<= y 1.15e+51)
(and (not (<= y 2.05e+151)) (<= y 1.1e+234)))
(* y x)
(* y z))))))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -8e+151) {
tmp = y * z;
} else if (y <= -6.6e+128) {
tmp = y * x;
} else if (y <= -3.3e+63) {
tmp = y * z;
} else if (y <= -3.45e+46) {
tmp = y * x;
} else if (y <= -1.9e-64) {
tmp = y * z;
} else if (y <= 4.2e-23) {
tmp = x;
} else if (y <= 6.4e+28) {
tmp = y * z;
} else if ((y <= 1.15e+51) || (!(y <= 2.05e+151) && (y <= 1.1e+234))) {
tmp = 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 (y <= (-8d+151)) then
tmp = y * z
else if (y <= (-6.6d+128)) then
tmp = y * x
else if (y <= (-3.3d+63)) then
tmp = y * z
else if (y <= (-3.45d+46)) then
tmp = y * x
else if (y <= (-1.9d-64)) then
tmp = y * z
else if (y <= 4.2d-23) then
tmp = x
else if (y <= 6.4d+28) then
tmp = y * z
else if ((y <= 1.15d+51) .or. (.not. (y <= 2.05d+151)) .and. (y <= 1.1d+234)) then
tmp = 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 (y <= -8e+151) {
tmp = y * z;
} else if (y <= -6.6e+128) {
tmp = y * x;
} else if (y <= -3.3e+63) {
tmp = y * z;
} else if (y <= -3.45e+46) {
tmp = y * x;
} else if (y <= -1.9e-64) {
tmp = y * z;
} else if (y <= 4.2e-23) {
tmp = x;
} else if (y <= 6.4e+28) {
tmp = y * z;
} else if ((y <= 1.15e+51) || (!(y <= 2.05e+151) && (y <= 1.1e+234))) {
tmp = y * x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -8e+151: tmp = y * z elif y <= -6.6e+128: tmp = y * x elif y <= -3.3e+63: tmp = y * z elif y <= -3.45e+46: tmp = y * x elif y <= -1.9e-64: tmp = y * z elif y <= 4.2e-23: tmp = x elif y <= 6.4e+28: tmp = y * z elif (y <= 1.15e+51) or (not (y <= 2.05e+151) and (y <= 1.1e+234)): tmp = y * x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -8e+151) tmp = Float64(y * z); elseif (y <= -6.6e+128) tmp = Float64(y * x); elseif (y <= -3.3e+63) tmp = Float64(y * z); elseif (y <= -3.45e+46) tmp = Float64(y * x); elseif (y <= -1.9e-64) tmp = Float64(y * z); elseif (y <= 4.2e-23) tmp = x; elseif (y <= 6.4e+28) tmp = Float64(y * z); elseif ((y <= 1.15e+51) || (!(y <= 2.05e+151) && (y <= 1.1e+234))) tmp = Float64(y * x); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -8e+151) tmp = y * z; elseif (y <= -6.6e+128) tmp = y * x; elseif (y <= -3.3e+63) tmp = y * z; elseif (y <= -3.45e+46) tmp = y * x; elseif (y <= -1.9e-64) tmp = y * z; elseif (y <= 4.2e-23) tmp = x; elseif (y <= 6.4e+28) tmp = y * z; elseif ((y <= 1.15e+51) || (~((y <= 2.05e+151)) && (y <= 1.1e+234))) tmp = y * x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -8e+151], N[(y * z), $MachinePrecision], If[LessEqual[y, -6.6e+128], N[(y * x), $MachinePrecision], If[LessEqual[y, -3.3e+63], N[(y * z), $MachinePrecision], If[LessEqual[y, -3.45e+46], N[(y * x), $MachinePrecision], If[LessEqual[y, -1.9e-64], N[(y * z), $MachinePrecision], If[LessEqual[y, 4.2e-23], x, If[LessEqual[y, 6.4e+28], N[(y * z), $MachinePrecision], If[Or[LessEqual[y, 1.15e+51], And[N[Not[LessEqual[y, 2.05e+151]], $MachinePrecision], LessEqual[y, 1.1e+234]]], N[(y * x), $MachinePrecision], N[(y * z), $MachinePrecision]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8 \cdot 10^{+151}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -6.6 \cdot 10^{+128}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -3.3 \cdot 10^{+63}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -3.45 \cdot 10^{+46}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -1.9 \cdot 10^{-64}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 4.2 \cdot 10^{-23}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 6.4 \cdot 10^{+28}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1.15 \cdot 10^{+51} \lor \neg \left(y \leq 2.05 \cdot 10^{+151}\right) \land y \leq 1.1 \cdot 10^{+234}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -8.00000000000000014e151 or -6.6000000000000001e128 < y < -3.3000000000000002e63 or -3.45000000000000009e46 < y < -1.9000000000000001e-64 or 4.2000000000000002e-23 < y < 6.4000000000000001e28 or 1.15000000000000003e51 < y < 2.0499999999999999e151 or 1.10000000000000004e234 < y Initial program 100.0%
Taylor expanded in x around -inf 97.2%
+-commutative97.2%
mul-1-neg97.2%
unsub-neg97.2%
sub-neg97.2%
metadata-eval97.2%
+-commutative97.2%
mul-1-neg97.2%
unsub-neg97.2%
Simplified97.2%
Taylor expanded in z around inf 69.0%
if -8.00000000000000014e151 < y < -6.6000000000000001e128 or -3.3000000000000002e63 < y < -3.45000000000000009e46 or 6.4000000000000001e28 < y < 1.15000000000000003e51 or 2.0499999999999999e151 < y < 1.10000000000000004e234Initial program 100.0%
Taylor expanded in x around inf 92.9%
+-commutative92.9%
Simplified92.9%
Taylor expanded in y around inf 92.9%
if -1.9000000000000001e-64 < y < 4.2000000000000002e-23Initial program 100.0%
Taylor expanded in y around 0 77.9%
Final simplification75.8%
(FPCore (x y z)
:precision binary64
(if (or (<= x -6.2e-84)
(and (not (<= x 6.5e-149)) (or (<= x 7.6e-68) (not (<= x 1.18e+24)))))
(* x (+ y 1.0))
(* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.2e-84) || (!(x <= 6.5e-149) && ((x <= 7.6e-68) || !(x <= 1.18e+24)))) {
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 ((x <= (-6.2d-84)) .or. (.not. (x <= 6.5d-149)) .and. (x <= 7.6d-68) .or. (.not. (x <= 1.18d+24))) 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 ((x <= -6.2e-84) || (!(x <= 6.5e-149) && ((x <= 7.6e-68) || !(x <= 1.18e+24)))) {
tmp = x * (y + 1.0);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.2e-84) or (not (x <= 6.5e-149) and ((x <= 7.6e-68) or not (x <= 1.18e+24))): tmp = x * (y + 1.0) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.2e-84) || (!(x <= 6.5e-149) && ((x <= 7.6e-68) || !(x <= 1.18e+24)))) 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 ((x <= -6.2e-84) || (~((x <= 6.5e-149)) && ((x <= 7.6e-68) || ~((x <= 1.18e+24))))) tmp = x * (y + 1.0); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.2e-84], And[N[Not[LessEqual[x, 6.5e-149]], $MachinePrecision], Or[LessEqual[x, 7.6e-68], N[Not[LessEqual[x, 1.18e+24]], $MachinePrecision]]]], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.2 \cdot 10^{-84} \lor \neg \left(x \leq 6.5 \cdot 10^{-149}\right) \land \left(x \leq 7.6 \cdot 10^{-68} \lor \neg \left(x \leq 1.18 \cdot 10^{+24}\right)\right):\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -6.20000000000000003e-84 or 6.50000000000000019e-149 < x < 7.60000000000000075e-68 or 1.17999999999999997e24 < x Initial program 100.0%
Taylor expanded in x around inf 86.8%
+-commutative86.8%
Simplified86.8%
if -6.20000000000000003e-84 < x < 6.50000000000000019e-149 or 7.60000000000000075e-68 < x < 1.17999999999999997e24Initial program 100.0%
Taylor expanded in x around -inf 99.9%
+-commutative99.9%
mul-1-neg99.9%
unsub-neg99.9%
sub-neg99.9%
metadata-eval99.9%
+-commutative99.9%
mul-1-neg99.9%
unsub-neg99.9%
Simplified99.9%
Taylor expanded in z around inf 75.0%
Final simplification82.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.35e-64) (not (<= y 7.5e-83))) (* y (+ x z)) (* x (+ y 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.35e-64) || !(y <= 7.5e-83)) {
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 <= (-2.35d-64)) .or. (.not. (y <= 7.5d-83))) 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 <= -2.35e-64) || !(y <= 7.5e-83)) {
tmp = y * (x + z);
} else {
tmp = x * (y + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.35e-64) or not (y <= 7.5e-83): tmp = y * (x + z) else: tmp = x * (y + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.35e-64) || !(y <= 7.5e-83)) 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 <= -2.35e-64) || ~((y <= 7.5e-83))) tmp = y * (x + z); else tmp = x * (y + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.35e-64], N[Not[LessEqual[y, 7.5e-83]], $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 -2.35 \cdot 10^{-64} \lor \neg \left(y \leq 7.5 \cdot 10^{-83}\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\end{array}
\end{array}
if y < -2.3499999999999999e-64 or 7.4999999999999997e-83 < y Initial program 100.0%
Taylor expanded in x around -inf 97.3%
+-commutative97.3%
mul-1-neg97.3%
unsub-neg97.3%
sub-neg97.3%
metadata-eval97.3%
+-commutative97.3%
mul-1-neg97.3%
unsub-neg97.3%
Simplified97.3%
Taylor expanded in y around inf 88.1%
cancel-sign-sub-inv88.1%
metadata-eval88.1%
*-lft-identity88.1%
+-commutative88.1%
Simplified88.1%
if -2.3499999999999999e-64 < y < 7.4999999999999997e-83Initial program 100.0%
Taylor expanded in x around inf 80.8%
+-commutative80.8%
Simplified80.8%
Final simplification85.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.2e+29) (not (<= y 1.0))) (* y (+ x z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.2e+29) || !(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 <= (-2.2d+29)) .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 <= -2.2e+29) || !(y <= 1.0)) {
tmp = y * (x + z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.2e+29) 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 <= -2.2e+29) || !(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 <= -2.2e+29) || ~((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, -2.2e+29], 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 -2.2 \cdot 10^{+29} \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 < -2.2000000000000001e29 or 1 < y Initial program 100.0%
Taylor expanded in x around -inf 96.3%
+-commutative96.3%
mul-1-neg96.3%
unsub-neg96.3%
sub-neg96.3%
metadata-eval96.3%
+-commutative96.3%
mul-1-neg96.3%
unsub-neg96.3%
Simplified96.3%
Taylor expanded in y around inf 98.6%
cancel-sign-sub-inv98.6%
metadata-eval98.6%
*-lft-identity98.6%
+-commutative98.6%
Simplified98.6%
if -2.2000000000000001e29 < y < 1Initial program 100.0%
Taylor expanded in z around inf 98.1%
Final simplification98.3%
(FPCore (x y z) :precision binary64 (if (<= y -1.0) (* y x) (if (<= y 1.0) x (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.0) {
tmp = y * x;
} else if (y <= 1.0) {
tmp = x;
} 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 <= (-1.0d0)) then
tmp = y * x
else if (y <= 1.0d0) then
tmp = x
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.0) {
tmp = y * x;
} else if (y <= 1.0) {
tmp = x;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.0: tmp = y * x elif y <= 1.0: tmp = x else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.0) tmp = Float64(y * x); elseif (y <= 1.0) tmp = x; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.0) tmp = y * x; elseif (y <= 1.0) tmp = x; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.0], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.0], x, N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
Taylor expanded in x around inf 49.6%
+-commutative49.6%
Simplified49.6%
Taylor expanded in y around inf 48.2%
if -1 < y < 1Initial program 100.0%
Taylor expanded in y around 0 69.7%
Final simplification60.4%
(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 40.7%
Final simplification40.7%
herbie shell --seed 2023271
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))