
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- 1.0 x) z)))
double code(double x, double y, double z) {
return (x * y) + ((1.0 - 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 = (x * y) + ((1.0d0 - x) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((1.0 - x) * z);
}
def code(x, y, z): return (x * y) + ((1.0 - x) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(1.0 - x) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((1.0 - x) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(1 - x\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- 1.0 x) z)))
double code(double x, double y, double z) {
return (x * y) + ((1.0 - 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 = (x * y) + ((1.0d0 - x) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((1.0 - x) * z);
}
def code(x, y, z): return (x * y) + ((1.0 - x) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(1.0 - x) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((1.0 - x) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(1 - x\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (fma (- y z) x z))
double code(double x, double y, double z) {
return fma((y - z), x, z);
}
function code(x, y, z) return fma(Float64(y - z), x, z) end
code[x_, y_, z_] := N[(N[(y - z), $MachinePrecision] * x + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y - z, x, z\right)
\end{array}
Initial program 98.0%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
sub-negN/A
mul-1-negN/A
+-commutativeN/A
distribute-lft1-inN/A
associate-*r*N/A
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
associate-+l-N/A
distribute-lft-out--N/A
unsub-negN/A
mul-1-negN/A
sub-negN/A
mul-1-negN/A
+-commutativeN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
Applied rewrites100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (- z) x)))
(if (<= x -4.5e+272)
(* y x)
(if (<= x -4.2e+69)
t_0
(if (<= x -7.5e-67)
(* y x)
(if (<= x 5.2e-18) (* 1.0 z) (if (<= x 1.2e+67) (* y x) t_0)))))))
double code(double x, double y, double z) {
double t_0 = -z * x;
double tmp;
if (x <= -4.5e+272) {
tmp = y * x;
} else if (x <= -4.2e+69) {
tmp = t_0;
} else if (x <= -7.5e-67) {
tmp = y * x;
} else if (x <= 5.2e-18) {
tmp = 1.0 * z;
} else if (x <= 1.2e+67) {
tmp = y * x;
} 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 = -z * x
if (x <= (-4.5d+272)) then
tmp = y * x
else if (x <= (-4.2d+69)) then
tmp = t_0
else if (x <= (-7.5d-67)) then
tmp = y * x
else if (x <= 5.2d-18) then
tmp = 1.0d0 * z
else if (x <= 1.2d+67) then
tmp = y * x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = -z * x;
double tmp;
if (x <= -4.5e+272) {
tmp = y * x;
} else if (x <= -4.2e+69) {
tmp = t_0;
} else if (x <= -7.5e-67) {
tmp = y * x;
} else if (x <= 5.2e-18) {
tmp = 1.0 * z;
} else if (x <= 1.2e+67) {
tmp = y * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -z * x tmp = 0 if x <= -4.5e+272: tmp = y * x elif x <= -4.2e+69: tmp = t_0 elif x <= -7.5e-67: tmp = y * x elif x <= 5.2e-18: tmp = 1.0 * z elif x <= 1.2e+67: tmp = y * x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(-z) * x) tmp = 0.0 if (x <= -4.5e+272) tmp = Float64(y * x); elseif (x <= -4.2e+69) tmp = t_0; elseif (x <= -7.5e-67) tmp = Float64(y * x); elseif (x <= 5.2e-18) tmp = Float64(1.0 * z); elseif (x <= 1.2e+67) tmp = Float64(y * x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -z * x; tmp = 0.0; if (x <= -4.5e+272) tmp = y * x; elseif (x <= -4.2e+69) tmp = t_0; elseif (x <= -7.5e-67) tmp = y * x; elseif (x <= 5.2e-18) tmp = 1.0 * z; elseif (x <= 1.2e+67) tmp = y * x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[((-z) * x), $MachinePrecision]}, If[LessEqual[x, -4.5e+272], N[(y * x), $MachinePrecision], If[LessEqual[x, -4.2e+69], t$95$0, If[LessEqual[x, -7.5e-67], N[(y * x), $MachinePrecision], If[LessEqual[x, 5.2e-18], N[(1.0 * z), $MachinePrecision], If[LessEqual[x, 1.2e+67], N[(y * x), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-z\right) \cdot x\\
\mathbf{if}\;x \leq -4.5 \cdot 10^{+272}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq -4.2 \cdot 10^{+69}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -7.5 \cdot 10^{-67}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 5.2 \cdot 10^{-18}:\\
\;\;\;\;1 \cdot z\\
\mathbf{elif}\;x \leq 1.2 \cdot 10^{+67}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -4.50000000000000029e272 or -4.2000000000000003e69 < x < -7.5000000000000005e-67 or 5.2000000000000001e-18 < x < 1.20000000000000001e67Initial program 98.0%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6462.2
Applied rewrites62.2%
if -4.50000000000000029e272 < x < -4.2000000000000003e69 or 1.20000000000000001e67 < x Initial program 95.6%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f64100.0
Applied rewrites100.0%
Taylor expanded in z around inf
Applied rewrites62.2%
if -7.5000000000000005e-67 < x < 5.2000000000000001e-18Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6480.3
Applied rewrites80.3%
Taylor expanded in x around 0
Applied rewrites80.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- y z) x))) (if (<= x -1.7e-72) t_0 (if (<= x 0.0007) (* (- 1.0 x) z) t_0))))
double code(double x, double y, double z) {
double t_0 = (y - z) * x;
double tmp;
if (x <= -1.7e-72) {
tmp = t_0;
} else if (x <= 0.0007) {
tmp = (1.0 - x) * z;
} 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 = (y - z) * x
if (x <= (-1.7d-72)) then
tmp = t_0
else if (x <= 0.0007d0) then
tmp = (1.0d0 - x) * z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (y - z) * x;
double tmp;
if (x <= -1.7e-72) {
tmp = t_0;
} else if (x <= 0.0007) {
tmp = (1.0 - x) * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (y - z) * x tmp = 0 if x <= -1.7e-72: tmp = t_0 elif x <= 0.0007: tmp = (1.0 - x) * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(y - z) * x) tmp = 0.0 if (x <= -1.7e-72) tmp = t_0; elseif (x <= 0.0007) tmp = Float64(Float64(1.0 - x) * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (y - z) * x; tmp = 0.0; if (x <= -1.7e-72) tmp = t_0; elseif (x <= 0.0007) tmp = (1.0 - x) * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y - z), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, -1.7e-72], t$95$0, If[LessEqual[x, 0.0007], N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(y - z\right) \cdot x\\
\mathbf{if}\;x \leq -1.7 \cdot 10^{-72}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 0.0007:\\
\;\;\;\;\left(1 - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.6999999999999999e-72 or 6.99999999999999993e-4 < x Initial program 96.5%
Taylor expanded in x around inf
*-commutativeN/A
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
mul-1-negN/A
distribute-neg-inN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6495.0
Applied rewrites95.0%
if -1.6999999999999999e-72 < x < 6.99999999999999993e-4Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6480.2
Applied rewrites80.2%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (- 1.0 x) z))) (if (<= z -1.85e-115) t_0 (if (<= z 1.32e-83) (* y x) t_0))))
double code(double x, double y, double z) {
double t_0 = (1.0 - x) * z;
double tmp;
if (z <= -1.85e-115) {
tmp = t_0;
} else if (z <= 1.32e-83) {
tmp = y * x;
} 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) * z
if (z <= (-1.85d-115)) then
tmp = t_0
else if (z <= 1.32d-83) then
tmp = y * x
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) * z;
double tmp;
if (z <= -1.85e-115) {
tmp = t_0;
} else if (z <= 1.32e-83) {
tmp = y * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (1.0 - x) * z tmp = 0 if z <= -1.85e-115: tmp = t_0 elif z <= 1.32e-83: tmp = y * x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(1.0 - x) * z) tmp = 0.0 if (z <= -1.85e-115) tmp = t_0; elseif (z <= 1.32e-83) tmp = Float64(y * x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (1.0 - x) * z; tmp = 0.0; if (z <= -1.85e-115) tmp = t_0; elseif (z <= 1.32e-83) tmp = y * x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[z, -1.85e-115], t$95$0, If[LessEqual[z, 1.32e-83], N[(y * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - x\right) \cdot z\\
\mathbf{if}\;z \leq -1.85 \cdot 10^{-115}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.32 \cdot 10^{-83}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.85e-115 or 1.31999999999999994e-83 < z Initial program 97.1%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6482.3
Applied rewrites82.3%
if -1.85e-115 < z < 1.31999999999999994e-83Initial program 100.0%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6472.9
Applied rewrites72.9%
(FPCore (x y z) :precision binary64 (if (<= x -7.5e-67) (* y x) (if (<= x 5.2e-18) (* 1.0 z) (* y x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -7.5e-67) {
tmp = y * x;
} else if (x <= 5.2e-18) {
tmp = 1.0 * z;
} else {
tmp = y * 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 (x <= (-7.5d-67)) then
tmp = y * x
else if (x <= 5.2d-18) then
tmp = 1.0d0 * z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -7.5e-67) {
tmp = y * x;
} else if (x <= 5.2e-18) {
tmp = 1.0 * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -7.5e-67: tmp = y * x elif x <= 5.2e-18: tmp = 1.0 * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -7.5e-67) tmp = Float64(y * x); elseif (x <= 5.2e-18) tmp = Float64(1.0 * z); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -7.5e-67) tmp = y * x; elseif (x <= 5.2e-18) tmp = 1.0 * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -7.5e-67], N[(y * x), $MachinePrecision], If[LessEqual[x, 5.2e-18], N[(1.0 * z), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.5 \cdot 10^{-67}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 5.2 \cdot 10^{-18}:\\
\;\;\;\;1 \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -7.5000000000000005e-67 or 5.2000000000000001e-18 < x Initial program 96.5%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6449.5
Applied rewrites49.5%
if -7.5000000000000005e-67 < x < 5.2000000000000001e-18Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6480.3
Applied rewrites80.3%
Taylor expanded in x around 0
Applied rewrites80.3%
(FPCore (x y z) :precision binary64 (* y x))
double code(double x, double y, double z) {
return y * x;
}
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
end function
public static double code(double x, double y, double z) {
return y * x;
}
def code(x, y, z): return y * x
function code(x, y, z) return Float64(y * x) end
function tmp = code(x, y, z) tmp = y * x; end
code[x_, y_, z_] := N[(y * x), $MachinePrecision]
\begin{array}{l}
\\
y \cdot x
\end{array}
Initial program 98.0%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6437.4
Applied rewrites37.4%
herbie shell --seed 2024254
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))