
(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 7 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 (+ 1.0 (/ y x))))
double code(double x, double y) {
return 100.0 / (1.0 + (y / x));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 100.0d0 / (1.0d0 + (y / x))
end function
public static double code(double x, double y) {
return 100.0 / (1.0 + (y / x));
}
def code(x, y): return 100.0 / (1.0 + (y / x))
function code(x, y) return Float64(100.0 / Float64(1.0 + Float64(y / x))) end
function tmp = code(x, y) tmp = 100.0 / (1.0 + (y / x)); end
code[x_, y_] := N[(100.0 / N[(1.0 + N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{100}{1 + \frac{y}{x}}
\end{array}
Initial program 99.3%
*-commutative99.3%
associate-/l*99.8%
Simplified99.8%
clear-num99.8%
un-div-inv99.8%
Applied egg-rr99.8%
Taylor expanded in x around inf 99.9%
Final simplification99.9%
(FPCore (x y)
:precision binary64
(if (<= x -1.45e+57)
100.0
(if (or (<= x -5.2e-10) (and (not (<= x -2.5e-40)) (<= x 3.1e-97)))
(* 100.0 (/ x y))
100.0)))
double code(double x, double y) {
double tmp;
if (x <= -1.45e+57) {
tmp = 100.0;
} else if ((x <= -5.2e-10) || (!(x <= -2.5e-40) && (x <= 3.1e-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 <= (-1.45d+57)) then
tmp = 100.0d0
else if ((x <= (-5.2d-10)) .or. (.not. (x <= (-2.5d-40))) .and. (x <= 3.1d-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 <= -1.45e+57) {
tmp = 100.0;
} else if ((x <= -5.2e-10) || (!(x <= -2.5e-40) && (x <= 3.1e-97))) {
tmp = 100.0 * (x / y);
} else {
tmp = 100.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.45e+57: tmp = 100.0 elif (x <= -5.2e-10) or (not (x <= -2.5e-40) and (x <= 3.1e-97)): tmp = 100.0 * (x / y) else: tmp = 100.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -1.45e+57) tmp = 100.0; elseif ((x <= -5.2e-10) || (!(x <= -2.5e-40) && (x <= 3.1e-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 <= -1.45e+57) tmp = 100.0; elseif ((x <= -5.2e-10) || (~((x <= -2.5e-40)) && (x <= 3.1e-97))) tmp = 100.0 * (x / y); else tmp = 100.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.45e+57], 100.0, If[Or[LessEqual[x, -5.2e-10], And[N[Not[LessEqual[x, -2.5e-40]], $MachinePrecision], LessEqual[x, 3.1e-97]]], N[(100.0 * N[(x / y), $MachinePrecision]), $MachinePrecision], 100.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.45 \cdot 10^{+57}:\\
\;\;\;\;100\\
\mathbf{elif}\;x \leq -5.2 \cdot 10^{-10} \lor \neg \left(x \leq -2.5 \cdot 10^{-40}\right) \land x \leq 3.1 \cdot 10^{-97}:\\
\;\;\;\;100 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;100\\
\end{array}
\end{array}
if x < -1.4500000000000001e57 or -5.19999999999999962e-10 < x < -2.49999999999999982e-40 or 3.10000000000000002e-97 < x Initial program 99.1%
*-commutative99.1%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around inf 79.9%
if -1.4500000000000001e57 < x < -5.19999999999999962e-10 or -2.49999999999999982e-40 < x < 3.10000000000000002e-97Initial program 99.6%
*-commutative99.6%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in x around 0 78.2%
Final simplification79.1%
(FPCore (x y)
:precision binary64
(if (<= x -1.2e+51)
100.0
(if (<= x -8.5e-10)
(* 100.0 (/ x y))
(if (<= x -9.5e-47) 100.0 (if (<= x 3.1e-97) (* x (/ 100.0 y)) 100.0)))))
double code(double x, double y) {
double tmp;
if (x <= -1.2e+51) {
tmp = 100.0;
} else if (x <= -8.5e-10) {
tmp = 100.0 * (x / y);
} else if (x <= -9.5e-47) {
tmp = 100.0;
} else if (x <= 3.1e-97) {
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 <= (-1.2d+51)) then
tmp = 100.0d0
else if (x <= (-8.5d-10)) then
tmp = 100.0d0 * (x / y)
else if (x <= (-9.5d-47)) then
tmp = 100.0d0
else if (x <= 3.1d-97) 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 <= -1.2e+51) {
tmp = 100.0;
} else if (x <= -8.5e-10) {
tmp = 100.0 * (x / y);
} else if (x <= -9.5e-47) {
tmp = 100.0;
} else if (x <= 3.1e-97) {
tmp = x * (100.0 / y);
} else {
tmp = 100.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.2e+51: tmp = 100.0 elif x <= -8.5e-10: tmp = 100.0 * (x / y) elif x <= -9.5e-47: tmp = 100.0 elif x <= 3.1e-97: tmp = x * (100.0 / y) else: tmp = 100.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -1.2e+51) tmp = 100.0; elseif (x <= -8.5e-10) tmp = Float64(100.0 * Float64(x / y)); elseif (x <= -9.5e-47) tmp = 100.0; elseif (x <= 3.1e-97) 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 <= -1.2e+51) tmp = 100.0; elseif (x <= -8.5e-10) tmp = 100.0 * (x / y); elseif (x <= -9.5e-47) tmp = 100.0; elseif (x <= 3.1e-97) tmp = x * (100.0 / y); else tmp = 100.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.2e+51], 100.0, If[LessEqual[x, -8.5e-10], N[(100.0 * N[(x / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -9.5e-47], 100.0, If[LessEqual[x, 3.1e-97], N[(x * N[(100.0 / y), $MachinePrecision]), $MachinePrecision], 100.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.2 \cdot 10^{+51}:\\
\;\;\;\;100\\
\mathbf{elif}\;x \leq -8.5 \cdot 10^{-10}:\\
\;\;\;\;100 \cdot \frac{x}{y}\\
\mathbf{elif}\;x \leq -9.5 \cdot 10^{-47}:\\
\;\;\;\;100\\
\mathbf{elif}\;x \leq 3.1 \cdot 10^{-97}:\\
\;\;\;\;x \cdot \frac{100}{y}\\
\mathbf{else}:\\
\;\;\;\;100\\
\end{array}
\end{array}
if x < -1.1999999999999999e51 or -8.4999999999999996e-10 < x < -9.4999999999999991e-47 or 3.10000000000000002e-97 < x Initial program 99.1%
*-commutative99.1%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around inf 79.9%
if -1.1999999999999999e51 < x < -8.4999999999999996e-10Initial program 99.3%
*-commutative99.3%
associate-/l*99.5%
Simplified99.5%
Taylor expanded in x around 0 66.3%
if -9.4999999999999991e-47 < x < 3.10000000000000002e-97Initial program 99.6%
associate-/l*99.8%
*-commutative99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 79.8%
Final simplification79.2%
(FPCore (x y)
:precision binary64
(if (<= x -7e+75)
100.0
(if (<= x -1.76e-9)
(/ 100.0 (/ y x))
(if (<= x -2.9e-40) 100.0 (if (<= x 3.1e-97) (* x (/ 100.0 y)) 100.0)))))
double code(double x, double y) {
double tmp;
if (x <= -7e+75) {
tmp = 100.0;
} else if (x <= -1.76e-9) {
tmp = 100.0 / (y / x);
} else if (x <= -2.9e-40) {
tmp = 100.0;
} else if (x <= 3.1e-97) {
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 <= (-7d+75)) then
tmp = 100.0d0
else if (x <= (-1.76d-9)) then
tmp = 100.0d0 / (y / x)
else if (x <= (-2.9d-40)) then
tmp = 100.0d0
else if (x <= 3.1d-97) 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 <= -7e+75) {
tmp = 100.0;
} else if (x <= -1.76e-9) {
tmp = 100.0 / (y / x);
} else if (x <= -2.9e-40) {
tmp = 100.0;
} else if (x <= 3.1e-97) {
tmp = x * (100.0 / y);
} else {
tmp = 100.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -7e+75: tmp = 100.0 elif x <= -1.76e-9: tmp = 100.0 / (y / x) elif x <= -2.9e-40: tmp = 100.0 elif x <= 3.1e-97: tmp = x * (100.0 / y) else: tmp = 100.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -7e+75) tmp = 100.0; elseif (x <= -1.76e-9) tmp = Float64(100.0 / Float64(y / x)); elseif (x <= -2.9e-40) tmp = 100.0; elseif (x <= 3.1e-97) 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 <= -7e+75) tmp = 100.0; elseif (x <= -1.76e-9) tmp = 100.0 / (y / x); elseif (x <= -2.9e-40) tmp = 100.0; elseif (x <= 3.1e-97) tmp = x * (100.0 / y); else tmp = 100.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -7e+75], 100.0, If[LessEqual[x, -1.76e-9], N[(100.0 / N[(y / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -2.9e-40], 100.0, If[LessEqual[x, 3.1e-97], N[(x * N[(100.0 / y), $MachinePrecision]), $MachinePrecision], 100.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7 \cdot 10^{+75}:\\
\;\;\;\;100\\
\mathbf{elif}\;x \leq -1.76 \cdot 10^{-9}:\\
\;\;\;\;\frac{100}{\frac{y}{x}}\\
\mathbf{elif}\;x \leq -2.9 \cdot 10^{-40}:\\
\;\;\;\;100\\
\mathbf{elif}\;x \leq 3.1 \cdot 10^{-97}:\\
\;\;\;\;x \cdot \frac{100}{y}\\
\mathbf{else}:\\
\;\;\;\;100\\
\end{array}
\end{array}
if x < -6.9999999999999997e75 or -1.75999999999999992e-9 < x < -2.8999999999999999e-40 or 3.10000000000000002e-97 < x Initial program 99.1%
*-commutative99.1%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around inf 79.9%
if -6.9999999999999997e75 < x < -1.75999999999999992e-9Initial program 99.3%
*-commutative99.3%
associate-/l*99.5%
Simplified99.5%
clear-num99.5%
un-div-inv99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 66.3%
associate-*r/65.9%
associate-*l/66.3%
associate-/r/66.4%
Simplified66.4%
if -2.8999999999999999e-40 < x < 3.10000000000000002e-97Initial program 99.6%
associate-/l*99.8%
*-commutative99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 79.8%
Final simplification79.2%
(FPCore (x y)
:precision binary64
(if (<= x -1.9e+60)
100.0
(if (<= x -4.9e-9)
(/ x (* y 0.01))
(if (<= x -7.2e-47) 100.0 (if (<= x 8.6e-98) (* x (/ 100.0 y)) 100.0)))))
double code(double x, double y) {
double tmp;
if (x <= -1.9e+60) {
tmp = 100.0;
} else if (x <= -4.9e-9) {
tmp = x / (y * 0.01);
} else if (x <= -7.2e-47) {
tmp = 100.0;
} else if (x <= 8.6e-98) {
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 <= (-1.9d+60)) then
tmp = 100.0d0
else if (x <= (-4.9d-9)) then
tmp = x / (y * 0.01d0)
else if (x <= (-7.2d-47)) then
tmp = 100.0d0
else if (x <= 8.6d-98) 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 <= -1.9e+60) {
tmp = 100.0;
} else if (x <= -4.9e-9) {
tmp = x / (y * 0.01);
} else if (x <= -7.2e-47) {
tmp = 100.0;
} else if (x <= 8.6e-98) {
tmp = x * (100.0 / y);
} else {
tmp = 100.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.9e+60: tmp = 100.0 elif x <= -4.9e-9: tmp = x / (y * 0.01) elif x <= -7.2e-47: tmp = 100.0 elif x <= 8.6e-98: tmp = x * (100.0 / y) else: tmp = 100.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -1.9e+60) tmp = 100.0; elseif (x <= -4.9e-9) tmp = Float64(x / Float64(y * 0.01)); elseif (x <= -7.2e-47) tmp = 100.0; elseif (x <= 8.6e-98) 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 <= -1.9e+60) tmp = 100.0; elseif (x <= -4.9e-9) tmp = x / (y * 0.01); elseif (x <= -7.2e-47) tmp = 100.0; elseif (x <= 8.6e-98) tmp = x * (100.0 / y); else tmp = 100.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.9e+60], 100.0, If[LessEqual[x, -4.9e-9], N[(x / N[(y * 0.01), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -7.2e-47], 100.0, If[LessEqual[x, 8.6e-98], N[(x * N[(100.0 / y), $MachinePrecision]), $MachinePrecision], 100.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.9 \cdot 10^{+60}:\\
\;\;\;\;100\\
\mathbf{elif}\;x \leq -4.9 \cdot 10^{-9}:\\
\;\;\;\;\frac{x}{y \cdot 0.01}\\
\mathbf{elif}\;x \leq -7.2 \cdot 10^{-47}:\\
\;\;\;\;100\\
\mathbf{elif}\;x \leq 8.6 \cdot 10^{-98}:\\
\;\;\;\;x \cdot \frac{100}{y}\\
\mathbf{else}:\\
\;\;\;\;100\\
\end{array}
\end{array}
if x < -1.90000000000000005e60 or -4.90000000000000004e-9 < x < -7.19999999999999982e-47 or 8.59999999999999977e-98 < x Initial program 99.1%
*-commutative99.1%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around inf 79.9%
if -1.90000000000000005e60 < x < -4.90000000000000004e-9Initial program 99.3%
associate-/l*99.6%
*-commutative99.6%
Applied egg-rr99.6%
Taylor expanded in x around 0 66.3%
Taylor expanded in y around 0 66.3%
associate-*r/65.9%
associate-*l/66.3%
associate-/r/66.4%
metadata-eval66.4%
associate-/r*66.4%
associate-/l/66.3%
associate-/r/66.4%
*-commutative66.4%
associate-*r/66.4%
associate-*l/66.4%
*-rgt-identity66.4%
associate-/r*66.5%
Simplified66.5%
if -7.19999999999999982e-47 < x < 8.59999999999999977e-98Initial program 99.6%
associate-/l*99.8%
*-commutative99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 79.8%
Final simplification79.2%
(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(x / Float64(y + x))) end
function tmp = code(x, y) tmp = 100.0 * (x / (y + x)); end
code[x_, y_] := N[(100.0 * N[(x / N[(y + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
100 \cdot \frac{x}{y + x}
\end{array}
Initial program 99.3%
*-commutative99.3%
associate-/l*99.8%
Simplified99.8%
Final simplification99.8%
(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%
Simplified99.8%
Taylor expanded in x around inf 55.4%
Final simplification55.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 2024079
(FPCore (x y)
:name "Development.Shake.Progress:message from shake-0.15.5"
:precision binary64
:alt
(* (/ x 1.0) (/ 100.0 (+ x y)))
(/ (* x 100.0) (+ x y)))