
(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 (+ 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(x * Float64(100.0 / Float64(x + y))) end
function tmp = code(x, y) tmp = x * (100.0 / (x + y)); end
code[x_, y_] := N[(x * N[(100.0 / N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \frac{100}{x + y}
\end{array}
Initial program 99.7%
associate-/l*99.8%
*-commutative99.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x y)
:precision binary64
(if (<= x -3.2e+64)
100.0
(if (or (<= x -1.05e+36) (and (not (<= x -16500000000.0)) (<= x 5.8e+51)))
(* 100.0 (/ x y))
100.0)))
double code(double x, double y) {
double tmp;
if (x <= -3.2e+64) {
tmp = 100.0;
} else if ((x <= -1.05e+36) || (!(x <= -16500000000.0) && (x <= 5.8e+51))) {
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 (x <= (-3.2d+64)) then
tmp = 100.0d0
else if ((x <= (-1.05d+36)) .or. (.not. (x <= (-16500000000.0d0))) .and. (x <= 5.8d+51)) 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 (x <= -3.2e+64) {
tmp = 100.0;
} else if ((x <= -1.05e+36) || (!(x <= -16500000000.0) && (x <= 5.8e+51))) {
tmp = 100.0 * (x / y);
} else {
tmp = 100.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3.2e+64: tmp = 100.0 elif (x <= -1.05e+36) or (not (x <= -16500000000.0) and (x <= 5.8e+51)): tmp = 100.0 * (x / y) else: tmp = 100.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -3.2e+64) tmp = 100.0; elseif ((x <= -1.05e+36) || (!(x <= -16500000000.0) && (x <= 5.8e+51))) 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 (x <= -3.2e+64) tmp = 100.0; elseif ((x <= -1.05e+36) || (~((x <= -16500000000.0)) && (x <= 5.8e+51))) tmp = 100.0 * (x / y); else tmp = 100.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3.2e+64], 100.0, If[Or[LessEqual[x, -1.05e+36], And[N[Not[LessEqual[x, -16500000000.0]], $MachinePrecision], LessEqual[x, 5.8e+51]]], N[(100.0 * N[(x / y), $MachinePrecision]), $MachinePrecision], 100.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.2 \cdot 10^{+64}:\\
\;\;\;\;100\\
\mathbf{elif}\;x \leq -1.05 \cdot 10^{+36} \lor \neg \left(x \leq -16500000000\right) \land x \leq 5.8 \cdot 10^{+51}:\\
\;\;\;\;100 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;100\\
\end{array}
\end{array}
if x < -3.20000000000000019e64 or -1.05000000000000002e36 < x < -1.65e10 or 5.7999999999999997e51 < x Initial program 99.8%
*-commutative99.8%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around inf 86.7%
if -3.20000000000000019e64 < x < -1.05000000000000002e36 or -1.65e10 < x < 5.7999999999999997e51Initial program 99.6%
*-commutative99.6%
associate-/l*99.6%
Simplified99.6%
Taylor expanded in x around 0 80.2%
Final simplification83.1%
(FPCore (x y)
:precision binary64
(if (<= x -5e+64)
100.0
(if (<= x -2.95e+39)
(* 100.0 (/ x y))
(if (<= x -15500000000.0)
100.0
(if (<= x 2.2e+54) (* x (/ 100.0 y)) 100.0)))))
double code(double x, double y) {
double tmp;
if (x <= -5e+64) {
tmp = 100.0;
} else if (x <= -2.95e+39) {
tmp = 100.0 * (x / y);
} else if (x <= -15500000000.0) {
tmp = 100.0;
} else if (x <= 2.2e+54) {
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 (x <= (-5d+64)) then
tmp = 100.0d0
else if (x <= (-2.95d+39)) then
tmp = 100.0d0 * (x / y)
else if (x <= (-15500000000.0d0)) then
tmp = 100.0d0
else if (x <= 2.2d+54) 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 (x <= -5e+64) {
tmp = 100.0;
} else if (x <= -2.95e+39) {
tmp = 100.0 * (x / y);
} else if (x <= -15500000000.0) {
tmp = 100.0;
} else if (x <= 2.2e+54) {
tmp = x * (100.0 / y);
} else {
tmp = 100.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -5e+64: tmp = 100.0 elif x <= -2.95e+39: tmp = 100.0 * (x / y) elif x <= -15500000000.0: tmp = 100.0 elif x <= 2.2e+54: tmp = x * (100.0 / y) else: tmp = 100.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -5e+64) tmp = 100.0; elseif (x <= -2.95e+39) tmp = Float64(100.0 * Float64(x / y)); elseif (x <= -15500000000.0) tmp = 100.0; elseif (x <= 2.2e+54) 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 (x <= -5e+64) tmp = 100.0; elseif (x <= -2.95e+39) tmp = 100.0 * (x / y); elseif (x <= -15500000000.0) tmp = 100.0; elseif (x <= 2.2e+54) tmp = x * (100.0 / y); else tmp = 100.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -5e+64], 100.0, If[LessEqual[x, -2.95e+39], N[(100.0 * N[(x / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -15500000000.0], 100.0, If[LessEqual[x, 2.2e+54], N[(x * N[(100.0 / y), $MachinePrecision]), $MachinePrecision], 100.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{+64}:\\
\;\;\;\;100\\
\mathbf{elif}\;x \leq -2.95 \cdot 10^{+39}:\\
\;\;\;\;100 \cdot \frac{x}{y}\\
\mathbf{elif}\;x \leq -15500000000:\\
\;\;\;\;100\\
\mathbf{elif}\;x \leq 2.2 \cdot 10^{+54}:\\
\;\;\;\;x \cdot \frac{100}{y}\\
\mathbf{else}:\\
\;\;\;\;100\\
\end{array}
\end{array}
if x < -5e64 or -2.94999999999999983e39 < x < -1.55e10 or 2.1999999999999999e54 < x Initial program 99.8%
*-commutative99.8%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around inf 86.7%
if -5e64 < x < -2.94999999999999983e39Initial program 99.6%
*-commutative99.6%
associate-/l*99.6%
Simplified99.6%
Taylor expanded in x around 0 86.3%
if -1.55e10 < x < 2.1999999999999999e54Initial program 99.6%
associate-/l*99.7%
*-commutative99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 80.1%
Final simplification83.2%
(FPCore (x y)
:precision binary64
(if (<= x -1.6e+65)
100.0
(if (<= x -2e+32)
(/ 100.0 (/ y x))
(if (<= x -880000000.0)
100.0
(if (<= x 1.5e+51) (* x (/ 100.0 y)) 100.0)))))
double code(double x, double y) {
double tmp;
if (x <= -1.6e+65) {
tmp = 100.0;
} else if (x <= -2e+32) {
tmp = 100.0 / (y / x);
} else if (x <= -880000000.0) {
tmp = 100.0;
} else if (x <= 1.5e+51) {
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 (x <= (-1.6d+65)) then
tmp = 100.0d0
else if (x <= (-2d+32)) then
tmp = 100.0d0 / (y / x)
else if (x <= (-880000000.0d0)) then
tmp = 100.0d0
else if (x <= 1.5d+51) 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 (x <= -1.6e+65) {
tmp = 100.0;
} else if (x <= -2e+32) {
tmp = 100.0 / (y / x);
} else if (x <= -880000000.0) {
tmp = 100.0;
} else if (x <= 1.5e+51) {
tmp = x * (100.0 / y);
} else {
tmp = 100.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.6e+65: tmp = 100.0 elif x <= -2e+32: tmp = 100.0 / (y / x) elif x <= -880000000.0: tmp = 100.0 elif x <= 1.5e+51: tmp = x * (100.0 / y) else: tmp = 100.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -1.6e+65) tmp = 100.0; elseif (x <= -2e+32) tmp = Float64(100.0 / Float64(y / x)); elseif (x <= -880000000.0) tmp = 100.0; elseif (x <= 1.5e+51) 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 (x <= -1.6e+65) tmp = 100.0; elseif (x <= -2e+32) tmp = 100.0 / (y / x); elseif (x <= -880000000.0) tmp = 100.0; elseif (x <= 1.5e+51) tmp = x * (100.0 / y); else tmp = 100.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.6e+65], 100.0, If[LessEqual[x, -2e+32], N[(100.0 / N[(y / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -880000000.0], 100.0, If[LessEqual[x, 1.5e+51], N[(x * N[(100.0 / y), $MachinePrecision]), $MachinePrecision], 100.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.6 \cdot 10^{+65}:\\
\;\;\;\;100\\
\mathbf{elif}\;x \leq -2 \cdot 10^{+32}:\\
\;\;\;\;\frac{100}{\frac{y}{x}}\\
\mathbf{elif}\;x \leq -880000000:\\
\;\;\;\;100\\
\mathbf{elif}\;x \leq 1.5 \cdot 10^{+51}:\\
\;\;\;\;x \cdot \frac{100}{y}\\
\mathbf{else}:\\
\;\;\;\;100\\
\end{array}
\end{array}
if x < -1.60000000000000003e65 or -2.00000000000000011e32 < x < -8.8e8 or 1.5e51 < x Initial program 99.8%
*-commutative99.8%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around inf 86.7%
if -1.60000000000000003e65 < x < -2.00000000000000011e32Initial program 99.6%
associate-/l*99.6%
*-commutative99.6%
Applied egg-rr99.6%
Taylor expanded in x around 0 86.3%
div-inv86.3%
associate-*l*85.9%
associate-/r/86.3%
un-div-inv86.7%
Applied egg-rr86.7%
if -8.8e8 < x < 1.5e51Initial program 99.6%
associate-/l*99.7%
*-commutative99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 80.1%
Final simplification83.2%
(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.7%
*-commutative99.7%
associate-/l*99.7%
Simplified99.7%
Final simplification99.7%
(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.7%
Simplified99.7%
Taylor expanded in x around inf 50.6%
Final simplification50.6%
(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 2024075
(FPCore (x y)
:name "Development.Shake.Progress:message from shake-0.15.5"
:precision binary64
:alt
(* (/ x 1.0) (/ 100.0 (+ x y)))
(/ (* x 100.0) (+ x y)))