
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* (- 1.0 y) z))))
double code(double x, double y, double z) {
return x * (1.0 - ((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 - ((1.0d0 - y) * z))
end function
public static double code(double x, double y, double z) {
return x * (1.0 - ((1.0 - y) * z));
}
def code(x, y, z): return x * (1.0 - ((1.0 - y) * z))
function code(x, y, z) return Float64(x * Float64(1.0 - Float64(Float64(1.0 - y) * z))) end
function tmp = code(x, y, z) tmp = x * (1.0 - ((1.0 - y) * z)); end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* (- 1.0 y) z))))
double code(double x, double y, double z) {
return x * (1.0 - ((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 - ((1.0d0 - y) * z))
end function
public static double code(double x, double y, double z) {
return x * (1.0 - ((1.0 - y) * z));
}
def code(x, y, z): return x * (1.0 - ((1.0 - y) * z))
function code(x, y, z) return Float64(x * Float64(1.0 - Float64(Float64(1.0 - y) * z))) end
function tmp = code(x, y, z) tmp = x * (1.0 - ((1.0 - y) * z)); end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
\end{array}
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (- 1.0 y))))
(if (<= t_0 (- INFINITY))
(* (* x z) y)
(if (<= t_0 5e+174) (* x (- 1.0 t_0)) (* (* x z) (+ -1.0 y))))))
double code(double x, double y, double z) {
double t_0 = z * (1.0 - y);
double tmp;
if (t_0 <= -((double) INFINITY)) {
tmp = (x * z) * y;
} else if (t_0 <= 5e+174) {
tmp = x * (1.0 - t_0);
} else {
tmp = (x * z) * (-1.0 + y);
}
return tmp;
}
public static double code(double x, double y, double z) {
double t_0 = z * (1.0 - y);
double tmp;
if (t_0 <= -Double.POSITIVE_INFINITY) {
tmp = (x * z) * y;
} else if (t_0 <= 5e+174) {
tmp = x * (1.0 - t_0);
} else {
tmp = (x * z) * (-1.0 + y);
}
return tmp;
}
def code(x, y, z): t_0 = z * (1.0 - y) tmp = 0 if t_0 <= -math.inf: tmp = (x * z) * y elif t_0 <= 5e+174: tmp = x * (1.0 - t_0) else: tmp = (x * z) * (-1.0 + y) return tmp
function code(x, y, z) t_0 = Float64(z * Float64(1.0 - y)) tmp = 0.0 if (t_0 <= Float64(-Inf)) tmp = Float64(Float64(x * z) * y); elseif (t_0 <= 5e+174) tmp = Float64(x * Float64(1.0 - t_0)); else tmp = Float64(Float64(x * z) * Float64(-1.0 + y)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * (1.0 - y); tmp = 0.0; if (t_0 <= -Inf) tmp = (x * z) * y; elseif (t_0 <= 5e+174) tmp = x * (1.0 - t_0); else tmp = (x * z) * (-1.0 + y); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(N[(x * z), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[t$95$0, 5e+174], N[(x * N[(1.0 - t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[(x * z), $MachinePrecision] * N[(-1.0 + y), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(1 - y\right)\\
\mathbf{if}\;t\_0 \leq -\infty:\\
\;\;\;\;\left(x \cdot z\right) \cdot y\\
\mathbf{elif}\;t\_0 \leq 5 \cdot 10^{+174}:\\
\;\;\;\;x \cdot \left(1 - t\_0\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot z\right) \cdot \left(-1 + y\right)\\
\end{array}
\end{array}
if (*.f64 (-.f64 #s(literal 1 binary64) y) z) < -inf.0Initial program 49.3%
Taylor expanded in y around inf 99.9%
+-commutative99.9%
associate-/l*99.9%
distribute-lft-out99.9%
Simplified99.9%
Taylor expanded in y around inf 99.9%
if -inf.0 < (*.f64 (-.f64 #s(literal 1 binary64) y) z) < 4.9999999999999997e174Initial program 99.9%
if 4.9999999999999997e174 < (*.f64 (-.f64 #s(literal 1 binary64) y) z) Initial program 88.7%
Taylor expanded in z around inf 88.7%
associate-*r*99.9%
*-commutative99.9%
sub-neg99.9%
metadata-eval99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 2.1e-8))) (* (* x z) (+ -1.0 y)) (+ x (* x (* z y)))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 2.1e-8)) {
tmp = (x * z) * (-1.0 + y);
} else {
tmp = x + (x * (z * y));
}
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 ((z <= (-1.0d0)) .or. (.not. (z <= 2.1d-8))) then
tmp = (x * z) * ((-1.0d0) + y)
else
tmp = x + (x * (z * y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 2.1e-8)) {
tmp = (x * z) * (-1.0 + y);
} else {
tmp = x + (x * (z * y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.0) or not (z <= 2.1e-8): tmp = (x * z) * (-1.0 + y) else: tmp = x + (x * (z * y)) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 2.1e-8)) tmp = Float64(Float64(x * z) * Float64(-1.0 + y)); else tmp = Float64(x + Float64(x * Float64(z * y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.0) || ~((z <= 2.1e-8))) tmp = (x * z) * (-1.0 + y); else tmp = x + (x * (z * y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 2.1e-8]], $MachinePrecision]], N[(N[(x * z), $MachinePrecision] * N[(-1.0 + y), $MachinePrecision]), $MachinePrecision], N[(x + N[(x * N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 2.1 \cdot 10^{-8}\right):\\
\;\;\;\;\left(x \cdot z\right) \cdot \left(-1 + y\right)\\
\mathbf{else}:\\
\;\;\;\;x + x \cdot \left(z \cdot y\right)\\
\end{array}
\end{array}
if z < -1 or 2.09999999999999994e-8 < z Initial program 91.3%
Taylor expanded in z around inf 90.4%
associate-*r*98.9%
*-commutative98.9%
sub-neg98.9%
metadata-eval98.9%
Simplified98.9%
if -1 < z < 2.09999999999999994e-8Initial program 99.8%
Taylor expanded in z around 0 99.8%
Taylor expanded in y around inf 99.0%
*-commutative99.0%
Simplified99.0%
Final simplification99.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -8.6e+141) (not (<= y 2.3e+51))) (* (* x z) y) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -8.6e+141) || !(y <= 2.3e+51)) {
tmp = (x * z) * y;
} else {
tmp = x * (1.0 - 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 <= (-8.6d+141)) .or. (.not. (y <= 2.3d+51))) then
tmp = (x * z) * y
else
tmp = x * (1.0d0 - z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -8.6e+141) || !(y <= 2.3e+51)) {
tmp = (x * z) * y;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -8.6e+141) or not (y <= 2.3e+51): tmp = (x * z) * y else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -8.6e+141) || !(y <= 2.3e+51)) tmp = Float64(Float64(x * z) * y); else tmp = Float64(x * Float64(1.0 - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -8.6e+141) || ~((y <= 2.3e+51))) tmp = (x * z) * y; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -8.6e+141], N[Not[LessEqual[y, 2.3e+51]], $MachinePrecision]], N[(N[(x * z), $MachinePrecision] * y), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.6 \cdot 10^{+141} \lor \neg \left(y \leq 2.3 \cdot 10^{+51}\right):\\
\;\;\;\;\left(x \cdot z\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < -8.5999999999999997e141 or 2.30000000000000005e51 < y Initial program 88.3%
Taylor expanded in y around inf 92.8%
+-commutative92.8%
associate-/l*94.8%
distribute-lft-out95.8%
Simplified95.8%
Taylor expanded in y around inf 83.7%
if -8.5999999999999997e141 < y < 2.30000000000000005e51Initial program 100.0%
Taylor expanded in y around 0 93.0%
Final simplification89.4%
(FPCore (x y z) :precision binary64 (if (<= y -8.6e+141) (* (* x z) y) (if (<= y 2.5e+51) (* x (- 1.0 z)) (* z (* x y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -8.6e+141) {
tmp = (x * z) * y;
} else if (y <= 2.5e+51) {
tmp = x * (1.0 - z);
} else {
tmp = z * (x * y);
}
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 <= (-8.6d+141)) then
tmp = (x * z) * y
else if (y <= 2.5d+51) then
tmp = x * (1.0d0 - z)
else
tmp = z * (x * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -8.6e+141) {
tmp = (x * z) * y;
} else if (y <= 2.5e+51) {
tmp = x * (1.0 - z);
} else {
tmp = z * (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -8.6e+141: tmp = (x * z) * y elif y <= 2.5e+51: tmp = x * (1.0 - z) else: tmp = z * (x * y) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -8.6e+141) tmp = Float64(Float64(x * z) * y); elseif (y <= 2.5e+51) tmp = Float64(x * Float64(1.0 - z)); else tmp = Float64(z * Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -8.6e+141) tmp = (x * z) * y; elseif (y <= 2.5e+51) tmp = x * (1.0 - z); else tmp = z * (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -8.6e+141], N[(N[(x * z), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[y, 2.5e+51], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(z * N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.6 \cdot 10^{+141}:\\
\;\;\;\;\left(x \cdot z\right) \cdot y\\
\mathbf{elif}\;y \leq 2.5 \cdot 10^{+51}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x \cdot y\right)\\
\end{array}
\end{array}
if y < -8.5999999999999997e141Initial program 87.2%
Taylor expanded in y around inf 99.8%
+-commutative99.8%
associate-/l*99.8%
distribute-lft-out99.8%
Simplified99.8%
Taylor expanded in y around inf 93.9%
if -8.5999999999999997e141 < y < 2.5e51Initial program 100.0%
Taylor expanded in y around 0 93.0%
if 2.5e51 < y Initial program 89.2%
Taylor expanded in y around inf 71.8%
*-commutative71.8%
*-commutative71.8%
associate-*l*77.4%
Simplified77.4%
Final simplification89.8%
(FPCore (x y z) :precision binary64 (+ x (* (* x z) (+ -1.0 y))))
double code(double x, double y, double z) {
return x + ((x * z) * (-1.0 + y));
}
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 * z) * ((-1.0d0) + y))
end function
public static double code(double x, double y, double z) {
return x + ((x * z) * (-1.0 + y));
}
def code(x, y, z): return x + ((x * z) * (-1.0 + y))
function code(x, y, z) return Float64(x + Float64(Float64(x * z) * Float64(-1.0 + y))) end
function tmp = code(x, y, z) tmp = x + ((x * z) * (-1.0 + y)); end
code[x_, y_, z_] := N[(x + N[(N[(x * z), $MachinePrecision] * N[(-1.0 + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(x \cdot z\right) \cdot \left(-1 + y\right)
\end{array}
Initial program 95.5%
Taylor expanded in z around 0 95.5%
Taylor expanded in y around 0 92.3%
*-commutative92.3%
*-commutative92.3%
associate-*r*92.5%
distribute-lft-in98.4%
Simplified98.4%
(FPCore (x y z) :precision binary64 (* x (- 1.0 z)))
double code(double x, double y, double z) {
return x * (1.0 - 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 - z)
end function
public static double code(double x, double y, double z) {
return x * (1.0 - z);
}
def code(x, y, z): return x * (1.0 - z)
function code(x, y, z) return Float64(x * Float64(1.0 - z)) end
function tmp = code(x, y, z) tmp = x * (1.0 - z); end
code[x_, y_, z_] := N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - z\right)
\end{array}
Initial program 95.5%
Taylor expanded in y around 0 62.8%
(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 95.5%
Taylor expanded in z around 0 34.6%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- 1.0 (* (- 1.0 y) z))))
(t_1 (+ x (* (- 1.0 y) (* (- z) x)))))
(if (< t_0 -1.618195973607049e+50)
t_1
(if (< t_0 3.892237649663903e+134) (- (* (* x y) z) (- (* x z) x)) t_1))))
double code(double x, double y, double z) {
double t_0 = x * (1.0 - ((1.0 - y) * z));
double t_1 = x + ((1.0 - y) * (-z * x));
double tmp;
if (t_0 < -1.618195973607049e+50) {
tmp = t_1;
} else if (t_0 < 3.892237649663903e+134) {
tmp = ((x * y) * z) - ((x * z) - x);
} 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 = x * (1.0d0 - ((1.0d0 - y) * z))
t_1 = x + ((1.0d0 - y) * (-z * x))
if (t_0 < (-1.618195973607049d+50)) then
tmp = t_1
else if (t_0 < 3.892237649663903d+134) then
tmp = ((x * y) * z) - ((x * z) - x)
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (1.0 - ((1.0 - y) * z));
double t_1 = x + ((1.0 - y) * (-z * x));
double tmp;
if (t_0 < -1.618195973607049e+50) {
tmp = t_1;
} else if (t_0 < 3.892237649663903e+134) {
tmp = ((x * y) * z) - ((x * z) - x);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = x * (1.0 - ((1.0 - y) * z)) t_1 = x + ((1.0 - y) * (-z * x)) tmp = 0 if t_0 < -1.618195973607049e+50: tmp = t_1 elif t_0 < 3.892237649663903e+134: tmp = ((x * y) * z) - ((x * z) - x) else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(1.0 - Float64(Float64(1.0 - y) * z))) t_1 = Float64(x + Float64(Float64(1.0 - y) * Float64(Float64(-z) * x))) tmp = 0.0 if (t_0 < -1.618195973607049e+50) tmp = t_1; elseif (t_0 < 3.892237649663903e+134) tmp = Float64(Float64(Float64(x * y) * z) - Float64(Float64(x * z) - x)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (1.0 - ((1.0 - y) * z)); t_1 = x + ((1.0 - y) * (-z * x)); tmp = 0.0; if (t_0 < -1.618195973607049e+50) tmp = t_1; elseif (t_0 < 3.892237649663903e+134) tmp = ((x * y) * z) - ((x * z) - x); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(1.0 - N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x + N[(N[(1.0 - y), $MachinePrecision] * N[((-z) * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Less[t$95$0, -1.618195973607049e+50], t$95$1, If[Less[t$95$0, 3.892237649663903e+134], N[(N[(N[(x * y), $MachinePrecision] * z), $MachinePrecision] - N[(N[(x * z), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(1 - \left(1 - y\right) \cdot z\right)\\
t_1 := x + \left(1 - y\right) \cdot \left(\left(-z\right) \cdot x\right)\\
\mathbf{if}\;t\_0 < -1.618195973607049 \cdot 10^{+50}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 < 3.892237649663903 \cdot 10^{+134}:\\
\;\;\;\;\left(x \cdot y\right) \cdot z - \left(x \cdot z - x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
herbie shell --seed 2024136
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, J"
:precision binary64
:alt
(! :herbie-platform default (if (< (* x (- 1 (* (- 1 y) z))) -161819597360704900000000000000000000000000000000000) (+ x (* (- 1 y) (* (- z) x))) (if (< (* x (- 1 (* (- 1 y) z))) 389223764966390300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (- (* (* x y) z) (- (* x z) x)) (+ x (* (- 1 y) (* (- z) x))))))
(* x (- 1.0 (* (- 1.0 y) z))))