
(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 (fma (- y 1.0) (* x z) x))
double code(double x, double y, double z) {
return fma((y - 1.0), (x * z), x);
}
function code(x, y, z) return fma(Float64(y - 1.0), Float64(x * z), x) end
code[x_, y_, z_] := N[(N[(y - 1.0), $MachinePrecision] * N[(x * z), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y - 1, x \cdot z, x\right)
\end{array}
Initial program 93.3%
Applied rewrites98.4%
Final simplification98.4%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (- 1.0 y) z)) (t_1 (* (* x (- y 1.0)) z)))
(if (<= t_0 -50000000.0)
t_1
(if (<= t_0 5000000000000.0) (fma (- z) x x) t_1))))
double code(double x, double y, double z) {
double t_0 = (1.0 - y) * z;
double t_1 = (x * (y - 1.0)) * z;
double tmp;
if (t_0 <= -50000000.0) {
tmp = t_1;
} else if (t_0 <= 5000000000000.0) {
tmp = fma(-z, x, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(1.0 - y) * z) t_1 = Float64(Float64(x * Float64(y - 1.0)) * z) tmp = 0.0 if (t_0 <= -50000000.0) tmp = t_1; elseif (t_0 <= 5000000000000.0) tmp = fma(Float64(-z), x, x); else tmp = t_1; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x * N[(y - 1.0), $MachinePrecision]), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[t$95$0, -50000000.0], t$95$1, If[LessEqual[t$95$0, 5000000000000.0], N[((-z) * x + x), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - y\right) \cdot z\\
t_1 := \left(x \cdot \left(y - 1\right)\right) \cdot z\\
\mathbf{if}\;t\_0 \leq -50000000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 5000000000000:\\
\;\;\;\;\mathsf{fma}\left(-z, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 (-.f64 #s(literal 1 binary64) y) z) < -5e7 or 5e12 < (*.f64 (-.f64 #s(literal 1 binary64) y) z) Initial program 89.3%
Taylor expanded in z around inf
associate-*r*N/A
sub-negN/A
metadata-evalN/A
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
cancel-sign-subN/A
mul-1-negN/A
*-rgt-identityN/A
distribute-lft-out--N/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
neg-mul-1N/A
distribute-rgt-neg-inN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites98.3%
if -5e7 < (*.f64 (-.f64 #s(literal 1 binary64) y) z) < 5e12Initial program 100.0%
Applied rewrites100.0%
Applied rewrites99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f6498.1
Applied rewrites98.1%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- 1.0 y) z)) (t_1 (* (- x) z))) (if (<= t_0 -200.0) t_1 (if (<= t_0 1e-6) (* 1.0 x) t_1))))
double code(double x, double y, double z) {
double t_0 = (1.0 - y) * z;
double t_1 = -x * z;
double tmp;
if (t_0 <= -200.0) {
tmp = t_1;
} else if (t_0 <= 1e-6) {
tmp = 1.0 * 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 = (1.0d0 - y) * z
t_1 = -x * z
if (t_0 <= (-200.0d0)) then
tmp = t_1
else if (t_0 <= 1d-6) then
tmp = 1.0d0 * x
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 = -x * z;
double tmp;
if (t_0 <= -200.0) {
tmp = t_1;
} else if (t_0 <= 1e-6) {
tmp = 1.0 * x;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = (1.0 - y) * z t_1 = -x * z tmp = 0 if t_0 <= -200.0: tmp = t_1 elif t_0 <= 1e-6: tmp = 1.0 * x else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(Float64(1.0 - y) * z) t_1 = Float64(Float64(-x) * z) tmp = 0.0 if (t_0 <= -200.0) tmp = t_1; elseif (t_0 <= 1e-6) tmp = Float64(1.0 * x); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (1.0 - y) * z; t_1 = -x * z; tmp = 0.0; if (t_0 <= -200.0) tmp = t_1; elseif (t_0 <= 1e-6) tmp = 1.0 * x; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision]}, Block[{t$95$1 = N[((-x) * z), $MachinePrecision]}, If[LessEqual[t$95$0, -200.0], t$95$1, If[LessEqual[t$95$0, 1e-6], N[(1.0 * x), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - y\right) \cdot z\\
t_1 := \left(-x\right) \cdot z\\
\mathbf{if}\;t\_0 \leq -200:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 10^{-6}:\\
\;\;\;\;1 \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 (-.f64 #s(literal 1 binary64) y) z) < -200 or 9.99999999999999955e-7 < (*.f64 (-.f64 #s(literal 1 binary64) y) z) Initial program 89.5%
Taylor expanded in z around inf
associate-*r*N/A
sub-negN/A
metadata-evalN/A
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
cancel-sign-subN/A
mul-1-negN/A
*-rgt-identityN/A
distribute-lft-out--N/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
neg-mul-1N/A
distribute-rgt-neg-inN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites97.8%
Taylor expanded in y around 0
Applied rewrites43.3%
if -200 < (*.f64 (-.f64 #s(literal 1 binary64) y) z) < 9.99999999999999955e-7Initial program 100.0%
Taylor expanded in z around 0
Applied rewrites96.9%
Final simplification62.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (* x y) z))) (if (<= (- 1.0 y) -1e+33) t_0 (if (<= (- 1.0 y) 2.0) (fma (- z) x x) t_0))))
double code(double x, double y, double z) {
double t_0 = (x * y) * z;
double tmp;
if ((1.0 - y) <= -1e+33) {
tmp = t_0;
} else if ((1.0 - y) <= 2.0) {
tmp = fma(-z, x, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(x * y) * z) tmp = 0.0 if (Float64(1.0 - y) <= -1e+33) tmp = t_0; elseif (Float64(1.0 - y) <= 2.0) tmp = fma(Float64(-z), x, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * y), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[N[(1.0 - y), $MachinePrecision], -1e+33], t$95$0, If[LessEqual[N[(1.0 - y), $MachinePrecision], 2.0], N[((-z) * x + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x \cdot y\right) \cdot z\\
\mathbf{if}\;1 - y \leq -1 \cdot 10^{+33}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;1 - y \leq 2:\\
\;\;\;\;\mathsf{fma}\left(-z, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) y) < -9.9999999999999995e32 or 2 < (-.f64 #s(literal 1 binary64) y) Initial program 86.4%
Applied rewrites51.2%
Taylor expanded in y around inf
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6479.2
Applied rewrites79.2%
if -9.9999999999999995e32 < (-.f64 #s(literal 1 binary64) y) < 2Initial program 100.0%
Applied rewrites100.0%
Applied rewrites99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f6497.8
Applied rewrites97.8%
Final simplification88.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (* x z) y))) (if (<= (- 1.0 y) -1e+33) t_0 (if (<= (- 1.0 y) 2.0) (fma (- z) x x) t_0))))
double code(double x, double y, double z) {
double t_0 = (x * z) * y;
double tmp;
if ((1.0 - y) <= -1e+33) {
tmp = t_0;
} else if ((1.0 - y) <= 2.0) {
tmp = fma(-z, x, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(x * z) * y) tmp = 0.0 if (Float64(1.0 - y) <= -1e+33) tmp = t_0; elseif (Float64(1.0 - y) <= 2.0) tmp = fma(Float64(-z), x, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * z), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[N[(1.0 - y), $MachinePrecision], -1e+33], t$95$0, If[LessEqual[N[(1.0 - y), $MachinePrecision], 2.0], N[((-z) * x + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x \cdot z\right) \cdot y\\
\mathbf{if}\;1 - y \leq -1 \cdot 10^{+33}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;1 - y \leq 2:\\
\;\;\;\;\mathsf{fma}\left(-z, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (-.f64 #s(literal 1 binary64) y) < -9.9999999999999995e32 or 2 < (-.f64 #s(literal 1 binary64) y) Initial program 86.4%
Taylor expanded in y around inf
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f6477.8
Applied rewrites77.8%
if -9.9999999999999995e32 < (-.f64 #s(literal 1 binary64) y) < 2Initial program 100.0%
Applied rewrites100.0%
Applied rewrites99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f6497.8
Applied rewrites97.8%
(FPCore (x y z) :precision binary64 (fma (- z) x x))
double code(double x, double y, double z) {
return fma(-z, x, x);
}
function code(x, y, z) return fma(Float64(-z), x, x) end
code[x_, y_, z_] := N[((-z) * x + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(-z, x, x\right)
\end{array}
Initial program 93.3%
Applied rewrites98.4%
Applied rewrites98.3%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f6463.6
Applied rewrites63.6%
(FPCore (x y z) :precision binary64 (* 1.0 x))
double code(double x, double y, double z) {
return 1.0 * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 1.0d0 * x
end function
public static double code(double x, double y, double z) {
return 1.0 * x;
}
def code(x, y, z): return 1.0 * x
function code(x, y, z) return Float64(1.0 * x) end
function tmp = code(x, y, z) tmp = 1.0 * x; end
code[x_, y_, z_] := N[(1.0 * x), $MachinePrecision]
\begin{array}{l}
\\
1 \cdot x
\end{array}
Initial program 93.3%
Taylor expanded in z around 0
Applied rewrites37.1%
Final simplification37.1%
(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 2024277
(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))))