
(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 (* (+ x y) 0.01)))
double code(double x, double y) {
return x / ((x + y) * 0.01);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x / ((x + y) * 0.01d0)
end function
public static double code(double x, double y) {
return x / ((x + y) * 0.01);
}
def code(x, y): return x / ((x + y) * 0.01)
function code(x, y) return Float64(x / Float64(Float64(x + y) * 0.01)) end
function tmp = code(x, y) tmp = x / ((x + y) * 0.01); end
code[x_, y_] := N[(x / N[(N[(x + y), $MachinePrecision] * 0.01), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{\left(x + y\right) \cdot 0.01}
\end{array}
Initial program 99.4%
*-commutative99.4%
associate-/l*98.6%
Simplified98.6%
associate-/l*99.4%
*-commutative99.4%
expm1-log1p-u98.2%
expm1-udef64.1%
associate-/l*64.5%
div-inv64.5%
metadata-eval64.5%
Applied egg-rr64.5%
expm1-def98.6%
expm1-log1p99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (x y) :precision binary64 (if (or (<= y -3.5e+15) (not (<= y 3.8e+86))) (* x (/ 100.0 y)) 100.0))
double code(double x, double y) {
double tmp;
if ((y <= -3.5e+15) || !(y <= 3.8e+86)) {
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 <= (-3.5d+15)) .or. (.not. (y <= 3.8d+86))) 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 <= -3.5e+15) || !(y <= 3.8e+86)) {
tmp = x * (100.0 / y);
} else {
tmp = 100.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -3.5e+15) or not (y <= 3.8e+86): tmp = x * (100.0 / y) else: tmp = 100.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= -3.5e+15) || !(y <= 3.8e+86)) 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 <= -3.5e+15) || ~((y <= 3.8e+86))) tmp = x * (100.0 / y); else tmp = 100.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -3.5e+15], N[Not[LessEqual[y, 3.8e+86]], $MachinePrecision]], N[(x * N[(100.0 / y), $MachinePrecision]), $MachinePrecision], 100.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.5 \cdot 10^{+15} \lor \neg \left(y \leq 3.8 \cdot 10^{+86}\right):\\
\;\;\;\;x \cdot \frac{100}{y}\\
\mathbf{else}:\\
\;\;\;\;100\\
\end{array}
\end{array}
if y < -3.5e15 or 3.79999999999999978e86 < y Initial program 99.7%
*-commutative99.7%
associate-/l*97.7%
Simplified97.7%
Taylor expanded in x around 0 84.1%
associate-*r/84.4%
associate-/l*82.3%
associate-/r/84.4%
Simplified84.4%
if -3.5e15 < y < 3.79999999999999978e86Initial program 99.1%
*-commutative99.1%
associate-/l*99.3%
Simplified99.3%
Taylor expanded in x around inf 77.6%
Final simplification80.6%
(FPCore (x y) :precision binary64 (if (<= y -2.8e+15) (/ x (/ y 100.0)) (if (<= y 5.4e+85) 100.0 (* x (/ 100.0 y)))))
double code(double x, double y) {
double tmp;
if (y <= -2.8e+15) {
tmp = x / (y / 100.0);
} else if (y <= 5.4e+85) {
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 <= (-2.8d+15)) then
tmp = x / (y / 100.0d0)
else if (y <= 5.4d+85) 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 <= -2.8e+15) {
tmp = x / (y / 100.0);
} else if (y <= 5.4e+85) {
tmp = 100.0;
} else {
tmp = x * (100.0 / y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.8e+15: tmp = x / (y / 100.0) elif y <= 5.4e+85: tmp = 100.0 else: tmp = x * (100.0 / y) return tmp
function code(x, y) tmp = 0.0 if (y <= -2.8e+15) tmp = Float64(x / Float64(y / 100.0)); elseif (y <= 5.4e+85) 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 <= -2.8e+15) tmp = x / (y / 100.0); elseif (y <= 5.4e+85) tmp = 100.0; else tmp = x * (100.0 / y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.8e+15], N[(x / N[(y / 100.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 5.4e+85], 100.0, N[(x * N[(100.0 / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.8 \cdot 10^{+15}:\\
\;\;\;\;\frac{x}{\frac{y}{100}}\\
\mathbf{elif}\;y \leq 5.4 \cdot 10^{+85}:\\
\;\;\;\;100\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{100}{y}\\
\end{array}
\end{array}
if y < -2.8e15Initial program 99.7%
*-commutative99.7%
associate-/l*98.7%
Simplified98.7%
Taylor expanded in x around 0 78.1%
*-commutative78.1%
associate-/r/78.3%
Simplified78.3%
if -2.8e15 < y < 5.39999999999999966e85Initial program 99.1%
*-commutative99.1%
associate-/l*99.3%
Simplified99.3%
Taylor expanded in x around inf 77.6%
if 5.39999999999999966e85 < y Initial program 99.8%
*-commutative99.8%
associate-/l*96.2%
Simplified96.2%
Taylor expanded in x around 0 92.6%
associate-*r/93.1%
associate-/l*89.6%
associate-/r/93.2%
Simplified93.2%
Final simplification80.6%
(FPCore (x y) :precision binary64 (/ 100.0 (/ (+ x y) x)))
double code(double x, double y) {
return 100.0 / ((x + y) / x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 100.0d0 / ((x + y) / x)
end function
public static double code(double x, double y) {
return 100.0 / ((x + y) / x);
}
def code(x, y): return 100.0 / ((x + y) / x)
function code(x, y) return Float64(100.0 / Float64(Float64(x + y) / x)) end
function tmp = code(x, y) tmp = 100.0 / ((x + y) / x); end
code[x_, y_] := N[(100.0 / N[(N[(x + y), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{100}{\frac{x + y}{x}}
\end{array}
Initial program 99.4%
*-commutative99.4%
associate-/l*98.6%
Simplified98.6%
Final simplification98.6%
(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*98.6%
Simplified98.6%
Taylor expanded in x around inf 50.8%
Final simplification50.8%
(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 2024036
(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)))