
(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 (* 100.0 (/ x (+ x y))))
double code(double x, double y) {
return 100.0 * (x / (x + y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 100.0d0 * (x / (x + y))
end function
public static double code(double x, double y) {
return 100.0 * (x / (x + y));
}
def code(x, y): return 100.0 * (x / (x + y))
function code(x, y) return Float64(100.0 * Float64(x / Float64(x + y))) end
function tmp = code(x, y) tmp = 100.0 * (x / (x + y)); end
code[x_, y_] := N[(100.0 * N[(x / N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
100 \cdot \frac{x}{x + y}
\end{array}
Initial program 99.3%
*-commutative99.3%
associate-/l*99.7%
Simplified99.7%
(FPCore (x y) :precision binary64 (if (or (<= y -1.75e+50) (not (<= y 1.55e+19))) (/ x (* y 0.01)) 100.0))
double code(double x, double y) {
double tmp;
if ((y <= -1.75e+50) || !(y <= 1.55e+19)) {
tmp = x / (y * 0.01);
} 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 <= (-1.75d+50)) .or. (.not. (y <= 1.55d+19))) then
tmp = x / (y * 0.01d0)
else
tmp = 100.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.75e+50) || !(y <= 1.55e+19)) {
tmp = x / (y * 0.01);
} else {
tmp = 100.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.75e+50) or not (y <= 1.55e+19): tmp = x / (y * 0.01) else: tmp = 100.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.75e+50) || !(y <= 1.55e+19)) tmp = Float64(x / Float64(y * 0.01)); else tmp = 100.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.75e+50) || ~((y <= 1.55e+19))) tmp = x / (y * 0.01); else tmp = 100.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.75e+50], N[Not[LessEqual[y, 1.55e+19]], $MachinePrecision]], N[(x / N[(y * 0.01), $MachinePrecision]), $MachinePrecision], 100.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.75 \cdot 10^{+50} \lor \neg \left(y \leq 1.55 \cdot 10^{+19}\right):\\
\;\;\;\;\frac{x}{y \cdot 0.01}\\
\mathbf{else}:\\
\;\;\;\;100\\
\end{array}
\end{array}
if y < -1.75000000000000003e50 or 1.55e19 < y Initial program 99.7%
*-commutative99.7%
associate-/l*99.6%
Simplified99.6%
Taylor expanded in x around 0 77.5%
associate-*r/77.7%
*-commutative77.7%
associate-*r/77.6%
Simplified77.6%
clear-num77.6%
un-div-inv77.7%
div-inv77.7%
metadata-eval77.7%
Applied egg-rr77.7%
if -1.75000000000000003e50 < y < 1.55e19Initial program 98.9%
*-commutative98.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around inf 74.5%
Final simplification76.1%
(FPCore (x y) :precision binary64 (if (or (<= y -1.2e+49) (not (<= y 62000000.0))) (* x (/ 100.0 y)) 100.0))
double code(double x, double y) {
double tmp;
if ((y <= -1.2e+49) || !(y <= 62000000.0)) {
tmp = x * (100.0 / 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 <= (-1.2d+49)) .or. (.not. (y <= 62000000.0d0))) then
tmp = x * (100.0d0 / y)
else
tmp = 100.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.2e+49) || !(y <= 62000000.0)) {
tmp = x * (100.0 / y);
} else {
tmp = 100.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.2e+49) or not (y <= 62000000.0): tmp = x * (100.0 / y) else: tmp = 100.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.2e+49) || !(y <= 62000000.0)) tmp = Float64(x * Float64(100.0 / y)); else tmp = 100.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.2e+49) || ~((y <= 62000000.0))) tmp = x * (100.0 / y); else tmp = 100.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.2e+49], N[Not[LessEqual[y, 62000000.0]], $MachinePrecision]], N[(x * N[(100.0 / y), $MachinePrecision]), $MachinePrecision], 100.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.2 \cdot 10^{+49} \lor \neg \left(y \leq 62000000\right):\\
\;\;\;\;x \cdot \frac{100}{y}\\
\mathbf{else}:\\
\;\;\;\;100\\
\end{array}
\end{array}
if y < -1.2e49 or 6.2e7 < y Initial program 99.7%
*-commutative99.7%
associate-/l*99.6%
Simplified99.6%
Taylor expanded in x around 0 77.5%
associate-*r/77.7%
*-commutative77.7%
associate-*r/77.6%
Simplified77.6%
if -1.2e49 < y < 6.2e7Initial program 98.9%
*-commutative98.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around inf 74.5%
Final simplification76.1%
(FPCore (x y) :precision binary64 (if (or (<= y -1.9e+49) (not (<= y 42000.0))) (* 100.0 (/ x y)) 100.0))
double code(double x, double y) {
double tmp;
if ((y <= -1.9e+49) || !(y <= 42000.0)) {
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 <= (-1.9d+49)) .or. (.not. (y <= 42000.0d0))) 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 <= -1.9e+49) || !(y <= 42000.0)) {
tmp = 100.0 * (x / y);
} else {
tmp = 100.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.9e+49) or not (y <= 42000.0): tmp = 100.0 * (x / y) else: tmp = 100.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.9e+49) || !(y <= 42000.0)) 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 <= -1.9e+49) || ~((y <= 42000.0))) tmp = 100.0 * (x / y); else tmp = 100.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.9e+49], N[Not[LessEqual[y, 42000.0]], $MachinePrecision]], N[(100.0 * N[(x / y), $MachinePrecision]), $MachinePrecision], 100.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.9 \cdot 10^{+49} \lor \neg \left(y \leq 42000\right):\\
\;\;\;\;100 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;100\\
\end{array}
\end{array}
if y < -1.8999999999999999e49 or 42000 < y Initial program 99.7%
*-commutative99.7%
associate-/l*99.6%
Simplified99.6%
Taylor expanded in x around 0 77.5%
if -1.8999999999999999e49 < y < 42000Initial program 98.9%
*-commutative98.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around inf 74.5%
Final simplification76.0%
(FPCore (x y) :precision binary64 (if (<= y -1.06e+51) (/ (* 100.0 x) y) (if (<= y 5.3e+16) 100.0 (/ x (* y 0.01)))))
double code(double x, double y) {
double tmp;
if (y <= -1.06e+51) {
tmp = (100.0 * x) / y;
} else if (y <= 5.3e+16) {
tmp = 100.0;
} else {
tmp = x / (y * 0.01);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-1.06d+51)) then
tmp = (100.0d0 * x) / y
else if (y <= 5.3d+16) then
tmp = 100.0d0
else
tmp = x / (y * 0.01d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.06e+51) {
tmp = (100.0 * x) / y;
} else if (y <= 5.3e+16) {
tmp = 100.0;
} else {
tmp = x / (y * 0.01);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.06e+51: tmp = (100.0 * x) / y elif y <= 5.3e+16: tmp = 100.0 else: tmp = x / (y * 0.01) return tmp
function code(x, y) tmp = 0.0 if (y <= -1.06e+51) tmp = Float64(Float64(100.0 * x) / y); elseif (y <= 5.3e+16) tmp = 100.0; else tmp = Float64(x / Float64(y * 0.01)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.06e+51) tmp = (100.0 * x) / y; elseif (y <= 5.3e+16) tmp = 100.0; else tmp = x / (y * 0.01); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.06e+51], N[(N[(100.0 * x), $MachinePrecision] / y), $MachinePrecision], If[LessEqual[y, 5.3e+16], 100.0, N[(x / N[(y * 0.01), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.06 \cdot 10^{+51}:\\
\;\;\;\;\frac{100 \cdot x}{y}\\
\mathbf{elif}\;y \leq 5.3 \cdot 10^{+16}:\\
\;\;\;\;100\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y \cdot 0.01}\\
\end{array}
\end{array}
if y < -1.06000000000000004e51Initial program 99.8%
Taylor expanded in x around 0 83.8%
if -1.06000000000000004e51 < y < 5.3e16Initial program 98.9%
*-commutative98.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around inf 74.5%
if 5.3e16 < y Initial program 99.7%
*-commutative99.7%
associate-/l*99.7%
Simplified99.7%
Taylor expanded in x around 0 73.3%
associate-*r/73.3%
*-commutative73.3%
associate-*r/73.3%
Simplified73.3%
clear-num73.2%
un-div-inv73.3%
div-inv73.4%
metadata-eval73.4%
Applied egg-rr73.4%
Final simplification76.1%
(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}
Initial program 99.3%
*-commutative99.3%
associate-/l*99.7%
Simplified99.7%
Taylor expanded in x around inf 48.9%
(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 2024165
(FPCore (x y)
:name "Development.Shake.Progress:message from shake-0.15.5"
:precision binary64
:alt
(! :herbie-platform default (* (/ x 1) (/ 100 (+ x y))))
(/ (* x 100.0) (+ x y)))