
(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 7 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 (- z (* x (- z y))))
double code(double x, double y, double z) {
return z - (x * (z - y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z - (x * (z - y))
end function
public static double code(double x, double y, double z) {
return z - (x * (z - y));
}
def code(x, y, z): return z - (x * (z - y))
function code(x, y, z) return Float64(z - Float64(x * Float64(z - y))) end
function tmp = code(x, y, z) tmp = z - (x * (z - y)); end
code[x_, y_, z_] := N[(z - N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z - x \cdot \left(z - y\right)
\end{array}
Initial program 97.3%
+-commutative97.3%
remove-double-neg97.3%
distribute-rgt-neg-out97.3%
neg-sub097.3%
neg-sub097.3%
*-commutative97.3%
distribute-lft-neg-in97.3%
remove-double-neg97.3%
distribute-rgt-out--97.3%
*-lft-identity97.3%
associate-+l-97.3%
distribute-lft-out--100.0%
Simplified100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- z))))
(if (<= x -2.9e+48)
(* x y)
(if (<= x -1.0)
t_0
(if (<= x 1.9e-6) z (if (<= x 6.2e+264) (* x y) t_0))))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (x <= -2.9e+48) {
tmp = x * y;
} else if (x <= -1.0) {
tmp = t_0;
} else if (x <= 1.9e-6) {
tmp = z;
} else if (x <= 6.2e+264) {
tmp = 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 = x * -z
if (x <= (-2.9d+48)) then
tmp = x * y
else if (x <= (-1.0d0)) then
tmp = t_0
else if (x <= 1.9d-6) then
tmp = z
else if (x <= 6.2d+264) then
tmp = 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 = x * -z;
double tmp;
if (x <= -2.9e+48) {
tmp = x * y;
} else if (x <= -1.0) {
tmp = t_0;
} else if (x <= 1.9e-6) {
tmp = z;
} else if (x <= 6.2e+264) {
tmp = x * y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if x <= -2.9e+48: tmp = x * y elif x <= -1.0: tmp = t_0 elif x <= 1.9e-6: tmp = z elif x <= 6.2e+264: tmp = x * y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-z)) tmp = 0.0 if (x <= -2.9e+48) tmp = Float64(x * y); elseif (x <= -1.0) tmp = t_0; elseif (x <= 1.9e-6) tmp = z; elseif (x <= 6.2e+264) tmp = Float64(x * y); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -z; tmp = 0.0; if (x <= -2.9e+48) tmp = x * y; elseif (x <= -1.0) tmp = t_0; elseif (x <= 1.9e-6) tmp = z; elseif (x <= 6.2e+264) tmp = x * y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-z)), $MachinePrecision]}, If[LessEqual[x, -2.9e+48], N[(x * y), $MachinePrecision], If[LessEqual[x, -1.0], t$95$0, If[LessEqual[x, 1.9e-6], z, If[LessEqual[x, 6.2e+264], N[(x * y), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;x \leq -2.9 \cdot 10^{+48}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.9 \cdot 10^{-6}:\\
\;\;\;\;z\\
\mathbf{elif}\;x \leq 6.2 \cdot 10^{+264}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -2.8999999999999999e48 or 1.9e-6 < x < 6.19999999999999962e264Initial program 94.4%
Taylor expanded in y around inf 59.4%
if -2.8999999999999999e48 < x < -1 or 6.19999999999999962e264 < x Initial program 95.7%
Taylor expanded in x around inf 99.5%
neg-mul-199.5%
sub-neg99.5%
Simplified99.5%
Taylor expanded in y around 0 79.9%
mul-1-neg79.9%
distribute-rgt-neg-out79.9%
Simplified79.9%
if -1 < x < 1.9e-6Initial program 100.0%
Taylor expanded in x around 0 80.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -510000.0) (not (<= x 1.0))) (* x (- y z)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -510000.0) || !(x <= 1.0)) {
tmp = x * (y - z);
} else {
tmp = z + (x * y);
}
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 <= (-510000.0d0)) .or. (.not. (x <= 1.0d0))) then
tmp = x * (y - z)
else
tmp = z + (x * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -510000.0) || !(x <= 1.0)) {
tmp = x * (y - z);
} else {
tmp = z + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -510000.0) or not (x <= 1.0): tmp = x * (y - z) else: tmp = z + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -510000.0) || !(x <= 1.0)) tmp = Float64(x * Float64(y - z)); else tmp = Float64(z + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -510000.0) || ~((x <= 1.0))) tmp = x * (y - z); else tmp = z + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -510000.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -510000 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if x < -5.1e5 or 1 < x Initial program 94.6%
Taylor expanded in x around inf 98.8%
neg-mul-198.8%
sub-neg98.8%
Simplified98.8%
if -5.1e5 < x < 1Initial program 100.0%
+-commutative100.0%
remove-double-neg100.0%
distribute-rgt-neg-out100.0%
neg-sub0100.0%
neg-sub0100.0%
*-commutative100.0%
distribute-lft-neg-in100.0%
remove-double-neg100.0%
distribute-rgt-out--100.0%
*-lft-identity100.0%
associate-+l-100.0%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 99.2%
mul-1-neg99.2%
distribute-rgt-neg-out99.2%
Simplified99.2%
sub-neg99.2%
+-commutative99.2%
distribute-rgt-neg-out99.2%
remove-double-neg99.2%
Applied egg-rr99.2%
Final simplification99.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.8e-29) (not (<= x 1040000000.0))) (* x (- y z)) (* z (- 1.0 x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.8e-29) || !(x <= 1040000000.0)) {
tmp = x * (y - z);
} else {
tmp = z * (1.0 - 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 <= (-5.8d-29)) .or. (.not. (x <= 1040000000.0d0))) then
tmp = x * (y - z)
else
tmp = z * (1.0d0 - x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -5.8e-29) || !(x <= 1040000000.0)) {
tmp = x * (y - z);
} else {
tmp = z * (1.0 - x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.8e-29) or not (x <= 1040000000.0): tmp = x * (y - z) else: tmp = z * (1.0 - x) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.8e-29) || !(x <= 1040000000.0)) tmp = Float64(x * Float64(y - z)); else tmp = Float64(z * Float64(1.0 - x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -5.8e-29) || ~((x <= 1040000000.0))) tmp = x * (y - z); else tmp = z * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.8e-29], N[Not[LessEqual[x, 1040000000.0]], $MachinePrecision]], N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision], N[(z * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.8 \cdot 10^{-29} \lor \neg \left(x \leq 1040000000\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if x < -5.80000000000000048e-29 or 1.04e9 < x Initial program 94.8%
Taylor expanded in x around inf 97.1%
neg-mul-197.1%
sub-neg97.1%
Simplified97.1%
if -5.80000000000000048e-29 < x < 1.04e9Initial program 100.0%
Taylor expanded in y around 0 83.8%
Final simplification90.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -9.8e-29) (not (<= x 2.55e-9))) (* x (- y z)) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9.8e-29) || !(x <= 2.55e-9)) {
tmp = x * (y - z);
} else {
tmp = z;
}
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 <= (-9.8d-29)) .or. (.not. (x <= 2.55d-9))) then
tmp = x * (y - z)
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -9.8e-29) || !(x <= 2.55e-9)) {
tmp = x * (y - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -9.8e-29) or not (x <= 2.55e-9): tmp = x * (y - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -9.8e-29) || !(x <= 2.55e-9)) tmp = Float64(x * Float64(y - z)); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -9.8e-29) || ~((x <= 2.55e-9))) tmp = x * (y - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -9.8e-29], N[Not[LessEqual[x, 2.55e-9]], $MachinePrecision]], N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.8 \cdot 10^{-29} \lor \neg \left(x \leq 2.55 \cdot 10^{-9}\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -9.7999999999999997e-29 or 2.55000000000000009e-9 < x Initial program 94.9%
Taylor expanded in x around inf 96.2%
neg-mul-196.2%
sub-neg96.2%
Simplified96.2%
if -9.7999999999999997e-29 < x < 2.55000000000000009e-9Initial program 100.0%
Taylor expanded in x around 0 83.9%
Final simplification90.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.8e-29) (not (<= x 1.1e-5))) (* x y) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.8e-29) || !(x <= 1.1e-5)) {
tmp = x * y;
} else {
tmp = z;
}
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 <= (-6.8d-29)) .or. (.not. (x <= 1.1d-5))) then
tmp = x * y
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -6.8e-29) || !(x <= 1.1e-5)) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.8e-29) or not (x <= 1.1e-5): tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.8e-29) || !(x <= 1.1e-5)) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -6.8e-29) || ~((x <= 1.1e-5))) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.8e-29], N[Not[LessEqual[x, 1.1e-5]], $MachinePrecision]], N[(x * y), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.8 \cdot 10^{-29} \lor \neg \left(x \leq 1.1 \cdot 10^{-5}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -6.79999999999999945e-29 or 1.1e-5 < x Initial program 94.9%
Taylor expanded in y around inf 53.1%
if -6.79999999999999945e-29 < x < 1.1e-5Initial program 100.0%
Taylor expanded in x around 0 83.9%
Final simplification67.2%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 97.3%
Taylor expanded in x around 0 40.9%
herbie shell --seed 2024085
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))