
(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 (* (- y z) x)))
double code(double x, double y, double z) {
return z + ((y - z) * x);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + ((y - z) * x)
end function
public static double code(double x, double y, double z) {
return z + ((y - z) * x);
}
def code(x, y, z): return z + ((y - z) * x)
function code(x, y, z) return Float64(z + Float64(Float64(y - z) * x)) end
function tmp = code(x, y, z) tmp = z + ((y - z) * x); end
code[x_, y_, z_] := N[(z + N[(N[(y - z), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + \left(y - z\right) \cdot x
\end{array}
Initial program 97.2%
*-commutative97.2%
distribute-lft-out--97.3%
*-rgt-identity97.3%
cancel-sign-sub-inv97.3%
+-commutative97.3%
associate-+r+97.3%
*-commutative97.3%
distribute-rgt-out100.0%
+-commutative100.0%
fma-def100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (- x))))
(if (<= x -1.7e+72)
t_0
(if (<= x -1.8e-6) (* y x) (if (<= x 175000000.0) z t_0)))))
double code(double x, double y, double z) {
double t_0 = z * -x;
double tmp;
if (x <= -1.7e+72) {
tmp = t_0;
} else if (x <= -1.8e-6) {
tmp = y * x;
} else if (x <= 175000000.0) {
tmp = 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 = z * -x
if (x <= (-1.7d+72)) then
tmp = t_0
else if (x <= (-1.8d-6)) then
tmp = y * x
else if (x <= 175000000.0d0) then
tmp = z
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 <= -1.7e+72) {
tmp = t_0;
} else if (x <= -1.8e-6) {
tmp = y * x;
} else if (x <= 175000000.0) {
tmp = z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * -x tmp = 0 if x <= -1.7e+72: tmp = t_0 elif x <= -1.8e-6: tmp = y * x elif x <= 175000000.0: tmp = z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * Float64(-x)) tmp = 0.0 if (x <= -1.7e+72) tmp = t_0; elseif (x <= -1.8e-6) tmp = Float64(y * x); elseif (x <= 175000000.0) tmp = z; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * -x; tmp = 0.0; if (x <= -1.7e+72) tmp = t_0; elseif (x <= -1.8e-6) tmp = y * x; elseif (x <= 175000000.0) tmp = z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * (-x)), $MachinePrecision]}, If[LessEqual[x, -1.7e+72], t$95$0, If[LessEqual[x, -1.8e-6], N[(y * x), $MachinePrecision], If[LessEqual[x, 175000000.0], z, t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(-x\right)\\
\mathbf{if}\;x \leq -1.7 \cdot 10^{+72}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -1.8 \cdot 10^{-6}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 175000000:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < -1.6999999999999999e72 or 1.75e8 < x Initial program 93.3%
Taylor expanded in y around 0 61.8%
Taylor expanded in x around inf 61.8%
mul-1-neg61.8%
distribute-rgt-neg-out61.8%
Simplified61.8%
if -1.6999999999999999e72 < x < -1.79999999999999992e-6Initial program 100.0%
Taylor expanded in y around inf 65.6%
if -1.79999999999999992e-6 < x < 1.75e8Initial program 100.0%
Taylor expanded in x around 0 68.7%
Final simplification65.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -9e-6) (not (<= x 1.0))) (* (- y z) x) (* z (- 1.0 x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9e-6) || !(x <= 1.0)) {
tmp = (y - z) * x;
} 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 <= (-9d-6)) .or. (.not. (x <= 1.0d0))) then
tmp = (y - z) * x
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 <= -9e-6) || !(x <= 1.0)) {
tmp = (y - z) * x;
} else {
tmp = z * (1.0 - x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -9e-6) or not (x <= 1.0): tmp = (y - z) * x else: tmp = z * (1.0 - x) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -9e-6) || !(x <= 1.0)) tmp = Float64(Float64(y - z) * x); else tmp = Float64(z * Float64(1.0 - x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -9e-6) || ~((x <= 1.0))) tmp = (y - z) * x; else tmp = z * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -9e-6], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(N[(y - z), $MachinePrecision] * x), $MachinePrecision], N[(z * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9 \cdot 10^{-6} \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\left(y - z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if x < -9.00000000000000023e-6 or 1 < x Initial program 94.2%
*-commutative94.2%
distribute-lft-out--94.2%
*-rgt-identity94.2%
cancel-sign-sub-inv94.2%
+-commutative94.2%
associate-+r+94.2%
*-commutative94.2%
distribute-rgt-out100.0%
+-commutative100.0%
fma-def100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 99.7%
if -9.00000000000000023e-6 < x < 1Initial program 100.0%
Taylor expanded in y around 0 71.1%
Final simplification84.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.05e-5) (not (<= x 85.0))) (* (- y z) x) (- z (* z x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.05e-5) || !(x <= 85.0)) {
tmp = (y - z) * x;
} else {
tmp = z - (z * 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 <= (-1.05d-5)) .or. (.not. (x <= 85.0d0))) then
tmp = (y - z) * x
else
tmp = z - (z * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.05e-5) || !(x <= 85.0)) {
tmp = (y - z) * x;
} else {
tmp = z - (z * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.05e-5) or not (x <= 85.0): tmp = (y - z) * x else: tmp = z - (z * x) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.05e-5) || !(x <= 85.0)) tmp = Float64(Float64(y - z) * x); else tmp = Float64(z - Float64(z * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.05e-5) || ~((x <= 85.0))) tmp = (y - z) * x; else tmp = z - (z * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.05e-5], N[Not[LessEqual[x, 85.0]], $MachinePrecision]], N[(N[(y - z), $MachinePrecision] * x), $MachinePrecision], N[(z - N[(z * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.05 \cdot 10^{-5} \lor \neg \left(x \leq 85\right):\\
\;\;\;\;\left(y - z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;z - z \cdot x\\
\end{array}
\end{array}
if x < -1.04999999999999994e-5 or 85 < x Initial program 94.2%
*-commutative94.2%
distribute-lft-out--94.2%
*-rgt-identity94.2%
cancel-sign-sub-inv94.2%
+-commutative94.2%
associate-+r+94.2%
*-commutative94.2%
distribute-rgt-out100.0%
+-commutative100.0%
fma-def100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 99.7%
if -1.04999999999999994e-5 < x < 85Initial program 100.0%
Taylor expanded in y around 0 71.1%
sub-neg71.1%
distribute-rgt-in71.2%
*-un-lft-identity71.2%
Applied egg-rr71.2%
distribute-lft-neg-out71.2%
unsub-neg71.2%
*-commutative71.2%
Applied egg-rr71.2%
Final simplification84.7%
(FPCore (x y z) :precision binary64 (if (<= y -3.5e-32) (* y x) (if (<= y 8.4e+18) (* z (- 1.0 x)) (* y x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.5e-32) {
tmp = y * x;
} else if (y <= 8.4e+18) {
tmp = z * (1.0 - x);
} 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 (y <= (-3.5d-32)) then
tmp = y * x
else if (y <= 8.4d+18) then
tmp = z * (1.0d0 - x)
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -3.5e-32) {
tmp = y * x;
} else if (y <= 8.4e+18) {
tmp = z * (1.0 - x);
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.5e-32: tmp = y * x elif y <= 8.4e+18: tmp = z * (1.0 - x) else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.5e-32) tmp = Float64(y * x); elseif (y <= 8.4e+18) tmp = Float64(z * Float64(1.0 - x)); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.5e-32) tmp = y * x; elseif (y <= 8.4e+18) tmp = z * (1.0 - x); else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.5e-32], N[(y * x), $MachinePrecision], If[LessEqual[y, 8.4e+18], N[(z * N[(1.0 - x), $MachinePrecision]), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.5 \cdot 10^{-32}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 8.4 \cdot 10^{+18}:\\
\;\;\;\;z \cdot \left(1 - x\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -3.4999999999999999e-32 or 8.4e18 < y Initial program 94.3%
Taylor expanded in y around inf 69.2%
if -3.4999999999999999e-32 < y < 8.4e18Initial program 100.0%
Taylor expanded in y around 0 88.0%
Final simplification79.0%
(FPCore (x y z) :precision binary64 (if (<= x -2.5e-6) (* y x) (if (<= x 6.5e-10) z (* y x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.5e-6) {
tmp = y * x;
} else if (x <= 6.5e-10) {
tmp = 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 <= (-2.5d-6)) then
tmp = y * x
else if (x <= 6.5d-10) then
tmp = 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 <= -2.5e-6) {
tmp = y * x;
} else if (x <= 6.5e-10) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.5e-6: tmp = y * x elif x <= 6.5e-10: tmp = z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.5e-6) tmp = Float64(y * x); elseif (x <= 6.5e-10) tmp = z; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.5e-6) tmp = y * x; elseif (x <= 6.5e-10) tmp = z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.5e-6], N[(y * x), $MachinePrecision], If[LessEqual[x, 6.5e-10], z, N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.5 \cdot 10^{-6}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 6.5 \cdot 10^{-10}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -2.5000000000000002e-6 or 6.5000000000000003e-10 < x Initial program 94.4%
Taylor expanded in y around inf 50.6%
if -2.5000000000000002e-6 < x < 6.5000000000000003e-10Initial program 100.0%
Taylor expanded in x around 0 70.6%
Final simplification60.8%
(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.2%
Taylor expanded in x around 0 37.9%
Final simplification37.9%
herbie shell --seed 2023274
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))