
(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 -1.9e+36)
(* y x)
(if (<= y -1.7e-6)
(* y z)
(if (<= y 520000000000.0) x (if (<= y 7.8e+251) (* y x) (* y z))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.9e+36) {
tmp = y * x;
} else if (y <= -1.7e-6) {
tmp = y * z;
} else if (y <= 520000000000.0) {
tmp = x;
} else if (y <= 7.8e+251) {
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 <= (-1.9d+36)) then
tmp = y * x
else if (y <= (-1.7d-6)) then
tmp = y * z
else if (y <= 520000000000.0d0) then
tmp = x
else if (y <= 7.8d+251) 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 <= -1.9e+36) {
tmp = y * x;
} else if (y <= -1.7e-6) {
tmp = y * z;
} else if (y <= 520000000000.0) {
tmp = x;
} else if (y <= 7.8e+251) {
tmp = y * x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.9e+36: tmp = y * x elif y <= -1.7e-6: tmp = y * z elif y <= 520000000000.0: tmp = x elif y <= 7.8e+251: tmp = y * x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.9e+36) tmp = Float64(y * x); elseif (y <= -1.7e-6) tmp = Float64(y * z); elseif (y <= 520000000000.0) tmp = x; elseif (y <= 7.8e+251) 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 <= -1.9e+36) tmp = y * x; elseif (y <= -1.7e-6) tmp = y * z; elseif (y <= 520000000000.0) tmp = x; elseif (y <= 7.8e+251) tmp = y * x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.9e+36], N[(y * x), $MachinePrecision], If[LessEqual[y, -1.7e-6], N[(y * z), $MachinePrecision], If[LessEqual[y, 520000000000.0], x, If[LessEqual[y, 7.8e+251], N[(y * x), $MachinePrecision], N[(y * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.9 \cdot 10^{+36}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -1.7 \cdot 10^{-6}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 520000000000:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 7.8 \cdot 10^{+251}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -1.90000000000000012e36 or 5.2e11 < y < 7.79999999999999951e251Initial program 100.0%
Taylor expanded in x around -inf 99.1%
+-commutative99.1%
mul-1-neg99.1%
unsub-neg99.1%
sub-neg99.1%
metadata-eval99.1%
+-commutative99.1%
mul-1-neg99.1%
unsub-neg99.1%
Simplified99.1%
Taylor expanded in y around inf 98.9%
mul-1-neg98.9%
*-commutative98.9%
distribute-rgt-neg-in98.9%
Simplified98.9%
Taylor expanded in z around 0 61.9%
*-commutative61.9%
Simplified61.9%
if -1.90000000000000012e36 < y < -1.70000000000000003e-6 or 7.79999999999999951e251 < y Initial program 99.9%
Taylor expanded in x around -inf 96.2%
+-commutative96.2%
mul-1-neg96.2%
unsub-neg96.2%
sub-neg96.2%
metadata-eval96.2%
+-commutative96.2%
mul-1-neg96.2%
unsub-neg96.2%
Simplified96.2%
Taylor expanded in y around inf 85.6%
mul-1-neg85.6%
*-commutative85.6%
distribute-rgt-neg-in85.6%
Simplified85.6%
Taylor expanded in z around inf 68.2%
if -1.70000000000000003e-6 < y < 5.2e11Initial program 100.0%
Taylor expanded in y around 0 66.6%
Final simplification64.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.7e-18) (not (<= x 5.2e-24))) (* x (+ y 1.0)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.7e-18) || !(x <= 5.2e-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 <= (-4.7d-18)) .or. (.not. (x <= 5.2d-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 <= -4.7e-18) || !(x <= 5.2e-24)) {
tmp = x * (y + 1.0);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.7e-18) or not (x <= 5.2e-24): tmp = x * (y + 1.0) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.7e-18) || !(x <= 5.2e-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 <= -4.7e-18) || ~((x <= 5.2e-24))) tmp = x * (y + 1.0); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.7e-18], N[Not[LessEqual[x, 5.2e-24]], $MachinePrecision]], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.7 \cdot 10^{-18} \lor \neg \left(x \leq 5.2 \cdot 10^{-24}\right):\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -4.6999999999999996e-18 or 5.2e-24 < x Initial program 100.0%
Taylor expanded in x around inf 85.6%
+-commutative85.6%
Simplified85.6%
if -4.6999999999999996e-18 < x < 5.2e-24Initial program 100.0%
Taylor expanded in x around -inf 100.0%
+-commutative100.0%
mul-1-neg100.0%
unsub-neg100.0%
sub-neg100.0%
metadata-eval100.0%
+-commutative100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in y around inf 83.1%
mul-1-neg83.1%
*-commutative83.1%
distribute-rgt-neg-in83.1%
Simplified83.1%
Taylor expanded in z around inf 69.6%
Final simplification78.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -6.6) (not (<= y 6e-61))) (* y (+ x z)) (* x (+ y 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -6.6) || !(y <= 6e-61)) {
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 <= (-6.6d0)) .or. (.not. (y <= 6d-61))) 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 <= -6.6) || !(y <= 6e-61)) {
tmp = y * (x + z);
} else {
tmp = x * (y + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -6.6) or not (y <= 6e-61): tmp = y * (x + z) else: tmp = x * (y + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -6.6) || !(y <= 6e-61)) 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 <= -6.6) || ~((y <= 6e-61))) tmp = y * (x + z); else tmp = x * (y + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -6.6], N[Not[LessEqual[y, 6e-61]], $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 -6.6 \lor \neg \left(y \leq 6 \cdot 10^{-61}\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\end{array}
\end{array}
if y < -6.5999999999999996 or 6.00000000000000024e-61 < y Initial program 100.0%
Taylor expanded in x around -inf 98.6%
+-commutative98.6%
mul-1-neg98.6%
unsub-neg98.6%
sub-neg98.6%
metadata-eval98.6%
+-commutative98.6%
mul-1-neg98.6%
unsub-neg98.6%
Simplified98.6%
Taylor expanded in y around inf 95.3%
mul-1-neg95.3%
*-commutative95.3%
distribute-rgt-neg-in95.3%
Simplified95.3%
distribute-lft-out--96.6%
*-commutative96.6%
sub-neg96.6%
remove-double-neg96.6%
Applied egg-rr96.6%
if -6.5999999999999996 < y < 6.00000000000000024e-61Initial program 100.0%
Taylor expanded in x around inf 71.0%
+-commutative71.0%
Simplified71.0%
Final simplification85.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (* y (+ x z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.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 <= (-1.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 <= -1.0) || !(y <= 1.0)) {
tmp = y * (x + z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.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 <= -1.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 <= -1.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, -1.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 -1 \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 or 1 < y Initial program 100.0%
Taylor expanded in x around -inf 98.6%
+-commutative98.6%
mul-1-neg98.6%
unsub-neg98.6%
sub-neg98.6%
metadata-eval98.6%
+-commutative98.6%
mul-1-neg98.6%
unsub-neg98.6%
Simplified98.6%
Taylor expanded in y around inf 97.1%
mul-1-neg97.1%
*-commutative97.1%
distribute-rgt-neg-in97.1%
Simplified97.1%
distribute-lft-out--98.5%
*-commutative98.5%
sub-neg98.5%
remove-double-neg98.5%
Applied egg-rr98.5%
if -1 < y < 1Initial program 100.0%
Taylor expanded in z around inf 97.4%
Final simplification98.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 520000000000.0))) (* y x) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 520000000000.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 <= 520000000000.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 <= 520000000000.0)) {
tmp = y * x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.0) or not (y <= 520000000000.0): tmp = y * x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 520000000000.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 <= 520000000000.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, 520000000000.0]], $MachinePrecision]], N[(y * x), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 520000000000\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1 or 5.2e11 < y Initial program 100.0%
Taylor expanded in x around -inf 98.5%
+-commutative98.5%
mul-1-neg98.5%
unsub-neg98.5%
sub-neg98.5%
metadata-eval98.5%
+-commutative98.5%
mul-1-neg98.5%
unsub-neg98.5%
Simplified98.5%
Taylor expanded in y around inf 97.0%
mul-1-neg97.0%
*-commutative97.0%
distribute-rgt-neg-in97.0%
Simplified97.0%
Taylor expanded in z around 0 56.1%
*-commutative56.1%
Simplified56.1%
if -1 < y < 5.2e11Initial program 100.0%
Taylor expanded in y around 0 65.2%
Final simplification60.2%
(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 31.3%
Final simplification31.3%
herbie shell --seed 2023310
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))