
(FPCore (x y z) :precision binary64 :pre TRUE (* 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)
use fmin_fmax_functions
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]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = x * ((1) - (((1) - y) * z)) END code
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 :pre TRUE (* 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)
use fmin_fmax_functions
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]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = x * ((1) - (((1) - y) * z)) END code
x \cdot \left(1 - \left(1 - y\right) \cdot z\right)
(FPCore (x y z) :precision binary64 :pre TRUE (* (copysign 1.0 x) (if (<= (fabs x) 3.790276828303043e-54) (fma z (* (- y 1.0) (fabs x)) (fabs x)) (* (fabs x) (- 1.0 (* (- 1.0 y) z))))))
double code(double x, double y, double z) {
double tmp;
if (fabs(x) <= 3.790276828303043e-54) {
tmp = fma(z, ((y - 1.0) * fabs(x)), fabs(x));
} else {
tmp = fabs(x) * (1.0 - ((1.0 - y) * z));
}
return copysign(1.0, x) * tmp;
}
function code(x, y, z) tmp = 0.0 if (abs(x) <= 3.790276828303043e-54) tmp = fma(z, Float64(Float64(y - 1.0) * abs(x)), abs(x)); else tmp = Float64(abs(x) * Float64(1.0 - Float64(Float64(1.0 - y) * z))); end return Float64(copysign(1.0, x) * tmp) end
code[x_, y_, z_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[x], $MachinePrecision], 3.790276828303043e-54], N[(z * N[(N[(y - 1.0), $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision] + N[Abs[x], $MachinePrecision]), $MachinePrecision], N[(N[Abs[x], $MachinePrecision] * N[(1.0 - N[(N[(1.0 - y), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\mathsf{copysign}\left(1, x\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 3.790276828303043 \cdot 10^{-54}:\\
\;\;\;\;\mathsf{fma}\left(z, \left(y - 1\right) \cdot \left|x\right|, \left|x\right|\right)\\
\mathbf{else}:\\
\;\;\;\;\left|x\right| \cdot \left(1 - \left(1 - y\right) \cdot z\right)\\
\end{array}
if x < 3.790276828303043e-54Initial program 96.2%
Applied rewrites96.2%
if 3.790276828303043e-54 < x Initial program 96.2%
(FPCore (x y z) :precision binary64 :pre TRUE (* (copysign 1.0 x) (if (<= (fabs x) 3.3832657300342604e-87) (fma z (* (- y 1.0) (fabs x)) (fabs x)) (fma (* z (fabs x)) (- y 1.0) (fabs x)))))
double code(double x, double y, double z) {
double tmp;
if (fabs(x) <= 3.3832657300342604e-87) {
tmp = fma(z, ((y - 1.0) * fabs(x)), fabs(x));
} else {
tmp = fma((z * fabs(x)), (y - 1.0), fabs(x));
}
return copysign(1.0, x) * tmp;
}
function code(x, y, z) tmp = 0.0 if (abs(x) <= 3.3832657300342604e-87) tmp = fma(z, Float64(Float64(y - 1.0) * abs(x)), abs(x)); else tmp = fma(Float64(z * abs(x)), Float64(y - 1.0), abs(x)); end return Float64(copysign(1.0, x) * tmp) end
code[x_, y_, z_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[x], $MachinePrecision], 3.3832657300342604e-87], N[(z * N[(N[(y - 1.0), $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision] + N[Abs[x], $MachinePrecision]), $MachinePrecision], N[(N[(z * N[Abs[x], $MachinePrecision]), $MachinePrecision] * N[(y - 1.0), $MachinePrecision] + N[Abs[x], $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\mathsf{copysign}\left(1, x\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 3.3832657300342604 \cdot 10^{-87}:\\
\;\;\;\;\mathsf{fma}\left(z, \left(y - 1\right) \cdot \left|x\right|, \left|x\right|\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z \cdot \left|x\right|, y - 1, \left|x\right|\right)\\
\end{array}
if x < 3.3832657300342604e-87Initial program 96.2%
Applied rewrites96.2%
if 3.3832657300342604e-87 < x Initial program 96.2%
Applied rewrites97.8%
(FPCore (x y z) :precision binary64 :pre TRUE (fma z (* (- y 1.0) x) x))
double code(double x, double y, double z) {
return fma(z, ((y - 1.0) * x), x);
}
function code(x, y, z) return fma(z, Float64(Float64(y - 1.0) * x), x) end
code[x_, y_, z_] := N[(z * N[(N[(y - 1.0), $MachinePrecision] * x), $MachinePrecision] + x), $MachinePrecision]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = (z * ((y - (1)) * x)) + x END code
\mathsf{fma}\left(z, \left(y - 1\right) \cdot x, x\right)
Initial program 96.2%
Applied rewrites96.2%
(FPCore (x y z)
:precision binary64
:pre TRUE
(let* ((t_0 (fma z (* x y) x)))
(if (<= (- 1.0 y) -5000000.0)
t_0
(if (<= (- 1.0 y) 1.02) (* x (- 1.0 z)) t_0))))double code(double x, double y, double z) {
double t_0 = fma(z, (x * y), x);
double tmp;
if ((1.0 - y) <= -5000000.0) {
tmp = t_0;
} else if ((1.0 - y) <= 1.02) {
tmp = x * (1.0 - z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(z, Float64(x * y), x) tmp = 0.0 if (Float64(1.0 - y) <= -5000000.0) tmp = t_0; elseif (Float64(1.0 - y) <= 1.02) tmp = Float64(x * Float64(1.0 - z)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[(x * y), $MachinePrecision] + x), $MachinePrecision]}, If[LessEqual[N[(1.0 - y), $MachinePrecision], -5000000.0], t$95$0, If[LessEqual[N[(1.0 - y), $MachinePrecision], 1.02], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = LET t_0 = ((z * (x * y)) + x) IN LET tmp_1 = IF (((1) - y) <= (1020000000000000017763568394002504646778106689453125e-51)) THEN (x * ((1) - z)) ELSE t_0 ENDIF IN LET tmp = IF (((1) - y) <= (-5e6)) THEN t_0 ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
t_0 := \mathsf{fma}\left(z, x \cdot y, x\right)\\
\mathbf{if}\;1 - y \leq -5000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;1 - y \leq 1.02:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if (-.f64 #s(literal 1 binary64) y) < -5e6 or 1.02 < (-.f64 #s(literal 1 binary64) y) Initial program 96.2%
Applied rewrites96.2%
Taylor expanded in y around inf
Applied rewrites72.1%
if -5e6 < (-.f64 #s(literal 1 binary64) y) < 1.02Initial program 96.2%
Taylor expanded in y around 0
Applied rewrites66.0%
(FPCore (x y z)
:precision binary64
:pre TRUE
(let* ((t_0 (* x (* y z))))
(if (<= y -2.7021837473509395e+34)
t_0
(if (<= y 8862164.475566508) (* x (- 1.0 z)) t_0))))double code(double x, double y, double z) {
double t_0 = x * (y * z);
double tmp;
if (y <= -2.7021837473509395e+34) {
tmp = t_0;
} else if (y <= 8862164.475566508) {
tmp = x * (1.0 - z);
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = x * (y * z)
if (y <= (-2.7021837473509395d+34)) then
tmp = t_0
else if (y <= 8862164.475566508d0) then
tmp = x * (1.0d0 - z)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * (y * z);
double tmp;
if (y <= -2.7021837473509395e+34) {
tmp = t_0;
} else if (y <= 8862164.475566508) {
tmp = x * (1.0 - z);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y * z) tmp = 0 if y <= -2.7021837473509395e+34: tmp = t_0 elif y <= 8862164.475566508: tmp = x * (1.0 - z) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(y * z)) tmp = 0.0 if (y <= -2.7021837473509395e+34) tmp = t_0; elseif (y <= 8862164.475566508) tmp = Float64(x * Float64(1.0 - z)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (y * z); tmp = 0.0; if (y <= -2.7021837473509395e+34) tmp = t_0; elseif (y <= 8862164.475566508) tmp = x * (1.0 - z); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2.7021837473509395e+34], t$95$0, If[LessEqual[y, 8862164.475566508], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = LET t_0 = (x * (y * z)) IN LET tmp_1 = IF (y <= (886216447556650824844837188720703125e-29)) THEN (x * ((1) - z)) ELSE t_0 ENDIF IN LET tmp = IF (y <= (-27021837473509394603557797526241280)) THEN t_0 ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
t_0 := x \cdot \left(y \cdot z\right)\\
\mathbf{if}\;y \leq -2.7021837473509395 \cdot 10^{+34}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 8862164.475566508:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if y < -2.7021837473509395e34 or 8862164.4755665082 < y Initial program 96.2%
Taylor expanded in y around inf
Applied rewrites35.8%
if -2.7021837473509395e34 < y < 8862164.4755665082Initial program 96.2%
Taylor expanded in y around 0
Applied rewrites66.0%
(FPCore (x y z) :precision binary64 :pre TRUE (* x (- 1.0 z)))
double code(double x, double y, double z) {
return x * (1.0 - z);
}
real(8) function code(x, y, z)
use fmin_fmax_functions
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]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = x * ((1) - z) END code
x \cdot \left(1 - z\right)
Initial program 96.2%
Taylor expanded in y around 0
Applied rewrites66.0%
(FPCore (x y z) :precision binary64 :pre TRUE (* x 1.0))
double code(double x, double y, double z) {
return x * 1.0;
}
real(8) function code(x, y, z)
use fmin_fmax_functions
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]
f(x, y, z): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf] code: THEORY BEGIN f(x, y, z: real): real = x * (1) END code
x \cdot 1
Initial program 96.2%
Taylor expanded in y around inf
Applied rewrites35.8%
Taylor expanded in z around 0
Applied rewrites38.8%
herbie shell --seed 2026092
(FPCore (x y z)
:name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, J"
:precision binary64
(* x (- 1.0 (* (- 1.0 y) z))))