
(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 8 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 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(Float64(x + y) / x)) end
function tmp = code(x, y) tmp = 100.0 / ((x + y) / x); end
code[x_, y_] := N[(100.0 / N[(N[(x + y), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{100}{\frac{x + y}{x}}
\end{array}
Initial program 99.3%
*-commutative99.3%
associate-/l*99.8%
Simplified99.8%
clear-num99.7%
un-div-inv99.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x y) :precision binary64 (if (or (<= y -1.25e+24) (not (<= y 3.2e-67))) (* 100.0 (/ x y)) 100.0))
double code(double x, double y) {
double tmp;
if ((y <= -1.25e+24) || !(y <= 3.2e-67)) {
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 <= (-1.25d+24)) .or. (.not. (y <= 3.2d-67))) 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 <= -1.25e+24) || !(y <= 3.2e-67)) {
tmp = 100.0 * (x / y);
} else {
tmp = 100.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.25e+24) or not (y <= 3.2e-67): tmp = 100.0 * (x / y) else: tmp = 100.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.25e+24) || !(y <= 3.2e-67)) 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 <= -1.25e+24) || ~((y <= 3.2e-67))) tmp = 100.0 * (x / y); else tmp = 100.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.25e+24], N[Not[LessEqual[y, 3.2e-67]], $MachinePrecision]], N[(100.0 * N[(x / y), $MachinePrecision]), $MachinePrecision], 100.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.25 \cdot 10^{+24} \lor \neg \left(y \leq 3.2 \cdot 10^{-67}\right):\\
\;\;\;\;100 \cdot \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;100\\
\end{array}
\end{array}
if y < -1.25000000000000011e24 or 3.20000000000000021e-67 < y Initial program 99.7%
*-commutative99.7%
associate-/l*99.7%
Simplified99.7%
Taylor expanded in x around 0 76.0%
if -1.25000000000000011e24 < y < 3.20000000000000021e-67Initial program 98.9%
*-commutative98.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around inf 77.6%
Final simplification76.8%
(FPCore (x y) :precision binary64 (if (or (<= y -7.4e+23) (not (<= y 5.2e-62))) (* x (/ 100.0 y)) 100.0))
double code(double x, double y) {
double tmp;
if ((y <= -7.4e+23) || !(y <= 5.2e-62)) {
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 <= (-7.4d+23)) .or. (.not. (y <= 5.2d-62))) 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 <= -7.4e+23) || !(y <= 5.2e-62)) {
tmp = x * (100.0 / y);
} else {
tmp = 100.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -7.4e+23) or not (y <= 5.2e-62): tmp = x * (100.0 / y) else: tmp = 100.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= -7.4e+23) || !(y <= 5.2e-62)) 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 <= -7.4e+23) || ~((y <= 5.2e-62))) tmp = x * (100.0 / y); else tmp = 100.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -7.4e+23], N[Not[LessEqual[y, 5.2e-62]], $MachinePrecision]], N[(x * N[(100.0 / y), $MachinePrecision]), $MachinePrecision], 100.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.4 \cdot 10^{+23} \lor \neg \left(y \leq 5.2 \cdot 10^{-62}\right):\\
\;\;\;\;x \cdot \frac{100}{y}\\
\mathbf{else}:\\
\;\;\;\;100\\
\end{array}
\end{array}
if y < -7.40000000000000025e23 or 5.1999999999999999e-62 < y Initial program 99.7%
*-commutative99.7%
associate-/l*99.7%
Simplified99.7%
clear-num99.6%
un-div-inv99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 76.0%
*-commutative76.0%
associate-*l/76.1%
associate-*r/76.1%
Simplified76.1%
if -7.40000000000000025e23 < y < 5.1999999999999999e-62Initial program 98.9%
*-commutative98.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around inf 77.6%
Final simplification76.9%
(FPCore (x y) :precision binary64 (if (<= y -4.2e+23) (* x (/ 100.0 y)) (if (<= y 9.8e-63) 100.0 (/ 100.0 (/ y x)))))
double code(double x, double y) {
double tmp;
if (y <= -4.2e+23) {
tmp = x * (100.0 / y);
} else if (y <= 9.8e-63) {
tmp = 100.0;
} else {
tmp = 100.0 / (y / x);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-4.2d+23)) then
tmp = x * (100.0d0 / y)
else if (y <= 9.8d-63) then
tmp = 100.0d0
else
tmp = 100.0d0 / (y / x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -4.2e+23) {
tmp = x * (100.0 / y);
} else if (y <= 9.8e-63) {
tmp = 100.0;
} else {
tmp = 100.0 / (y / x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4.2e+23: tmp = x * (100.0 / y) elif y <= 9.8e-63: tmp = 100.0 else: tmp = 100.0 / (y / x) return tmp
function code(x, y) tmp = 0.0 if (y <= -4.2e+23) tmp = Float64(x * Float64(100.0 / y)); elseif (y <= 9.8e-63) tmp = 100.0; else tmp = Float64(100.0 / Float64(y / x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -4.2e+23) tmp = x * (100.0 / y); elseif (y <= 9.8e-63) tmp = 100.0; else tmp = 100.0 / (y / x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4.2e+23], N[(x * N[(100.0 / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 9.8e-63], 100.0, N[(100.0 / N[(y / x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.2 \cdot 10^{+23}:\\
\;\;\;\;x \cdot \frac{100}{y}\\
\mathbf{elif}\;y \leq 9.8 \cdot 10^{-63}:\\
\;\;\;\;100\\
\mathbf{else}:\\
\;\;\;\;\frac{100}{\frac{y}{x}}\\
\end{array}
\end{array}
if y < -4.2000000000000003e23Initial program 99.7%
*-commutative99.7%
associate-/l*99.6%
Simplified99.6%
clear-num99.5%
un-div-inv99.6%
Applied egg-rr99.6%
Taylor expanded in x around 0 78.9%
*-commutative78.9%
associate-*l/79.1%
associate-*r/79.1%
Simplified79.1%
if -4.2000000000000003e23 < y < 9.8000000000000003e-63Initial program 98.9%
*-commutative98.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around inf 77.6%
if 9.8000000000000003e-63 < y Initial program 99.7%
*-commutative99.7%
associate-/l*99.7%
Simplified99.7%
clear-num99.8%
un-div-inv99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 73.8%
associate-*r/73.7%
metadata-eval73.7%
associate-/r/73.6%
associate-/r*73.7%
*-commutative73.7%
associate-*r/73.7%
*-commutative73.7%
associate-*r/73.7%
associate-/r*73.9%
metadata-eval73.9%
Simplified73.9%
Final simplification76.9%
(FPCore (x y) :precision binary64 (if (<= y -6.8e+23) (/ x (* y 0.01)) (if (<= y 1.4e-61) 100.0 (/ 100.0 (/ y x)))))
double code(double x, double y) {
double tmp;
if (y <= -6.8e+23) {
tmp = x / (y * 0.01);
} else if (y <= 1.4e-61) {
tmp = 100.0;
} else {
tmp = 100.0 / (y / x);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-6.8d+23)) then
tmp = x / (y * 0.01d0)
else if (y <= 1.4d-61) then
tmp = 100.0d0
else
tmp = 100.0d0 / (y / x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -6.8e+23) {
tmp = x / (y * 0.01);
} else if (y <= 1.4e-61) {
tmp = 100.0;
} else {
tmp = 100.0 / (y / x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -6.8e+23: tmp = x / (y * 0.01) elif y <= 1.4e-61: tmp = 100.0 else: tmp = 100.0 / (y / x) return tmp
function code(x, y) tmp = 0.0 if (y <= -6.8e+23) tmp = Float64(x / Float64(y * 0.01)); elseif (y <= 1.4e-61) tmp = 100.0; else tmp = Float64(100.0 / Float64(y / x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -6.8e+23) tmp = x / (y * 0.01); elseif (y <= 1.4e-61) tmp = 100.0; else tmp = 100.0 / (y / x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -6.8e+23], N[(x / N[(y * 0.01), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.4e-61], 100.0, N[(100.0 / N[(y / x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.8 \cdot 10^{+23}:\\
\;\;\;\;\frac{x}{y \cdot 0.01}\\
\mathbf{elif}\;y \leq 1.4 \cdot 10^{-61}:\\
\;\;\;\;100\\
\mathbf{else}:\\
\;\;\;\;\frac{100}{\frac{y}{x}}\\
\end{array}
\end{array}
if y < -6.79999999999999983e23Initial program 99.7%
associate-/l*99.8%
*-commutative99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 78.9%
associate-*r/79.1%
*-commutative79.1%
associate-*r/79.1%
metadata-eval79.1%
associate-/r*79.1%
*-commutative79.1%
associate-*r/79.1%
*-rgt-identity79.1%
Simplified79.1%
if -6.79999999999999983e23 < y < 1.4000000000000001e-61Initial program 98.9%
*-commutative98.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around inf 77.6%
if 1.4000000000000001e-61 < y Initial program 99.7%
*-commutative99.7%
associate-/l*99.7%
Simplified99.7%
clear-num99.8%
un-div-inv99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 73.8%
associate-*r/73.7%
metadata-eval73.7%
associate-/r/73.6%
associate-/r*73.7%
*-commutative73.7%
associate-*r/73.7%
*-commutative73.7%
associate-*r/73.7%
associate-/r*73.9%
metadata-eval73.9%
Simplified73.9%
Final simplification76.9%
(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.3%
*-commutative99.3%
associate-/l*99.8%
Simplified99.8%
Final simplification99.8%
(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.3%
associate-/l*99.8%
*-commutative99.8%
Applied egg-rr99.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 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 2024115
(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)))