
(FPCore (x y) :precision binary64 (/ (* x 100.0) (+ x y)))
double code(double x, double y) {
return (x * 100.0) / (x + y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * 100.0d0) / (x + y)
end function
public static double code(double x, double y) {
return (x * 100.0) / (x + y);
}
def code(x, y): return (x * 100.0) / (x + y)
function code(x, y) return Float64(Float64(x * 100.0) / Float64(x + y)) end
function tmp = code(x, y) tmp = (x * 100.0) / (x + y); end
code[x_, y_] := N[(N[(x * 100.0), $MachinePrecision] / N[(x + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot 100}{x + y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ (* x 100.0) (+ x y)))
double code(double x, double y) {
return (x * 100.0) / (x + y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * 100.0d0) / (x + y)
end function
public static double code(double x, double y) {
return (x * 100.0) / (x + y);
}
def code(x, y): return (x * 100.0) / (x + y)
function code(x, y) return Float64(Float64(x * 100.0) / Float64(x + y)) end
function tmp = code(x, y) tmp = (x * 100.0) / (x + y); end
code[x_, y_] := N[(N[(x * 100.0), $MachinePrecision] / N[(x + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot 100}{x + y}
\end{array}
(FPCore (x y) :precision binary64 (* x (/ 100.0 (+ y x))))
double code(double x, double y) {
return x * (100.0 / (y + x));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * (100.0d0 / (y + x))
end function
public static double code(double x, double y) {
return x * (100.0 / (y + x));
}
def code(x, y): return x * (100.0 / (y + x))
function code(x, y) return Float64(x * Float64(100.0 / Float64(y + x))) end
function tmp = code(x, y) tmp = x * (100.0 / (y + x)); end
code[x_, y_] := N[(x * N[(100.0 / N[(y + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \frac{100}{y + x}
\end{array}
(FPCore (x y)
:precision binary64
(if (or (<= y -2e-40)
(not
(or (<= y -4.4e-88)
(and (not (<= y -1e-107))
(or (<= y 1.96e-75)
(and (not (<= y 6.2e-51)) (<= y 3.4e+25)))))))
(* 100.0 (/ x y))
100.0))
double code(double x, double y) {
double tmp;
if ((y <= -2e-40) || !((y <= -4.4e-88) || (!(y <= -1e-107) && ((y <= 1.96e-75) || (!(y <= 6.2e-51) && (y <= 3.4e+25)))))) {
tmp = 100.0 * (x / y);
} else {
tmp = 100.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-2d-40)) .or. (.not. (y <= (-4.4d-88)) .or. (.not. (y <= (-1d-107))) .and. (y <= 1.96d-75) .or. (.not. (y <= 6.2d-51)) .and. (y <= 3.4d+25))) then
tmp = 100.0d0 * (x / y)
else
tmp = 100.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -2e-40) || !((y <= -4.4e-88) || (!(y <= -1e-107) && ((y <= 1.96e-75) || (!(y <= 6.2e-51) && (y <= 3.4e+25)))))) {
tmp = 100.0 * (x / y);
} else {
tmp = 100.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -2e-40) or not ((y <= -4.4e-88) or (not (y <= -1e-107) and ((y <= 1.96e-75) or (not (y <= 6.2e-51) and (y <= 3.4e+25))))): tmp = 100.0 * (x / y) else: tmp = 100.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= -2e-40) || !((y <= -4.4e-88) || (!(y <= -1e-107) && ((y <= 1.96e-75) || (!(y <= 6.2e-51) && (y <= 3.4e+25)))))) tmp = Float64(100.0 * Float64(x / y)); else tmp = 100.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -2e-40) || ~(((y <= -4.4e-88) || (~((y <= -1e-107)) && ((y <= 1.96e-75) || (~((y <= 6.2e-51)) && (y <= 3.4e+25))))))) tmp = 100.0 * (x / y); else tmp = 100.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -2e-40], N[Not[Or[LessEqual[y, -4.4e-88], And[N[Not[LessEqual[y, -1e-107]], $MachinePrecision], Or[LessEqual[y, 1.96e-75], And[N[Not[LessEqual[y, 6.2e-51]], $MachinePrecision], LessEqual[y, 3.4e+25]]]]]], $MachinePrecision]], N[(100.0 * N[(x / y), $MachinePrecision]), $MachinePrecision], 100.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{-40} \lor \neg \left(y \leq -4.4 \cdot 10^{-88} \lor \neg \left(y \leq -1 \cdot 10^{-107}\right) \land \left(y \leq 1.96 \cdot 10^{-75} \lor \neg \left(y \leq 6.2 \cdot 10^{-51}\right) \land y \leq 3.4 \cdot 10^{+25}\right)\right):\\
\;\;\;\;100 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;100\\
\end{array}
\end{array}
(FPCore (x y)
:precision binary64
(let* ((t_0 (* 100.0 (/ x y))) (t_1 (* x (/ 100.0 y))))
(if (<= y -1.45e-40)
t_1
(if (<= y -2.5e-88)
100.0
(if (<= y -3.5e-108)
t_0
(if (<= y 4e-76)
100.0
(if (<= y 1.38e-49) t_0 (if (<= y 2.6e+25) 100.0 t_1))))))))
double code(double x, double y) {
double t_0 = 100.0 * (x / y);
double t_1 = x * (100.0 / y);
double tmp;
if (y <= -1.45e-40) {
tmp = t_1;
} else if (y <= -2.5e-88) {
tmp = 100.0;
} else if (y <= -3.5e-108) {
tmp = t_0;
} else if (y <= 4e-76) {
tmp = 100.0;
} else if (y <= 1.38e-49) {
tmp = t_0;
} else if (y <= 2.6e+25) {
tmp = 100.0;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = 100.0d0 * (x / y)
t_1 = x * (100.0d0 / y)
if (y <= (-1.45d-40)) then
tmp = t_1
else if (y <= (-2.5d-88)) then
tmp = 100.0d0
else if (y <= (-3.5d-108)) then
tmp = t_0
else if (y <= 4d-76) then
tmp = 100.0d0
else if (y <= 1.38d-49) then
tmp = t_0
else if (y <= 2.6d+25) then
tmp = 100.0d0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 100.0 * (x / y);
double t_1 = x * (100.0 / y);
double tmp;
if (y <= -1.45e-40) {
tmp = t_1;
} else if (y <= -2.5e-88) {
tmp = 100.0;
} else if (y <= -3.5e-108) {
tmp = t_0;
} else if (y <= 4e-76) {
tmp = 100.0;
} else if (y <= 1.38e-49) {
tmp = t_0;
} else if (y <= 2.6e+25) {
tmp = 100.0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y): t_0 = 100.0 * (x / y) t_1 = x * (100.0 / y) tmp = 0 if y <= -1.45e-40: tmp = t_1 elif y <= -2.5e-88: tmp = 100.0 elif y <= -3.5e-108: tmp = t_0 elif y <= 4e-76: tmp = 100.0 elif y <= 1.38e-49: tmp = t_0 elif y <= 2.6e+25: tmp = 100.0 else: tmp = t_1 return tmp
function code(x, y) t_0 = Float64(100.0 * Float64(x / y)) t_1 = Float64(x * Float64(100.0 / y)) tmp = 0.0 if (y <= -1.45e-40) tmp = t_1; elseif (y <= -2.5e-88) tmp = 100.0; elseif (y <= -3.5e-108) tmp = t_0; elseif (y <= 4e-76) tmp = 100.0; elseif (y <= 1.38e-49) tmp = t_0; elseif (y <= 2.6e+25) tmp = 100.0; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y) t_0 = 100.0 * (x / y); t_1 = x * (100.0 / y); tmp = 0.0; if (y <= -1.45e-40) tmp = t_1; elseif (y <= -2.5e-88) tmp = 100.0; elseif (y <= -3.5e-108) tmp = t_0; elseif (y <= 4e-76) tmp = 100.0; elseif (y <= 1.38e-49) tmp = t_0; elseif (y <= 2.6e+25) tmp = 100.0; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(100.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[(100.0 / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.45e-40], t$95$1, If[LessEqual[y, -2.5e-88], 100.0, If[LessEqual[y, -3.5e-108], t$95$0, If[LessEqual[y, 4e-76], 100.0, If[LessEqual[y, 1.38e-49], t$95$0, If[LessEqual[y, 2.6e+25], 100.0, t$95$1]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 100 \cdot \frac{x}{y}\\
t_1 := x \cdot \frac{100}{y}\\
\mathbf{if}\;y \leq -1.45 \cdot 10^{-40}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq -2.5 \cdot 10^{-88}:\\
\;\;\;\;100\\
\mathbf{elif}\;y \leq -3.5 \cdot 10^{-108}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 4 \cdot 10^{-76}:\\
\;\;\;\;100\\
\mathbf{elif}\;y \leq 1.38 \cdot 10^{-49}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 2.6 \cdot 10^{+25}:\\
\;\;\;\;100\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
(FPCore (x y)
:precision binary64
(let* ((t_0 (* 100.0 (/ x y))) (t_1 (/ x (/ y 100.0))))
(if (<= y -1.35e-40)
t_1
(if (<= y -2.1e-88)
100.0
(if (<= y -6.6e-108)
t_0
(if (<= y 1.8e-75)
100.0
(if (<= y 1.5e-50) t_0 (if (<= y 2.2e+25) 100.0 t_1))))))))
double code(double x, double y) {
double t_0 = 100.0 * (x / y);
double t_1 = x / (y / 100.0);
double tmp;
if (y <= -1.35e-40) {
tmp = t_1;
} else if (y <= -2.1e-88) {
tmp = 100.0;
} else if (y <= -6.6e-108) {
tmp = t_0;
} else if (y <= 1.8e-75) {
tmp = 100.0;
} else if (y <= 1.5e-50) {
tmp = t_0;
} else if (y <= 2.2e+25) {
tmp = 100.0;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = 100.0d0 * (x / y)
t_1 = x / (y / 100.0d0)
if (y <= (-1.35d-40)) then
tmp = t_1
else if (y <= (-2.1d-88)) then
tmp = 100.0d0
else if (y <= (-6.6d-108)) then
tmp = t_0
else if (y <= 1.8d-75) then
tmp = 100.0d0
else if (y <= 1.5d-50) then
tmp = t_0
else if (y <= 2.2d+25) then
tmp = 100.0d0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 100.0 * (x / y);
double t_1 = x / (y / 100.0);
double tmp;
if (y <= -1.35e-40) {
tmp = t_1;
} else if (y <= -2.1e-88) {
tmp = 100.0;
} else if (y <= -6.6e-108) {
tmp = t_0;
} else if (y <= 1.8e-75) {
tmp = 100.0;
} else if (y <= 1.5e-50) {
tmp = t_0;
} else if (y <= 2.2e+25) {
tmp = 100.0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y): t_0 = 100.0 * (x / y) t_1 = x / (y / 100.0) tmp = 0 if y <= -1.35e-40: tmp = t_1 elif y <= -2.1e-88: tmp = 100.0 elif y <= -6.6e-108: tmp = t_0 elif y <= 1.8e-75: tmp = 100.0 elif y <= 1.5e-50: tmp = t_0 elif y <= 2.2e+25: tmp = 100.0 else: tmp = t_1 return tmp
function code(x, y) t_0 = Float64(100.0 * Float64(x / y)) t_1 = Float64(x / Float64(y / 100.0)) tmp = 0.0 if (y <= -1.35e-40) tmp = t_1; elseif (y <= -2.1e-88) tmp = 100.0; elseif (y <= -6.6e-108) tmp = t_0; elseif (y <= 1.8e-75) tmp = 100.0; elseif (y <= 1.5e-50) tmp = t_0; elseif (y <= 2.2e+25) tmp = 100.0; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y) t_0 = 100.0 * (x / y); t_1 = x / (y / 100.0); tmp = 0.0; if (y <= -1.35e-40) tmp = t_1; elseif (y <= -2.1e-88) tmp = 100.0; elseif (y <= -6.6e-108) tmp = t_0; elseif (y <= 1.8e-75) tmp = 100.0; elseif (y <= 1.5e-50) tmp = t_0; elseif (y <= 2.2e+25) tmp = 100.0; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(100.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x / N[(y / 100.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.35e-40], t$95$1, If[LessEqual[y, -2.1e-88], 100.0, If[LessEqual[y, -6.6e-108], t$95$0, If[LessEqual[y, 1.8e-75], 100.0, If[LessEqual[y, 1.5e-50], t$95$0, If[LessEqual[y, 2.2e+25], 100.0, t$95$1]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 100 \cdot \frac{x}{y}\\
t_1 := \frac{x}{\frac{y}{100}}\\
\mathbf{if}\;y \leq -1.35 \cdot 10^{-40}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq -2.1 \cdot 10^{-88}:\\
\;\;\;\;100\\
\mathbf{elif}\;y \leq -6.6 \cdot 10^{-108}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 1.8 \cdot 10^{-75}:\\
\;\;\;\;100\\
\mathbf{elif}\;y \leq 1.5 \cdot 10^{-50}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 2.2 \cdot 10^{+25}:\\
\;\;\;\;100\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ x (/ y 100.0))))
(if (<= y -1e-40)
t_0
(if (<= y -2.6e-88)
100.0
(if (<= y -8.5e-108)
(* 100.0 (/ x y))
(if (<= y 6.5e-76)
100.0
(if (<= y 4.8e-51)
(/ (* 100.0 x) y)
(if (<= y 3e+25) 100.0 t_0))))))))
double code(double x, double y) {
double t_0 = x / (y / 100.0);
double tmp;
if (y <= -1e-40) {
tmp = t_0;
} else if (y <= -2.6e-88) {
tmp = 100.0;
} else if (y <= -8.5e-108) {
tmp = 100.0 * (x / y);
} else if (y <= 6.5e-76) {
tmp = 100.0;
} else if (y <= 4.8e-51) {
tmp = (100.0 * x) / y;
} else if (y <= 3e+25) {
tmp = 100.0;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = x / (y / 100.0d0)
if (y <= (-1d-40)) then
tmp = t_0
else if (y <= (-2.6d-88)) then
tmp = 100.0d0
else if (y <= (-8.5d-108)) then
tmp = 100.0d0 * (x / y)
else if (y <= 6.5d-76) then
tmp = 100.0d0
else if (y <= 4.8d-51) then
tmp = (100.0d0 * x) / y
else if (y <= 3d+25) then
tmp = 100.0d0
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x / (y / 100.0);
double tmp;
if (y <= -1e-40) {
tmp = t_0;
} else if (y <= -2.6e-88) {
tmp = 100.0;
} else if (y <= -8.5e-108) {
tmp = 100.0 * (x / y);
} else if (y <= 6.5e-76) {
tmp = 100.0;
} else if (y <= 4.8e-51) {
tmp = (100.0 * x) / y;
} else if (y <= 3e+25) {
tmp = 100.0;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = x / (y / 100.0) tmp = 0 if y <= -1e-40: tmp = t_0 elif y <= -2.6e-88: tmp = 100.0 elif y <= -8.5e-108: tmp = 100.0 * (x / y) elif y <= 6.5e-76: tmp = 100.0 elif y <= 4.8e-51: tmp = (100.0 * x) / y elif y <= 3e+25: tmp = 100.0 else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(x / Float64(y / 100.0)) tmp = 0.0 if (y <= -1e-40) tmp = t_0; elseif (y <= -2.6e-88) tmp = 100.0; elseif (y <= -8.5e-108) tmp = Float64(100.0 * Float64(x / y)); elseif (y <= 6.5e-76) tmp = 100.0; elseif (y <= 4.8e-51) tmp = Float64(Float64(100.0 * x) / y); elseif (y <= 3e+25) tmp = 100.0; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = x / (y / 100.0); tmp = 0.0; if (y <= -1e-40) tmp = t_0; elseif (y <= -2.6e-88) tmp = 100.0; elseif (y <= -8.5e-108) tmp = 100.0 * (x / y); elseif (y <= 6.5e-76) tmp = 100.0; elseif (y <= 4.8e-51) tmp = (100.0 * x) / y; elseif (y <= 3e+25) tmp = 100.0; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x / N[(y / 100.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1e-40], t$95$0, If[LessEqual[y, -2.6e-88], 100.0, If[LessEqual[y, -8.5e-108], N[(100.0 * N[(x / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 6.5e-76], 100.0, If[LessEqual[y, 4.8e-51], N[(N[(100.0 * x), $MachinePrecision] / y), $MachinePrecision], If[LessEqual[y, 3e+25], 100.0, t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{\frac{y}{100}}\\
\mathbf{if}\;y \leq -1 \cdot 10^{-40}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -2.6 \cdot 10^{-88}:\\
\;\;\;\;100\\
\mathbf{elif}\;y \leq -8.5 \cdot 10^{-108}:\\
\;\;\;\;100 \cdot \frac{x}{y}\\
\mathbf{elif}\;y \leq 6.5 \cdot 10^{-76}:\\
\;\;\;\;100\\
\mathbf{elif}\;y \leq 4.8 \cdot 10^{-51}:\\
\;\;\;\;\frac{100 \cdot x}{y}\\
\mathbf{elif}\;y \leq 3 \cdot 10^{+25}:\\
\;\;\;\;100\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
(FPCore (x y) :precision binary64 100.0)
double code(double x, double y) {
return 100.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 100.0d0
end function
public static double code(double x, double y) {
return 100.0;
}
def code(x, y): return 100.0
function code(x, y) return 100.0 end
function tmp = code(x, y) tmp = 100.0; end
code[x_, y_] := 100.0
\begin{array}{l}
\\
100
\end{array}
(FPCore (x y) :precision binary64 (* (/ x 1.0) (/ 100.0 (+ x y))))
double code(double x, double y) {
return (x / 1.0) * (100.0 / (x + y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x / 1.0d0) * (100.0d0 / (x + y))
end function
public static double code(double x, double y) {
return (x / 1.0) * (100.0 / (x + y));
}
def code(x, y): return (x / 1.0) * (100.0 / (x + y))
function code(x, y) return Float64(Float64(x / 1.0) * Float64(100.0 / Float64(x + y))) end
function tmp = code(x, y) tmp = (x / 1.0) * (100.0 / (x + y)); end
code[x_, y_] := N[(N[(x / 1.0), $MachinePrecision] * N[(100.0 / N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{1} \cdot \frac{100}{x + y}
\end{array}
herbie shell --seed 2023350
(FPCore (x y)
:name "Development.Shake.Progress:message from shake-0.15.5"
:precision binary64
:herbie-target
(* (/ x 1.0) (/ 100.0 (+ x y)))
(/ (* x 100.0) (+ x y)))