
(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 9 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 (fma (sqrt x) (- y) x)))
double code(double x, double y) {
return 1.0 - fma(sqrt(x), -y, x);
}
function code(x, y) return Float64(1.0 - fma(sqrt(x), Float64(-y), x)) end
code[x_, y_] := N[(1.0 - N[(N[Sqrt[x], $MachinePrecision] * (-y) + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 - \mathsf{fma}\left(\sqrt{x}, -y, x\right)
\end{array}
Initial program 99.9%
lift-+.f64N/A
lift--.f64N/A
associate-+l-N/A
lower--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lower-neg.f6499.9
Applied rewrites99.9%
(FPCore (x y)
:precision binary64
(let* ((t_0 (+ (- 1.0 x) (* (sqrt x) y))))
(if (<= t_0 -2e+15)
(fma (sqrt x) y (- x))
(if (<= t_0 0.9999999999996) (- 1.0 x) (fma (sqrt x) y 1.0)))))
double code(double x, double y) {
double t_0 = (1.0 - x) + (sqrt(x) * y);
double tmp;
if (t_0 <= -2e+15) {
tmp = fma(sqrt(x), y, -x);
} else if (t_0 <= 0.9999999999996) {
tmp = 1.0 - x;
} else {
tmp = fma(sqrt(x), y, 1.0);
}
return tmp;
}
function code(x, y) t_0 = Float64(Float64(1.0 - x) + Float64(sqrt(x) * y)) tmp = 0.0 if (t_0 <= -2e+15) tmp = fma(sqrt(x), y, Float64(-x)); elseif (t_0 <= 0.9999999999996) tmp = Float64(1.0 - x); else tmp = fma(sqrt(x), y, 1.0); end return tmp end
code[x_, y_] := Block[{t$95$0 = N[(N[(1.0 - x), $MachinePrecision] + N[(N[Sqrt[x], $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e+15], N[(N[Sqrt[x], $MachinePrecision] * y + (-x)), $MachinePrecision], If[LessEqual[t$95$0, 0.9999999999996], N[(1.0 - x), $MachinePrecision], N[(N[Sqrt[x], $MachinePrecision] * y + 1.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - x\right) + \sqrt{x} \cdot y\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{+15}:\\
\;\;\;\;\mathsf{fma}\left(\sqrt{x}, y, -x\right)\\
\mathbf{elif}\;t\_0 \leq 0.9999999999996:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sqrt{x}, y, 1\right)\\
\end{array}
\end{array}
if (+.f64 (-.f64 #s(literal 1 binary64) x) (*.f64 y (sqrt.f64 x))) < -2e15Initial program 99.9%
Taylor expanded in x around inf
sub-negN/A
metadata-evalN/A
+-commutativeN/A
distribute-rgt-inN/A
cancel-sign-subN/A
distribute-rgt-neg-outN/A
mul-1-negN/A
rem-square-sqrtN/A
unpow2N/A
*-commutativeN/A
distribute-rgt-out--N/A
unsub-negN/A
metadata-evalN/A
distribute-neg-inN/A
lower-*.f64N/A
Applied rewrites95.1%
Applied rewrites99.9%
if -2e15 < (+.f64 (-.f64 #s(literal 1 binary64) x) (*.f64 y (sqrt.f64 x))) < 0.999999999999599987Initial program 99.9%
Taylor expanded in y around 0
lower--.f6491.3
Applied rewrites91.3%
if 0.999999999999599987 < (+.f64 (-.f64 #s(literal 1 binary64) x) (*.f64 y (sqrt.f64 x))) Initial program 99.8%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
lower-sqrt.f6499.4
Applied rewrites99.4%
Final simplification99.2%
(FPCore (x y) :precision binary64 (if (<= (+ (- 1.0 x) (* (sqrt x) y)) -500.0) (- x) 1.0))
double code(double x, double y) {
double tmp;
if (((1.0 - x) + (sqrt(x) * y)) <= -500.0) {
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 (((1.0d0 - x) + (sqrt(x) * y)) <= (-500.0d0)) then
tmp = -x
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (((1.0 - x) + (Math.sqrt(x) * y)) <= -500.0) {
tmp = -x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if ((1.0 - x) + (math.sqrt(x) * y)) <= -500.0: tmp = -x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (Float64(Float64(1.0 - x) + Float64(sqrt(x) * y)) <= -500.0) tmp = Float64(-x); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((1.0 - x) + (sqrt(x) * y)) <= -500.0) tmp = -x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(N[(1.0 - x), $MachinePrecision] + N[(N[Sqrt[x], $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], -500.0], (-x), 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(1 - x\right) + \sqrt{x} \cdot y \leq -500:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if (+.f64 (-.f64 #s(literal 1 binary64) x) (*.f64 y (sqrt.f64 x))) < -500Initial program 99.9%
Taylor expanded in y around 0
lower--.f6461.5
Applied rewrites61.5%
Taylor expanded in x around inf
Applied rewrites59.9%
if -500 < (+.f64 (-.f64 #s(literal 1 binary64) x) (*.f64 y (sqrt.f64 x))) Initial program 99.8%
Taylor expanded in y around 0
lower--.f6459.8
Applied rewrites59.8%
Taylor expanded in x around 0
Applied rewrites57.5%
Final simplification58.7%
(FPCore (x y) :precision binary64 (let* ((t_0 (fma (sqrt x) y 1.0))) (if (<= y -8.6e+52) t_0 (if (<= y 8e+50) (- 1.0 x) t_0))))
double code(double x, double y) {
double t_0 = fma(sqrt(x), y, 1.0);
double tmp;
if (y <= -8.6e+52) {
tmp = t_0;
} else if (y <= 8e+50) {
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 <= -8.6e+52) tmp = t_0; elseif (y <= 8e+50) 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, -8.6e+52], t$95$0, If[LessEqual[y, 8e+50], 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 -8.6 \cdot 10^{+52}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 8 \cdot 10^{+50}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -8.5999999999999999e52 or 8.0000000000000006e50 < y Initial program 99.7%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
lower-sqrt.f6493.4
Applied rewrites93.4%
if -8.5999999999999999e52 < y < 8.0000000000000006e50Initial program 100.0%
Taylor expanded in y around 0
lower--.f6497.1
Applied rewrites97.1%
(FPCore (x y) :precision binary64 (let* ((t_0 (* (sqrt x) y))) (if (<= y -5.2e+53) t_0 (if (<= y 8.6e+82) (- 1.0 x) t_0))))
double code(double x, double y) {
double t_0 = sqrt(x) * y;
double tmp;
if (y <= -5.2e+53) {
tmp = t_0;
} else if (y <= 8.6e+82) {
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 = sqrt(x) * y
if (y <= (-5.2d+53)) then
tmp = t_0
else if (y <= 8.6d+82) 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 = Math.sqrt(x) * y;
double tmp;
if (y <= -5.2e+53) {
tmp = t_0;
} else if (y <= 8.6e+82) {
tmp = 1.0 - x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = math.sqrt(x) * y tmp = 0 if y <= -5.2e+53: tmp = t_0 elif y <= 8.6e+82: tmp = 1.0 - x else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(sqrt(x) * y) tmp = 0.0 if (y <= -5.2e+53) tmp = t_0; elseif (y <= 8.6e+82) tmp = Float64(1.0 - x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = sqrt(x) * y; tmp = 0.0; if (y <= -5.2e+53) tmp = t_0; elseif (y <= 8.6e+82) tmp = 1.0 - x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[Sqrt[x], $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -5.2e+53], t$95$0, If[LessEqual[y, 8.6e+82], N[(1.0 - x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{x} \cdot y\\
\mathbf{if}\;y \leq -5.2 \cdot 10^{+53}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 8.6 \cdot 10^{+82}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -5.19999999999999996e53 or 8.60000000000000029e82 < y Initial program 99.7%
Taylor expanded in y around inf
lower-*.f64N/A
lower-sqrt.f6490.1
Applied rewrites90.1%
if -5.19999999999999996e53 < y < 8.60000000000000029e82Initial program 100.0%
Taylor expanded in y around 0
lower--.f6494.8
Applied rewrites94.8%
(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%
lift-+.f64N/A
lift--.f64N/A
associate-+l-N/A
lower--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lower-neg.f6499.9
Applied rewrites99.9%
lift--.f64N/A
lift-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lift-neg.f64N/A
cancel-sign-sub-invN/A
associate-+l-N/A
lift--.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6499.9
Applied rewrites99.9%
(FPCore (x y) :precision binary64 (- (fma y (sqrt x) 1.0) x))
double code(double x, double y) {
return fma(y, sqrt(x), 1.0) - x;
}
function code(x, y) return Float64(fma(y, sqrt(x), 1.0) - x) end
code[x_, y_] := N[(N[(y * N[Sqrt[x], $MachinePrecision] + 1.0), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, \sqrt{x}, 1\right) - x
\end{array}
Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift--.f64N/A
associate-+r-N/A
lower--.f64N/A
lift-*.f64N/A
lower-fma.f6499.9
Applied rewrites99.9%
(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
lower--.f6460.6
Applied rewrites60.6%
(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
lower--.f6460.6
Applied rewrites60.6%
Taylor expanded in x around 0
Applied rewrites29.7%
herbie shell --seed 2024233
(FPCore (x y)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, E"
:precision binary64
(+ (- 1.0 x) (* y (sqrt x))))