
(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 (* 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.4%
*-commutative99.4%
associate-/l*99.8%
Simplified99.8%
(FPCore (x y) :precision binary64 (if (or (<= y -2.4e-31) (not (<= y 7e+21))) (* 100.0 (/ x y)) 100.0))
double code(double x, double y) {
double tmp;
if ((y <= -2.4e-31) || !(y <= 7e+21)) {
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 <= (-2.4d-31)) .or. (.not. (y <= 7d+21))) 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 <= -2.4e-31) || !(y <= 7e+21)) {
tmp = 100.0 * (x / y);
} else {
tmp = 100.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -2.4e-31) or not (y <= 7e+21): tmp = 100.0 * (x / y) else: tmp = 100.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= -2.4e-31) || !(y <= 7e+21)) 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 <= -2.4e-31) || ~((y <= 7e+21))) tmp = 100.0 * (x / y); else tmp = 100.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -2.4e-31], N[Not[LessEqual[y, 7e+21]], $MachinePrecision]], N[(100.0 * N[(x / y), $MachinePrecision]), $MachinePrecision], 100.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.4 \cdot 10^{-31} \lor \neg \left(y \leq 7 \cdot 10^{+21}\right):\\
\;\;\;\;100 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;100\\
\end{array}
\end{array}
if y < -2.4e-31 or 7e21 < y Initial program 99.1%
*-commutative99.1%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in x around 0 72.4%
if -2.4e-31 < y < 7e21Initial program 99.7%
*-commutative99.7%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around inf 76.3%
Final simplification74.3%
(FPCore (x y) :precision binary64 (if (<= y -3.2e-33) (/ (* 100.0 x) y) (if (<= y 7.8e+21) 100.0 (* 100.0 (/ x y)))))
double code(double x, double y) {
double tmp;
if (y <= -3.2e-33) {
tmp = (100.0 * x) / y;
} else if (y <= 7.8e+21) {
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.2d-33)) then
tmp = (100.0d0 * x) / y
else if (y <= 7.8d+21) 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.2e-33) {
tmp = (100.0 * x) / y;
} else if (y <= 7.8e+21) {
tmp = 100.0;
} else {
tmp = 100.0 * (x / y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3.2e-33: tmp = (100.0 * x) / y elif y <= 7.8e+21: tmp = 100.0 else: tmp = 100.0 * (x / y) return tmp
function code(x, y) tmp = 0.0 if (y <= -3.2e-33) tmp = Float64(Float64(100.0 * x) / y); elseif (y <= 7.8e+21) 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.2e-33) tmp = (100.0 * x) / y; elseif (y <= 7.8e+21) tmp = 100.0; else tmp = 100.0 * (x / y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3.2e-33], N[(N[(100.0 * x), $MachinePrecision] / y), $MachinePrecision], If[LessEqual[y, 7.8e+21], 100.0, N[(100.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.2 \cdot 10^{-33}:\\
\;\;\;\;\frac{100 \cdot x}{y}\\
\mathbf{elif}\;y \leq 7.8 \cdot 10^{+21}:\\
\;\;\;\;100\\
\mathbf{else}:\\
\;\;\;\;100 \cdot \frac{x}{y}\\
\end{array}
\end{array}
if y < -3.19999999999999977e-33Initial program 98.6%
Taylor expanded in x around 0 71.0%
if -3.19999999999999977e-33 < y < 7.8e21Initial program 99.7%
*-commutative99.7%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around inf 76.3%
if 7.8e21 < y Initial program 99.8%
*-commutative99.8%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in x around 0 75.0%
Final simplification74.3%
(FPCore (x y) :precision binary64 (if (<= y -3.9e-31) (* x (/ 100.0 y)) (if (<= y 9.5e+21) 100.0 (* 100.0 (/ x y)))))
double code(double x, double y) {
double tmp;
if (y <= -3.9e-31) {
tmp = x * (100.0 / y);
} else if (y <= 9.5e+21) {
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.9d-31)) then
tmp = x * (100.0d0 / y)
else if (y <= 9.5d+21) 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.9e-31) {
tmp = x * (100.0 / y);
} else if (y <= 9.5e+21) {
tmp = 100.0;
} else {
tmp = 100.0 * (x / y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3.9e-31: tmp = x * (100.0 / y) elif y <= 9.5e+21: tmp = 100.0 else: tmp = 100.0 * (x / y) return tmp
function code(x, y) tmp = 0.0 if (y <= -3.9e-31) tmp = Float64(x * Float64(100.0 / y)); elseif (y <= 9.5e+21) 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.9e-31) tmp = x * (100.0 / y); elseif (y <= 9.5e+21) tmp = 100.0; else tmp = 100.0 * (x / y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3.9e-31], N[(x * N[(100.0 / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 9.5e+21], 100.0, N[(100.0 * N[(x / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.9 \cdot 10^{-31}:\\
\;\;\;\;x \cdot \frac{100}{y}\\
\mathbf{elif}\;y \leq 9.5 \cdot 10^{+21}:\\
\;\;\;\;100\\
\mathbf{else}:\\
\;\;\;\;100 \cdot \frac{x}{y}\\
\end{array}
\end{array}
if y < -3.9000000000000001e-31Initial program 98.6%
*-commutative98.6%
associate-/l*99.7%
Simplified99.7%
Taylor expanded in x around 0 70.9%
associate-*r/71.0%
*-commutative71.0%
associate-*r/70.9%
Simplified70.9%
if -3.9000000000000001e-31 < y < 9.500000000000001e21Initial program 99.7%
*-commutative99.7%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around inf 76.3%
if 9.500000000000001e21 < y Initial program 99.8%
*-commutative99.8%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in x around 0 75.0%
(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%
Simplified99.8%
Taylor expanded in x around inf 51.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 2024139
(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)))