
(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 (/ 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*99.8%
+-commutative99.8%
remove-double-neg99.8%
unsub-neg99.8%
div-sub99.9%
distribute-frac-neg99.9%
*-inverses99.9%
metadata-eval99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y)
:precision binary64
(if (<= x -1.65e+109)
100.0
(if (or (<= x -0.00018) (and (not (<= x -4.6e-108)) (<= x 1.06e+53)))
(* 100.0 (/ x y))
100.0)))
double code(double x, double y) {
double tmp;
if (x <= -1.65e+109) {
tmp = 100.0;
} else if ((x <= -0.00018) || (!(x <= -4.6e-108) && (x <= 1.06e+53))) {
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 <= (-1.65d+109)) then
tmp = 100.0d0
else if ((x <= (-0.00018d0)) .or. (.not. (x <= (-4.6d-108))) .and. (x <= 1.06d+53)) 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 <= -1.65e+109) {
tmp = 100.0;
} else if ((x <= -0.00018) || (!(x <= -4.6e-108) && (x <= 1.06e+53))) {
tmp = 100.0 * (x / y);
} else {
tmp = 100.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.65e+109: tmp = 100.0 elif (x <= -0.00018) or (not (x <= -4.6e-108) and (x <= 1.06e+53)): tmp = 100.0 * (x / y) else: tmp = 100.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -1.65e+109) tmp = 100.0; elseif ((x <= -0.00018) || (!(x <= -4.6e-108) && (x <= 1.06e+53))) 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 <= -1.65e+109) tmp = 100.0; elseif ((x <= -0.00018) || (~((x <= -4.6e-108)) && (x <= 1.06e+53))) tmp = 100.0 * (x / y); else tmp = 100.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.65e+109], 100.0, If[Or[LessEqual[x, -0.00018], And[N[Not[LessEqual[x, -4.6e-108]], $MachinePrecision], LessEqual[x, 1.06e+53]]], N[(100.0 * N[(x / y), $MachinePrecision]), $MachinePrecision], 100.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.65 \cdot 10^{+109}:\\
\;\;\;\;100\\
\mathbf{elif}\;x \leq -0.00018 \lor \neg \left(x \leq -4.6 \cdot 10^{-108}\right) \land x \leq 1.06 \cdot 10^{+53}:\\
\;\;\;\;100 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;100\\
\end{array}
\end{array}
if x < -1.6499999999999999e109 or -1.80000000000000011e-4 < x < -4.59999999999999992e-108 or 1.05999999999999999e53 < x Initial program 99.0%
*-commutative99.0%
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.6499999999999999e109 < x < -1.80000000000000011e-4 or -4.59999999999999992e-108 < x < 1.05999999999999999e53Initial program 99.7%
*-commutative99.7%
associate-/l*99.8%
+-commutative99.8%
remove-double-neg99.8%
unsub-neg99.8%
div-sub99.8%
distribute-frac-neg99.8%
*-inverses99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in y around inf 80.3%
Final simplification81.5%
(FPCore (x y)
:precision binary64
(if (<= x -1.85e+109)
100.0
(if (<= x -0.02)
(* 100.0 (/ x y))
(if (<= x -4.8e-108)
100.0
(if (<= x 1.15e+53) (/ 100.0 (/ y x)) 100.0)))))
double code(double x, double y) {
double tmp;
if (x <= -1.85e+109) {
tmp = 100.0;
} else if (x <= -0.02) {
tmp = 100.0 * (x / y);
} else if (x <= -4.8e-108) {
tmp = 100.0;
} else if (x <= 1.15e+53) {
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 <= (-1.85d+109)) then
tmp = 100.0d0
else if (x <= (-0.02d0)) then
tmp = 100.0d0 * (x / y)
else if (x <= (-4.8d-108)) then
tmp = 100.0d0
else if (x <= 1.15d+53) 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 <= -1.85e+109) {
tmp = 100.0;
} else if (x <= -0.02) {
tmp = 100.0 * (x / y);
} else if (x <= -4.8e-108) {
tmp = 100.0;
} else if (x <= 1.15e+53) {
tmp = 100.0 / (y / x);
} else {
tmp = 100.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.85e+109: tmp = 100.0 elif x <= -0.02: tmp = 100.0 * (x / y) elif x <= -4.8e-108: tmp = 100.0 elif x <= 1.15e+53: tmp = 100.0 / (y / x) else: tmp = 100.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -1.85e+109) tmp = 100.0; elseif (x <= -0.02) tmp = Float64(100.0 * Float64(x / y)); elseif (x <= -4.8e-108) tmp = 100.0; elseif (x <= 1.15e+53) 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 <= -1.85e+109) tmp = 100.0; elseif (x <= -0.02) tmp = 100.0 * (x / y); elseif (x <= -4.8e-108) tmp = 100.0; elseif (x <= 1.15e+53) tmp = 100.0 / (y / x); else tmp = 100.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.85e+109], 100.0, If[LessEqual[x, -0.02], N[(100.0 * N[(x / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -4.8e-108], 100.0, If[LessEqual[x, 1.15e+53], N[(100.0 / N[(y / x), $MachinePrecision]), $MachinePrecision], 100.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.85 \cdot 10^{+109}:\\
\;\;\;\;100\\
\mathbf{elif}\;x \leq -0.02:\\
\;\;\;\;100 \cdot \frac{x}{y}\\
\mathbf{elif}\;x \leq -4.8 \cdot 10^{-108}:\\
\;\;\;\;100\\
\mathbf{elif}\;x \leq 1.15 \cdot 10^{+53}:\\
\;\;\;\;\frac{100}{\frac{y}{x}}\\
\mathbf{else}:\\
\;\;\;\;100\\
\end{array}
\end{array}
if x < -1.8500000000000001e109 or -0.0200000000000000004 < x < -4.80000000000000034e-108 or 1.1500000000000001e53 < x Initial program 99.0%
*-commutative99.0%
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.8500000000000001e109 < x < -0.0200000000000000004Initial program 99.3%
*-commutative99.3%
associate-/l*99.8%
+-commutative99.8%
remove-double-neg99.8%
unsub-neg99.8%
div-sub99.8%
distribute-frac-neg99.8%
*-inverses99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in y around inf 65.0%
if -4.80000000000000034e-108 < x < 1.1500000000000001e53Initial program 99.8%
*-commutative99.8%
associate-/l*99.8%
+-commutative99.8%
remove-double-neg99.8%
unsub-neg99.8%
div-sub99.8%
distribute-frac-neg99.8%
*-inverses99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in y around inf 82.7%
associate-*r/82.8%
*-commutative82.8%
associate-/l*82.7%
Simplified82.7%
Taylor expanded in x around 0 82.7%
associate-*r/82.8%
associate-/l*82.8%
Simplified82.8%
Final simplification81.5%
(FPCore (x y)
:precision binary64
(if (<= x -2.5e+111)
100.0
(if (<= x -0.16)
(* 100.0 (/ x y))
(if (<= x -6.2e-108) 100.0 (if (<= x 1.5e+53) (/ (* 100.0 x) y) 100.0)))))
double code(double x, double y) {
double tmp;
if (x <= -2.5e+111) {
tmp = 100.0;
} else if (x <= -0.16) {
tmp = 100.0 * (x / y);
} else if (x <= -6.2e-108) {
tmp = 100.0;
} else if (x <= 1.5e+53) {
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 <= (-2.5d+111)) then
tmp = 100.0d0
else if (x <= (-0.16d0)) then
tmp = 100.0d0 * (x / y)
else if (x <= (-6.2d-108)) then
tmp = 100.0d0
else if (x <= 1.5d+53) 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 <= -2.5e+111) {
tmp = 100.0;
} else if (x <= -0.16) {
tmp = 100.0 * (x / y);
} else if (x <= -6.2e-108) {
tmp = 100.0;
} else if (x <= 1.5e+53) {
tmp = (100.0 * x) / y;
} else {
tmp = 100.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -2.5e+111: tmp = 100.0 elif x <= -0.16: tmp = 100.0 * (x / y) elif x <= -6.2e-108: tmp = 100.0 elif x <= 1.5e+53: tmp = (100.0 * x) / y else: tmp = 100.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -2.5e+111) tmp = 100.0; elseif (x <= -0.16) tmp = Float64(100.0 * Float64(x / y)); elseif (x <= -6.2e-108) tmp = 100.0; elseif (x <= 1.5e+53) tmp = Float64(Float64(100.0 * x) / y); else tmp = 100.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -2.5e+111) tmp = 100.0; elseif (x <= -0.16) tmp = 100.0 * (x / y); elseif (x <= -6.2e-108) tmp = 100.0; elseif (x <= 1.5e+53) tmp = (100.0 * x) / y; else tmp = 100.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -2.5e+111], 100.0, If[LessEqual[x, -0.16], N[(100.0 * N[(x / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -6.2e-108], 100.0, If[LessEqual[x, 1.5e+53], N[(N[(100.0 * x), $MachinePrecision] / y), $MachinePrecision], 100.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.5 \cdot 10^{+111}:\\
\;\;\;\;100\\
\mathbf{elif}\;x \leq -0.16:\\
\;\;\;\;100 \cdot \frac{x}{y}\\
\mathbf{elif}\;x \leq -6.2 \cdot 10^{-108}:\\
\;\;\;\;100\\
\mathbf{elif}\;x \leq 1.5 \cdot 10^{+53}:\\
\;\;\;\;\frac{100 \cdot x}{y}\\
\mathbf{else}:\\
\;\;\;\;100\\
\end{array}
\end{array}
if x < -2.4999999999999998e111 or -0.160000000000000003 < x < -6.20000000000000028e-108 or 1.49999999999999999e53 < x Initial program 99.0%
*-commutative99.0%
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 -2.4999999999999998e111 < x < -0.160000000000000003Initial program 99.3%
*-commutative99.3%
associate-/l*99.8%
+-commutative99.8%
remove-double-neg99.8%
unsub-neg99.8%
div-sub99.8%
distribute-frac-neg99.8%
*-inverses99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in y around inf 65.0%
if -6.20000000000000028e-108 < x < 1.49999999999999999e53Initial program 99.8%
*-commutative99.8%
associate-/l*99.8%
+-commutative99.8%
remove-double-neg99.8%
unsub-neg99.8%
div-sub99.8%
distribute-frac-neg99.8%
*-inverses99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in y around inf 82.7%
associate-*r/82.8%
Applied egg-rr82.8%
Final simplification81.5%
(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*99.8%
+-commutative99.8%
remove-double-neg99.8%
unsub-neg99.8%
div-sub99.9%
distribute-frac-neg99.9%
*-inverses99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in y around 0 51.3%
Final simplification51.3%
(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 2024020
(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)))