
(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 10 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 (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
+-commutativeN/A
mul-1-negN/A
sub-negN/A
associate-+l-N/A
sub-negN/A
*-lft-identityN/A
lft-mult-inverseN/A
distribute-lft-neg-outN/A
distribute-rgt-inN/A
sub-negN/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
distribute-rgt-neg-outN/A
rgt-mult-inverseN/A
metadata-evalN/A
*-rgt-identityN/A
associate--r+N/A
Simplified99.9%
associate--l+N/A
accelerator-lowering-fma.f64N/A
sqrt-lowering-sqrt.f64N/A
--lowering--.f6499.9
Applied egg-rr99.9%
(FPCore (x y) :precision binary64 (if (<= (+ (- 1.0 x) (* (sqrt x) y)) -10000.0) (- x) (+ x 1.0)))
double code(double x, double y) {
double tmp;
if (((1.0 - x) + (sqrt(x) * y)) <= -10000.0) {
tmp = -x;
} else {
tmp = 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 (((1.0d0 - x) + (sqrt(x) * y)) <= (-10000.0d0)) then
tmp = -x
else
tmp = x + 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)) <= -10000.0) {
tmp = -x;
} else {
tmp = x + 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if ((1.0 - x) + (math.sqrt(x) * y)) <= -10000.0: tmp = -x else: tmp = x + 1.0 return tmp
function code(x, y) tmp = 0.0 if (Float64(Float64(1.0 - x) + Float64(sqrt(x) * y)) <= -10000.0) tmp = Float64(-x); else tmp = Float64(x + 1.0); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((1.0 - x) + (sqrt(x) * y)) <= -10000.0) tmp = -x; else tmp = x + 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], -10000.0], (-x), N[(x + 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(1 - x\right) + \sqrt{x} \cdot y \leq -10000:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;x + 1\\
\end{array}
\end{array}
if (+.f64 (-.f64 #s(literal 1 binary64) x) (*.f64 y (sqrt.f64 x))) < -1e4Initial program 99.9%
Taylor expanded in y around 0
--lowering--.f6461.9
Simplified61.9%
Taylor expanded in x around inf
mul-1-negN/A
neg-lowering-neg.f6461.5
Simplified61.5%
if -1e4 < (+.f64 (-.f64 #s(literal 1 binary64) x) (*.f64 y (sqrt.f64 x))) Initial program 99.9%
Taylor expanded in y around 0
--lowering--.f6464.4
Simplified64.4%
sub-negN/A
flip3-+N/A
metadata-evalN/A
cube-negN/A
sub-negN/A
metadata-evalN/A
sqr-powN/A
pow-prod-downN/A
sqr-negN/A
pow-prod-downN/A
sqr-powN/A
sqr-negN/A
flip3--N/A
Applied egg-rr63.4%
Final simplification62.6%
(FPCore (x y) :precision binary64 (if (<= (+ (- 1.0 x) (* (sqrt x) y)) -10000.0) (- x) 1.0))
double code(double x, double y) {
double tmp;
if (((1.0 - x) + (sqrt(x) * y)) <= -10000.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)) <= (-10000.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)) <= -10000.0) {
tmp = -x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if ((1.0 - x) + (math.sqrt(x) * y)) <= -10000.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)) <= -10000.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)) <= -10000.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], -10000.0], (-x), 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(1 - x\right) + \sqrt{x} \cdot y \leq -10000:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if (+.f64 (-.f64 #s(literal 1 binary64) x) (*.f64 y (sqrt.f64 x))) < -1e4Initial program 99.9%
Taylor expanded in y around 0
--lowering--.f6461.9
Simplified61.9%
Taylor expanded in x around inf
mul-1-negN/A
neg-lowering-neg.f6461.5
Simplified61.5%
if -1e4 < (+.f64 (-.f64 #s(literal 1 binary64) x) (*.f64 y (sqrt.f64 x))) Initial program 99.9%
Taylor expanded in y around 0
--lowering--.f6464.4
Simplified64.4%
Taylor expanded in x around 0
Simplified63.1%
Final simplification62.4%
(FPCore (x y) :precision binary64 (let* ((t_0 (fma (sqrt x) y 1.0))) (if (<= y -1.02e+18) t_0 (if (<= y 7e+55) (- 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.02e+18) {
tmp = t_0;
} else if (y <= 7e+55) {
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.02e+18) tmp = t_0; elseif (y <= 7e+55) 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.02e+18], t$95$0, If[LessEqual[y, 7e+55], 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.02 \cdot 10^{+18}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 7 \cdot 10^{+55}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.02e18 or 7.00000000000000021e55 < y Initial program 99.8%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f64N/A
sqrt-lowering-sqrt.f6494.2
Simplified94.2%
if -1.02e18 < y < 7.00000000000000021e55Initial program 100.0%
Taylor expanded in y around 0
--lowering--.f6498.5
Simplified98.5%
(FPCore (x y) :precision binary64 (let* ((t_0 (* (sqrt x) y))) (if (<= y -3.1e+98) t_0 (if (<= y 2.9e+56) (- 1.0 x) t_0))))
double code(double x, double y) {
double t_0 = sqrt(x) * y;
double tmp;
if (y <= -3.1e+98) {
tmp = t_0;
} else if (y <= 2.9e+56) {
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 <= (-3.1d+98)) then
tmp = t_0
else if (y <= 2.9d+56) 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 <= -3.1e+98) {
tmp = t_0;
} else if (y <= 2.9e+56) {
tmp = 1.0 - x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = math.sqrt(x) * y tmp = 0 if y <= -3.1e+98: tmp = t_0 elif y <= 2.9e+56: 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 <= -3.1e+98) tmp = t_0; elseif (y <= 2.9e+56) 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 <= -3.1e+98) tmp = t_0; elseif (y <= 2.9e+56) 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, -3.1e+98], t$95$0, If[LessEqual[y, 2.9e+56], N[(1.0 - x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{x} \cdot y\\
\mathbf{if}\;y \leq -3.1 \cdot 10^{+98}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 2.9 \cdot 10^{+56}:\\
\;\;\;\;1 - x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -3.10000000000000019e98 or 2.90000000000000007e56 < y Initial program 99.7%
Taylor expanded in y around inf
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f6490.5
Simplified90.5%
if -3.10000000000000019e98 < y < 2.90000000000000007e56Initial program 100.0%
Taylor expanded in y around 0
--lowering--.f6493.5
Simplified93.5%
(FPCore (x y) :precision binary64 (if (<= x 0.12) (fma (sqrt x) y 1.0) (fma (sqrt x) y (- x))))
double code(double x, double y) {
double tmp;
if (x <= 0.12) {
tmp = fma(sqrt(x), y, 1.0);
} else {
tmp = fma(sqrt(x), y, -x);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (x <= 0.12) tmp = fma(sqrt(x), y, 1.0); else tmp = fma(sqrt(x), y, Float64(-x)); end return tmp end
code[x_, y_] := If[LessEqual[x, 0.12], N[(N[Sqrt[x], $MachinePrecision] * y + 1.0), $MachinePrecision], N[(N[Sqrt[x], $MachinePrecision] * y + (-x)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.12:\\
\;\;\;\;\mathsf{fma}\left(\sqrt{x}, y, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sqrt{x}, y, -x\right)\\
\end{array}
\end{array}
if x < 0.12Initial program 99.8%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f64N/A
sqrt-lowering-sqrt.f6497.9
Simplified97.9%
if 0.12 < x Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
+-commutativeN/A
mul-1-negN/A
sub-negN/A
associate-+l-N/A
sub-negN/A
*-lft-identityN/A
lft-mult-inverseN/A
distribute-lft-neg-outN/A
distribute-rgt-inN/A
sub-negN/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
distribute-rgt-neg-outN/A
rgt-mult-inverseN/A
metadata-evalN/A
*-rgt-identityN/A
associate--r+N/A
Simplified99.9%
Taylor expanded in x around inf
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f6499.0
Simplified99.0%
sub-negN/A
accelerator-lowering-fma.f64N/A
sqrt-lowering-sqrt.f64N/A
neg-lowering-neg.f6499.1
Applied egg-rr99.1%
(FPCore (x y) :precision binary64 (if (<= x 0.12) (fma (sqrt x) y 1.0) (- (* (sqrt x) y) x)))
double code(double x, double y) {
double tmp;
if (x <= 0.12) {
tmp = fma(sqrt(x), y, 1.0);
} else {
tmp = (sqrt(x) * y) - x;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (x <= 0.12) tmp = fma(sqrt(x), y, 1.0); else tmp = Float64(Float64(sqrt(x) * y) - x); end return tmp end
code[x_, y_] := If[LessEqual[x, 0.12], N[(N[Sqrt[x], $MachinePrecision] * y + 1.0), $MachinePrecision], N[(N[(N[Sqrt[x], $MachinePrecision] * y), $MachinePrecision] - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.12:\\
\;\;\;\;\mathsf{fma}\left(\sqrt{x}, y, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x} \cdot y - x\\
\end{array}
\end{array}
if x < 0.12Initial program 99.8%
Taylor expanded in x around 0
+-commutativeN/A
accelerator-lowering-fma.f64N/A
sqrt-lowering-sqrt.f6497.9
Simplified97.9%
if 0.12 < x Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
+-commutativeN/A
mul-1-negN/A
sub-negN/A
associate-+l-N/A
sub-negN/A
*-lft-identityN/A
lft-mult-inverseN/A
distribute-lft-neg-outN/A
distribute-rgt-inN/A
sub-negN/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
distribute-rgt-neg-outN/A
rgt-mult-inverseN/A
metadata-evalN/A
*-rgt-identityN/A
associate--r+N/A
Simplified99.9%
Taylor expanded in x around inf
*-lowering-*.f64N/A
sqrt-lowering-sqrt.f6499.0
Simplified99.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 Float64(fma(sqrt(x), y, 1.0) - x) end
code[x_, y_] := N[(N[(N[Sqrt[x], $MachinePrecision] * y + 1.0), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sqrt{x}, y, 1\right) - x
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
+-commutativeN/A
mul-1-negN/A
sub-negN/A
associate-+l-N/A
sub-negN/A
*-lft-identityN/A
lft-mult-inverseN/A
distribute-lft-neg-outN/A
distribute-rgt-inN/A
sub-negN/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
distribute-rgt-neg-outN/A
rgt-mult-inverseN/A
metadata-evalN/A
*-rgt-identityN/A
associate--r+N/A
Simplified99.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
--lowering--.f6463.2
Simplified63.2%
(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--.f6463.2
Simplified63.2%
Taylor expanded in x around 0
Simplified35.0%
herbie shell --seed 2024204
(FPCore (x y)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, E"
:precision binary64
(+ (- 1.0 x) (* y (sqrt x))))