
(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 (* (+ 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.3%
expm1-log1p-u98.3%
expm1-udef65.6%
associate-/l*66.0%
div-inv66.0%
+-commutative66.0%
metadata-eval66.0%
Applied egg-rr66.0%
expm1-def98.7%
expm1-log1p99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (x y)
:precision binary64
(if (<= x -3.5e+38)
100.0
(if (or (<= x 2.8e-79) (and (not (<= x 1.02e+18)) (<= x 1.4e+97)))
(* 100.0 (/ x y))
100.0)))
double code(double x, double y) {
double tmp;
if (x <= -3.5e+38) {
tmp = 100.0;
} else if ((x <= 2.8e-79) || (!(x <= 1.02e+18) && (x <= 1.4e+97))) {
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.5d+38)) then
tmp = 100.0d0
else if ((x <= 2.8d-79) .or. (.not. (x <= 1.02d+18)) .and. (x <= 1.4d+97)) 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.5e+38) {
tmp = 100.0;
} else if ((x <= 2.8e-79) || (!(x <= 1.02e+18) && (x <= 1.4e+97))) {
tmp = 100.0 * (x / y);
} else {
tmp = 100.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3.5e+38: tmp = 100.0 elif (x <= 2.8e-79) or (not (x <= 1.02e+18) and (x <= 1.4e+97)): tmp = 100.0 * (x / y) else: tmp = 100.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -3.5e+38) tmp = 100.0; elseif ((x <= 2.8e-79) || (!(x <= 1.02e+18) && (x <= 1.4e+97))) 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.5e+38) tmp = 100.0; elseif ((x <= 2.8e-79) || (~((x <= 1.02e+18)) && (x <= 1.4e+97))) tmp = 100.0 * (x / y); else tmp = 100.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3.5e+38], 100.0, If[Or[LessEqual[x, 2.8e-79], And[N[Not[LessEqual[x, 1.02e+18]], $MachinePrecision], LessEqual[x, 1.4e+97]]], N[(100.0 * N[(x / y), $MachinePrecision]), $MachinePrecision], 100.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.5 \cdot 10^{+38}:\\
\;\;\;\;100\\
\mathbf{elif}\;x \leq 2.8 \cdot 10^{-79} \lor \neg \left(x \leq 1.02 \cdot 10^{+18}\right) \land x \leq 1.4 \cdot 10^{+97}:\\
\;\;\;\;100 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;100\\
\end{array}
\end{array}
if x < -3.50000000000000002e38 or 2.80000000000000012e-79 < x < 1.02e18 or 1.4e97 < x Initial program 98.9%
*-commutative98.9%
associate-/l*99.9%
+-commutative99.9%
remove-double-neg99.9%
unsub-neg99.9%
div-sub99.9%
distribute-frac-neg99.9%
*-inverses99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in y around 0 82.7%
if -3.50000000000000002e38 < x < 2.80000000000000012e-79 or 1.02e18 < x < 1.4e97Initial program 99.8%
*-commutative99.8%
associate-/l*98.0%
+-commutative98.0%
remove-double-neg98.0%
unsub-neg98.0%
div-sub98.0%
distribute-frac-neg98.0%
*-inverses98.0%
metadata-eval98.0%
Simplified98.0%
Taylor expanded in y around inf 79.1%
Final simplification80.8%
(FPCore (x y)
:precision binary64
(if (<= x -4e+35)
100.0
(if (or (<= x 3.1e-79) (and (not (<= x 3.7e+18)) (<= x 1.3e+97)))
(/ x (* y 0.01))
100.0)))
double code(double x, double y) {
double tmp;
if (x <= -4e+35) {
tmp = 100.0;
} else if ((x <= 3.1e-79) || (!(x <= 3.7e+18) && (x <= 1.3e+97))) {
tmp = x / (y * 0.01);
} 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 <= (-4d+35)) then
tmp = 100.0d0
else if ((x <= 3.1d-79) .or. (.not. (x <= 3.7d+18)) .and. (x <= 1.3d+97)) then
tmp = x / (y * 0.01d0)
else
tmp = 100.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -4e+35) {
tmp = 100.0;
} else if ((x <= 3.1e-79) || (!(x <= 3.7e+18) && (x <= 1.3e+97))) {
tmp = x / (y * 0.01);
} else {
tmp = 100.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -4e+35: tmp = 100.0 elif (x <= 3.1e-79) or (not (x <= 3.7e+18) and (x <= 1.3e+97)): tmp = x / (y * 0.01) else: tmp = 100.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -4e+35) tmp = 100.0; elseif ((x <= 3.1e-79) || (!(x <= 3.7e+18) && (x <= 1.3e+97))) tmp = Float64(x / Float64(y * 0.01)); else tmp = 100.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -4e+35) tmp = 100.0; elseif ((x <= 3.1e-79) || (~((x <= 3.7e+18)) && (x <= 1.3e+97))) tmp = x / (y * 0.01); else tmp = 100.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -4e+35], 100.0, If[Or[LessEqual[x, 3.1e-79], And[N[Not[LessEqual[x, 3.7e+18]], $MachinePrecision], LessEqual[x, 1.3e+97]]], N[(x / N[(y * 0.01), $MachinePrecision]), $MachinePrecision], 100.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{+35}:\\
\;\;\;\;100\\
\mathbf{elif}\;x \leq 3.1 \cdot 10^{-79} \lor \neg \left(x \leq 3.7 \cdot 10^{+18}\right) \land x \leq 1.3 \cdot 10^{+97}:\\
\;\;\;\;\frac{x}{y \cdot 0.01}\\
\mathbf{else}:\\
\;\;\;\;100\\
\end{array}
\end{array}
if x < -3.9999999999999999e35 or 3.0999999999999999e-79 < x < 3.7e18 or 1.3e97 < x Initial program 98.9%
*-commutative98.9%
associate-/l*99.9%
+-commutative99.9%
remove-double-neg99.9%
unsub-neg99.9%
div-sub99.9%
distribute-frac-neg99.9%
*-inverses99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in y around 0 82.7%
if -3.9999999999999999e35 < x < 3.0999999999999999e-79 or 3.7e18 < x < 1.3e97Initial program 99.8%
expm1-log1p-u99.3%
expm1-udef51.0%
associate-/l*51.0%
div-inv51.0%
+-commutative51.0%
metadata-eval51.0%
Applied egg-rr51.0%
expm1-def99.3%
expm1-log1p99.7%
Simplified99.7%
Taylor expanded in x around 0 79.1%
metadata-eval79.1%
times-frac79.4%
*-commutative79.4%
*-lft-identity79.4%
Simplified79.4%
Final simplification81.0%
(FPCore (x y)
:precision binary64
(if (<= x -1.2e+35)
100.0
(if (<= x 3.1e-79)
(/ (* x 100.0) y)
(if (<= x 3.7e+18) 100.0 (if (<= x 1.3e+97) (/ x (* y 0.01)) 100.0)))))
double code(double x, double y) {
double tmp;
if (x <= -1.2e+35) {
tmp = 100.0;
} else if (x <= 3.1e-79) {
tmp = (x * 100.0) / y;
} else if (x <= 3.7e+18) {
tmp = 100.0;
} else if (x <= 1.3e+97) {
tmp = x / (y * 0.01);
} 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.2d+35)) then
tmp = 100.0d0
else if (x <= 3.1d-79) then
tmp = (x * 100.0d0) / y
else if (x <= 3.7d+18) then
tmp = 100.0d0
else if (x <= 1.3d+97) then
tmp = x / (y * 0.01d0)
else
tmp = 100.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.2e+35) {
tmp = 100.0;
} else if (x <= 3.1e-79) {
tmp = (x * 100.0) / y;
} else if (x <= 3.7e+18) {
tmp = 100.0;
} else if (x <= 1.3e+97) {
tmp = x / (y * 0.01);
} else {
tmp = 100.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.2e+35: tmp = 100.0 elif x <= 3.1e-79: tmp = (x * 100.0) / y elif x <= 3.7e+18: tmp = 100.0 elif x <= 1.3e+97: tmp = x / (y * 0.01) else: tmp = 100.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -1.2e+35) tmp = 100.0; elseif (x <= 3.1e-79) tmp = Float64(Float64(x * 100.0) / y); elseif (x <= 3.7e+18) tmp = 100.0; elseif (x <= 1.3e+97) tmp = Float64(x / Float64(y * 0.01)); else tmp = 100.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.2e+35) tmp = 100.0; elseif (x <= 3.1e-79) tmp = (x * 100.0) / y; elseif (x <= 3.7e+18) tmp = 100.0; elseif (x <= 1.3e+97) tmp = x / (y * 0.01); else tmp = 100.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.2e+35], 100.0, If[LessEqual[x, 3.1e-79], N[(N[(x * 100.0), $MachinePrecision] / y), $MachinePrecision], If[LessEqual[x, 3.7e+18], 100.0, If[LessEqual[x, 1.3e+97], N[(x / N[(y * 0.01), $MachinePrecision]), $MachinePrecision], 100.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.2 \cdot 10^{+35}:\\
\;\;\;\;100\\
\mathbf{elif}\;x \leq 3.1 \cdot 10^{-79}:\\
\;\;\;\;\frac{x \cdot 100}{y}\\
\mathbf{elif}\;x \leq 3.7 \cdot 10^{+18}:\\
\;\;\;\;100\\
\mathbf{elif}\;x \leq 1.3 \cdot 10^{+97}:\\
\;\;\;\;\frac{x}{y \cdot 0.01}\\
\mathbf{else}:\\
\;\;\;\;100\\
\end{array}
\end{array}
if x < -1.20000000000000007e35 or 3.0999999999999999e-79 < x < 3.7e18 or 1.3e97 < x Initial program 98.9%
*-commutative98.9%
associate-/l*99.9%
+-commutative99.9%
remove-double-neg99.9%
unsub-neg99.9%
div-sub99.9%
distribute-frac-neg99.9%
*-inverses99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in y around 0 82.7%
if -1.20000000000000007e35 < x < 3.0999999999999999e-79Initial program 99.8%
expm1-log1p-u99.4%
expm1-udef53.7%
associate-/l*53.7%
div-inv53.7%
+-commutative53.7%
metadata-eval53.7%
Applied egg-rr53.7%
expm1-def99.3%
expm1-log1p99.7%
Simplified99.7%
Taylor expanded in x around 0 80.5%
associate-*r/80.9%
Simplified80.9%
if 3.7e18 < x < 1.3e97Initial program 99.6%
expm1-log1p-u98.9%
expm1-udef34.9%
associate-/l*34.9%
div-inv34.9%
+-commutative34.9%
metadata-eval34.9%
Applied egg-rr34.9%
expm1-def99.2%
expm1-log1p99.8%
Simplified99.8%
Taylor expanded in x around 0 70.7%
metadata-eval70.7%
times-frac70.7%
*-commutative70.7%
*-lft-identity70.7%
Simplified70.7%
Final simplification81.0%
(FPCore (x y) :precision binary64 (/ 100.0 (- (/ y x) -1.0)))
double code(double x, double y) {
return 100.0 / ((y / x) - -1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 100.0d0 / ((y / x) - (-1.0d0))
end function
public static double code(double x, double y) {
return 100.0 / ((y / x) - -1.0);
}
def code(x, y): return 100.0 / ((y / x) - -1.0)
function code(x, y) return Float64(100.0 / Float64(Float64(y / x) - -1.0)) end
function tmp = code(x, y) tmp = 100.0 / ((y / x) - -1.0); end
code[x_, y_] := N[(100.0 / N[(N[(y / x), $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{100}{\frac{y}{x} - -1}
\end{array}
Initial program 99.3%
*-commutative99.3%
associate-/l*98.9%
+-commutative98.9%
remove-double-neg98.9%
unsub-neg98.9%
div-sub98.9%
distribute-frac-neg98.9%
*-inverses98.9%
metadata-eval98.9%
Simplified98.9%
Final simplification98.9%
(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.3%
*-commutative99.3%
associate-/l*98.9%
+-commutative98.9%
remove-double-neg98.9%
unsub-neg98.9%
div-sub98.9%
distribute-frac-neg98.9%
*-inverses98.9%
metadata-eval98.9%
Simplified98.9%
Taylor expanded in y around 0 51.4%
Final simplification51.4%
(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 2023334
(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)))