
(FPCore (x y z) :precision binary64 (+ (* (- 1.0 x) y) (* x z)))
double code(double x, double y, double z) {
return ((1.0 - x) * y) + (x * z);
}
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) * y) + (x * z)
end function
public static double code(double x, double y, double z) {
return ((1.0 - x) * y) + (x * z);
}
def code(x, y, z): return ((1.0 - x) * y) + (x * z)
function code(x, y, z) return Float64(Float64(Float64(1.0 - x) * y) + Float64(x * z)) end
function tmp = code(x, y, z) tmp = ((1.0 - x) * y) + (x * z); end
code[x_, y_, z_] := N[(N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision] + N[(x * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(1 - x\right) \cdot y + x \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* (- 1.0 x) y) (* x z)))
double code(double x, double y, double z) {
return ((1.0 - x) * y) + (x * z);
}
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) * y) + (x * z)
end function
public static double code(double x, double y, double z) {
return ((1.0 - x) * y) + (x * z);
}
def code(x, y, z): return ((1.0 - x) * y) + (x * z)
function code(x, y, z) return Float64(Float64(Float64(1.0 - x) * y) + Float64(x * z)) end
function tmp = code(x, y, z) tmp = ((1.0 - x) * y) + (x * z); end
code[x_, y_, z_] := N[(N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision] + N[(x * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(1 - x\right) \cdot y + x \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (+ (* (- 1.0 x) y) (* x z)))
double code(double x, double y, double z) {
return ((1.0 - x) * y) + (x * z);
}
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) * y) + (x * z)
end function
public static double code(double x, double y, double z) {
return ((1.0 - x) * y) + (x * z);
}
def code(x, y, z): return ((1.0 - x) * y) + (x * z)
function code(x, y, z) return Float64(Float64(Float64(1.0 - x) * y) + Float64(x * z)) end
function tmp = code(x, y, z) tmp = ((1.0 - x) * y) + (x * z); end
code[x_, y_, z_] := N[(N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision] + N[(x * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(1 - x\right) \cdot y + x \cdot z
\end{array}
Initial program 99.2%
(FPCore (x y z) :precision binary64 (let* ((t_0 (+ (- 1.0 x) (* x z)))) (if (<= z -6.8e+137) t_0 (if (<= z 7.8e+64) (* (- 1.0 x) y) t_0))))
double code(double x, double y, double z) {
double t_0 = (1.0 - x) + (x * z);
double tmp;
if (z <= -6.8e+137) {
tmp = t_0;
} else if (z <= 7.8e+64) {
tmp = (1.0 - x) * y;
} else {
tmp = t_0;
}
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) :: tmp
t_0 = (1.0d0 - x) + (x * z)
if (z <= (-6.8d+137)) then
tmp = t_0
else if (z <= 7.8d+64) then
tmp = (1.0d0 - x) * y
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (1.0 - x) + (x * z);
double tmp;
if (z <= -6.8e+137) {
tmp = t_0;
} else if (z <= 7.8e+64) {
tmp = (1.0 - x) * y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (1.0 - x) + (x * z) tmp = 0 if z <= -6.8e+137: tmp = t_0 elif z <= 7.8e+64: tmp = (1.0 - x) * y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(1.0 - x) + Float64(x * z)) tmp = 0.0 if (z <= -6.8e+137) tmp = t_0; elseif (z <= 7.8e+64) tmp = Float64(Float64(1.0 - x) * y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (1.0 - x) + (x * z); tmp = 0.0; if (z <= -6.8e+137) tmp = t_0; elseif (z <= 7.8e+64) tmp = (1.0 - x) * y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(1.0 - x), $MachinePrecision] + N[(x * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -6.8e+137], t$95$0, If[LessEqual[z, 7.8e+64], N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - x\right) + x \cdot z\\
\mathbf{if}\;z \leq -6.8 \cdot 10^{+137}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 7.8 \cdot 10^{+64}:\\
\;\;\;\;\left(1 - x\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -6.79999999999999973e137 or 7.7999999999999996e64 < z Initial program 97.8%
Taylor expanded in x around 0
Applied rewrites62.0%
if -6.79999999999999973e137 < z < 7.7999999999999996e64Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites80.3%
(FPCore (x y z) :precision binary64 (* (- 1.0 x) y))
double code(double x, double y, double z) {
return (1.0 - x) * y;
}
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) * y
end function
public static double code(double x, double y, double z) {
return (1.0 - x) * y;
}
def code(x, y, z): return (1.0 - x) * y
function code(x, y, z) return Float64(Float64(1.0 - x) * y) end
function tmp = code(x, y, z) tmp = (1.0 - x) * y; end
code[x_, y_, z_] := N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision]
\begin{array}{l}
\\
\left(1 - x\right) \cdot y
\end{array}
Initial program 99.2%
Taylor expanded in x around 0
Applied rewrites65.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 - x
\end{array}
Initial program 99.2%
Taylor expanded in x around 0
Applied rewrites65.6%
Taylor expanded in x around 0
Applied rewrites3.5%
(FPCore (x y z) :precision binary64 (- y (* x (- y z))))
double code(double x, double y, double z) {
return y - (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 = y - (x * (y - z))
end function
public static double code(double x, double y, double z) {
return y - (x * (y - z));
}
def code(x, y, z): return y - (x * (y - z))
function code(x, y, z) return Float64(y - Float64(x * Float64(y - z))) end
function tmp = code(x, y, z) tmp = y - (x * (y - z)); end
code[x_, y_, z_] := N[(y - N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y - x \cdot \left(y - z\right)
\end{array}
herbie shell --seed 2024321
(FPCore (x y z)
:name "Diagrams.Color.HSV:lerp from diagrams-contrib-1.3.0.5"
:precision binary64
:pre (TRUE)
:alt
(! :herbie-platform default (- y (* x (- y z))))
(+ (* (- 1.0 x) y) (* x z)))