
(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 97.3%
Taylor expanded in x around 0
+-commutativeN/A
*-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
Applied rewrites100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (- z) x)))
(if (<= x -1.35e+175)
(* y x)
(if (<= x -1.05e+57)
t_0
(if (<= x -8e-43)
(* y x)
(if (<= x 2.35e-167) (* 1.0 z) (if (<= x 1.4e+84) (* y x) t_0)))))))
double code(double x, double y, double z) {
double t_0 = -z * x;
double tmp;
if (x <= -1.35e+175) {
tmp = y * x;
} else if (x <= -1.05e+57) {
tmp = t_0;
} else if (x <= -8e-43) {
tmp = y * x;
} else if (x <= 2.35e-167) {
tmp = 1.0 * z;
} else if (x <= 1.4e+84) {
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 <= (-1.35d+175)) then
tmp = y * x
else if (x <= (-1.05d+57)) then
tmp = t_0
else if (x <= (-8d-43)) then
tmp = y * x
else if (x <= 2.35d-167) then
tmp = 1.0d0 * z
else if (x <= 1.4d+84) 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 <= -1.35e+175) {
tmp = y * x;
} else if (x <= -1.05e+57) {
tmp = t_0;
} else if (x <= -8e-43) {
tmp = y * x;
} else if (x <= 2.35e-167) {
tmp = 1.0 * z;
} else if (x <= 1.4e+84) {
tmp = y * x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -z * x tmp = 0 if x <= -1.35e+175: tmp = y * x elif x <= -1.05e+57: tmp = t_0 elif x <= -8e-43: tmp = y * x elif x <= 2.35e-167: tmp = 1.0 * z elif x <= 1.4e+84: 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 <= -1.35e+175) tmp = Float64(y * x); elseif (x <= -1.05e+57) tmp = t_0; elseif (x <= -8e-43) tmp = Float64(y * x); elseif (x <= 2.35e-167) tmp = Float64(1.0 * z); elseif (x <= 1.4e+84) 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 <= -1.35e+175) tmp = y * x; elseif (x <= -1.05e+57) tmp = t_0; elseif (x <= -8e-43) tmp = y * x; elseif (x <= 2.35e-167) tmp = 1.0 * z; elseif (x <= 1.4e+84) 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, -1.35e+175], N[(y * x), $MachinePrecision], If[LessEqual[x, -1.05e+57], t$95$0, If[LessEqual[x, -8e-43], N[(y * x), $MachinePrecision], If[LessEqual[x, 2.35e-167], N[(1.0 * z), $MachinePrecision], If[LessEqual[x, 1.4e+84], N[(y * x), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-z\right) \cdot x\\
\mathbf{if}\;x \leq -1.35 \cdot 10^{+175}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq -1.05 \cdot 10^{+57}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -8 \cdot 10^{-43}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 2.35 \cdot 10^{-167}:\\
\;\;\;\;1 \cdot z\\
\mathbf{elif}\;x \leq 1.4 \cdot 10^{+84}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.35e175 or -1.04999999999999995e57 < x < -8.00000000000000062e-43 or 2.34999999999999985e-167 < x < 1.39999999999999991e84Initial program 95.3%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6442.3
Applied rewrites42.3%
Taylor expanded in x around 0
Applied rewrites20.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6461.2
Applied rewrites61.2%
if -1.35e175 < x < -1.04999999999999995e57 or 1.39999999999999991e84 < x Initial program 97.0%
Taylor expanded in x around inf
*-commutativeN/A
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--.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites65.8%
if -8.00000000000000062e-43 < x < 2.34999999999999985e-167Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6476.3
Applied rewrites76.3%
Taylor expanded in x around 0
Applied rewrites76.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.3e-44) (not (<= x 2.35e-167))) (* (- y z) x) (* 1.0 z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.3e-44) || !(x <= 2.35e-167)) {
tmp = (y - z) * x;
} else {
tmp = 1.0 * 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 <= (-4.3d-44)) .or. (.not. (x <= 2.35d-167))) then
tmp = (y - z) * x
else
tmp = 1.0d0 * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4.3e-44) || !(x <= 2.35e-167)) {
tmp = (y - z) * x;
} else {
tmp = 1.0 * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.3e-44) or not (x <= 2.35e-167): tmp = (y - z) * x else: tmp = 1.0 * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.3e-44) || !(x <= 2.35e-167)) tmp = Float64(Float64(y - z) * x); else tmp = Float64(1.0 * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.3e-44) || ~((x <= 2.35e-167))) tmp = (y - z) * x; else tmp = 1.0 * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.3e-44], N[Not[LessEqual[x, 2.35e-167]], $MachinePrecision]], N[(N[(y - z), $MachinePrecision] * x), $MachinePrecision], N[(1.0 * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.3 \cdot 10^{-44} \lor \neg \left(x \leq 2.35 \cdot 10^{-167}\right):\\
\;\;\;\;\left(y - z\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;1 \cdot z\\
\end{array}
\end{array}
if x < -4.30000000000000013e-44 or 2.34999999999999985e-167 < x Initial program 96.0%
Taylor expanded in x around inf
*-commutativeN/A
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--.f6488.9
Applied rewrites88.9%
if -4.30000000000000013e-44 < x < 2.34999999999999985e-167Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6476.3
Applied rewrites76.3%
Taylor expanded in x around 0
Applied rewrites76.3%
Final simplification84.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.1e-95) (not (<= z 540000000000.0))) (* (- 1.0 x) z) (* y x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.1e-95) || !(z <= 540000000000.0)) {
tmp = (1.0 - x) * 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 ((z <= (-2.1d-95)) .or. (.not. (z <= 540000000000.0d0))) then
tmp = (1.0d0 - x) * z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2.1e-95) || !(z <= 540000000000.0)) {
tmp = (1.0 - x) * z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.1e-95) or not (z <= 540000000000.0): tmp = (1.0 - x) * z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.1e-95) || !(z <= 540000000000.0)) tmp = Float64(Float64(1.0 - x) * z); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.1e-95) || ~((z <= 540000000000.0))) tmp = (1.0 - x) * z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.1e-95], N[Not[LessEqual[z, 540000000000.0]], $MachinePrecision]], N[(N[(1.0 - x), $MachinePrecision] * z), $MachinePrecision], N[(y * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.1 \cdot 10^{-95} \lor \neg \left(z \leq 540000000000\right):\\
\;\;\;\;\left(1 - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if z < -2.1e-95 or 5.4e11 < z Initial program 94.8%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6486.6
Applied rewrites86.6%
if -2.1e-95 < z < 5.4e11Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6429.6
Applied rewrites29.6%
Taylor expanded in x around 0
Applied rewrites23.4%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6471.9
Applied rewrites71.9%
Final simplification79.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -8e-43) (not (<= x 2.35e-167))) (* y x) (* 1.0 z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8e-43) || !(x <= 2.35e-167)) {
tmp = y * x;
} else {
tmp = 1.0 * 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 <= (-8d-43)) .or. (.not. (x <= 2.35d-167))) then
tmp = y * x
else
tmp = 1.0d0 * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -8e-43) || !(x <= 2.35e-167)) {
tmp = y * x;
} else {
tmp = 1.0 * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8e-43) or not (x <= 2.35e-167): tmp = y * x else: tmp = 1.0 * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8e-43) || !(x <= 2.35e-167)) tmp = Float64(y * x); else tmp = Float64(1.0 * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -8e-43) || ~((x <= 2.35e-167))) tmp = y * x; else tmp = 1.0 * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8e-43], N[Not[LessEqual[x, 2.35e-167]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(1.0 * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8 \cdot 10^{-43} \lor \neg \left(x \leq 2.35 \cdot 10^{-167}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;1 \cdot z\\
\end{array}
\end{array}
if x < -8.00000000000000062e-43 or 2.34999999999999985e-167 < x Initial program 96.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6451.3
Applied rewrites51.3%
Taylor expanded in x around 0
Applied rewrites13.4%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6452.7
Applied rewrites52.7%
if -8.00000000000000062e-43 < x < 2.34999999999999985e-167Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6476.3
Applied rewrites76.3%
Taylor expanded in x around 0
Applied rewrites76.3%
Final simplification60.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 97.3%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f6459.4
Applied rewrites59.4%
Taylor expanded in x around 0
Applied rewrites33.8%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6443.8
Applied rewrites43.8%
herbie shell --seed 2024323
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))