
(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 5 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}
Initial program 99.7%
*-commutative99.7%
associate-/l*99.1%
Simplified99.1%
associate-/r/99.7%
+-commutative99.7%
Applied egg-rr99.7%
Final simplification99.7%
(FPCore (x y) :precision binary64 (if (or (<= y -410000000.0) (not (<= y 3.2e+130))) (* 100.0 (/ x y)) 100.0))
double code(double x, double y) {
double tmp;
if ((y <= -410000000.0) || !(y <= 3.2e+130)) {
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 <= (-410000000.0d0)) .or. (.not. (y <= 3.2d+130))) 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 <= -410000000.0) || !(y <= 3.2e+130)) {
tmp = 100.0 * (x / y);
} else {
tmp = 100.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -410000000.0) or not (y <= 3.2e+130): tmp = 100.0 * (x / y) else: tmp = 100.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= -410000000.0) || !(y <= 3.2e+130)) 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 <= -410000000.0) || ~((y <= 3.2e+130))) tmp = 100.0 * (x / y); else tmp = 100.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -410000000.0], N[Not[LessEqual[y, 3.2e+130]], $MachinePrecision]], N[(100.0 * N[(x / y), $MachinePrecision]), $MachinePrecision], 100.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -410000000 \lor \neg \left(y \leq 3.2 \cdot 10^{+130}\right):\\
\;\;\;\;100 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;100\\
\end{array}
\end{array}
if y < -4.1e8 or 3.2e130 < y Initial program 99.7%
*-commutative99.7%
associate-/l*98.1%
+-commutative98.1%
remove-double-neg98.1%
unsub-neg98.1%
div-sub98.1%
distribute-frac-neg98.1%
*-inverses98.1%
metadata-eval98.1%
Simplified98.1%
Taylor expanded in y around inf 80.8%
if -4.1e8 < y < 3.2e130Initial program 99.7%
*-commutative99.7%
associate-/l*99.9%
+-commutative99.9%
remove-double-neg99.9%
unsub-neg99.9%
div-sub99.8%
distribute-frac-neg99.8%
*-inverses99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in y around 0 74.8%
Final simplification77.4%
(FPCore (x y) :precision binary64 (if (or (<= y -32000000.0) (not (<= y 4.1e+95))) (* x (/ 100.0 y)) 100.0))
double code(double x, double y) {
double tmp;
if ((y <= -32000000.0) || !(y <= 4.1e+95)) {
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 <= (-32000000.0d0)) .or. (.not. (y <= 4.1d+95))) 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 <= -32000000.0) || !(y <= 4.1e+95)) {
tmp = x * (100.0 / y);
} else {
tmp = 100.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -32000000.0) or not (y <= 4.1e+95): tmp = x * (100.0 / y) else: tmp = 100.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= -32000000.0) || !(y <= 4.1e+95)) 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 <= -32000000.0) || ~((y <= 4.1e+95))) tmp = x * (100.0 / y); else tmp = 100.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -32000000.0], N[Not[LessEqual[y, 4.1e+95]], $MachinePrecision]], N[(x * N[(100.0 / y), $MachinePrecision]), $MachinePrecision], 100.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -32000000 \lor \neg \left(y \leq 4.1 \cdot 10^{+95}\right):\\
\;\;\;\;x \cdot \frac{100}{y}\\
\mathbf{else}:\\
\;\;\;\;100\\
\end{array}
\end{array}
if y < -3.2e7 or 4.09999999999999986e95 < y Initial program 99.7%
*-commutative99.7%
associate-/l*98.2%
Simplified98.2%
associate-/r/99.7%
+-commutative99.7%
Applied egg-rr99.7%
Taylor expanded in y around inf 79.4%
if -3.2e7 < y < 4.09999999999999986e95Initial program 99.7%
*-commutative99.7%
associate-/l*99.9%
+-commutative99.9%
remove-double-neg99.9%
unsub-neg99.9%
div-sub99.8%
distribute-frac-neg99.8%
*-inverses99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in y around 0 75.8%
Final simplification77.4%
(FPCore (x y) :precision binary64 (if (<= y -1200000.0) (/ (* 100.0 x) y) (if (<= y 4.8e+95) 100.0 (* x (/ 100.0 y)))))
double code(double x, double y) {
double tmp;
if (y <= -1200000.0) {
tmp = (100.0 * x) / y;
} else if (y <= 4.8e+95) {
tmp = 100.0;
} else {
tmp = x * (100.0 / y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-1200000.0d0)) then
tmp = (100.0d0 * x) / y
else if (y <= 4.8d+95) then
tmp = 100.0d0
else
tmp = x * (100.0d0 / y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1200000.0) {
tmp = (100.0 * x) / y;
} else if (y <= 4.8e+95) {
tmp = 100.0;
} else {
tmp = x * (100.0 / y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1200000.0: tmp = (100.0 * x) / y elif y <= 4.8e+95: tmp = 100.0 else: tmp = x * (100.0 / y) return tmp
function code(x, y) tmp = 0.0 if (y <= -1200000.0) tmp = Float64(Float64(100.0 * x) / y); elseif (y <= 4.8e+95) tmp = 100.0; else tmp = Float64(x * Float64(100.0 / y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1200000.0) tmp = (100.0 * x) / y; elseif (y <= 4.8e+95) tmp = 100.0; else tmp = x * (100.0 / y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1200000.0], N[(N[(100.0 * x), $MachinePrecision] / y), $MachinePrecision], If[LessEqual[y, 4.8e+95], 100.0, N[(x * N[(100.0 / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1200000:\\
\;\;\;\;\frac{100 \cdot x}{y}\\
\mathbf{elif}\;y \leq 4.8 \cdot 10^{+95}:\\
\;\;\;\;100\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{100}{y}\\
\end{array}
\end{array}
if y < -1.2e6Initial program 99.8%
*-commutative99.8%
associate-/l*98.5%
+-commutative98.5%
remove-double-neg98.5%
unsub-neg98.5%
div-sub98.5%
distribute-frac-neg98.5%
*-inverses98.5%
metadata-eval98.5%
Simplified98.5%
Taylor expanded in y around inf 72.9%
associate-*r/73.0%
Applied egg-rr73.0%
if -1.2e6 < y < 4.8000000000000001e95Initial program 99.7%
*-commutative99.7%
associate-/l*99.9%
+-commutative99.9%
remove-double-neg99.9%
unsub-neg99.9%
div-sub99.8%
distribute-frac-neg99.8%
*-inverses99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in y around 0 75.8%
if 4.8000000000000001e95 < y Initial program 99.7%
*-commutative99.7%
associate-/l*97.9%
Simplified97.9%
associate-/r/99.8%
+-commutative99.8%
Applied egg-rr99.8%
Taylor expanded in y around inf 86.9%
Final simplification77.4%
(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.7%
*-commutative99.7%
associate-/l*99.1%
+-commutative99.1%
remove-double-neg99.1%
unsub-neg99.1%
div-sub99.1%
distribute-frac-neg99.1%
*-inverses99.1%
metadata-eval99.1%
Simplified99.1%
Taylor expanded in y around 0 52.1%
Final simplification52.1%
(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 2024024
(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)))