
(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
(let* ((t_0 (* y (+ x z))))
(if (<= y -0.0048)
t_0
(if (<= y -3.8e-44)
x
(if (<= y -1.12e-63)
(* y z)
(if (or (<= y 9e-85) (and (not (<= y 1.65e-51)) (<= y 5.8e-9)))
x
t_0))))))
double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -0.0048) {
tmp = t_0;
} else if (y <= -3.8e-44) {
tmp = x;
} else if (y <= -1.12e-63) {
tmp = y * z;
} else if ((y <= 9e-85) || (!(y <= 1.65e-51) && (y <= 5.8e-9))) {
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 <= (-0.0048d0)) then
tmp = t_0
else if (y <= (-3.8d-44)) then
tmp = x
else if (y <= (-1.12d-63)) then
tmp = y * z
else if ((y <= 9d-85) .or. (.not. (y <= 1.65d-51)) .and. (y <= 5.8d-9)) 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 <= -0.0048) {
tmp = t_0;
} else if (y <= -3.8e-44) {
tmp = x;
} else if (y <= -1.12e-63) {
tmp = y * z;
} else if ((y <= 9e-85) || (!(y <= 1.65e-51) && (y <= 5.8e-9))) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x + z) tmp = 0 if y <= -0.0048: tmp = t_0 elif y <= -3.8e-44: tmp = x elif y <= -1.12e-63: tmp = y * z elif (y <= 9e-85) or (not (y <= 1.65e-51) and (y <= 5.8e-9)): 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 <= -0.0048) tmp = t_0; elseif (y <= -3.8e-44) tmp = x; elseif (y <= -1.12e-63) tmp = Float64(y * z); elseif ((y <= 9e-85) || (!(y <= 1.65e-51) && (y <= 5.8e-9))) 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 <= -0.0048) tmp = t_0; elseif (y <= -3.8e-44) tmp = x; elseif (y <= -1.12e-63) tmp = y * z; elseif ((y <= 9e-85) || (~((y <= 1.65e-51)) && (y <= 5.8e-9))) 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, -0.0048], t$95$0, If[LessEqual[y, -3.8e-44], x, If[LessEqual[y, -1.12e-63], N[(y * z), $MachinePrecision], If[Or[LessEqual[y, 9e-85], And[N[Not[LessEqual[y, 1.65e-51]], $MachinePrecision], LessEqual[y, 5.8e-9]]], x, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x + z\right)\\
\mathbf{if}\;y \leq -0.0048:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -3.8 \cdot 10^{-44}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq -1.12 \cdot 10^{-63}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 9 \cdot 10^{-85} \lor \neg \left(y \leq 1.65 \cdot 10^{-51}\right) \land y \leq 5.8 \cdot 10^{-9}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.00479999999999999958 or 9.00000000000000008e-85 < y < 1.64999999999999986e-51 or 5.79999999999999982e-9 < 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 95.4%
cancel-sign-sub-inv95.4%
metadata-eval95.4%
*-lft-identity95.4%
+-commutative95.4%
Simplified95.4%
if -0.00479999999999999958 < y < -3.8000000000000001e-44 or -1.12000000000000002e-63 < y < 9.00000000000000008e-85 or 1.64999999999999986e-51 < y < 5.79999999999999982e-9Initial program 100.0%
Taylor expanded in y around 0 74.4%
if -3.8000000000000001e-44 < y < -1.12000000000000002e-63Initial 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 z around inf 81.2%
Final simplification85.5%
(FPCore (x y z)
:precision binary64
(if (<= y -0.0048)
(* y z)
(if (<= y -1e-42)
x
(if (<= y -1e-63)
(* y z)
(if (<= y 1.0)
x
(if (or (<= y 4.65e+213) (not (<= y 2.7e+252))) (* y x) (* y z)))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -0.0048) {
tmp = y * z;
} else if (y <= -1e-42) {
tmp = x;
} else if (y <= -1e-63) {
tmp = y * z;
} else if (y <= 1.0) {
tmp = x;
} else if ((y <= 4.65e+213) || !(y <= 2.7e+252)) {
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 <= (-0.0048d0)) then
tmp = y * z
else if (y <= (-1d-42)) then
tmp = x
else if (y <= (-1d-63)) then
tmp = y * z
else if (y <= 1.0d0) then
tmp = x
else if ((y <= 4.65d+213) .or. (.not. (y <= 2.7d+252))) 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 <= -0.0048) {
tmp = y * z;
} else if (y <= -1e-42) {
tmp = x;
} else if (y <= -1e-63) {
tmp = y * z;
} else if (y <= 1.0) {
tmp = x;
} else if ((y <= 4.65e+213) || !(y <= 2.7e+252)) {
tmp = y * x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -0.0048: tmp = y * z elif y <= -1e-42: tmp = x elif y <= -1e-63: tmp = y * z elif y <= 1.0: tmp = x elif (y <= 4.65e+213) or not (y <= 2.7e+252): tmp = y * x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -0.0048) tmp = Float64(y * z); elseif (y <= -1e-42) tmp = x; elseif (y <= -1e-63) tmp = Float64(y * z); elseif (y <= 1.0) tmp = x; elseif ((y <= 4.65e+213) || !(y <= 2.7e+252)) 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 <= -0.0048) tmp = y * z; elseif (y <= -1e-42) tmp = x; elseif (y <= -1e-63) tmp = y * z; elseif (y <= 1.0) tmp = x; elseif ((y <= 4.65e+213) || ~((y <= 2.7e+252))) tmp = y * x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -0.0048], N[(y * z), $MachinePrecision], If[LessEqual[y, -1e-42], x, If[LessEqual[y, -1e-63], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.0], x, If[Or[LessEqual[y, 4.65e+213], N[Not[LessEqual[y, 2.7e+252]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(y * z), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0048:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -1 \cdot 10^{-42}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq -1 \cdot 10^{-63}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 4.65 \cdot 10^{+213} \lor \neg \left(y \leq 2.7 \cdot 10^{+252}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -0.00479999999999999958 or -1.00000000000000004e-42 < y < -1.00000000000000007e-63 or 4.6500000000000002e213 < y < 2.7000000000000001e252Initial 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 z around inf 65.1%
if -0.00479999999999999958 < y < -1.00000000000000004e-42 or -1.00000000000000007e-63 < y < 1Initial program 100.0%
Taylor expanded in y around 0 70.0%
if 1 < y < 4.6500000000000002e213 or 2.7000000000000001e252 < y Initial program 100.0%
Taylor expanded in z around 0 66.7%
*-commutative66.7%
Simplified66.7%
Taylor expanded in y around inf 63.9%
Final simplification67.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.8e-13) (not (<= z 4.5e+88))) (* y (+ x z)) (+ x (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.8e-13) || !(z <= 4.5e+88)) {
tmp = y * (x + 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.8d-13)) .or. (.not. (z <= 4.5d+88))) then
tmp = y * (x + 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.8e-13) || !(z <= 4.5e+88)) {
tmp = y * (x + z);
} else {
tmp = x + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.8e-13) or not (z <= 4.5e+88): tmp = y * (x + z) else: tmp = x + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.8e-13) || !(z <= 4.5e+88)) tmp = Float64(y * Float64(x + 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.8e-13) || ~((z <= 4.5e+88))) tmp = y * (x + z); else tmp = x + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.8e-13], N[Not[LessEqual[z, 4.5e+88]], $MachinePrecision]], N[(y * N[(x + z), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.8 \cdot 10^{-13} \lor \neg \left(z \leq 4.5 \cdot 10^{+88}\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot x\\
\end{array}
\end{array}
if z < -2.8000000000000002e-13 or 4.5e88 < z Initial program 100.0%
Taylor expanded in x around -inf 98.3%
+-commutative98.3%
mul-1-neg98.3%
unsub-neg98.3%
sub-neg98.3%
metadata-eval98.3%
+-commutative98.3%
mul-1-neg98.3%
unsub-neg98.3%
Simplified98.3%
Taylor expanded in y around inf 80.7%
cancel-sign-sub-inv80.7%
metadata-eval80.7%
*-lft-identity80.7%
+-commutative80.7%
Simplified80.7%
if -2.8000000000000002e-13 < z < 4.5e88Initial program 100.0%
Taylor expanded in z around 0 87.1%
*-commutative87.1%
Simplified87.1%
Final simplification84.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 0.0045))) (* y (+ x z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(y <= 0.0045)) {
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 <= 0.0045d0))) 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 <= 0.0045)) {
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 <= 0.0045): tmp = y * (x + z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(y <= 0.0045)) 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 <= 0.0045))) 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, 0.0045]], $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 0.0045\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -1 or 0.00449999999999999966 < y Initial program 100.0%
Taylor expanded in x around -inf 98.3%
+-commutative98.3%
mul-1-neg98.3%
unsub-neg98.3%
sub-neg98.3%
metadata-eval98.3%
+-commutative98.3%
mul-1-neg98.3%
unsub-neg98.3%
Simplified98.3%
Taylor expanded in y around inf 97.9%
cancel-sign-sub-inv97.9%
metadata-eval97.9%
*-lft-identity97.9%
+-commutative97.9%
Simplified97.9%
if -1 < y < 0.00449999999999999966Initial program 100.0%
Taylor expanded in z around inf 97.9%
Final simplification97.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (* y x) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.0) || !(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 <= (-1.0d0)) .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 <= -1.0) || !(y <= 1.0)) {
tmp = y * x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.0) or not (y <= 1.0): tmp = y * x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.0) || !(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 <= -1.0) || ~((y <= 1.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, 1.0]], $MachinePrecision]], N[(y * x), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
Taylor expanded in z around 0 52.9%
*-commutative52.9%
Simplified52.9%
Taylor expanded in y around inf 51.0%
if -1 < y < 1Initial program 100.0%
Taylor expanded in y around 0 66.9%
Final simplification59.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 36.9%
Final simplification36.9%
herbie shell --seed 2024031
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))