
(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 4 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 (- 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 97.6%
Final simplification97.6%
(FPCore (x y z) :precision binary64 (if (or (<= (* y z) -200.0) (not (<= (* y z) 0.05))) (* z (* y (- x))) x))
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -200.0) || !((y * z) <= 0.05)) {
tmp = z * (y * -x);
} else {
tmp = x;
}
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) <= (-200.0d0)) .or. (.not. ((y * z) <= 0.05d0))) then
tmp = z * (y * -x)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -200.0) || !((y * z) <= 0.05)) {
tmp = z * (y * -x);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((y * z) <= -200.0) or not ((y * z) <= 0.05): tmp = z * (y * -x) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((Float64(y * z) <= -200.0) || !(Float64(y * z) <= 0.05)) tmp = Float64(z * Float64(y * Float64(-x))); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (((y * z) <= -200.0) || ~(((y * z) <= 0.05))) tmp = z * (y * -x); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[N[(y * z), $MachinePrecision], -200.0], N[Not[LessEqual[N[(y * z), $MachinePrecision], 0.05]], $MachinePrecision]], N[(z * N[(y * (-x)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -200 \lor \neg \left(y \cdot z \leq 0.05\right):\\
\;\;\;\;z \cdot \left(y \cdot \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 y z) < -200 or 0.050000000000000003 < (*.f64 y z) Initial program 95.6%
flip3--39.9%
associate-*r/35.8%
metadata-eval35.8%
metadata-eval35.8%
distribute-rgt-out35.8%
+-commutative35.8%
Applied egg-rr35.8%
associate-/l*39.7%
Simplified39.7%
Taylor expanded in y around inf 94.3%
associate-/r/94.4%
associate-*r*88.0%
div-inv88.0%
metadata-eval88.0%
Applied egg-rr88.0%
*-commutative88.0%
associate-*r*88.0%
associate-*r*88.0%
neg-mul-188.0%
associate-*r*93.9%
distribute-rgt-neg-out93.9%
distribute-rgt-neg-out93.9%
add-sqr-sqrt49.0%
sqrt-unprod39.1%
sqr-neg39.1%
sqrt-unprod0.5%
add-sqr-sqrt0.9%
distribute-rgt-neg-out0.9%
distribute-rgt-neg-out0.9%
associate-*r*1.0%
*-commutative1.0%
add-sqr-sqrt0.5%
sqrt-unprod36.6%
sqr-neg36.6%
sqrt-unprod45.3%
add-sqr-sqrt88.0%
Applied egg-rr88.0%
if -200 < (*.f64 y z) < 0.050000000000000003Initial program 100.0%
Taylor expanded in y around 0 97.7%
Final simplification92.4%
(FPCore (x y z) :precision binary64 (if (or (<= (* y z) -1.0) (not (<= (* y z) 0.05))) (* x (* y (- z))) x))
double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -1.0) || !((y * z) <= 0.05)) {
tmp = x * (y * -z);
} else {
tmp = x;
}
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) <= (-1.0d0)) .or. (.not. ((y * z) <= 0.05d0))) then
tmp = x * (y * -z)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (((y * z) <= -1.0) || !((y * z) <= 0.05)) {
tmp = x * (y * -z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if ((y * z) <= -1.0) or not ((y * z) <= 0.05): tmp = x * (y * -z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((Float64(y * z) <= -1.0) || !(Float64(y * z) <= 0.05)) tmp = Float64(x * Float64(y * Float64(-z))); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (((y * z) <= -1.0) || ~(((y * z) <= 0.05))) tmp = x * (y * -z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[N[(y * z), $MachinePrecision], -1.0], N[Not[LessEqual[N[(y * z), $MachinePrecision], 0.05]], $MachinePrecision]], N[(x * N[(y * (-z)), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -1 \lor \neg \left(y \cdot z \leq 0.05\right):\\
\;\;\;\;x \cdot \left(y \cdot \left(-z\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (*.f64 y z) < -1 or 0.050000000000000003 < (*.f64 y z) Initial program 95.7%
Taylor expanded in y around inf 93.3%
mul-1-neg93.3%
associate-*r*93.9%
distribute-lft-neg-in93.9%
distribute-rgt-neg-out93.9%
*-commutative93.9%
Simplified93.9%
if -1 < (*.f64 y z) < 0.050000000000000003Initial program 100.0%
Taylor expanded in y around 0 98.4%
Final simplification95.9%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 97.6%
Taylor expanded in y around 0 46.6%
Final simplification46.6%
herbie shell --seed 2023182
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
:precision binary64
(* x (- 1.0 (* y z))))