
(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 -4e+253)
(* y z)
(if (<= y -1.02e+16)
(* y x)
(if (<= y -3.5e-24)
(* y z)
(if (<= y -2.65e-49)
x
(if (<= y -5.5e-97)
(* y z)
(if (<= y 1e-51) x (if (<= y 5.9e+138) (* y z) (* y x)))))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -4e+253) {
tmp = y * z;
} else if (y <= -1.02e+16) {
tmp = y * x;
} else if (y <= -3.5e-24) {
tmp = y * z;
} else if (y <= -2.65e-49) {
tmp = x;
} else if (y <= -5.5e-97) {
tmp = y * z;
} else if (y <= 1e-51) {
tmp = x;
} else if (y <= 5.9e+138) {
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 <= (-4d+253)) then
tmp = y * z
else if (y <= (-1.02d+16)) then
tmp = y * x
else if (y <= (-3.5d-24)) then
tmp = y * z
else if (y <= (-2.65d-49)) then
tmp = x
else if (y <= (-5.5d-97)) then
tmp = y * z
else if (y <= 1d-51) then
tmp = x
else if (y <= 5.9d+138) 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 <= -4e+253) {
tmp = y * z;
} else if (y <= -1.02e+16) {
tmp = y * x;
} else if (y <= -3.5e-24) {
tmp = y * z;
} else if (y <= -2.65e-49) {
tmp = x;
} else if (y <= -5.5e-97) {
tmp = y * z;
} else if (y <= 1e-51) {
tmp = x;
} else if (y <= 5.9e+138) {
tmp = y * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -4e+253: tmp = y * z elif y <= -1.02e+16: tmp = y * x elif y <= -3.5e-24: tmp = y * z elif y <= -2.65e-49: tmp = x elif y <= -5.5e-97: tmp = y * z elif y <= 1e-51: tmp = x elif y <= 5.9e+138: tmp = y * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -4e+253) tmp = Float64(y * z); elseif (y <= -1.02e+16) tmp = Float64(y * x); elseif (y <= -3.5e-24) tmp = Float64(y * z); elseif (y <= -2.65e-49) tmp = x; elseif (y <= -5.5e-97) tmp = Float64(y * z); elseif (y <= 1e-51) tmp = x; elseif (y <= 5.9e+138) 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 <= -4e+253) tmp = y * z; elseif (y <= -1.02e+16) tmp = y * x; elseif (y <= -3.5e-24) tmp = y * z; elseif (y <= -2.65e-49) tmp = x; elseif (y <= -5.5e-97) tmp = y * z; elseif (y <= 1e-51) tmp = x; elseif (y <= 5.9e+138) tmp = y * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -4e+253], N[(y * z), $MachinePrecision], If[LessEqual[y, -1.02e+16], N[(y * x), $MachinePrecision], If[LessEqual[y, -3.5e-24], N[(y * z), $MachinePrecision], If[LessEqual[y, -2.65e-49], x, If[LessEqual[y, -5.5e-97], N[(y * z), $MachinePrecision], If[LessEqual[y, 1e-51], x, If[LessEqual[y, 5.9e+138], N[(y * z), $MachinePrecision], N[(y * x), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{+253}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -1.02 \cdot 10^{+16}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -3.5 \cdot 10^{-24}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -2.65 \cdot 10^{-49}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq -5.5 \cdot 10^{-97}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 10^{-51}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 5.9 \cdot 10^{+138}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -3.9999999999999997e253 or -1.02e16 < y < -3.4999999999999996e-24 or -2.6500000000000001e-49 < y < -5.49999999999999948e-97 or 1e-51 < y < 5.8999999999999999e138Initial program 100.0%
Taylor expanded in x around 0 74.3%
if -3.9999999999999997e253 < y < -1.02e16 or 5.8999999999999999e138 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in z around 0 61.5%
*-commutative61.5%
Simplified61.5%
if -3.4999999999999996e-24 < y < -2.6500000000000001e-49 or -5.49999999999999948e-97 < y < 1e-51Initial program 100.0%
Taylor expanded in y around 0 75.6%
Final simplification70.5%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (+ x z))))
(if (<= y -1.12e-24)
t_0
(if (<= y -3.9e-44)
x
(if (<= y -4.3e-97) (* y z) (if (<= y 5.2e-52) x t_0))))))
double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -1.12e-24) {
tmp = t_0;
} else if (y <= -3.9e-44) {
tmp = x;
} else if (y <= -4.3e-97) {
tmp = y * z;
} else if (y <= 5.2e-52) {
tmp = x;
} 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.12d-24)) then
tmp = t_0
else if (y <= (-3.9d-44)) then
tmp = x
else if (y <= (-4.3d-97)) then
tmp = y * z
else if (y <= 5.2d-52) then
tmp = x
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.12e-24) {
tmp = t_0;
} else if (y <= -3.9e-44) {
tmp = x;
} else if (y <= -4.3e-97) {
tmp = y * z;
} else if (y <= 5.2e-52) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x + z) tmp = 0 if y <= -1.12e-24: tmp = t_0 elif y <= -3.9e-44: tmp = x elif y <= -4.3e-97: tmp = y * z elif y <= 5.2e-52: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x + z)) tmp = 0.0 if (y <= -1.12e-24) tmp = t_0; elseif (y <= -3.9e-44) tmp = x; elseif (y <= -4.3e-97) tmp = Float64(y * z); elseif (y <= 5.2e-52) tmp = x; 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.12e-24) tmp = t_0; elseif (y <= -3.9e-44) tmp = x; elseif (y <= -4.3e-97) tmp = y * z; elseif (y <= 5.2e-52) tmp = x; 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.12e-24], t$95$0, If[LessEqual[y, -3.9e-44], x, If[LessEqual[y, -4.3e-97], N[(y * z), $MachinePrecision], If[LessEqual[y, 5.2e-52], x, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x + z\right)\\
\mathbf{if}\;y \leq -1.12 \cdot 10^{-24}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -3.9 \cdot 10^{-44}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq -4.3 \cdot 10^{-97}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{-52}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -1.11999999999999995e-24 or 5.1999999999999997e-52 < y Initial program 100.0%
Taylor expanded in y around inf 96.8%
+-commutative96.8%
Simplified96.8%
if -1.11999999999999995e-24 < y < -3.9000000000000002e-44 or -4.3e-97 < y < 5.1999999999999997e-52Initial program 100.0%
Taylor expanded in y around 0 75.6%
if -3.9000000000000002e-44 < y < -4.3e-97Initial program 100.0%
Taylor expanded in x around 0 87.1%
Final simplification87.6%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (+ x z))))
(if (<= y -1.4e-23)
t_0
(if (<= y -3.25e-49)
(+ x (* y x))
(if (<= y -8e-98) (* y z) (if (<= y 1.5e-51) x t_0))))))
double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -1.4e-23) {
tmp = t_0;
} else if (y <= -3.25e-49) {
tmp = x + (y * x);
} else if (y <= -8e-98) {
tmp = y * z;
} else if (y <= 1.5e-51) {
tmp = x;
} 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.4d-23)) then
tmp = t_0
else if (y <= (-3.25d-49)) then
tmp = x + (y * x)
else if (y <= (-8d-98)) then
tmp = y * z
else if (y <= 1.5d-51) then
tmp = x
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.4e-23) {
tmp = t_0;
} else if (y <= -3.25e-49) {
tmp = x + (y * x);
} else if (y <= -8e-98) {
tmp = y * z;
} else if (y <= 1.5e-51) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x + z) tmp = 0 if y <= -1.4e-23: tmp = t_0 elif y <= -3.25e-49: tmp = x + (y * x) elif y <= -8e-98: tmp = y * z elif y <= 1.5e-51: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(x + z)) tmp = 0.0 if (y <= -1.4e-23) tmp = t_0; elseif (y <= -3.25e-49) tmp = Float64(x + Float64(y * x)); elseif (y <= -8e-98) tmp = Float64(y * z); elseif (y <= 1.5e-51) tmp = x; 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.4e-23) tmp = t_0; elseif (y <= -3.25e-49) tmp = x + (y * x); elseif (y <= -8e-98) tmp = y * z; elseif (y <= 1.5e-51) tmp = x; 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.4e-23], t$95$0, If[LessEqual[y, -3.25e-49], N[(x + N[(y * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, -8e-98], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.5e-51], x, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x + z\right)\\
\mathbf{if}\;y \leq -1.4 \cdot 10^{-23}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -3.25 \cdot 10^{-49}:\\
\;\;\;\;x + y \cdot x\\
\mathbf{elif}\;y \leq -8 \cdot 10^{-98}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1.5 \cdot 10^{-51}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -1.3999999999999999e-23 or 1.50000000000000001e-51 < y Initial program 100.0%
Taylor expanded in y around inf 96.8%
+-commutative96.8%
Simplified96.8%
if -1.3999999999999999e-23 < y < -3.24999999999999984e-49Initial program 99.7%
Taylor expanded in z around 0 75.4%
*-commutative2.2%
Simplified75.4%
if -3.24999999999999984e-49 < y < -7.99999999999999951e-98Initial program 100.0%
Taylor expanded in x around 0 87.1%
if -7.99999999999999951e-98 < y < 1.50000000000000001e-51Initial program 100.0%
Taylor expanded in y around 0 75.6%
Final simplification87.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -8.4e-8) (not (<= y 1400000000000.0))) (* y x) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -8.4e-8) || !(y <= 1400000000000.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 <= (-8.4d-8)) .or. (.not. (y <= 1400000000000.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 <= -8.4e-8) || !(y <= 1400000000000.0)) {
tmp = y * x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -8.4e-8) or not (y <= 1400000000000.0): tmp = y * x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -8.4e-8) || !(y <= 1400000000000.0)) tmp = Float64(y * x); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -8.4e-8) || ~((y <= 1400000000000.0))) tmp = y * x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -8.4e-8], N[Not[LessEqual[y, 1400000000000.0]], $MachinePrecision]], N[(y * x), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.4 \cdot 10^{-8} \lor \neg \left(y \leq 1400000000000\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -8.39999999999999978e-8 or 1.4e12 < y Initial program 100.0%
Taylor expanded in y around inf 99.5%
+-commutative99.5%
Simplified99.5%
Taylor expanded in z around 0 51.9%
*-commutative51.9%
Simplified51.9%
if -8.39999999999999978e-8 < y < 1.4e12Initial program 100.0%
Taylor expanded in y around 0 66.0%
Final simplification59.1%
(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 35.1%
Final simplification35.1%
herbie shell --seed 2023332
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))