
(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 5 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 (- x (* x (* y z))))
double code(double x, double y, double z) {
return x - (x * (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 - (x * (y * z))
end function
public static double code(double x, double y, double z) {
return x - (x * (y * z));
}
def code(x, y, z): return x - (x * (y * z))
function code(x, y, z) return Float64(x - Float64(x * Float64(y * z))) end
function tmp = code(x, y, z) tmp = x - (x * (y * z)); end
code[x_, y_, z_] := N[(x - N[(x * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - x \cdot \left(y \cdot z\right)
\end{array}
Initial program 98.0%
lift-*.f64N/A
lift--.f64N/A
sub-negN/A
distribute-rgt-inN/A
*-lft-identityN/A
distribute-lft-neg-outN/A
unsub-negN/A
lower--.f64N/A
lower-*.f6498.1
Applied rewrites98.1%
Final simplification98.1%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- 1.0 (* y z))) (t_1 (* y (* x (- z))))) (if (<= t_0 -500000000.0) t_1 (if (<= t_0 400000.0) (* x 1.0) t_1))))
double code(double x, double y, double z) {
double t_0 = 1.0 - (y * z);
double t_1 = y * (x * -z);
double tmp;
if (t_0 <= -500000000.0) {
tmp = t_1;
} else if (t_0 <= 400000.0) {
tmp = x * 1.0;
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: tmp
t_0 = 1.0d0 - (y * z)
t_1 = y * (x * -z)
if (t_0 <= (-500000000.0d0)) then
tmp = t_1
else if (t_0 <= 400000.0d0) then
tmp = x * 1.0d0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = 1.0 - (y * z);
double t_1 = y * (x * -z);
double tmp;
if (t_0 <= -500000000.0) {
tmp = t_1;
} else if (t_0 <= 400000.0) {
tmp = x * 1.0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = 1.0 - (y * z) t_1 = y * (x * -z) tmp = 0 if t_0 <= -500000000.0: tmp = t_1 elif t_0 <= 400000.0: tmp = x * 1.0 else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(1.0 - Float64(y * z)) t_1 = Float64(y * Float64(x * Float64(-z))) tmp = 0.0 if (t_0 <= -500000000.0) tmp = t_1; elseif (t_0 <= 400000.0) tmp = Float64(x * 1.0); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = 1.0 - (y * z); t_1 = y * (x * -z); tmp = 0.0; if (t_0 <= -500000000.0) tmp = t_1; elseif (t_0 <= 400000.0) tmp = x * 1.0; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -500000000.0], t$95$1, If[LessEqual[t$95$0, 400000.0], N[(x * 1.0), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - y \cdot z\\
t_1 := y \cdot \left(x \cdot \left(-z\right)\right)\\
\mathbf{if}\;t\_0 \leq -500000000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 400000:\\
\;\;\;\;x \cdot 1\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) (*.f64 y z)) < -5e8 or 4e5 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) Initial program 95.8%
Taylor expanded in y around inf
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6491.7
Applied rewrites91.7%
if -5e8 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) < 4e5Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites97.1%
Final simplification94.6%
(FPCore (x y z) :precision binary64 (if (<= (* y z) -50000000.0) (* y (* x (- z))) (if (<= (* y z) 1e-9) (* x 1.0) (* x (- (* y z))))))
double code(double x, double y, double z) {
double tmp;
if ((y * z) <= -50000000.0) {
tmp = y * (x * -z);
} else if ((y * z) <= 1e-9) {
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) <= (-50000000.0d0)) then
tmp = y * (x * -z)
else if ((y * z) <= 1d-9) 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) <= -50000000.0) {
tmp = y * (x * -z);
} else if ((y * z) <= 1e-9) {
tmp = x * 1.0;
} else {
tmp = x * -(y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y * z) <= -50000000.0: tmp = y * (x * -z) elif (y * z) <= 1e-9: tmp = x * 1.0 else: tmp = x * -(y * z) return tmp
function code(x, y, z) tmp = 0.0 if (Float64(y * z) <= -50000000.0) tmp = Float64(y * Float64(x * Float64(-z))); elseif (Float64(y * z) <= 1e-9) 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) <= -50000000.0) tmp = y * (x * -z); elseif ((y * z) <= 1e-9) tmp = x * 1.0; else tmp = x * -(y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[N[(y * z), $MachinePrecision], -50000000.0], N[(y * N[(x * (-z)), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 1e-9], N[(x * 1.0), $MachinePrecision], N[(x * (-N[(y * z), $MachinePrecision])), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -50000000:\\
\;\;\;\;y \cdot \left(x \cdot \left(-z\right)\right)\\
\mathbf{elif}\;y \cdot z \leq 10^{-9}:\\
\;\;\;\;x \cdot 1\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(-y \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 y z) < -5e7Initial program 93.9%
Taylor expanded in y around inf
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6497.4
Applied rewrites97.4%
if -5e7 < (*.f64 y z) < 1.00000000000000006e-9Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites97.1%
if 1.00000000000000006e-9 < (*.f64 y z) Initial program 98.0%
Taylor expanded in y around inf
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6496.3
Applied rewrites96.3%
Final simplification97.0%
(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}
Initial program 98.0%
(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 98.0%
Taylor expanded in y around 0
Applied rewrites53.6%
herbie shell --seed 2024257
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))