
(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 (* 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.0%
*-commutative99.0%
associate-/l*99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (x y)
:precision binary64
(if (<= x -3800.0)
100.0
(if (or (<= x 1.04e-53) (and (not (<= x 8.1e+43)) (<= x 1.95e+61)))
(* 100.0 (/ x y))
100.0)))
double code(double x, double y) {
double tmp;
if (x <= -3800.0) {
tmp = 100.0;
} else if ((x <= 1.04e-53) || (!(x <= 8.1e+43) && (x <= 1.95e+61))) {
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 <= (-3800.0d0)) then
tmp = 100.0d0
else if ((x <= 1.04d-53) .or. (.not. (x <= 8.1d+43)) .and. (x <= 1.95d+61)) 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 <= -3800.0) {
tmp = 100.0;
} else if ((x <= 1.04e-53) || (!(x <= 8.1e+43) && (x <= 1.95e+61))) {
tmp = 100.0 * (x / y);
} else {
tmp = 100.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3800.0: tmp = 100.0 elif (x <= 1.04e-53) or (not (x <= 8.1e+43) and (x <= 1.95e+61)): tmp = 100.0 * (x / y) else: tmp = 100.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -3800.0) tmp = 100.0; elseif ((x <= 1.04e-53) || (!(x <= 8.1e+43) && (x <= 1.95e+61))) 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 <= -3800.0) tmp = 100.0; elseif ((x <= 1.04e-53) || (~((x <= 8.1e+43)) && (x <= 1.95e+61))) tmp = 100.0 * (x / y); else tmp = 100.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3800.0], 100.0, If[Or[LessEqual[x, 1.04e-53], And[N[Not[LessEqual[x, 8.1e+43]], $MachinePrecision], LessEqual[x, 1.95e+61]]], N[(100.0 * N[(x / y), $MachinePrecision]), $MachinePrecision], 100.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3800:\\
\;\;\;\;100\\
\mathbf{elif}\;x \leq 1.04 \cdot 10^{-53} \lor \neg \left(x \leq 8.1 \cdot 10^{+43}\right) \land x \leq 1.95 \cdot 10^{+61}:\\
\;\;\;\;100 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;100\\
\end{array}
\end{array}
if x < -3800 or 1.04000000000000001e-53 < x < 8.0999999999999996e43 or 1.94999999999999994e61 < x Initial program 98.3%
*-commutative98.3%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in x around inf 75.3%
if -3800 < x < 1.04000000000000001e-53 or 8.0999999999999996e43 < x < 1.94999999999999994e61Initial program 99.7%
*-commutative99.7%
associate-/l*99.7%
Simplified99.7%
Taylor expanded in x around 0 78.1%
Final simplification76.6%
(FPCore (x y)
:precision binary64
(if (<= x -840.0)
100.0
(if (or (<= x 8.5e-54) (and (not (<= x 8.8e+43)) (<= x 1.9e+61)))
(* x (/ 100.0 y))
100.0)))
double code(double x, double y) {
double tmp;
if (x <= -840.0) {
tmp = 100.0;
} else if ((x <= 8.5e-54) || (!(x <= 8.8e+43) && (x <= 1.9e+61))) {
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 <= (-840.0d0)) then
tmp = 100.0d0
else if ((x <= 8.5d-54) .or. (.not. (x <= 8.8d+43)) .and. (x <= 1.9d+61)) 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 <= -840.0) {
tmp = 100.0;
} else if ((x <= 8.5e-54) || (!(x <= 8.8e+43) && (x <= 1.9e+61))) {
tmp = x * (100.0 / y);
} else {
tmp = 100.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -840.0: tmp = 100.0 elif (x <= 8.5e-54) or (not (x <= 8.8e+43) and (x <= 1.9e+61)): tmp = x * (100.0 / y) else: tmp = 100.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -840.0) tmp = 100.0; elseif ((x <= 8.5e-54) || (!(x <= 8.8e+43) && (x <= 1.9e+61))) 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 <= -840.0) tmp = 100.0; elseif ((x <= 8.5e-54) || (~((x <= 8.8e+43)) && (x <= 1.9e+61))) tmp = x * (100.0 / y); else tmp = 100.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -840.0], 100.0, If[Or[LessEqual[x, 8.5e-54], And[N[Not[LessEqual[x, 8.8e+43]], $MachinePrecision], LessEqual[x, 1.9e+61]]], N[(x * N[(100.0 / y), $MachinePrecision]), $MachinePrecision], 100.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -840:\\
\;\;\;\;100\\
\mathbf{elif}\;x \leq 8.5 \cdot 10^{-54} \lor \neg \left(x \leq 8.8 \cdot 10^{+43}\right) \land x \leq 1.9 \cdot 10^{+61}:\\
\;\;\;\;x \cdot \frac{100}{y}\\
\mathbf{else}:\\
\;\;\;\;100\\
\end{array}
\end{array}
if x < -840 or 8.5e-54 < x < 8.80000000000000002e43 or 1.89999999999999998e61 < x Initial program 98.3%
*-commutative98.3%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in x around inf 75.3%
if -840 < x < 8.5e-54 or 8.80000000000000002e43 < x < 1.89999999999999998e61Initial program 99.7%
*-commutative99.7%
associate-/l*99.7%
Simplified99.7%
Taylor expanded in x around 0 78.1%
associate-*r/78.2%
*-commutative78.2%
associate-/l*78.2%
Simplified78.2%
Final simplification76.7%
(FPCore (x y)
:precision binary64
(if (<= x -4200.0)
100.0
(if (<= x 1.9e-56)
(* x (/ 100.0 y))
(if (<= x 8.1e+43) 100.0 (if (<= x 1.85e+61) (/ 100.0 (/ y x)) 100.0)))))
double code(double x, double y) {
double tmp;
if (x <= -4200.0) {
tmp = 100.0;
} else if (x <= 1.9e-56) {
tmp = x * (100.0 / y);
} else if (x <= 8.1e+43) {
tmp = 100.0;
} else if (x <= 1.85e+61) {
tmp = 100.0 / (y / x);
} 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 <= (-4200.0d0)) then
tmp = 100.0d0
else if (x <= 1.9d-56) then
tmp = x * (100.0d0 / y)
else if (x <= 8.1d+43) then
tmp = 100.0d0
else if (x <= 1.85d+61) then
tmp = 100.0d0 / (y / x)
else
tmp = 100.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -4200.0) {
tmp = 100.0;
} else if (x <= 1.9e-56) {
tmp = x * (100.0 / y);
} else if (x <= 8.1e+43) {
tmp = 100.0;
} else if (x <= 1.85e+61) {
tmp = 100.0 / (y / x);
} else {
tmp = 100.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -4200.0: tmp = 100.0 elif x <= 1.9e-56: tmp = x * (100.0 / y) elif x <= 8.1e+43: tmp = 100.0 elif x <= 1.85e+61: tmp = 100.0 / (y / x) else: tmp = 100.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -4200.0) tmp = 100.0; elseif (x <= 1.9e-56) tmp = Float64(x * Float64(100.0 / y)); elseif (x <= 8.1e+43) tmp = 100.0; elseif (x <= 1.85e+61) tmp = Float64(100.0 / Float64(y / x)); else tmp = 100.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -4200.0) tmp = 100.0; elseif (x <= 1.9e-56) tmp = x * (100.0 / y); elseif (x <= 8.1e+43) tmp = 100.0; elseif (x <= 1.85e+61) tmp = 100.0 / (y / x); else tmp = 100.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -4200.0], 100.0, If[LessEqual[x, 1.9e-56], N[(x * N[(100.0 / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 8.1e+43], 100.0, If[LessEqual[x, 1.85e+61], N[(100.0 / N[(y / x), $MachinePrecision]), $MachinePrecision], 100.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4200:\\
\;\;\;\;100\\
\mathbf{elif}\;x \leq 1.9 \cdot 10^{-56}:\\
\;\;\;\;x \cdot \frac{100}{y}\\
\mathbf{elif}\;x \leq 8.1 \cdot 10^{+43}:\\
\;\;\;\;100\\
\mathbf{elif}\;x \leq 1.85 \cdot 10^{+61}:\\
\;\;\;\;\frac{100}{\frac{y}{x}}\\
\mathbf{else}:\\
\;\;\;\;100\\
\end{array}
\end{array}
if x < -4200 or 1.9000000000000001e-56 < x < 8.0999999999999996e43 or 1.85000000000000001e61 < x Initial program 98.3%
*-commutative98.3%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in x around inf 75.3%
if -4200 < x < 1.9000000000000001e-56Initial program 99.8%
*-commutative99.8%
associate-/l*99.7%
Simplified99.7%
Taylor expanded in x around 0 76.8%
associate-*r/76.9%
*-commutative76.9%
associate-/l*76.9%
Simplified76.9%
if 8.0999999999999996e43 < x < 1.85000000000000001e61Initial program 98.9%
*-commutative98.9%
associate-/l*99.3%
Simplified99.3%
clear-num99.6%
un-div-inv100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 100.0%
Final simplification76.7%
(FPCore (x y)
:precision binary64
(if (<= x -114.0)
100.0
(if (<= x 1.35e-53)
(/ (* 100.0 x) y)
(if (<= x 7.4e+43) 100.0 (if (<= x 1.85e+61) (/ 100.0 (/ y x)) 100.0)))))
double code(double x, double y) {
double tmp;
if (x <= -114.0) {
tmp = 100.0;
} else if (x <= 1.35e-53) {
tmp = (100.0 * x) / y;
} else if (x <= 7.4e+43) {
tmp = 100.0;
} else if (x <= 1.85e+61) {
tmp = 100.0 / (y / x);
} 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 <= (-114.0d0)) then
tmp = 100.0d0
else if (x <= 1.35d-53) then
tmp = (100.0d0 * x) / y
else if (x <= 7.4d+43) then
tmp = 100.0d0
else if (x <= 1.85d+61) then
tmp = 100.0d0 / (y / x)
else
tmp = 100.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -114.0) {
tmp = 100.0;
} else if (x <= 1.35e-53) {
tmp = (100.0 * x) / y;
} else if (x <= 7.4e+43) {
tmp = 100.0;
} else if (x <= 1.85e+61) {
tmp = 100.0 / (y / x);
} else {
tmp = 100.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -114.0: tmp = 100.0 elif x <= 1.35e-53: tmp = (100.0 * x) / y elif x <= 7.4e+43: tmp = 100.0 elif x <= 1.85e+61: tmp = 100.0 / (y / x) else: tmp = 100.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -114.0) tmp = 100.0; elseif (x <= 1.35e-53) tmp = Float64(Float64(100.0 * x) / y); elseif (x <= 7.4e+43) tmp = 100.0; elseif (x <= 1.85e+61) tmp = Float64(100.0 / Float64(y / x)); else tmp = 100.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -114.0) tmp = 100.0; elseif (x <= 1.35e-53) tmp = (100.0 * x) / y; elseif (x <= 7.4e+43) tmp = 100.0; elseif (x <= 1.85e+61) tmp = 100.0 / (y / x); else tmp = 100.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -114.0], 100.0, If[LessEqual[x, 1.35e-53], N[(N[(100.0 * x), $MachinePrecision] / y), $MachinePrecision], If[LessEqual[x, 7.4e+43], 100.0, If[LessEqual[x, 1.85e+61], N[(100.0 / N[(y / x), $MachinePrecision]), $MachinePrecision], 100.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -114:\\
\;\;\;\;100\\
\mathbf{elif}\;x \leq 1.35 \cdot 10^{-53}:\\
\;\;\;\;\frac{100 \cdot x}{y}\\
\mathbf{elif}\;x \leq 7.4 \cdot 10^{+43}:\\
\;\;\;\;100\\
\mathbf{elif}\;x \leq 1.85 \cdot 10^{+61}:\\
\;\;\;\;\frac{100}{\frac{y}{x}}\\
\mathbf{else}:\\
\;\;\;\;100\\
\end{array}
\end{array}
if x < -114 or 1.35e-53 < x < 7.4000000000000002e43 or 1.85000000000000001e61 < x Initial program 98.3%
*-commutative98.3%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in x around inf 75.3%
if -114 < x < 1.35e-53Initial program 99.8%
*-commutative99.8%
associate-/l*99.7%
Simplified99.7%
Taylor expanded in x around 0 76.8%
associate-*r/76.9%
Simplified76.9%
if 7.4000000000000002e43 < x < 1.85000000000000001e61Initial program 98.9%
*-commutative98.9%
associate-/l*99.3%
Simplified99.3%
clear-num99.6%
un-div-inv100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 100.0%
Final simplification76.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.0%
*-commutative99.0%
associate-/l*99.7%
Simplified99.7%
Taylor expanded in x around inf 51.1%
Final simplification51.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 2024039
(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)))