
(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-define100.0%
+-commutative100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= y -3.15e+196)
(* y z)
(if (<= y -9.0)
(* y x)
(if (<= y 1.4e-88)
x
(if (<= y 1.22e-79)
(* y z)
(if (<= y 4.2e-34)
x
(if (or (<= y 1.35e+33) (not (<= y 1.9e+236)))
(* y z)
(* y x))))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.15e+196) {
tmp = y * z;
} else if (y <= -9.0) {
tmp = y * x;
} else if (y <= 1.4e-88) {
tmp = x;
} else if (y <= 1.22e-79) {
tmp = y * z;
} else if (y <= 4.2e-34) {
tmp = x;
} else if ((y <= 1.35e+33) || !(y <= 1.9e+236)) {
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 <= (-3.15d+196)) then
tmp = y * z
else if (y <= (-9.0d0)) then
tmp = y * x
else if (y <= 1.4d-88) then
tmp = x
else if (y <= 1.22d-79) then
tmp = y * z
else if (y <= 4.2d-34) then
tmp = x
else if ((y <= 1.35d+33) .or. (.not. (y <= 1.9d+236))) 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 <= -3.15e+196) {
tmp = y * z;
} else if (y <= -9.0) {
tmp = y * x;
} else if (y <= 1.4e-88) {
tmp = x;
} else if (y <= 1.22e-79) {
tmp = y * z;
} else if (y <= 4.2e-34) {
tmp = x;
} else if ((y <= 1.35e+33) || !(y <= 1.9e+236)) {
tmp = y * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.15e+196: tmp = y * z elif y <= -9.0: tmp = y * x elif y <= 1.4e-88: tmp = x elif y <= 1.22e-79: tmp = y * z elif y <= 4.2e-34: tmp = x elif (y <= 1.35e+33) or not (y <= 1.9e+236): tmp = y * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.15e+196) tmp = Float64(y * z); elseif (y <= -9.0) tmp = Float64(y * x); elseif (y <= 1.4e-88) tmp = x; elseif (y <= 1.22e-79) tmp = Float64(y * z); elseif (y <= 4.2e-34) tmp = x; elseif ((y <= 1.35e+33) || !(y <= 1.9e+236)) 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 <= -3.15e+196) tmp = y * z; elseif (y <= -9.0) tmp = y * x; elseif (y <= 1.4e-88) tmp = x; elseif (y <= 1.22e-79) tmp = y * z; elseif (y <= 4.2e-34) tmp = x; elseif ((y <= 1.35e+33) || ~((y <= 1.9e+236))) tmp = y * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.15e+196], N[(y * z), $MachinePrecision], If[LessEqual[y, -9.0], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.4e-88], x, If[LessEqual[y, 1.22e-79], N[(y * z), $MachinePrecision], If[LessEqual[y, 4.2e-34], x, If[Or[LessEqual[y, 1.35e+33], N[Not[LessEqual[y, 1.9e+236]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(y * x), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.15 \cdot 10^{+196}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -9:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1.4 \cdot 10^{-88}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.22 \cdot 10^{-79}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 4.2 \cdot 10^{-34}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.35 \cdot 10^{+33} \lor \neg \left(y \leq 1.9 \cdot 10^{+236}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -3.15000000000000001e196 or 1.39999999999999988e-88 < y < 1.22e-79 or 4.2000000000000002e-34 < y < 1.34999999999999996e33 or 1.89999999999999993e236 < y Initial program 100.0%
Taylor expanded in z around inf 79.5%
Taylor expanded in z around inf 79.5%
Taylor expanded in z around inf 75.6%
if -3.15000000000000001e196 < y < -9 or 1.34999999999999996e33 < y < 1.89999999999999993e236Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in y around inf 99.0%
+-commutative99.0%
Simplified99.0%
Taylor expanded in z around 0 60.0%
*-commutative60.0%
Simplified60.0%
if -9 < y < 1.39999999999999988e-88 or 1.22e-79 < y < 4.2000000000000002e-34Initial program 100.0%
Taylor expanded in y around 0 75.8%
Final simplification70.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (+ x z))))
(if (<= y -4.8e-15)
t_0
(if (<= y 1.65e-88)
x
(if (<= y 6.5e-76) (* y z) (if (<= y 1.4e-34) x t_0))))))
double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -4.8e-15) {
tmp = t_0;
} else if (y <= 1.65e-88) {
tmp = x;
} else if (y <= 6.5e-76) {
tmp = y * z;
} else if (y <= 1.4e-34) {
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 <= (-4.8d-15)) then
tmp = t_0
else if (y <= 1.65d-88) then
tmp = x
else if (y <= 6.5d-76) then
tmp = y * z
else if (y <= 1.4d-34) 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 <= -4.8e-15) {
tmp = t_0;
} else if (y <= 1.65e-88) {
tmp = x;
} else if (y <= 6.5e-76) {
tmp = y * z;
} else if (y <= 1.4e-34) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x + z) tmp = 0 if y <= -4.8e-15: tmp = t_0 elif y <= 1.65e-88: tmp = x elif y <= 6.5e-76: tmp = y * z elif y <= 1.4e-34: 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 <= -4.8e-15) tmp = t_0; elseif (y <= 1.65e-88) tmp = x; elseif (y <= 6.5e-76) tmp = Float64(y * z); elseif (y <= 1.4e-34) 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 <= -4.8e-15) tmp = t_0; elseif (y <= 1.65e-88) tmp = x; elseif (y <= 6.5e-76) tmp = y * z; elseif (y <= 1.4e-34) 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, -4.8e-15], t$95$0, If[LessEqual[y, 1.65e-88], x, If[LessEqual[y, 6.5e-76], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.4e-34], x, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x + z\right)\\
\mathbf{if}\;y \leq -4.8 \cdot 10^{-15}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.65 \cdot 10^{-88}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 6.5 \cdot 10^{-76}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1.4 \cdot 10^{-34}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -4.7999999999999999e-15 or 1.39999999999999998e-34 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in y around inf 96.3%
+-commutative96.3%
Simplified96.3%
if -4.7999999999999999e-15 < y < 1.64999999999999997e-88 or 6.5e-76 < y < 1.39999999999999998e-34Initial program 100.0%
Taylor expanded in y around 0 78.4%
if 1.64999999999999997e-88 < y < 6.5e-76Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in z around inf 100.0%
Final simplification88.3%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (+ x z))))
(if (<= y -9.4e-7)
t_0
(if (<= y 9e-89)
(+ x (* y x))
(if (<= y 1.22e-79) (* y z) (if (<= y 4.8e-34) x t_0))))))
double code(double x, double y, double z) {
double t_0 = y * (x + z);
double tmp;
if (y <= -9.4e-7) {
tmp = t_0;
} else if (y <= 9e-89) {
tmp = x + (y * x);
} else if (y <= 1.22e-79) {
tmp = y * z;
} else if (y <= 4.8e-34) {
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 <= (-9.4d-7)) then
tmp = t_0
else if (y <= 9d-89) then
tmp = x + (y * x)
else if (y <= 1.22d-79) then
tmp = y * z
else if (y <= 4.8d-34) 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 <= -9.4e-7) {
tmp = t_0;
} else if (y <= 9e-89) {
tmp = x + (y * x);
} else if (y <= 1.22e-79) {
tmp = y * z;
} else if (y <= 4.8e-34) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (x + z) tmp = 0 if y <= -9.4e-7: tmp = t_0 elif y <= 9e-89: tmp = x + (y * x) elif y <= 1.22e-79: tmp = y * z elif y <= 4.8e-34: 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 <= -9.4e-7) tmp = t_0; elseif (y <= 9e-89) tmp = Float64(x + Float64(y * x)); elseif (y <= 1.22e-79) tmp = Float64(y * z); elseif (y <= 4.8e-34) 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 <= -9.4e-7) tmp = t_0; elseif (y <= 9e-89) tmp = x + (y * x); elseif (y <= 1.22e-79) tmp = y * z; elseif (y <= 4.8e-34) 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, -9.4e-7], t$95$0, If[LessEqual[y, 9e-89], N[(x + N[(y * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.22e-79], N[(y * z), $MachinePrecision], If[LessEqual[y, 4.8e-34], x, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(x + z\right)\\
\mathbf{if}\;y \leq -9.4 \cdot 10^{-7}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 9 \cdot 10^{-89}:\\
\;\;\;\;x + y \cdot x\\
\mathbf{elif}\;y \leq 1.22 \cdot 10^{-79}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 4.8 \cdot 10^{-34}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -9.4e-7 or 4.79999999999999982e-34 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in y around inf 97.0%
+-commutative97.0%
Simplified97.0%
if -9.4e-7 < y < 8.9999999999999998e-89Initial program 100.0%
Taylor expanded in z around 0 77.8%
*-commutative3.5%
Simplified77.8%
if 8.9999999999999998e-89 < y < 1.22e-79Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in z around inf 100.0%
if 1.22e-79 < y < 4.79999999999999982e-34Initial program 99.8%
Taylor expanded in y around 0 79.1%
Final simplification88.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -540.0) (not (<= y 0.0065))) (* y (+ x z)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -540.0) || !(y <= 0.0065)) {
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 <= (-540.0d0)) .or. (.not. (y <= 0.0065d0))) 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 <= -540.0) || !(y <= 0.0065)) {
tmp = y * (x + z);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -540.0) or not (y <= 0.0065): tmp = y * (x + z) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -540.0) || !(y <= 0.0065)) 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 <= -540.0) || ~((y <= 0.0065))) tmp = y * (x + z); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -540.0], N[Not[LessEqual[y, 0.0065]], $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 -540 \lor \neg \left(y \leq 0.0065\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -540 or 0.0064999999999999997 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in y around inf 98.9%
+-commutative98.9%
Simplified98.9%
if -540 < y < 0.0064999999999999997Initial program 100.0%
Taylor expanded in z around inf 99.0%
Final simplification99.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -9.0) (not (<= y 0.0065))) (* y x) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -9.0) || !(y <= 0.0065)) {
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 <= (-9.0d0)) .or. (.not. (y <= 0.0065d0))) 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 <= -9.0) || !(y <= 0.0065)) {
tmp = y * x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -9.0) or not (y <= 0.0065): tmp = y * x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -9.0) || !(y <= 0.0065)) tmp = Float64(y * x); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -9.0) || ~((y <= 0.0065))) tmp = y * x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -9.0], N[Not[LessEqual[y, 0.0065]], $MachinePrecision]], N[(y * x), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9 \lor \neg \left(y \leq 0.0065\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -9 or 0.0064999999999999997 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in y around inf 98.9%
+-commutative98.9%
Simplified98.9%
Taylor expanded in z around 0 53.4%
*-commutative53.4%
Simplified53.4%
if -9 < y < 0.0064999999999999997Initial program 100.0%
Taylor expanded in y around 0 71.0%
Final simplification62.5%
(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 38.0%
Final simplification38.0%
herbie shell --seed 2024055
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))