
(FPCore (x y) :precision binary64 (* x (- 1.0 (* x y))))
double code(double x, double y) {
return x * (1.0 - (x * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * (1.0d0 - (x * y))
end function
public static double code(double x, double y) {
return x * (1.0 - (x * y));
}
def code(x, y): return x * (1.0 - (x * y))
function code(x, y) return Float64(x * Float64(1.0 - Float64(x * y))) end
function tmp = code(x, y) tmp = x * (1.0 - (x * y)); end
code[x_, y_] := N[(x * N[(1.0 - N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - x \cdot y\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (* x (- 1.0 (* x y))))
double code(double x, double y) {
return x * (1.0 - (x * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * (1.0d0 - (x * y))
end function
public static double code(double x, double y) {
return x * (1.0 - (x * y));
}
def code(x, y): return x * (1.0 - (x * y))
function code(x, y) return Float64(x * Float64(1.0 - Float64(x * y))) end
function tmp = code(x, y) tmp = x * (1.0 - (x * y)); end
code[x_, y_] := N[(x * N[(1.0 - N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - x \cdot y\right)
\end{array}
(FPCore (x y) :precision binary64 (- x (* x (* x y))))
double code(double x, double y) {
return x - (x * (x * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x - (x * (x * y))
end function
public static double code(double x, double y) {
return x - (x * (x * y));
}
def code(x, y): return x - (x * (x * y))
function code(x, y) return Float64(x - Float64(x * Float64(x * y))) end
function tmp = code(x, y) tmp = x - (x * (x * y)); end
code[x_, y_] := N[(x - N[(x * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - x \cdot \left(x \cdot y\right)
\end{array}
Initial program 99.9%
Taylor expanded in x around 0 91.5%
+-commutative91.5%
mul-1-neg91.5%
unpow291.5%
sub-neg91.5%
*-commutative91.5%
associate-*r*99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y)
:precision binary64
(if (or (<= y -9.4e+61)
(and (not (<= y -1.35e+31))
(or (<= y -1.85e-28) (not (<= y 4.2e-38)))))
(* x (* x (- y)))
x))
double code(double x, double y) {
double tmp;
if ((y <= -9.4e+61) || (!(y <= -1.35e+31) && ((y <= -1.85e-28) || !(y <= 4.2e-38)))) {
tmp = x * (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 ((y <= (-9.4d+61)) .or. (.not. (y <= (-1.35d+31))) .and. (y <= (-1.85d-28)) .or. (.not. (y <= 4.2d-38))) then
tmp = x * (x * -y)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -9.4e+61) || (!(y <= -1.35e+31) && ((y <= -1.85e-28) || !(y <= 4.2e-38)))) {
tmp = x * (x * -y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -9.4e+61) or (not (y <= -1.35e+31) and ((y <= -1.85e-28) or not (y <= 4.2e-38))): tmp = x * (x * -y) else: tmp = x return tmp
function code(x, y) tmp = 0.0 if ((y <= -9.4e+61) || (!(y <= -1.35e+31) && ((y <= -1.85e-28) || !(y <= 4.2e-38)))) tmp = Float64(x * Float64(x * Float64(-y))); else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -9.4e+61) || (~((y <= -1.35e+31)) && ((y <= -1.85e-28) || ~((y <= 4.2e-38))))) tmp = x * (x * -y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -9.4e+61], And[N[Not[LessEqual[y, -1.35e+31]], $MachinePrecision], Or[LessEqual[y, -1.85e-28], N[Not[LessEqual[y, 4.2e-38]], $MachinePrecision]]]], N[(x * N[(x * (-y)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.4 \cdot 10^{+61} \lor \neg \left(y \leq -1.35 \cdot 10^{+31}\right) \land \left(y \leq -1.85 \cdot 10^{-28} \lor \neg \left(y \leq 4.2 \cdot 10^{-38}\right)\right):\\
\;\;\;\;x \cdot \left(x \cdot \left(-y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -9.3999999999999997e61 or -1.34999999999999993e31 < y < -1.8500000000000001e-28 or 4.20000000000000026e-38 < y Initial program 99.9%
Taylor expanded in x around inf 72.6%
mul-1-neg72.6%
unpow272.6%
*-commutative72.6%
associate-*r*78.0%
distribute-rgt-neg-in78.0%
distribute-rgt-neg-in78.0%
Simplified78.0%
if -9.3999999999999997e61 < y < -1.34999999999999993e31 or -1.8500000000000001e-28 < y < 4.20000000000000026e-38Initial program 99.9%
Taylor expanded in x around 0 81.8%
Final simplification79.7%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* x (* x (- y)))))
(if (<= y -1.25e+62)
t_0
(if (<= y -4.9e+31)
x
(if (<= y -1.7e-28) (* (- y) (* x x)) (if (<= y 7.5e-38) x t_0))))))
double code(double x, double y) {
double t_0 = x * (x * -y);
double tmp;
if (y <= -1.25e+62) {
tmp = t_0;
} else if (y <= -4.9e+31) {
tmp = x;
} else if (y <= -1.7e-28) {
tmp = -y * (x * x);
} else if (y <= 7.5e-38) {
tmp = 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 = x * (x * -y)
if (y <= (-1.25d+62)) then
tmp = t_0
else if (y <= (-4.9d+31)) then
tmp = x
else if (y <= (-1.7d-28)) then
tmp = -y * (x * x)
else if (y <= 7.5d-38) then
tmp = x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x * (x * -y);
double tmp;
if (y <= -1.25e+62) {
tmp = t_0;
} else if (y <= -4.9e+31) {
tmp = x;
} else if (y <= -1.7e-28) {
tmp = -y * (x * x);
} else if (y <= 7.5e-38) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = x * (x * -y) tmp = 0 if y <= -1.25e+62: tmp = t_0 elif y <= -4.9e+31: tmp = x elif y <= -1.7e-28: tmp = -y * (x * x) elif y <= 7.5e-38: tmp = x else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(x * Float64(x * Float64(-y))) tmp = 0.0 if (y <= -1.25e+62) tmp = t_0; elseif (y <= -4.9e+31) tmp = x; elseif (y <= -1.7e-28) tmp = Float64(Float64(-y) * Float64(x * x)); elseif (y <= 7.5e-38) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = x * (x * -y); tmp = 0.0; if (y <= -1.25e+62) tmp = t_0; elseif (y <= -4.9e+31) tmp = x; elseif (y <= -1.7e-28) tmp = -y * (x * x); elseif (y <= 7.5e-38) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x * N[(x * (-y)), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.25e+62], t$95$0, If[LessEqual[y, -4.9e+31], x, If[LessEqual[y, -1.7e-28], N[((-y) * N[(x * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 7.5e-38], x, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(x \cdot \left(-y\right)\right)\\
\mathbf{if}\;y \leq -1.25 \cdot 10^{+62}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -4.9 \cdot 10^{+31}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq -1.7 \cdot 10^{-28}:\\
\;\;\;\;\left(-y\right) \cdot \left(x \cdot x\right)\\
\mathbf{elif}\;y \leq 7.5 \cdot 10^{-38}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -1.25000000000000007e62 or 7.5e-38 < y Initial program 99.9%
Taylor expanded in x around inf 72.6%
mul-1-neg72.6%
unpow272.6%
*-commutative72.6%
associate-*r*78.6%
distribute-rgt-neg-in78.6%
distribute-rgt-neg-in78.6%
Simplified78.6%
if -1.25000000000000007e62 < y < -4.89999999999999996e31 or -1.7e-28 < y < 7.5e-38Initial program 99.9%
Taylor expanded in x around 0 81.8%
if -4.89999999999999996e31 < y < -1.7e-28Initial program 99.6%
Taylor expanded in x around 0 99.9%
+-commutative99.9%
mul-1-neg99.9%
unpow299.9%
sub-neg99.9%
*-commutative99.9%
associate-*r*99.8%
Simplified99.8%
Taylor expanded in x around inf 72.7%
mul-1-neg72.7%
unpow272.7%
*-commutative72.7%
distribute-rgt-neg-in72.7%
Simplified72.7%
Final simplification79.7%
(FPCore (x y) :precision binary64 (* x (- 1.0 (* x y))))
double code(double x, double y) {
return x * (1.0 - (x * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * (1.0d0 - (x * y))
end function
public static double code(double x, double y) {
return x * (1.0 - (x * y));
}
def code(x, y): return x * (1.0 - (x * y))
function code(x, y) return Float64(x * Float64(1.0 - Float64(x * y))) end
function tmp = code(x, y) tmp = x * (1.0 - (x * y)); end
code[x_, y_] := N[(x * N[(1.0 - N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - x \cdot y\right)
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 x)
double code(double x, double y) {
return x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x
end function
public static double code(double x, double y) {
return x;
}
def code(x, y): return x
function code(x, y) return x end
function tmp = code(x, y) tmp = x; end
code[x_, y_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.9%
Taylor expanded in x around 0 50.5%
Final simplification50.5%
herbie shell --seed 2023240
(FPCore (x y)
:name "Numeric.SpecFunctions:log1p from math-functions-0.1.5.2, A"
:precision binary64
(* x (- 1.0 (* x y))))