
(FPCore (x y) :precision binary64 (/ (* x (+ (/ x y) 1.0)) (+ x 1.0)))
double code(double x, double y) {
return (x * ((x / y) + 1.0)) / (x + 1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * ((x / y) + 1.0d0)) / (x + 1.0d0)
end function
public static double code(double x, double y) {
return (x * ((x / y) + 1.0)) / (x + 1.0);
}
def code(x, y): return (x * ((x / y) + 1.0)) / (x + 1.0)
function code(x, y) return Float64(Float64(x * Float64(Float64(x / y) + 1.0)) / Float64(x + 1.0)) end
function tmp = code(x, y) tmp = (x * ((x / y) + 1.0)) / (x + 1.0); end
code[x_, y_] := N[(N[(x * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ (* x (+ (/ x y) 1.0)) (+ x 1.0)))
double code(double x, double y) {
return (x * ((x / y) + 1.0)) / (x + 1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * ((x / y) + 1.0d0)) / (x + 1.0d0)
end function
public static double code(double x, double y) {
return (x * ((x / y) + 1.0)) / (x + 1.0);
}
def code(x, y): return (x * ((x / y) + 1.0)) / (x + 1.0)
function code(x, y) return Float64(Float64(x * Float64(Float64(x / y) + 1.0)) / Float64(x + 1.0)) end
function tmp = code(x, y) tmp = (x * ((x / y) + 1.0)) / (x + 1.0); end
code[x_, y_] := N[(N[(x * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}
\end{array}
(FPCore (x y) :precision binary64 (* x (/ (+ (/ x y) 1.0) (+ x 1.0))))
double code(double x, double y) {
return x * (((x / y) + 1.0) / (x + 1.0));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * (((x / y) + 1.0d0) / (x + 1.0d0))
end function
public static double code(double x, double y) {
return x * (((x / y) + 1.0) / (x + 1.0));
}
def code(x, y): return x * (((x / y) + 1.0) / (x + 1.0))
function code(x, y) return Float64(x * Float64(Float64(Float64(x / y) + 1.0) / Float64(x + 1.0))) end
function tmp = code(x, y) tmp = x * (((x / y) + 1.0) / (x + 1.0)); end
code[x_, y_] := N[(x * N[(N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \frac{\frac{x}{y} + 1}{x + 1}
\end{array}
Initial program 88.2%
associate-/l*99.8%
Simplified99.8%
(FPCore (x y) :precision binary64 (if (or (<= x -500000000.0) (not (<= x 380000.0))) (+ (/ x y) 1.0) (/ x (+ x 1.0))))
double code(double x, double y) {
double tmp;
if ((x <= -500000000.0) || !(x <= 380000.0)) {
tmp = (x / y) + 1.0;
} else {
tmp = x / (x + 1.0);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-500000000.0d0)) .or. (.not. (x <= 380000.0d0))) then
tmp = (x / y) + 1.0d0
else
tmp = x / (x + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -500000000.0) || !(x <= 380000.0)) {
tmp = (x / y) + 1.0;
} else {
tmp = x / (x + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -500000000.0) or not (x <= 380000.0): tmp = (x / y) + 1.0 else: tmp = x / (x + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((x <= -500000000.0) || !(x <= 380000.0)) tmp = Float64(Float64(x / y) + 1.0); else tmp = Float64(x / Float64(x + 1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -500000000.0) || ~((x <= 380000.0))) tmp = (x / y) + 1.0; else tmp = x / (x + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -500000000.0], N[Not[LessEqual[x, 380000.0]], $MachinePrecision]], N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision], N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -500000000 \lor \neg \left(x \leq 380000\right):\\
\;\;\;\;\frac{x}{y} + 1\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{x + 1}\\
\end{array}
\end{array}
if x < -5e8 or 3.8e5 < x Initial program 76.3%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around 0 68.2%
*-commutative68.2%
+-commutative68.2%
associate-/l*71.4%
+-commutative71.4%
unpow271.4%
+-commutative71.4%
associate-/l*100.0%
+-commutative100.0%
distribute-rgt-out100.0%
Simplified100.0%
Taylor expanded in x around inf 99.5%
Taylor expanded in y around 0 99.5%
+-commutative99.5%
*-lft-identity99.5%
associate-*l/99.1%
+-commutative99.1%
distribute-lft-in99.2%
associate-*l/99.5%
*-lft-identity99.5%
lft-mult-inverse99.5%
Simplified99.5%
if -5e8 < x < 3.8e5Initial program 99.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in y around inf 76.9%
Final simplification88.1%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 4.1e-8))) (+ (/ x y) 1.0) x))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 4.1e-8)) {
tmp = (x / y) + 1.0;
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-1.0d0)) .or. (.not. (x <= 4.1d-8))) then
tmp = (x / y) + 1.0d0
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 4.1e-8)) {
tmp = (x / y) + 1.0;
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.0) or not (x <= 4.1e-8): tmp = (x / y) + 1.0 else: tmp = x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 4.1e-8)) tmp = Float64(Float64(x / y) + 1.0); else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1.0) || ~((x <= 4.1e-8))) tmp = (x / y) + 1.0; else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 4.1e-8]], $MachinePrecision]], N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 4.1 \cdot 10^{-8}\right):\\
\;\;\;\;\frac{x}{y} + 1\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1 or 4.10000000000000032e-8 < x Initial program 77.5%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around 0 69.8%
*-commutative69.8%
+-commutative69.8%
associate-/l*72.9%
+-commutative72.9%
unpow272.9%
+-commutative72.9%
associate-/l*100.0%
+-commutative100.0%
distribute-rgt-out100.0%
Simplified100.0%
Taylor expanded in x around inf 95.8%
Taylor expanded in y around 0 95.8%
+-commutative95.8%
*-lft-identity95.8%
associate-*l/95.5%
+-commutative95.5%
distribute-lft-in95.5%
associate-*l/95.8%
*-lft-identity95.8%
lft-mult-inverse95.8%
Simplified95.8%
if -1 < x < 4.10000000000000032e-8Initial program 99.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around 0 77.8%
Final simplification87.2%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 4.1e-8))) (/ x y) x))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 4.1e-8)) {
tmp = x / y;
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-1.0d0)) .or. (.not. (x <= 4.1d-8))) then
tmp = x / y
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 4.1e-8)) {
tmp = x / y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.0) or not (x <= 4.1e-8): tmp = x / y else: tmp = x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 4.1e-8)) tmp = Float64(x / y); else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1.0) || ~((x <= 4.1e-8))) tmp = x / y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 4.1e-8]], $MachinePrecision]], N[(x / y), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 4.1 \cdot 10^{-8}\right):\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1 or 4.10000000000000032e-8 < x Initial program 77.5%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in x around inf 75.9%
if -1 < x < 4.10000000000000032e-8Initial program 99.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around 0 77.8%
Final simplification76.8%
(FPCore (x y) :precision binary64 (if (<= x -3.8e-5) 1.0 (if (<= x 4.1e-8) x 1.0)))
double code(double x, double y) {
double tmp;
if (x <= -3.8e-5) {
tmp = 1.0;
} else if (x <= 4.1e-8) {
tmp = x;
} else {
tmp = 1.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.8d-5)) then
tmp = 1.0d0
else if (x <= 4.1d-8) then
tmp = x
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -3.8e-5) {
tmp = 1.0;
} else if (x <= 4.1e-8) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3.8e-5: tmp = 1.0 elif x <= 4.1e-8: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (x <= -3.8e-5) tmp = 1.0; elseif (x <= 4.1e-8) tmp = x; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -3.8e-5) tmp = 1.0; elseif (x <= 4.1e-8) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3.8e-5], 1.0, If[LessEqual[x, 4.1e-8], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.8 \cdot 10^{-5}:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 4.1 \cdot 10^{-8}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -3.8000000000000002e-5 or 4.10000000000000032e-8 < x Initial program 77.9%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around 0 70.3%
*-commutative70.3%
+-commutative70.3%
associate-/l*73.3%
+-commutative73.3%
unpow273.3%
+-commutative73.3%
associate-/l*100.0%
+-commutative100.0%
distribute-rgt-out100.0%
Simplified100.0%
Taylor expanded in x around inf 94.4%
Taylor expanded in y around inf 21.2%
if -3.8000000000000002e-5 < x < 4.10000000000000032e-8Initial program 99.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around 0 79.0%
(FPCore (x y) :precision binary64 1.0)
double code(double x, double y) {
return 1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0
end function
public static double code(double x, double y) {
return 1.0;
}
def code(x, y): return 1.0
function code(x, y) return 1.0 end
function tmp = code(x, y) tmp = 1.0; end
code[x_, y_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 88.2%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in y around 0 75.6%
*-commutative75.6%
+-commutative75.6%
associate-/l*77.2%
+-commutative77.2%
unpow277.2%
+-commutative77.2%
associate-/l*91.4%
+-commutative91.4%
distribute-rgt-out91.4%
Simplified91.4%
Taylor expanded in x around inf 51.8%
Taylor expanded in y around inf 12.9%
(FPCore (x y) :precision binary64 (* (/ x 1.0) (/ (+ (/ x y) 1.0) (+ x 1.0))))
double code(double x, double y) {
return (x / 1.0) * (((x / y) + 1.0) / (x + 1.0));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x / 1.0d0) * (((x / y) + 1.0d0) / (x + 1.0d0))
end function
public static double code(double x, double y) {
return (x / 1.0) * (((x / y) + 1.0) / (x + 1.0));
}
def code(x, y): return (x / 1.0) * (((x / y) + 1.0) / (x + 1.0))
function code(x, y) return Float64(Float64(x / 1.0) * Float64(Float64(Float64(x / y) + 1.0) / Float64(x + 1.0))) end
function tmp = code(x, y) tmp = (x / 1.0) * (((x / y) + 1.0) / (x + 1.0)); end
code[x_, y_] := N[(N[(x / 1.0), $MachinePrecision] * N[(N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{1} \cdot \frac{\frac{x}{y} + 1}{x + 1}
\end{array}
herbie shell --seed 2024096
(FPCore (x y)
:name "Codec.Picture.Types:toneMapping from JuicyPixels-3.2.6.1"
:precision binary64
:alt
(* (/ x 1.0) (/ (+ (/ x y) 1.0) (+ x 1.0)))
(/ (* x (+ (/ x y) 1.0)) (+ x 1.0)))