
(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 x (- y z) z))
double code(double x, double y, double z) {
return fma(x, (y - z), z);
}
function code(x, y, z) return fma(x, Float64(y - z), z) end
code[x_, y_, z_] := N[(x * N[(y - z), $MachinePrecision] + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y - z, z\right)
\end{array}
Initial program 96.8%
Taylor expanded in x around 0
+-commutativeN/A
mul-1-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f64100.0
Simplified100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (- x))))
(if (<= x -8.2e+253)
t_0
(if (<= x -6e-69) (* x y) (if (<= x 1.9) (fma z x z) t_0)))))
double code(double x, double y, double z) {
double t_0 = z * -x;
double tmp;
if (x <= -8.2e+253) {
tmp = t_0;
} else if (x <= -6e-69) {
tmp = x * y;
} else if (x <= 1.9) {
tmp = fma(z, x, z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(z * Float64(-x)) tmp = 0.0 if (x <= -8.2e+253) tmp = t_0; elseif (x <= -6e-69) tmp = Float64(x * y); elseif (x <= 1.9) tmp = fma(z, x, z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * (-x)), $MachinePrecision]}, If[LessEqual[x, -8.2e+253], t$95$0, If[LessEqual[x, -6e-69], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.9], N[(z * x + z), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(-x\right)\\
\mathbf{if}\;x \leq -8.2 \cdot 10^{+253}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -6 \cdot 10^{-69}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.9:\\
\;\;\;\;\mathsf{fma}\left(z, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -8.2e253 or 1.8999999999999999 < x Initial program 93.1%
Taylor expanded in x around inf
mul-1-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6498.2
Simplified98.2%
Taylor expanded in y around 0
mul-1-negN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6464.8
Simplified64.8%
if -8.2e253 < x < -5.99999999999999978e-69Initial program 96.0%
Taylor expanded in y around inf
lower-*.f6454.2
Simplified54.2%
if -5.99999999999999978e-69 < x < 1.8999999999999999Initial program 100.0%
Taylor expanded in y around 0
distribute-rgt-out--N/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6475.5
Simplified75.5%
lift-*.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6475.5
Applied egg-rr75.5%
neg-sub0N/A
flip3--N/A
metadata-evalN/A
sub0-negN/A
cube-negN/A
lift-neg.f64N/A
sqr-powN/A
unpow-prod-downN/A
lift-neg.f64N/A
lift-neg.f64N/A
sqr-negN/A
pow-prod-downN/A
sqr-powN/A
metadata-evalN/A
+-lft-identityN/A
distribute-rgt-outN/A
+-commutativeN/A
+-lft-identityN/A
pow2N/A
pow-divN/A
metadata-evalN/A
unpow175.1
Applied egg-rr75.1%
Final simplification66.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (- y z)))) (if (<= x -2.7e-69) t_0 (if (<= x 1.4e-13) (- z (* x z)) t_0))))
double code(double x, double y, double z) {
double t_0 = x * (y - z);
double tmp;
if (x <= -2.7e-69) {
tmp = t_0;
} else if (x <= 1.4e-13) {
tmp = z - (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 = x * (y - z)
if (x <= (-2.7d-69)) then
tmp = t_0
else if (x <= 1.4d-13) then
tmp = z - (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 = x * (y - z);
double tmp;
if (x <= -2.7e-69) {
tmp = t_0;
} else if (x <= 1.4e-13) {
tmp = z - (x * z);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (y - z) tmp = 0 if x <= -2.7e-69: tmp = t_0 elif x <= 1.4e-13: tmp = z - (x * z) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(y - z)) tmp = 0.0 if (x <= -2.7e-69) tmp = t_0; elseif (x <= 1.4e-13) tmp = Float64(z - Float64(x * 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 (x <= -2.7e-69) tmp = t_0; elseif (x <= 1.4e-13) tmp = z - (x * 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[x, -2.7e-69], t$95$0, If[LessEqual[x, 1.4e-13], N[(z - N[(x * z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y - z\right)\\
\mathbf{if}\;x \leq -2.7 \cdot 10^{-69}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.4 \cdot 10^{-13}:\\
\;\;\;\;z - x \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -2.6999999999999997e-69 or 1.4000000000000001e-13 < x Initial program 94.8%
Taylor expanded in x around inf
mul-1-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6492.6
Simplified92.6%
if -2.6999999999999997e-69 < x < 1.4000000000000001e-13Initial program 100.0%
Taylor expanded in y around 0
distribute-rgt-out--N/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6477.9
Simplified77.9%
Final simplification86.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (- y z)))) (if (<= x -2.7e-69) t_0 (if (<= x 1.9e-16) (fma z x z) t_0))))
double code(double x, double y, double z) {
double t_0 = x * (y - z);
double tmp;
if (x <= -2.7e-69) {
tmp = t_0;
} else if (x <= 1.9e-16) {
tmp = fma(z, x, z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * Float64(y - z)) tmp = 0.0 if (x <= -2.7e-69) tmp = t_0; elseif (x <= 1.9e-16) tmp = fma(z, x, z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -2.7e-69], t$95$0, If[LessEqual[x, 1.9e-16], N[(z * x + z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y - z\right)\\
\mathbf{if}\;x \leq -2.7 \cdot 10^{-69}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.9 \cdot 10^{-16}:\\
\;\;\;\;\mathsf{fma}\left(z, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -2.6999999999999997e-69 or 1.90000000000000006e-16 < x Initial program 94.8%
Taylor expanded in x around inf
mul-1-negN/A
remove-double-negN/A
mul-1-negN/A
distribute-neg-inN/A
+-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
distribute-neg-inN/A
mul-1-negN/A
remove-double-negN/A
unsub-negN/A
lower--.f6492.1
Simplified92.1%
if -2.6999999999999997e-69 < x < 1.90000000000000006e-16Initial program 100.0%
Taylor expanded in y around 0
distribute-rgt-out--N/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6478.5
Simplified78.5%
lift-*.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6478.5
Applied egg-rr78.5%
neg-sub0N/A
flip3--N/A
metadata-evalN/A
sub0-negN/A
cube-negN/A
lift-neg.f64N/A
sqr-powN/A
unpow-prod-downN/A
lift-neg.f64N/A
lift-neg.f64N/A
sqr-negN/A
pow-prod-downN/A
sqr-powN/A
metadata-evalN/A
+-lft-identityN/A
distribute-rgt-outN/A
+-commutativeN/A
+-lft-identityN/A
pow2N/A
pow-divN/A
metadata-evalN/A
unpow178.5
Applied egg-rr78.5%
(FPCore (x y z) :precision binary64 (if (<= x -6e-69) (* x y) (if (<= x 1.35e-16) (fma z x z) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -6e-69) {
tmp = x * y;
} else if (x <= 1.35e-16) {
tmp = fma(z, x, z);
} else {
tmp = x * y;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -6e-69) tmp = Float64(x * y); elseif (x <= 1.35e-16) tmp = fma(z, x, z); else tmp = Float64(x * y); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -6e-69], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.35e-16], N[(z * x + z), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6 \cdot 10^{-69}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.35 \cdot 10^{-16}:\\
\;\;\;\;\mathsf{fma}\left(z, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -5.99999999999999978e-69 or 1.35e-16 < x Initial program 94.8%
Taylor expanded in y around inf
lower-*.f6448.7
Simplified48.7%
if -5.99999999999999978e-69 < x < 1.35e-16Initial program 100.0%
Taylor expanded in y around 0
distribute-rgt-out--N/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6478.5
Simplified78.5%
lift-*.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6478.5
Applied egg-rr78.5%
neg-sub0N/A
flip3--N/A
metadata-evalN/A
sub0-negN/A
cube-negN/A
lift-neg.f64N/A
sqr-powN/A
unpow-prod-downN/A
lift-neg.f64N/A
lift-neg.f64N/A
sqr-negN/A
pow-prod-downN/A
sqr-powN/A
metadata-evalN/A
+-lft-identityN/A
distribute-rgt-outN/A
+-commutativeN/A
+-lft-identityN/A
pow2N/A
pow-divN/A
metadata-evalN/A
unpow178.5
Applied egg-rr78.5%
(FPCore (x y z) :precision binary64 (* x y))
double code(double x, double y, double z) {
return 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 = x * y
end function
public static double code(double x, double y, double z) {
return x * y;
}
def code(x, y, z): return x * y
function code(x, y, z) return Float64(x * y) end
function tmp = code(x, y, z) tmp = x * y; end
code[x_, y_, z_] := N[(x * y), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y
\end{array}
Initial program 96.8%
Taylor expanded in y around inf
lower-*.f6439.0
Simplified39.0%
herbie shell --seed 2024208
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))