
(FPCore (x y z) :precision binary64 (/ (* x (+ y z)) z))
double code(double x, double y, double z) {
return (x * (y + z)) / 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 + z)) / z
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
def code(x, y, z): return (x * (y + z)) / z
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) / z) end
function tmp = code(x, y, z) tmp = (x * (y + z)) / z; end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(y + z\right)}{z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (* x (+ y z)) z))
double code(double x, double y, double z) {
return (x * (y + z)) / 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 + z)) / z
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
def code(x, y, z): return (x * (y + z)) / z
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) / z) end
function tmp = code(x, y, z) tmp = (x * (y + z)) / z; end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(y + z\right)}{z}
\end{array}
(FPCore (x y z) :precision binary64 (+ (/ x (/ z y)) x))
double code(double x, double y, double z) {
return (x / (z / y)) + 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 / (z / y)) + x
end function
public static double code(double x, double y, double z) {
return (x / (z / y)) + x;
}
def code(x, y, z): return (x / (z / y)) + x
function code(x, y, z) return Float64(Float64(x / Float64(z / y)) + x) end
function tmp = code(x, y, z) tmp = (x / (z / y)) + x; end
code[x_, y_, z_] := N[(N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{\frac{z}{y}} + x
\end{array}
Initial program 85.1%
Simplified0
Applied egg-rr0
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ x (/ z y))))
(if (<= y -2.1e-129)
t_0
(if (<= y 8e-35)
x
(if (<= y 2.4e+114) t_0 (if (<= y 4.5e+129) x (* (/ x z) y)))))))
double code(double x, double y, double z) {
double t_0 = x / (z / y);
double tmp;
if (y <= -2.1e-129) {
tmp = t_0;
} else if (y <= 8e-35) {
tmp = x;
} else if (y <= 2.4e+114) {
tmp = t_0;
} else if (y <= 4.5e+129) {
tmp = x;
} else {
tmp = (x / z) * y;
}
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 = x / (z / y)
if (y <= (-2.1d-129)) then
tmp = t_0
else if (y <= 8d-35) then
tmp = x
else if (y <= 2.4d+114) then
tmp = t_0
else if (y <= 4.5d+129) then
tmp = x
else
tmp = (x / z) * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x / (z / y);
double tmp;
if (y <= -2.1e-129) {
tmp = t_0;
} else if (y <= 8e-35) {
tmp = x;
} else if (y <= 2.4e+114) {
tmp = t_0;
} else if (y <= 4.5e+129) {
tmp = x;
} else {
tmp = (x / z) * y;
}
return tmp;
}
def code(x, y, z): t_0 = x / (z / y) tmp = 0 if y <= -2.1e-129: tmp = t_0 elif y <= 8e-35: tmp = x elif y <= 2.4e+114: tmp = t_0 elif y <= 4.5e+129: tmp = x else: tmp = (x / z) * y return tmp
function code(x, y, z) t_0 = Float64(x / Float64(z / y)) tmp = 0.0 if (y <= -2.1e-129) tmp = t_0; elseif (y <= 8e-35) tmp = x; elseif (y <= 2.4e+114) tmp = t_0; elseif (y <= 4.5e+129) tmp = x; else tmp = Float64(Float64(x / z) * y); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x / (z / y); tmp = 0.0; if (y <= -2.1e-129) tmp = t_0; elseif (y <= 8e-35) tmp = x; elseif (y <= 2.4e+114) tmp = t_0; elseif (y <= 4.5e+129) tmp = x; else tmp = (x / z) * y; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2.1e-129], t$95$0, If[LessEqual[y, 8e-35], x, If[LessEqual[y, 2.4e+114], t$95$0, If[LessEqual[y, 4.5e+129], x, N[(N[(x / z), $MachinePrecision] * y), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{\frac{z}{y}}\\
\mathbf{if}\;y \leq -2.1 \cdot 10^{-129}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 8 \cdot 10^{-35}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 2.4 \cdot 10^{+114}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 4.5 \cdot 10^{+129}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z} \cdot y\\
\end{array}
\end{array}
if y < -2.1e-129 or 8.00000000000000006e-35 < y < 2.4e114Initial program 90.3%
Simplified0
Taylor expanded in y around inf 0
Simplified0
Applied egg-rr0
if -2.1e-129 < y < 8.00000000000000006e-35 or 2.4e114 < y < 4.5000000000000001e129Initial program 77.4%
Simplified0
Taylor expanded in y around 0 0
Simplified0
if 4.5000000000000001e129 < y Initial program 86.4%
Simplified0
Taylor expanded in y around inf 0
Simplified0
Applied egg-rr0
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (/ y z))))
(if (<= y -1.7e-129)
t_0
(if (<= y 7.2e-35)
x
(if (<= y 4.4e+114) t_0 (if (<= y 4.5e+129) x t_0))))))
double code(double x, double y, double z) {
double t_0 = x * (y / z);
double tmp;
if (y <= -1.7e-129) {
tmp = t_0;
} else if (y <= 7.2e-35) {
tmp = x;
} else if (y <= 4.4e+114) {
tmp = t_0;
} else if (y <= 4.5e+129) {
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 = x * (y / z)
if (y <= (-1.7d-129)) then
tmp = t_0
else if (y <= 7.2d-35) then
tmp = x
else if (y <= 4.4d+114) then
tmp = t_0
else if (y <= 4.5d+129) 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 = x * (y / z);
double tmp;
if (y <= -1.7e-129) {
tmp = t_0;
} else if (y <= 7.2e-35) {
tmp = x;
} else if (y <= 4.4e+114) {
tmp = t_0;
} else if (y <= 4.5e+129) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y / z) tmp = 0 if y <= -1.7e-129: tmp = t_0 elif y <= 7.2e-35: tmp = x elif y <= 4.4e+114: tmp = t_0 elif y <= 4.5e+129: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(y / z)) tmp = 0.0 if (y <= -1.7e-129) tmp = t_0; elseif (y <= 7.2e-35) tmp = x; elseif (y <= 4.4e+114) tmp = t_0; elseif (y <= 4.5e+129) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (y / z); tmp = 0.0; if (y <= -1.7e-129) tmp = t_0; elseif (y <= 7.2e-35) tmp = x; elseif (y <= 4.4e+114) tmp = t_0; elseif (y <= 4.5e+129) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.7e-129], t$95$0, If[LessEqual[y, 7.2e-35], x, If[LessEqual[y, 4.4e+114], t$95$0, If[LessEqual[y, 4.5e+129], x, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \frac{y}{z}\\
\mathbf{if}\;y \leq -1.7 \cdot 10^{-129}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 7.2 \cdot 10^{-35}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 4.4 \cdot 10^{+114}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 4.5 \cdot 10^{+129}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.70000000000000007e-129 or 7.20000000000000038e-35 < y < 4.4000000000000001e114 or 4.5000000000000001e129 < y Initial program 89.5%
Simplified0
Taylor expanded in y around inf 0
Simplified0
if -1.70000000000000007e-129 < y < 7.20000000000000038e-35 or 4.4000000000000001e114 < y < 4.5000000000000001e129Initial program 77.4%
Simplified0
Taylor expanded in y around 0 0
Simplified0
(FPCore (x y z) :precision binary64 (let* ((t_0 (/ (* x y) z))) (if (<= y -3.3e-106) t_0 (if (<= y 6e-35) x t_0))))
double code(double x, double y, double z) {
double t_0 = (x * y) / z;
double tmp;
if (y <= -3.3e-106) {
tmp = t_0;
} else if (y <= 6e-35) {
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 = (x * y) / z
if (y <= (-3.3d-106)) then
tmp = t_0
else if (y <= 6d-35) 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 = (x * y) / z;
double tmp;
if (y <= -3.3e-106) {
tmp = t_0;
} else if (y <= 6e-35) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (x * y) / z tmp = 0 if y <= -3.3e-106: tmp = t_0 elif y <= 6e-35: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(x * y) / z) tmp = 0.0 if (y <= -3.3e-106) tmp = t_0; elseif (y <= 6e-35) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x * y) / z; tmp = 0.0; if (y <= -3.3e-106) tmp = t_0; elseif (y <= 6e-35) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[y, -3.3e-106], t$95$0, If[LessEqual[y, 6e-35], x, t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x \cdot y}{z}\\
\mathbf{if}\;y \leq -3.3 \cdot 10^{-106}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 6 \cdot 10^{-35}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -3.30000000000000016e-106 or 5.99999999999999978e-35 < y Initial program 89.5%
Simplified0
Taylor expanded in y around inf 0
Simplified0
if -3.30000000000000016e-106 < y < 5.99999999999999978e-35Initial program 77.4%
Simplified0
Taylor expanded in y around 0 0
Simplified0
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (/ x z) y))) (if (<= y -2.1e-129) t_0 (if (<= y 1.2e-34) x t_0))))
double code(double x, double y, double z) {
double t_0 = (x / z) * y;
double tmp;
if (y <= -2.1e-129) {
tmp = t_0;
} else if (y <= 1.2e-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 = (x / z) * y
if (y <= (-2.1d-129)) then
tmp = t_0
else if (y <= 1.2d-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 = (x / z) * y;
double tmp;
if (y <= -2.1e-129) {
tmp = t_0;
} else if (y <= 1.2e-34) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (x / z) * y tmp = 0 if y <= -2.1e-129: tmp = t_0 elif y <= 1.2e-34: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(x / z) * y) tmp = 0.0 if (y <= -2.1e-129) tmp = t_0; elseif (y <= 1.2e-34) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x / z) * y; tmp = 0.0; if (y <= -2.1e-129) tmp = t_0; elseif (y <= 1.2e-34) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x / z), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -2.1e-129], t$95$0, If[LessEqual[y, 1.2e-34], x, t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{z} \cdot y\\
\mathbf{if}\;y \leq -2.1 \cdot 10^{-129}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.2 \cdot 10^{-34}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.1e-129 or 1.19999999999999996e-34 < y Initial program 88.7%
Simplified0
Taylor expanded in y around inf 0
Simplified0
Applied egg-rr0
if -2.1e-129 < y < 1.19999999999999996e-34Initial program 78.0%
Simplified0
Taylor expanded in y around 0 0
Simplified0
(FPCore (x y z) :precision binary64 (* x (+ (/ y z) 1.0)))
double code(double x, double y, double z) {
return x * ((y / z) + 1.0);
}
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) + 1.0d0)
end function
public static double code(double x, double y, double z) {
return x * ((y / z) + 1.0);
}
def code(x, y, z): return x * ((y / z) + 1.0)
function code(x, y, z) return Float64(x * Float64(Float64(y / z) + 1.0)) end
function tmp = code(x, y, z) tmp = x * ((y / z) + 1.0); end
code[x_, y_, z_] := N[(x * N[(N[(y / z), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(\frac{y}{z} + 1\right)
\end{array}
Initial program 85.1%
Simplified0
(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 85.1%
Simplified0
Taylor expanded in y around 0 0
Simplified0
(FPCore (x y z) :precision binary64 (/ x (/ z (+ y z))))
double code(double x, double y, double z) {
return x / (z / (y + 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 / (z / (y + z))
end function
public static double code(double x, double y, double z) {
return x / (z / (y + z));
}
def code(x, y, z): return x / (z / (y + z))
function code(x, y, z) return Float64(x / Float64(z / Float64(y + z))) end
function tmp = code(x, y, z) tmp = x / (z / (y + z)); end
code[x_, y_, z_] := N[(x / N[(z / N[(y + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{\frac{z}{y + z}}
\end{array}
herbie shell --seed 2024110
(FPCore (x y z)
:name "Numeric.SpecFunctions:choose from math-functions-0.1.5.2"
:precision binary64
:alt
(/ x (/ z (+ y z)))
(/ (* x (+ y z)) z))