
(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 (or (<= x -1.2e-9)
(not
(or (<= x -9e-49)
(and (not (<= x -1.18e-120))
(or (<= x 2.3e-133)
(and (not (<= x 2.4e-76)) (<= x 1.85e-35)))))))
(* x (+ y 1.0))
(* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.2e-9) || !((x <= -9e-49) || (!(x <= -1.18e-120) && ((x <= 2.3e-133) || (!(x <= 2.4e-76) && (x <= 1.85e-35)))))) {
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 <= (-1.2d-9)) .or. (.not. (x <= (-9d-49)) .or. (.not. (x <= (-1.18d-120))) .and. (x <= 2.3d-133) .or. (.not. (x <= 2.4d-76)) .and. (x <= 1.85d-35))) 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 <= -1.2e-9) || !((x <= -9e-49) || (!(x <= -1.18e-120) && ((x <= 2.3e-133) || (!(x <= 2.4e-76) && (x <= 1.85e-35)))))) {
tmp = x * (y + 1.0);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.2e-9) or not ((x <= -9e-49) or (not (x <= -1.18e-120) and ((x <= 2.3e-133) or (not (x <= 2.4e-76) and (x <= 1.85e-35))))): tmp = x * (y + 1.0) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.2e-9) || !((x <= -9e-49) || (!(x <= -1.18e-120) && ((x <= 2.3e-133) || (!(x <= 2.4e-76) && (x <= 1.85e-35)))))) 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 <= -1.2e-9) || ~(((x <= -9e-49) || (~((x <= -1.18e-120)) && ((x <= 2.3e-133) || (~((x <= 2.4e-76)) && (x <= 1.85e-35))))))) tmp = x * (y + 1.0); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.2e-9], N[Not[Or[LessEqual[x, -9e-49], And[N[Not[LessEqual[x, -1.18e-120]], $MachinePrecision], Or[LessEqual[x, 2.3e-133], And[N[Not[LessEqual[x, 2.4e-76]], $MachinePrecision], LessEqual[x, 1.85e-35]]]]]], $MachinePrecision]], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.2 \cdot 10^{-9} \lor \neg \left(x \leq -9 \cdot 10^{-49} \lor \neg \left(x \leq -1.18 \cdot 10^{-120}\right) \land \left(x \leq 2.3 \cdot 10^{-133} \lor \neg \left(x \leq 2.4 \cdot 10^{-76}\right) \land x \leq 1.85 \cdot 10^{-35}\right)\right):\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -1.2e-9 or -9.0000000000000004e-49 < x < -1.17999999999999999e-120 or 2.3e-133 < x < 2.40000000000000013e-76 or 1.8499999999999999e-35 < x Initial program 100.0%
Taylor expanded in x around inf 83.9%
+-commutative83.9%
Simplified83.9%
if -1.2e-9 < x < -9.0000000000000004e-49 or -1.17999999999999999e-120 < x < 2.3e-133 or 2.40000000000000013e-76 < x < 1.8499999999999999e-35Initial program 100.0%
Taylor expanded in x around 0 79.4%
Final simplification82.3%
(FPCore (x y z)
:precision binary64
(if (<= y -5.4e+83)
(* y z)
(if (<= y -2.4e+21)
(* y x)
(if (<= y -2.4e-112)
(* y z)
(if (<= y 1.32e-74) x (if (<= y 2.7e+130) (* y z) (* y x)))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.4e+83) {
tmp = y * z;
} else if (y <= -2.4e+21) {
tmp = y * x;
} else if (y <= -2.4e-112) {
tmp = y * z;
} else if (y <= 1.32e-74) {
tmp = x;
} else if (y <= 2.7e+130) {
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 <= (-5.4d+83)) then
tmp = y * z
else if (y <= (-2.4d+21)) then
tmp = y * x
else if (y <= (-2.4d-112)) then
tmp = y * z
else if (y <= 1.32d-74) then
tmp = x
else if (y <= 2.7d+130) 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 <= -5.4e+83) {
tmp = y * z;
} else if (y <= -2.4e+21) {
tmp = y * x;
} else if (y <= -2.4e-112) {
tmp = y * z;
} else if (y <= 1.32e-74) {
tmp = x;
} else if (y <= 2.7e+130) {
tmp = y * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.4e+83: tmp = y * z elif y <= -2.4e+21: tmp = y * x elif y <= -2.4e-112: tmp = y * z elif y <= 1.32e-74: tmp = x elif y <= 2.7e+130: tmp = y * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.4e+83) tmp = Float64(y * z); elseif (y <= -2.4e+21) tmp = Float64(y * x); elseif (y <= -2.4e-112) tmp = Float64(y * z); elseif (y <= 1.32e-74) tmp = x; elseif (y <= 2.7e+130) 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 <= -5.4e+83) tmp = y * z; elseif (y <= -2.4e+21) tmp = y * x; elseif (y <= -2.4e-112) tmp = y * z; elseif (y <= 1.32e-74) tmp = x; elseif (y <= 2.7e+130) tmp = y * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.4e+83], N[(y * z), $MachinePrecision], If[LessEqual[y, -2.4e+21], N[(y * x), $MachinePrecision], If[LessEqual[y, -2.4e-112], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.32e-74], x, If[LessEqual[y, 2.7e+130], N[(y * z), $MachinePrecision], N[(y * x), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.4 \cdot 10^{+83}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -2.4 \cdot 10^{+21}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -2.4 \cdot 10^{-112}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1.32 \cdot 10^{-74}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 2.7 \cdot 10^{+130}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -5.40000000000000014e83 or -2.4e21 < y < -2.4000000000000001e-112 or 1.32e-74 < y < 2.6999999999999998e130Initial program 100.0%
Taylor expanded in x around 0 62.8%
if -5.40000000000000014e83 < y < -2.4e21 or 2.6999999999999998e130 < y Initial program 100.0%
Taylor expanded in x around inf 65.1%
+-commutative65.1%
Simplified65.1%
Taylor expanded in y around inf 65.1%
if -2.4000000000000001e-112 < y < 1.32e-74Initial program 100.0%
Taylor expanded in y around 0 89.8%
Final simplification72.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.2e-112) (not (<= y 4.4e-78))) (* y (+ x z)) (* x (+ y 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.2e-112) || !(y <= 4.4e-78)) {
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 <= (-5.2d-112)) .or. (.not. (y <= 4.4d-78))) 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 <= -5.2e-112) || !(y <= 4.4e-78)) {
tmp = y * (x + z);
} else {
tmp = x * (y + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.2e-112) or not (y <= 4.4e-78): tmp = y * (x + z) else: tmp = x * (y + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.2e-112) || !(y <= 4.4e-78)) 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 <= -5.2e-112) || ~((y <= 4.4e-78))) tmp = y * (x + z); else tmp = x * (y + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.2e-112], N[Not[LessEqual[y, 4.4e-78]], $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 -5.2 \cdot 10^{-112} \lor \neg \left(y \leq 4.4 \cdot 10^{-78}\right):\\
\;\;\;\;y \cdot \left(x + z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\end{array}
\end{array}
if y < -5.19999999999999983e-112 or 4.3999999999999998e-78 < y Initial program 100.0%
Taylor expanded in y around inf 89.8%
+-commutative89.8%
Simplified89.8%
if -5.19999999999999983e-112 < y < 4.3999999999999998e-78Initial program 100.0%
Taylor expanded in x around inf 89.8%
+-commutative89.8%
Simplified89.8%
Final simplification89.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.7e-17) (not (<= y 115000000000.0))) (* y x) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.7e-17) || !(y <= 115000000000.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.7d-17)) .or. (.not. (y <= 115000000000.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.7e-17) || !(y <= 115000000000.0)) {
tmp = y * x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.7e-17) or not (y <= 115000000000.0): tmp = y * x else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.7e-17) || !(y <= 115000000000.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.7e-17) || ~((y <= 115000000000.0))) tmp = y * x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.7e-17], N[Not[LessEqual[y, 115000000000.0]], $MachinePrecision]], N[(y * x), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.7 \cdot 10^{-17} \lor \neg \left(y \leq 115000000000\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.6999999999999999e-17 or 1.15e11 < y Initial program 100.0%
Taylor expanded in x around inf 49.2%
+-commutative49.2%
Simplified49.2%
Taylor expanded in y around inf 48.3%
if -1.6999999999999999e-17 < y < 1.15e11Initial program 100.0%
Taylor expanded in y around 0 75.6%
Final simplification61.6%
(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.2%
Final simplification38.2%
herbie shell --seed 2024020
(FPCore (x y z)
:name "Main:bigenough2 from A"
:precision binary64
(+ x (* y (+ z x))))