
(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-*r/99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (x y)
:precision binary64
(if (or (<= y -3.7e-63)
(not (or (<= y 1.6e-160) (and (not (<= y 6.5e-87)) (<= y 2.25e+78)))))
(* 100.0 (/ x y))
100.0))
double code(double x, double y) {
double tmp;
if ((y <= -3.7e-63) || !((y <= 1.6e-160) || (!(y <= 6.5e-87) && (y <= 2.25e+78)))) {
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 <= (-3.7d-63)) .or. (.not. (y <= 1.6d-160) .or. (.not. (y <= 6.5d-87)) .and. (y <= 2.25d+78))) 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 <= -3.7e-63) || !((y <= 1.6e-160) || (!(y <= 6.5e-87) && (y <= 2.25e+78)))) {
tmp = 100.0 * (x / y);
} else {
tmp = 100.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -3.7e-63) or not ((y <= 1.6e-160) or (not (y <= 6.5e-87) and (y <= 2.25e+78))): tmp = 100.0 * (x / y) else: tmp = 100.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= -3.7e-63) || !((y <= 1.6e-160) || (!(y <= 6.5e-87) && (y <= 2.25e+78)))) 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 <= -3.7e-63) || ~(((y <= 1.6e-160) || (~((y <= 6.5e-87)) && (y <= 2.25e+78))))) tmp = 100.0 * (x / y); else tmp = 100.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -3.7e-63], N[Not[Or[LessEqual[y, 1.6e-160], And[N[Not[LessEqual[y, 6.5e-87]], $MachinePrecision], LessEqual[y, 2.25e+78]]]], $MachinePrecision]], N[(100.0 * N[(x / y), $MachinePrecision]), $MachinePrecision], 100.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.7 \cdot 10^{-63} \lor \neg \left(y \leq 1.6 \cdot 10^{-160} \lor \neg \left(y \leq 6.5 \cdot 10^{-87}\right) \land y \leq 2.25 \cdot 10^{+78}\right):\\
\;\;\;\;100 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;100\\
\end{array}
\end{array}
if y < -3.70000000000000012e-63 or 1.60000000000000004e-160 < y < 6.5000000000000003e-87 or 2.25e78 < y Initial program 99.8%
associate-*r/99.7%
Simplified99.7%
Taylor expanded in x around 0 79.3%
if -3.70000000000000012e-63 < y < 1.60000000000000004e-160 or 6.5000000000000003e-87 < y < 2.25e78Initial program 99.7%
associate-*r/99.8%
Simplified99.8%
Taylor expanded in x around inf 78.6%
Final simplification79.0%
(FPCore (x y)
:precision binary64
(if (or (<= y -4e-63)
(not
(or (<= y 1.45e-160) (and (not (<= y 7.6e-88)) (<= y 2.25e+78)))))
(* x (/ 100.0 y))
100.0))
double code(double x, double y) {
double tmp;
if ((y <= -4e-63) || !((y <= 1.45e-160) || (!(y <= 7.6e-88) && (y <= 2.25e+78)))) {
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 <= (-4d-63)) .or. (.not. (y <= 1.45d-160) .or. (.not. (y <= 7.6d-88)) .and. (y <= 2.25d+78))) 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 <= -4e-63) || !((y <= 1.45e-160) || (!(y <= 7.6e-88) && (y <= 2.25e+78)))) {
tmp = x * (100.0 / y);
} else {
tmp = 100.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -4e-63) or not ((y <= 1.45e-160) or (not (y <= 7.6e-88) and (y <= 2.25e+78))): tmp = x * (100.0 / y) else: tmp = 100.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= -4e-63) || !((y <= 1.45e-160) || (!(y <= 7.6e-88) && (y <= 2.25e+78)))) 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 <= -4e-63) || ~(((y <= 1.45e-160) || (~((y <= 7.6e-88)) && (y <= 2.25e+78))))) tmp = x * (100.0 / y); else tmp = 100.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -4e-63], N[Not[Or[LessEqual[y, 1.45e-160], And[N[Not[LessEqual[y, 7.6e-88]], $MachinePrecision], LessEqual[y, 2.25e+78]]]], $MachinePrecision]], N[(x * N[(100.0 / y), $MachinePrecision]), $MachinePrecision], 100.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{-63} \lor \neg \left(y \leq 1.45 \cdot 10^{-160} \lor \neg \left(y \leq 7.6 \cdot 10^{-88}\right) \land y \leq 2.25 \cdot 10^{+78}\right):\\
\;\;\;\;x \cdot \frac{100}{y}\\
\mathbf{else}:\\
\;\;\;\;100\\
\end{array}
\end{array}
if y < -4.00000000000000027e-63 or 1.45e-160 < y < 7.60000000000000022e-88 or 2.25e78 < y Initial program 99.8%
associate-*r/99.7%
Simplified99.7%
Taylor expanded in x around 0 79.4%
if -4.00000000000000027e-63 < y < 1.45e-160 or 7.60000000000000022e-88 < y < 2.25e78Initial program 99.7%
associate-*r/99.8%
Simplified99.8%
Taylor expanded in x around inf 78.6%
Final simplification79.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* x (/ 100.0 y))))
(if (<= y -3.3e-63)
t_0
(if (<= y 1.6e-160)
100.0
(if (<= y 7.6e-88) t_0 (if (<= y 5.8e+78) 100.0 (/ x (* y 0.01))))))))
double code(double x, double y) {
double t_0 = x * (100.0 / y);
double tmp;
if (y <= -3.3e-63) {
tmp = t_0;
} else if (y <= 1.6e-160) {
tmp = 100.0;
} else if (y <= 7.6e-88) {
tmp = t_0;
} else if (y <= 5.8e+78) {
tmp = 100.0;
} else {
tmp = x / (y * 0.01);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = x * (100.0d0 / y)
if (y <= (-3.3d-63)) then
tmp = t_0
else if (y <= 1.6d-160) then
tmp = 100.0d0
else if (y <= 7.6d-88) then
tmp = t_0
else if (y <= 5.8d+78) then
tmp = 100.0d0
else
tmp = x / (y * 0.01d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x * (100.0 / y);
double tmp;
if (y <= -3.3e-63) {
tmp = t_0;
} else if (y <= 1.6e-160) {
tmp = 100.0;
} else if (y <= 7.6e-88) {
tmp = t_0;
} else if (y <= 5.8e+78) {
tmp = 100.0;
} else {
tmp = x / (y * 0.01);
}
return tmp;
}
def code(x, y): t_0 = x * (100.0 / y) tmp = 0 if y <= -3.3e-63: tmp = t_0 elif y <= 1.6e-160: tmp = 100.0 elif y <= 7.6e-88: tmp = t_0 elif y <= 5.8e+78: tmp = 100.0 else: tmp = x / (y * 0.01) return tmp
function code(x, y) t_0 = Float64(x * Float64(100.0 / y)) tmp = 0.0 if (y <= -3.3e-63) tmp = t_0; elseif (y <= 1.6e-160) tmp = 100.0; elseif (y <= 7.6e-88) tmp = t_0; elseif (y <= 5.8e+78) tmp = 100.0; else tmp = Float64(x / Float64(y * 0.01)); end return tmp end
function tmp_2 = code(x, y) t_0 = x * (100.0 / y); tmp = 0.0; if (y <= -3.3e-63) tmp = t_0; elseif (y <= 1.6e-160) tmp = 100.0; elseif (y <= 7.6e-88) tmp = t_0; elseif (y <= 5.8e+78) tmp = 100.0; else tmp = x / (y * 0.01); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x * N[(100.0 / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -3.3e-63], t$95$0, If[LessEqual[y, 1.6e-160], 100.0, If[LessEqual[y, 7.6e-88], t$95$0, If[LessEqual[y, 5.8e+78], 100.0, N[(x / N[(y * 0.01), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \frac{100}{y}\\
\mathbf{if}\;y \leq -3.3 \cdot 10^{-63}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 1.6 \cdot 10^{-160}:\\
\;\;\;\;100\\
\mathbf{elif}\;y \leq 7.6 \cdot 10^{-88}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 5.8 \cdot 10^{+78}:\\
\;\;\;\;100\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y \cdot 0.01}\\
\end{array}
\end{array}
if y < -3.29999999999999994e-63 or 1.60000000000000004e-160 < y < 7.60000000000000022e-88Initial program 99.7%
associate-*r/99.7%
Simplified99.7%
Taylor expanded in x around 0 71.8%
if -3.29999999999999994e-63 < y < 1.60000000000000004e-160 or 7.60000000000000022e-88 < y < 5.80000000000000034e78Initial program 99.7%
associate-*r/99.8%
Simplified99.8%
Taylor expanded in x around inf 78.6%
if 5.80000000000000034e78 < y Initial program 99.8%
associate-/l*99.8%
remove-double-neg99.8%
sub0-neg99.8%
associate-+l-99.8%
neg-sub099.8%
distribute-frac-neg99.8%
div-sub99.8%
sub-neg99.8%
distribute-neg-frac99.8%
distribute-neg-out99.8%
neg-mul-199.8%
associate-/l*99.8%
associate-/r/99.8%
metadata-eval99.8%
*-inverses99.8%
distribute-frac-neg99.8%
associate-/r*99.8%
distribute-rgt-neg-in99.8%
neg-mul-199.8%
associate-/l*99.7%
associate-/r/99.8%
Simplified99.8%
Taylor expanded in x around 0 91.9%
*-commutative91.9%
Simplified91.9%
Final simplification79.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* x (/ 100.0 y))))
(if (<= y -2.2e-63)
t_0
(if (<= y 1.6e-160)
100.0
(if (<= y 2.05e-87) t_0 (if (<= y 6.5e+78) 100.0 (/ (* x 100.0) y)))))))
double code(double x, double y) {
double t_0 = x * (100.0 / y);
double tmp;
if (y <= -2.2e-63) {
tmp = t_0;
} else if (y <= 1.6e-160) {
tmp = 100.0;
} else if (y <= 2.05e-87) {
tmp = t_0;
} else if (y <= 6.5e+78) {
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) :: t_0
real(8) :: tmp
t_0 = x * (100.0d0 / y)
if (y <= (-2.2d-63)) then
tmp = t_0
else if (y <= 1.6d-160) then
tmp = 100.0d0
else if (y <= 2.05d-87) then
tmp = t_0
else if (y <= 6.5d+78) 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 t_0 = x * (100.0 / y);
double tmp;
if (y <= -2.2e-63) {
tmp = t_0;
} else if (y <= 1.6e-160) {
tmp = 100.0;
} else if (y <= 2.05e-87) {
tmp = t_0;
} else if (y <= 6.5e+78) {
tmp = 100.0;
} else {
tmp = (x * 100.0) / y;
}
return tmp;
}
def code(x, y): t_0 = x * (100.0 / y) tmp = 0 if y <= -2.2e-63: tmp = t_0 elif y <= 1.6e-160: tmp = 100.0 elif y <= 2.05e-87: tmp = t_0 elif y <= 6.5e+78: tmp = 100.0 else: tmp = (x * 100.0) / y return tmp
function code(x, y) t_0 = Float64(x * Float64(100.0 / y)) tmp = 0.0 if (y <= -2.2e-63) tmp = t_0; elseif (y <= 1.6e-160) tmp = 100.0; elseif (y <= 2.05e-87) tmp = t_0; elseif (y <= 6.5e+78) tmp = 100.0; else tmp = Float64(Float64(x * 100.0) / y); end return tmp end
function tmp_2 = code(x, y) t_0 = x * (100.0 / y); tmp = 0.0; if (y <= -2.2e-63) tmp = t_0; elseif (y <= 1.6e-160) tmp = 100.0; elseif (y <= 2.05e-87) tmp = t_0; elseif (y <= 6.5e+78) tmp = 100.0; else tmp = (x * 100.0) / y; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x * N[(100.0 / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2.2e-63], t$95$0, If[LessEqual[y, 1.6e-160], 100.0, If[LessEqual[y, 2.05e-87], t$95$0, If[LessEqual[y, 6.5e+78], 100.0, N[(N[(x * 100.0), $MachinePrecision] / y), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \frac{100}{y}\\
\mathbf{if}\;y \leq -2.2 \cdot 10^{-63}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 1.6 \cdot 10^{-160}:\\
\;\;\;\;100\\
\mathbf{elif}\;y \leq 2.05 \cdot 10^{-87}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 6.5 \cdot 10^{+78}:\\
\;\;\;\;100\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot 100}{y}\\
\end{array}
\end{array}
if y < -2.2e-63 or 1.60000000000000004e-160 < y < 2.05000000000000016e-87Initial program 99.7%
associate-*r/99.7%
Simplified99.7%
Taylor expanded in x around 0 71.8%
if -2.2e-63 < y < 1.60000000000000004e-160 or 2.05000000000000016e-87 < y < 6.50000000000000036e78Initial program 99.7%
associate-*r/99.8%
Simplified99.8%
Taylor expanded in x around inf 78.6%
if 6.50000000000000036e78 < y Initial program 99.8%
associate-*r/99.6%
Simplified99.6%
Taylor expanded in x around 0 91.7%
associate-*r/92.0%
Applied egg-rr92.0%
Final simplification79.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.7%
associate-*r/99.7%
Simplified99.7%
Taylor expanded in x around inf 48.8%
Final simplification48.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 2023268
(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)))