
(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 4 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 (- (/ y x) -1.0)))
double code(double x, double y) {
return 100.0 / ((y / x) - -1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 100.0d0 / ((y / x) - (-1.0d0))
end function
public static double code(double x, double y) {
return 100.0 / ((y / x) - -1.0);
}
def code(x, y): return 100.0 / ((y / x) - -1.0)
function code(x, y) return Float64(100.0 / Float64(Float64(y / x) - -1.0)) end
function tmp = code(x, y) tmp = 100.0 / ((y / x) - -1.0); end
code[x_, y_] := N[(100.0 / N[(N[(y / x), $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{100}{\frac{y}{x} - -1}
\end{array}
Initial program 99.4%
*-commutative99.4%
associate-/l*99.8%
+-commutative99.8%
remove-double-neg99.8%
unsub-neg99.8%
div-sub99.8%
distribute-frac-neg99.8%
*-inverses99.8%
metadata-eval99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y) :precision binary64 (if (or (<= y -1.4e-16) (not (<= y 1.52e+38))) (* 100.0 (/ x y)) 100.0))
double code(double x, double y) {
double tmp;
if ((y <= -1.4e-16) || !(y <= 1.52e+38)) {
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.4d-16)) .or. (.not. (y <= 1.52d+38))) 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.4e-16) || !(y <= 1.52e+38)) {
tmp = 100.0 * (x / y);
} else {
tmp = 100.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.4e-16) or not (y <= 1.52e+38): tmp = 100.0 * (x / y) else: tmp = 100.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.4e-16) || !(y <= 1.52e+38)) 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.4e-16) || ~((y <= 1.52e+38))) tmp = 100.0 * (x / y); else tmp = 100.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.4e-16], N[Not[LessEqual[y, 1.52e+38]], $MachinePrecision]], N[(100.0 * N[(x / y), $MachinePrecision]), $MachinePrecision], 100.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.4 \cdot 10^{-16} \lor \neg \left(y \leq 1.52 \cdot 10^{+38}\right):\\
\;\;\;\;100 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;100\\
\end{array}
\end{array}
if y < -1.4000000000000001e-16 or 1.51999999999999996e38 < y Initial program 99.8%
*-commutative99.8%
associate-/l*99.8%
+-commutative99.8%
remove-double-neg99.8%
unsub-neg99.8%
div-sub99.8%
distribute-frac-neg99.8%
*-inverses99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in y around inf 76.5%
if -1.4000000000000001e-16 < y < 1.51999999999999996e38Initial program 99.0%
*-commutative99.0%
associate-/l*99.9%
+-commutative99.9%
remove-double-neg99.9%
unsub-neg99.9%
div-sub99.9%
distribute-frac-neg99.9%
*-inverses99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in y around 0 76.4%
Final simplification76.4%
(FPCore (x y) :precision binary64 (if (<= y -3.4e-16) (/ x (/ y 100.0)) (if (<= y 2.75e+37) 100.0 (* 100.0 (/ x y)))))
double code(double x, double y) {
double tmp;
if (y <= -3.4e-16) {
tmp = x / (y / 100.0);
} else if (y <= 2.75e+37) {
tmp = 100.0;
} else {
tmp = 100.0 * (x / y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-3.4d-16)) then
tmp = x / (y / 100.0d0)
else if (y <= 2.75d+37) then
tmp = 100.0d0
else
tmp = 100.0d0 * (x / y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -3.4e-16) {
tmp = x / (y / 100.0);
} else if (y <= 2.75e+37) {
tmp = 100.0;
} else {
tmp = 100.0 * (x / y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3.4e-16: tmp = x / (y / 100.0) elif y <= 2.75e+37: tmp = 100.0 else: tmp = 100.0 * (x / y) return tmp
function code(x, y) tmp = 0.0 if (y <= -3.4e-16) tmp = Float64(x / Float64(y / 100.0)); elseif (y <= 2.75e+37) tmp = 100.0; else tmp = Float64(100.0 * Float64(x / y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -3.4e-16) tmp = x / (y / 100.0); elseif (y <= 2.75e+37) tmp = 100.0; else tmp = 100.0 * (x / y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3.4e-16], N[(x / N[(y / 100.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.75e+37], 100.0, N[(100.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.4 \cdot 10^{-16}:\\
\;\;\;\;\frac{x}{\frac{y}{100}}\\
\mathbf{elif}\;y \leq 2.75 \cdot 10^{+37}:\\
\;\;\;\;100\\
\mathbf{else}:\\
\;\;\;\;100 \cdot \frac{x}{y}\\
\end{array}
\end{array}
if y < -3.4e-16Initial program 99.9%
*-commutative99.9%
associate-/l*99.7%
+-commutative99.7%
remove-double-neg99.7%
unsub-neg99.7%
div-sub99.7%
distribute-frac-neg99.7%
*-inverses99.7%
metadata-eval99.7%
Simplified99.7%
Taylor expanded in y around inf 77.2%
associate-*r/77.3%
*-commutative77.3%
associate-/l*77.3%
Applied egg-rr77.3%
if -3.4e-16 < y < 2.75000000000000008e37Initial program 99.0%
*-commutative99.0%
associate-/l*99.9%
+-commutative99.9%
remove-double-neg99.9%
unsub-neg99.9%
div-sub99.9%
distribute-frac-neg99.9%
*-inverses99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in y around 0 76.4%
if 2.75000000000000008e37 < y Initial program 99.7%
*-commutative99.7%
associate-/l*99.8%
+-commutative99.8%
remove-double-neg99.8%
unsub-neg99.8%
div-sub99.8%
distribute-frac-neg99.8%
*-inverses99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in y around inf 75.7%
Final simplification76.5%
(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.4%
*-commutative99.4%
associate-/l*99.8%
+-commutative99.8%
remove-double-neg99.8%
unsub-neg99.8%
div-sub99.8%
distribute-frac-neg99.8%
*-inverses99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in y around 0 50.5%
Final simplification50.5%
(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 2024019
(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)))