
(FPCore (x y) :precision binary64 (+ (- 1.0 x) (* y (sqrt x))))
double code(double x, double y) {
return (1.0 - x) + (y * sqrt(x));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (1.0d0 - x) + (y * sqrt(x))
end function
public static double code(double x, double y) {
return (1.0 - x) + (y * Math.sqrt(x));
}
def code(x, y): return (1.0 - x) + (y * math.sqrt(x))
function code(x, y) return Float64(Float64(1.0 - x) + Float64(y * sqrt(x))) end
function tmp = code(x, y) tmp = (1.0 - x) + (y * sqrt(x)); end
code[x_, y_] := N[(N[(1.0 - x), $MachinePrecision] + N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(1 - x\right) + y \cdot \sqrt{x}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (+ (- 1.0 x) (* y (sqrt x))))
double code(double x, double y) {
return (1.0 - x) + (y * sqrt(x));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (1.0d0 - x) + (y * sqrt(x))
end function
public static double code(double x, double y) {
return (1.0 - x) + (y * Math.sqrt(x));
}
def code(x, y): return (1.0 - x) + (y * math.sqrt(x))
function code(x, y) return Float64(Float64(1.0 - x) + Float64(y * sqrt(x))) end
function tmp = code(x, y) tmp = (1.0 - x) + (y * sqrt(x)); end
code[x_, y_] := N[(N[(1.0 - x), $MachinePrecision] + N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(1 - x\right) + y \cdot \sqrt{x}
\end{array}
(FPCore (x y) :precision binary64 (+ (- 1.0 x) (* y (sqrt x))))
double code(double x, double y) {
return (1.0 - x) + (y * sqrt(x));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (1.0d0 - x) + (y * sqrt(x))
end function
public static double code(double x, double y) {
return (1.0 - x) + (y * Math.sqrt(x));
}
def code(x, y): return (1.0 - x) + (y * math.sqrt(x))
function code(x, y) return Float64(Float64(1.0 - x) + Float64(y * sqrt(x))) end
function tmp = code(x, y) tmp = (1.0 - x) + (y * sqrt(x)); end
code[x_, y_] := N[(N[(1.0 - x), $MachinePrecision] + N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(1 - x\right) + y \cdot \sqrt{x}
\end{array}
Initial program 99.9%
(FPCore (x y) :precision binary64 (if (<= y -1.12e+17) (+ 1.0 (* y (sqrt x))) (if (<= y 4.1e+29) (- 1.0 x) (fma (sqrt x) y 1.0))))
double code(double x, double y) {
double tmp;
if (y <= -1.12e+17) {
tmp = 1.0 + (y * sqrt(x));
} else if (y <= 4.1e+29) {
tmp = 1.0 - x;
} else {
tmp = fma(sqrt(x), y, 1.0);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (y <= -1.12e+17) tmp = Float64(1.0 + Float64(y * sqrt(x))); elseif (y <= 4.1e+29) tmp = Float64(1.0 - x); else tmp = fma(sqrt(x), y, 1.0); end return tmp end
code[x_, y_] := If[LessEqual[y, -1.12e+17], N[(1.0 + N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 4.1e+29], N[(1.0 - x), $MachinePrecision], N[(N[Sqrt[x], $MachinePrecision] * y + 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.12 \cdot 10^{+17}:\\
\;\;\;\;1 + y \cdot \sqrt{x}\\
\mathbf{elif}\;y \leq 4.1 \cdot 10^{+29}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sqrt{x}, y, 1\right)\\
\end{array}
\end{array}
if y < -1.12e17Initial program 99.8%
Taylor expanded in x around 0
Simplified90.3%
if -1.12e17 < y < 4.1000000000000003e29Initial program 100.0%
Taylor expanded in y around 0
--lowering--.f64100.0%
Simplified100.0%
if 4.1000000000000003e29 < y Initial program 99.8%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f64N/A
sqrt-lowering-sqrt.f6492.8%
Simplified92.8%
(FPCore (x y) :precision binary64 (let* ((t_0 (fma (sqrt x) y 1.0))) (if (<= y -1.12e+17) t_0 (if (<= y 4.9e+29) (- 1.0 x) t_0))))
double code(double x, double y) {
double t_0 = fma(sqrt(x), y, 1.0);
double tmp;
if (y <= -1.12e+17) {
tmp = t_0;
} else if (y <= 4.9e+29) {
tmp = 1.0 - x;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y) t_0 = fma(sqrt(x), y, 1.0) tmp = 0.0 if (y <= -1.12e+17) tmp = t_0; elseif (y <= 4.9e+29) tmp = Float64(1.0 - x); else tmp = t_0; end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[Sqrt[x], $MachinePrecision] * y + 1.0), $MachinePrecision]}, If[LessEqual[y, -1.12e+17], t$95$0, If[LessEqual[y, 4.9e+29], N[(1.0 - x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\sqrt{x}, y, 1\right)\\
\mathbf{if}\;y \leq -1.12 \cdot 10^{+17}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 4.9 \cdot 10^{+29}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.12e17 or 4.9000000000000001e29 < y Initial program 99.8%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f64N/A
sqrt-lowering-sqrt.f6491.5%
Simplified91.5%
if -1.12e17 < y < 4.9000000000000001e29Initial program 100.0%
Taylor expanded in y around 0
--lowering--.f64100.0%
Simplified100.0%
(FPCore (x y) :precision binary64 (let* ((t_0 (* y (sqrt x)))) (if (<= y -1.4e+116) t_0 (if (<= y 1.5e+55) (- 1.0 x) t_0))))
double code(double x, double y) {
double t_0 = y * sqrt(x);
double tmp;
if (y <= -1.4e+116) {
tmp = t_0;
} else if (y <= 1.5e+55) {
tmp = 1.0 - x;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = y * sqrt(x)
if (y <= (-1.4d+116)) then
tmp = t_0
else if (y <= 1.5d+55) then
tmp = 1.0d0 - x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = y * Math.sqrt(x);
double tmp;
if (y <= -1.4e+116) {
tmp = t_0;
} else if (y <= 1.5e+55) {
tmp = 1.0 - x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = y * math.sqrt(x) tmp = 0 if y <= -1.4e+116: tmp = t_0 elif y <= 1.5e+55: tmp = 1.0 - x else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(y * sqrt(x)) tmp = 0.0 if (y <= -1.4e+116) tmp = t_0; elseif (y <= 1.5e+55) tmp = Float64(1.0 - x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = y * sqrt(x); tmp = 0.0; if (y <= -1.4e+116) tmp = t_0; elseif (y <= 1.5e+55) tmp = 1.0 - x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(y * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.4e+116], t$95$0, If[LessEqual[y, 1.5e+55], N[(1.0 - x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \sqrt{x}\\
\mathbf{if}\;y \leq -1.4 \cdot 10^{+116}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.5 \cdot 10^{+55}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.40000000000000002e116 or 1.50000000000000008e55 < y Initial program 99.8%
Taylor expanded in x around 0
+-commutativeN/A
associate-+l+N/A
*-rgt-identityN/A
*-inversesN/A
associate-/l*N/A
associate-*l/N/A
mul-1-negN/A
distribute-neg-fracN/A
+-commutativeN/A
associate-+r+N/A
lft-mult-inverseN/A
distribute-rgt-inN/A
+-commutativeN/A
sub-negN/A
div-subN/A
*-commutativeN/A
distribute-lft-inN/A
distribute-rgt-inN/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
sqrt-lowering-sqrt.f64N/A
*-commutativeN/A
div-subN/A
sub-negN/A
Simplified99.8%
Taylor expanded in y around inf
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f6494.5%
Simplified94.5%
if -1.40000000000000002e116 < y < 1.50000000000000008e55Initial program 100.0%
Taylor expanded in y around 0
--lowering--.f6492.1%
Simplified92.1%
Final simplification93.0%
(FPCore (x y) :precision binary64 (fma (sqrt x) y (- 1.0 x)))
double code(double x, double y) {
return fma(sqrt(x), y, (1.0 - x));
}
function code(x, y) return fma(sqrt(x), y, Float64(1.0 - x)) end
code[x_, y_] := N[(N[Sqrt[x], $MachinePrecision] * y + N[(1.0 - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sqrt{x}, y, 1 - x\right)
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
associate-+l+N/A
*-rgt-identityN/A
*-inversesN/A
associate-/l*N/A
associate-*l/N/A
mul-1-negN/A
distribute-neg-fracN/A
+-commutativeN/A
associate-+r+N/A
lft-mult-inverseN/A
distribute-rgt-inN/A
+-commutativeN/A
sub-negN/A
div-subN/A
*-commutativeN/A
distribute-lft-inN/A
distribute-rgt-inN/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
sqrt-lowering-sqrt.f64N/A
*-commutativeN/A
div-subN/A
sub-negN/A
Simplified99.9%
(FPCore (x y) :precision binary64 (if (<= x 1.3e-6) 1.0 (- 0.0 x)))
double code(double x, double y) {
double tmp;
if (x <= 1.3e-6) {
tmp = 1.0;
} else {
tmp = 0.0 - 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.3d-6) then
tmp = 1.0d0
else
tmp = 0.0d0 - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 1.3e-6) {
tmp = 1.0;
} else {
tmp = 0.0 - x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 1.3e-6: tmp = 1.0 else: tmp = 0.0 - x return tmp
function code(x, y) tmp = 0.0 if (x <= 1.3e-6) tmp = 1.0; else tmp = Float64(0.0 - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 1.3e-6) tmp = 1.0; else tmp = 0.0 - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 1.3e-6], 1.0, N[(0.0 - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.3 \cdot 10^{-6}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;0 - x\\
\end{array}
\end{array}
if x < 1.30000000000000005e-6Initial program 99.9%
Taylor expanded in y around 0
--lowering--.f6458.1%
Simplified58.1%
Taylor expanded in x around 0
Simplified57.9%
if 1.30000000000000005e-6 < x Initial program 99.9%
Taylor expanded in y around 0
--lowering--.f6463.1%
Simplified63.1%
Taylor expanded in x around inf
mul-1-negN/A
neg-sub0N/A
--lowering--.f6461.5%
Simplified61.5%
sub0-negN/A
neg-lowering-neg.f6461.5%
Applied egg-rr61.5%
Final simplification59.8%
(FPCore (x y) :precision binary64 (- 1.0 x))
double code(double x, double y) {
return 1.0 - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 - x
end function
public static double code(double x, double y) {
return 1.0 - x;
}
def code(x, y): return 1.0 - x
function code(x, y) return Float64(1.0 - x) end
function tmp = code(x, y) tmp = 1.0 - x; end
code[x_, y_] := N[(1.0 - x), $MachinePrecision]
\begin{array}{l}
\\
1 - x
\end{array}
Initial program 99.9%
Taylor expanded in y around 0
--lowering--.f6460.7%
Simplified60.7%
(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 99.9%
Taylor expanded in y around 0
--lowering--.f6460.7%
Simplified60.7%
Taylor expanded in x around 0
Simplified28.2%
herbie shell --seed 2024193
(FPCore (x y)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, E"
:precision binary64
(+ (- 1.0 x) (* y (sqrt x))))