
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* y z))))
double code(double x, double y, double z) {
return x * (1.0 - (y * z));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * (1.0d0 - (y * z))
end function
public static double code(double x, double y, double z) {
return x * (1.0 - (y * z));
}
def code(x, y, z): return x * (1.0 - (y * z))
function code(x, y, z) return Float64(x * Float64(1.0 - Float64(y * z))) end
function tmp = code(x, y, z) tmp = x * (1.0 - (y * z)); end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - y \cdot z\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* y z))))
double code(double x, double y, double z) {
return x * (1.0 - (y * z));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * (1.0d0 - (y * z))
end function
public static double code(double x, double y, double z) {
return x * (1.0 - (y * z));
}
def code(x, y, z): return x * (1.0 - (y * z))
function code(x, y, z) return Float64(x * Float64(1.0 - Float64(y * z))) end
function tmp = code(x, y, z) tmp = x * (1.0 - (y * z)); end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - y \cdot z\right)
\end{array}
(FPCore (x y z) :precision binary64 (if (<= (* y z) -1e+191) (* (* (- x) y) z) (* x (fma (- z) y 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -1e+191) {
tmp = (-x * y) * z;
} else {
tmp = x * fma(-z, y, 1.0);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -1e+191) tmp = Float64(Float64(Float64(-x) * y) * z); else tmp = Float64(x * fma(Float64(-z), y, 1.0)); end return tmp end
code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], -1e+191], N[(N[((-x) * y), $MachinePrecision] * z), $MachinePrecision], N[(x * N[((-z) * y + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -1 \cdot 10^{+191}:\\
\;\;\;\;\left(\left(-x\right) \cdot y\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \mathsf{fma}\left(-z, y, 1\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -1.00000000000000007e191Initial program 83.7%
Taylor expanded in y around inf
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6483.7
Applied rewrites83.7%
Applied rewrites65.1%
Taylor expanded in y around inf
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6499.8
Applied rewrites99.8%
if -1.00000000000000007e191 < (*.f64 y z) Initial program 98.5%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6498.6
Applied rewrites98.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- 1.0 (* y z)))) (if (or (<= t_0 -0.02) (not (<= t_0 2.0))) (* (* (- x) z) y) (* x 1.0))))
double code(double x, double y, double z) {
double t_0 = 1.0 - (y * z);
double tmp;
if ((t_0 <= -0.02) || !(t_0 <= 2.0)) {
tmp = (-x * z) * y;
} else {
tmp = x * 1.0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = 1.0d0 - (y * z)
if ((t_0 <= (-0.02d0)) .or. (.not. (t_0 <= 2.0d0))) then
tmp = (-x * z) * y
else
tmp = x * 1.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = 1.0 - (y * z);
double tmp;
if ((t_0 <= -0.02) || !(t_0 <= 2.0)) {
tmp = (-x * z) * y;
} else {
tmp = x * 1.0;
}
return tmp;
}
def code(x, y, z): t_0 = 1.0 - (y * z) tmp = 0 if (t_0 <= -0.02) or not (t_0 <= 2.0): tmp = (-x * z) * y else: tmp = x * 1.0 return tmp
function code(x, y, z) t_0 = Float64(1.0 - Float64(y * z)) tmp = 0.0 if ((t_0 <= -0.02) || !(t_0 <= 2.0)) tmp = Float64(Float64(Float64(-x) * z) * y); else tmp = Float64(x * 1.0); end return tmp end
function tmp_2 = code(x, y, z) t_0 = 1.0 - (y * z); tmp = 0.0; if ((t_0 <= -0.02) || ~((t_0 <= 2.0))) tmp = (-x * z) * y; else tmp = x * 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -0.02], N[Not[LessEqual[t$95$0, 2.0]], $MachinePrecision]], N[(N[((-x) * z), $MachinePrecision] * y), $MachinePrecision], N[(x * 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - y \cdot z\\
\mathbf{if}\;t\_0 \leq -0.02 \lor \neg \left(t\_0 \leq 2\right):\\
\;\;\;\;\left(\left(-x\right) \cdot z\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 y z)) < -0.0200000000000000004 or 2 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) Initial program 92.5%
Taylor expanded in y around inf
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6488.9
Applied rewrites88.9%
Applied rewrites59.6%
Taylor expanded in y around inf
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6488.6
Applied rewrites88.6%
Applied rewrites88.2%
if -0.0200000000000000004 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) < 2Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites97.0%
Final simplification92.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- 1.0 (* y z)))) (if (or (<= t_0 -0.02) (not (<= t_0 2.0))) (* (* (- x) y) z) (* x 1.0))))
double code(double x, double y, double z) {
double t_0 = 1.0 - (y * z);
double tmp;
if ((t_0 <= -0.02) || !(t_0 <= 2.0)) {
tmp = (-x * y) * z;
} else {
tmp = x * 1.0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = 1.0d0 - (y * z)
if ((t_0 <= (-0.02d0)) .or. (.not. (t_0 <= 2.0d0))) then
tmp = (-x * y) * z
else
tmp = x * 1.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = 1.0 - (y * z);
double tmp;
if ((t_0 <= -0.02) || !(t_0 <= 2.0)) {
tmp = (-x * y) * z;
} else {
tmp = x * 1.0;
}
return tmp;
}
def code(x, y, z): t_0 = 1.0 - (y * z) tmp = 0 if (t_0 <= -0.02) or not (t_0 <= 2.0): tmp = (-x * y) * z else: tmp = x * 1.0 return tmp
function code(x, y, z) t_0 = Float64(1.0 - Float64(y * z)) tmp = 0.0 if ((t_0 <= -0.02) || !(t_0 <= 2.0)) tmp = Float64(Float64(Float64(-x) * y) * z); else tmp = Float64(x * 1.0); end return tmp end
function tmp_2 = code(x, y, z) t_0 = 1.0 - (y * z); tmp = 0.0; if ((t_0 <= -0.02) || ~((t_0 <= 2.0))) tmp = (-x * y) * z; else tmp = x * 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -0.02], N[Not[LessEqual[t$95$0, 2.0]], $MachinePrecision]], N[(N[((-x) * y), $MachinePrecision] * z), $MachinePrecision], N[(x * 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - y \cdot z\\
\mathbf{if}\;t\_0 \leq -0.02 \lor \neg \left(t\_0 \leq 2\right):\\
\;\;\;\;\left(\left(-x\right) \cdot y\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 y z)) < -0.0200000000000000004 or 2 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) Initial program 92.5%
Taylor expanded in y around inf
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6488.9
Applied rewrites88.9%
Applied rewrites59.6%
Taylor expanded in y around inf
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6488.6
Applied rewrites88.6%
if -0.0200000000000000004 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) < 2Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites97.0%
Final simplification92.8%
(FPCore (x y z) :precision binary64 (if (<= (* y z) -400000.0) (* (* (- x) z) y) (if (<= (* y z) 0.04) (* x 1.0) (* x (* (- y) z)))))
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -400000.0) {
tmp = (-x * z) * y;
} else if ((y * z) <= 0.04) {
tmp = x * 1.0;
} else {
tmp = x * (-y * z);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((y * z) <= (-400000.0d0)) then
tmp = (-x * z) * y
else if ((y * z) <= 0.04d0) then
tmp = x * 1.0d0
else
tmp = x * (-y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -400000.0) {
tmp = (-x * z) * y;
} else if ((y * z) <= 0.04) {
tmp = x * 1.0;
} else {
tmp = x * (-y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y * z) <= -400000.0: tmp = (-x * z) * y elif (y * z) <= 0.04: tmp = x * 1.0 else: tmp = x * (-y * z) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -400000.0) tmp = Float64(Float64(Float64(-x) * z) * y); elseif (Float64(y * z) <= 0.04) tmp = Float64(x * 1.0); else tmp = Float64(x * Float64(Float64(-y) * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y * z) <= -400000.0) tmp = (-x * z) * y; elseif ((y * z) <= 0.04) tmp = x * 1.0; else tmp = x * (-y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], -400000.0], N[(N[((-x) * z), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 0.04], N[(x * 1.0), $MachinePrecision], N[(x * N[((-y) * z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -400000:\\
\;\;\;\;\left(\left(-x\right) \cdot z\right) \cdot y\\
\mathbf{elif}\;y \cdot z \leq 0.04:\\
\;\;\;\;x \cdot 1\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(\left(-y\right) \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -4e5Initial program 90.6%
Taylor expanded in y around inf
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6488.0
Applied rewrites88.0%
Applied rewrites64.1%
Taylor expanded in y around inf
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6490.2
Applied rewrites90.2%
Applied rewrites89.9%
if -4e5 < (*.f64 y z) < 0.0400000000000000008Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites97.0%
if 0.0400000000000000008 < (*.f64 y z) Initial program 94.8%
Taylor expanded in y around inf
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6490.1
Applied rewrites90.1%
(FPCore (x y z) :precision binary64 (if (<= (* y z) -1e+191) (* (* (- x) y) z) (* x (- 1.0 (* y z)))))
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -1e+191) {
tmp = (-x * y) * z;
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((y * z) <= (-1d+191)) then
tmp = (-x * y) * z
else
tmp = x * (1.0d0 - (y * z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -1e+191) {
tmp = (-x * y) * z;
} else {
tmp = x * (1.0 - (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y * z) <= -1e+191: tmp = (-x * y) * z else: tmp = x * (1.0 - (y * z)) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -1e+191) tmp = Float64(Float64(Float64(-x) * y) * z); else tmp = Float64(x * Float64(1.0 - Float64(y * z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y * z) <= -1e+191) tmp = (-x * y) * z; else tmp = x * (1.0 - (y * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], -1e+191], N[(N[((-x) * y), $MachinePrecision] * z), $MachinePrecision], N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -1 \cdot 10^{+191}:\\
\;\;\;\;\left(\left(-x\right) \cdot y\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -1.00000000000000007e191Initial program 83.7%
Taylor expanded in y around inf
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6483.7
Applied rewrites83.7%
Applied rewrites65.1%
Taylor expanded in y around inf
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6499.8
Applied rewrites99.8%
if -1.00000000000000007e191 < (*.f64 y z) Initial program 98.5%
(FPCore (x y z) :precision binary64 (* x 1.0))
double code(double x, double y, double z) {
return x * 1.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * 1.0d0
end function
public static double code(double x, double y, double z) {
return x * 1.0;
}
def code(x, y, z): return x * 1.0
function code(x, y, z) return Float64(x * 1.0) end
function tmp = code(x, y, z) tmp = x * 1.0; end
code[x_, y_, z_] := N[(x * 1.0), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 1
\end{array}
Initial program 96.2%
Taylor expanded in y around 0
Applied rewrites49.7%
herbie shell --seed 2024324
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))