
(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 (+ z (* x (- y z))))
double code(double x, double y, double z) {
return z + (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 = z + (x * (y - z))
end function
public static double code(double x, double y, double z) {
return z + (x * (y - z));
}
def code(x, y, z): return z + (x * (y - z))
function code(x, y, z) return Float64(z + Float64(x * Float64(y - z))) end
function tmp = code(x, y, z) tmp = z + (x * (y - z)); end
code[x_, y_, z_] := N[(z + N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + x \cdot \left(y - z\right)
\end{array}
Initial program 97.3%
Taylor expanded in x around 0 100.0%
neg-mul-1100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (- x))))
(if (<= x -5.5e+140)
(* x y)
(if (<= x -2.05e+30)
t_0
(if (<= x -3.8e-112) (* x y) (if (<= x 1.0) z t_0))))))
double code(double x, double y, double z) {
double t_0 = z * -x;
double tmp;
if (x <= -5.5e+140) {
tmp = x * y;
} else if (x <= -2.05e+30) {
tmp = t_0;
} else if (x <= -3.8e-112) {
tmp = x * y;
} else if (x <= 1.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 <= (-5.5d+140)) then
tmp = x * y
else if (x <= (-2.05d+30)) then
tmp = t_0
else if (x <= (-3.8d-112)) then
tmp = x * y
else if (x <= 1.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 <= -5.5e+140) {
tmp = x * y;
} else if (x <= -2.05e+30) {
tmp = t_0;
} else if (x <= -3.8e-112) {
tmp = x * y;
} else if (x <= 1.0) {
tmp = z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * -x tmp = 0 if x <= -5.5e+140: tmp = x * y elif x <= -2.05e+30: tmp = t_0 elif x <= -3.8e-112: tmp = x * y elif x <= 1.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 <= -5.5e+140) tmp = Float64(x * y); elseif (x <= -2.05e+30) tmp = t_0; elseif (x <= -3.8e-112) tmp = Float64(x * y); elseif (x <= 1.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 <= -5.5e+140) tmp = x * y; elseif (x <= -2.05e+30) tmp = t_0; elseif (x <= -3.8e-112) tmp = x * y; elseif (x <= 1.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, -5.5e+140], N[(x * y), $MachinePrecision], If[LessEqual[x, -2.05e+30], t$95$0, If[LessEqual[x, -3.8e-112], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.0], z, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(-x\right)\\
\mathbf{if}\;x \leq -5.5 \cdot 10^{+140}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -2.05 \cdot 10^{+30}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -3.8 \cdot 10^{-112}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < -5.5e140 or -2.05000000000000003e30 < x < -3.79999999999999995e-112Initial program 92.0%
Taylor expanded in y around inf 70.8%
if -5.5e140 < x < -2.05000000000000003e30 or 1 < x Initial program 96.9%
Taylor expanded in x around inf 99.2%
neg-mul-199.2%
unsub-neg99.2%
Simplified99.2%
Taylor expanded in y around 0 62.6%
mul-1-neg62.6%
distribute-lft-neg-out62.6%
*-commutative62.6%
Simplified62.6%
if -3.79999999999999995e-112 < x < 1Initial program 100.0%
Taylor expanded in x around 0 77.7%
Final simplification70.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.8e-112) (not (<= x 7.5e-9))) (* x (- y z)) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.8e-112) || !(x <= 7.5e-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 <= (-3.8d-112)) .or. (.not. (x <= 7.5d-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 <= -3.8e-112) || !(x <= 7.5e-9)) {
tmp = x * (y - z);
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.8e-112) or not (x <= 7.5e-9): tmp = x * (y - z) else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.8e-112) || !(x <= 7.5e-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 <= -3.8e-112) || ~((x <= 7.5e-9))) tmp = x * (y - z); else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.8e-112], N[Not[LessEqual[x, 7.5e-9]], $MachinePrecision]], N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.8 \cdot 10^{-112} \lor \neg \left(x \leq 7.5 \cdot 10^{-9}\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -3.79999999999999995e-112 or 7.49999999999999933e-9 < x Initial program 95.2%
Taylor expanded in x around inf 95.1%
neg-mul-195.1%
unsub-neg95.1%
Simplified95.1%
if -3.79999999999999995e-112 < x < 7.49999999999999933e-9Initial program 100.0%
Taylor expanded in x around 0 77.7%
Final simplification87.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.5e-112) (not (<= x 58000.0))) (* x (- y z)) (* z (- 1.0 x))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.5e-112) || !(x <= 58000.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 <= (-3.5d-112)) .or. (.not. (x <= 58000.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 <= -3.5e-112) || !(x <= 58000.0)) {
tmp = x * (y - z);
} else {
tmp = z * (1.0 - x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.5e-112) or not (x <= 58000.0): tmp = x * (y - z) else: tmp = z * (1.0 - x) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.5e-112) || !(x <= 58000.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 <= -3.5e-112) || ~((x <= 58000.0))) tmp = x * (y - z); else tmp = z * (1.0 - x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.5e-112], N[Not[LessEqual[x, 58000.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 -3.5 \cdot 10^{-112} \lor \neg \left(x \leq 58000\right):\\
\;\;\;\;x \cdot \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if x < -3.49999999999999994e-112 or 58000 < x Initial program 95.2%
Taylor expanded in x around inf 95.6%
neg-mul-195.6%
unsub-neg95.6%
Simplified95.6%
if -3.49999999999999994e-112 < x < 58000Initial program 100.0%
Taylor expanded in y around 0 78.0%
Final simplification88.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.5e-112) (not (<= x 8.2e-7))) (* x y) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.5e-112) || !(x <= 8.2e-7)) {
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 <= (-3.5d-112)) .or. (.not. (x <= 8.2d-7))) 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 <= -3.5e-112) || !(x <= 8.2e-7)) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.5e-112) or not (x <= 8.2e-7): tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.5e-112) || !(x <= 8.2e-7)) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.5e-112) || ~((x <= 8.2e-7))) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.5e-112], N[Not[LessEqual[x, 8.2e-7]], $MachinePrecision]], N[(x * y), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.5 \cdot 10^{-112} \lor \neg \left(x \leq 8.2 \cdot 10^{-7}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -3.49999999999999994e-112 or 8.1999999999999998e-7 < x Initial program 95.2%
Taylor expanded in y around inf 56.4%
if -3.49999999999999994e-112 < x < 8.1999999999999998e-7Initial program 100.0%
Taylor expanded in x around 0 77.7%
Final simplification65.5%
(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 37.0%
Final simplification37.0%
herbie shell --seed 2023305
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))