
(FPCore (x y z) :precision binary64 (+ (* (- 1.0 x) y) (* x z)))
double code(double x, double y, double z) {
return ((1.0 - x) * y) + (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 = ((1.0d0 - x) * y) + (x * z)
end function
public static double code(double x, double y, double z) {
return ((1.0 - x) * y) + (x * z);
}
def code(x, y, z): return ((1.0 - x) * y) + (x * z)
function code(x, y, z) return Float64(Float64(Float64(1.0 - x) * y) + Float64(x * z)) end
function tmp = code(x, y, z) tmp = ((1.0 - x) * y) + (x * z); end
code[x_, y_, z_] := N[(N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision] + N[(x * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(1 - x\right) \cdot y + x \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* (- 1.0 x) y) (* x z)))
double code(double x, double y, double z) {
return ((1.0 - x) * y) + (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 = ((1.0d0 - x) * y) + (x * z)
end function
public static double code(double x, double y, double z) {
return ((1.0 - x) * y) + (x * z);
}
def code(x, y, z): return ((1.0 - x) * y) + (x * z)
function code(x, y, z) return Float64(Float64(Float64(1.0 - x) * y) + Float64(x * z)) end
function tmp = code(x, y, z) tmp = ((1.0 - x) * y) + (x * z); end
code[x_, y_, z_] := N[(N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision] + N[(x * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(1 - x\right) \cdot y + x \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (fma x (- z y) y))
double code(double x, double y, double z) {
return fma(x, (z - y), y);
}
function code(x, y, z) return fma(x, Float64(z - y), y) end
code[x_, y_, z_] := N[(x * N[(z - y), $MachinePrecision] + y), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, z - y, y\right)
\end{array}
Initial program 98.0%
*-commutative98.0%
distribute-lft-out--98.0%
*-rgt-identity98.0%
cancel-sign-sub-inv98.0%
+-commutative98.0%
+-commutative98.0%
associate-+l+98.0%
+-commutative98.0%
*-commutative98.0%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -7.5e-14)
(* x z)
(if (<= x -1.6e-103)
y
(if (<= x -1e-122)
(* x z)
(if (<= x 2.9e-104)
y
(if (or (<= x 1.6e+30) (and (not (<= x 1.2e+154)) (<= x 2.65e+272)))
(* x z)
(* x (- y))))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -7.5e-14) {
tmp = x * z;
} else if (x <= -1.6e-103) {
tmp = y;
} else if (x <= -1e-122) {
tmp = x * z;
} else if (x <= 2.9e-104) {
tmp = y;
} else if ((x <= 1.6e+30) || (!(x <= 1.2e+154) && (x <= 2.65e+272))) {
tmp = x * z;
} else {
tmp = 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 <= (-7.5d-14)) then
tmp = x * z
else if (x <= (-1.6d-103)) then
tmp = y
else if (x <= (-1d-122)) then
tmp = x * z
else if (x <= 2.9d-104) then
tmp = y
else if ((x <= 1.6d+30) .or. (.not. (x <= 1.2d+154)) .and. (x <= 2.65d+272)) then
tmp = x * z
else
tmp = x * -y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -7.5e-14) {
tmp = x * z;
} else if (x <= -1.6e-103) {
tmp = y;
} else if (x <= -1e-122) {
tmp = x * z;
} else if (x <= 2.9e-104) {
tmp = y;
} else if ((x <= 1.6e+30) || (!(x <= 1.2e+154) && (x <= 2.65e+272))) {
tmp = x * z;
} else {
tmp = x * -y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -7.5e-14: tmp = x * z elif x <= -1.6e-103: tmp = y elif x <= -1e-122: tmp = x * z elif x <= 2.9e-104: tmp = y elif (x <= 1.6e+30) or (not (x <= 1.2e+154) and (x <= 2.65e+272)): tmp = x * z else: tmp = x * -y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -7.5e-14) tmp = Float64(x * z); elseif (x <= -1.6e-103) tmp = y; elseif (x <= -1e-122) tmp = Float64(x * z); elseif (x <= 2.9e-104) tmp = y; elseif ((x <= 1.6e+30) || (!(x <= 1.2e+154) && (x <= 2.65e+272))) tmp = Float64(x * z); else tmp = Float64(x * Float64(-y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -7.5e-14) tmp = x * z; elseif (x <= -1.6e-103) tmp = y; elseif (x <= -1e-122) tmp = x * z; elseif (x <= 2.9e-104) tmp = y; elseif ((x <= 1.6e+30) || (~((x <= 1.2e+154)) && (x <= 2.65e+272))) tmp = x * z; else tmp = x * -y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -7.5e-14], N[(x * z), $MachinePrecision], If[LessEqual[x, -1.6e-103], y, If[LessEqual[x, -1e-122], N[(x * z), $MachinePrecision], If[LessEqual[x, 2.9e-104], y, If[Or[LessEqual[x, 1.6e+30], And[N[Not[LessEqual[x, 1.2e+154]], $MachinePrecision], LessEqual[x, 2.65e+272]]], N[(x * z), $MachinePrecision], N[(x * (-y)), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.5 \cdot 10^{-14}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -1.6 \cdot 10^{-103}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq -1 \cdot 10^{-122}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 2.9 \cdot 10^{-104}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq 1.6 \cdot 10^{+30} \lor \neg \left(x \leq 1.2 \cdot 10^{+154}\right) \land x \leq 2.65 \cdot 10^{+272}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(-y\right)\\
\end{array}
\end{array}
if x < -7.4999999999999996e-14 or -1.59999999999999988e-103 < x < -1.00000000000000006e-122 or 2.9000000000000001e-104 < x < 1.59999999999999986e30 or 1.20000000000000007e154 < x < 2.65000000000000005e272Initial program 97.5%
Taylor expanded in y around 0 69.4%
if -7.4999999999999996e-14 < x < -1.59999999999999988e-103 or -1.00000000000000006e-122 < x < 2.9000000000000001e-104Initial program 100.0%
Taylor expanded in x around 0 75.7%
if 1.59999999999999986e30 < x < 1.20000000000000007e154 or 2.65000000000000005e272 < x Initial program 95.1%
*-commutative95.1%
distribute-lft-out--95.1%
*-rgt-identity95.1%
cancel-sign-sub-inv95.1%
+-commutative95.1%
+-commutative95.1%
associate-+l+95.1%
+-commutative95.1%
*-commutative95.1%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in z around 0 77.9%
associate-*r*77.9%
neg-mul-177.9%
Simplified77.9%
Final simplification73.1%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- z y))))
(if (<= x -7e-14)
t_0
(if (<= x -9.5e-99)
y
(if (<= x -1.8e-122) (* x z) (if (<= x 2.55e-104) y t_0))))))
double code(double x, double y, double z) {
double t_0 = x * (z - y);
double tmp;
if (x <= -7e-14) {
tmp = t_0;
} else if (x <= -9.5e-99) {
tmp = y;
} else if (x <= -1.8e-122) {
tmp = x * z;
} else if (x <= 2.55e-104) {
tmp = 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 - y)
if (x <= (-7d-14)) then
tmp = t_0
else if (x <= (-9.5d-99)) then
tmp = y
else if (x <= (-1.8d-122)) then
tmp = x * z
else if (x <= 2.55d-104) then
tmp = 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 - y);
double tmp;
if (x <= -7e-14) {
tmp = t_0;
} else if (x <= -9.5e-99) {
tmp = y;
} else if (x <= -1.8e-122) {
tmp = x * z;
} else if (x <= 2.55e-104) {
tmp = y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (z - y) tmp = 0 if x <= -7e-14: tmp = t_0 elif x <= -9.5e-99: tmp = y elif x <= -1.8e-122: tmp = x * z elif x <= 2.55e-104: tmp = y else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(z - y)) tmp = 0.0 if (x <= -7e-14) tmp = t_0; elseif (x <= -9.5e-99) tmp = y; elseif (x <= -1.8e-122) tmp = Float64(x * z); elseif (x <= 2.55e-104) tmp = y; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (z - y); tmp = 0.0; if (x <= -7e-14) tmp = t_0; elseif (x <= -9.5e-99) tmp = y; elseif (x <= -1.8e-122) tmp = x * z; elseif (x <= 2.55e-104) tmp = y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -7e-14], t$95$0, If[LessEqual[x, -9.5e-99], y, If[LessEqual[x, -1.8e-122], N[(x * z), $MachinePrecision], If[LessEqual[x, 2.55e-104], y, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(z - y\right)\\
\mathbf{if}\;x \leq -7 \cdot 10^{-14}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -9.5 \cdot 10^{-99}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq -1.8 \cdot 10^{-122}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 2.55 \cdot 10^{-104}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < -7.0000000000000005e-14 or 2.54999999999999996e-104 < x Initial program 96.8%
*-commutative96.8%
distribute-lft-out--96.8%
*-rgt-identity96.8%
cancel-sign-sub-inv96.8%
+-commutative96.8%
+-commutative96.8%
associate-+l+96.8%
+-commutative96.8%
*-commutative96.8%
distribute-rgt-out99.9%
fma-def100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 92.2%
if -7.0000000000000005e-14 < x < -9.5000000000000008e-99 or -1.79999999999999997e-122 < x < 2.54999999999999996e-104Initial program 100.0%
Taylor expanded in x around 0 75.7%
if -9.5000000000000008e-99 < x < -1.79999999999999997e-122Initial program 100.0%
Taylor expanded in y around 0 100.0%
Final simplification86.3%
(FPCore (x y z)
:precision binary64
(if (<= x -7.8e-14)
(* x z)
(if (<= x -1.1e-102)
y
(if (<= x -4e-125) (* x z) (if (<= x 9.5e-107) y (* x z))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -7.8e-14) {
tmp = x * z;
} else if (x <= -1.1e-102) {
tmp = y;
} else if (x <= -4e-125) {
tmp = x * z;
} else if (x <= 9.5e-107) {
tmp = y;
} else {
tmp = x * 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 <= (-7.8d-14)) then
tmp = x * z
else if (x <= (-1.1d-102)) then
tmp = y
else if (x <= (-4d-125)) then
tmp = x * z
else if (x <= 9.5d-107) then
tmp = y
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -7.8e-14) {
tmp = x * z;
} else if (x <= -1.1e-102) {
tmp = y;
} else if (x <= -4e-125) {
tmp = x * z;
} else if (x <= 9.5e-107) {
tmp = y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -7.8e-14: tmp = x * z elif x <= -1.1e-102: tmp = y elif x <= -4e-125: tmp = x * z elif x <= 9.5e-107: tmp = y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -7.8e-14) tmp = Float64(x * z); elseif (x <= -1.1e-102) tmp = y; elseif (x <= -4e-125) tmp = Float64(x * z); elseif (x <= 9.5e-107) tmp = y; else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -7.8e-14) tmp = x * z; elseif (x <= -1.1e-102) tmp = y; elseif (x <= -4e-125) tmp = x * z; elseif (x <= 9.5e-107) tmp = y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -7.8e-14], N[(x * z), $MachinePrecision], If[LessEqual[x, -1.1e-102], y, If[LessEqual[x, -4e-125], N[(x * z), $MachinePrecision], If[LessEqual[x, 9.5e-107], y, N[(x * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.8 \cdot 10^{-14}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -1.1 \cdot 10^{-102}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq -4 \cdot 10^{-125}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 9.5 \cdot 10^{-107}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -7.7999999999999996e-14 or -1.10000000000000006e-102 < x < -4.00000000000000005e-125 or 9.4999999999999999e-107 < x Initial program 96.9%
Taylor expanded in y around 0 58.5%
if -7.7999999999999996e-14 < x < -1.10000000000000006e-102 or -4.00000000000000005e-125 < x < 9.4999999999999999e-107Initial program 100.0%
Taylor expanded in x around 0 75.7%
Final simplification64.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -70.0) (not (<= x 1.0))) (* x (- z y)) (+ y (* x z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -70.0) || !(x <= 1.0)) {
tmp = x * (z - y);
} else {
tmp = y + (x * 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 <= (-70.0d0)) .or. (.not. (x <= 1.0d0))) then
tmp = x * (z - y)
else
tmp = y + (x * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -70.0) || !(x <= 1.0)) {
tmp = x * (z - y);
} else {
tmp = y + (x * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -70.0) or not (x <= 1.0): tmp = x * (z - y) else: tmp = y + (x * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -70.0) || !(x <= 1.0)) tmp = Float64(x * Float64(z - y)); else tmp = Float64(y + Float64(x * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -70.0) || ~((x <= 1.0))) tmp = x * (z - y); else tmp = y + (x * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -70.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision], N[(y + N[(x * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -70 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;x \cdot \left(z - y\right)\\
\mathbf{else}:\\
\;\;\;\;y + x \cdot z\\
\end{array}
\end{array}
if x < -70 or 1 < x Initial program 96.1%
*-commutative96.1%
distribute-lft-out--96.1%
*-rgt-identity96.1%
cancel-sign-sub-inv96.1%
+-commutative96.1%
+-commutative96.1%
associate-+l+96.1%
+-commutative96.1%
*-commutative96.1%
distribute-rgt-out99.9%
fma-def99.9%
+-commutative99.9%
unsub-neg99.9%
Simplified99.9%
Taylor expanded in x around inf 99.7%
if -70 < x < 1Initial program 100.0%
*-commutative100.0%
distribute-lft-out--100.0%
*-rgt-identity100.0%
cancel-sign-sub-inv100.0%
+-commutative100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
*-commutative100.0%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in z around inf 98.5%
Final simplification99.1%
(FPCore (x y z) :precision binary64 (+ y (* x (- z y))))
double code(double x, double y, double z) {
return y + (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 = y + (x * (z - y))
end function
public static double code(double x, double y, double z) {
return y + (x * (z - y));
}
def code(x, y, z): return y + (x * (z - y))
function code(x, y, z) return Float64(y + Float64(x * Float64(z - y))) end
function tmp = code(x, y, z) tmp = y + (x * (z - y)); end
code[x_, y_, z_] := N[(y + N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y + x \cdot \left(z - y\right)
\end{array}
Initial program 98.0%
*-commutative98.0%
distribute-lft-out--98.0%
*-rgt-identity98.0%
cancel-sign-sub-inv98.0%
+-commutative98.0%
+-commutative98.0%
associate-+l+98.0%
+-commutative98.0%
*-commutative98.0%
distribute-rgt-out100.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 y)
double code(double x, double y, double z) {
return y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y
end function
public static double code(double x, double y, double z) {
return y;
}
def code(x, y, z): return y
function code(x, y, z) return y end
function tmp = code(x, y, z) tmp = y; end
code[x_, y_, z_] := y
\begin{array}{l}
\\
y
\end{array}
Initial program 98.0%
Taylor expanded in x around 0 32.9%
Final simplification32.9%
(FPCore (x y z) :precision binary64 (- y (* x (- y z))))
double code(double x, double y, double z) {
return y - (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 = y - (x * (y - z))
end function
public static double code(double x, double y, double z) {
return y - (x * (y - z));
}
def code(x, y, z): return y - (x * (y - z))
function code(x, y, z) return Float64(y - Float64(x * Float64(y - z))) end
function tmp = code(x, y, z) tmp = y - (x * (y - z)); end
code[x_, y_, z_] := N[(y - N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y - x \cdot \left(y - z\right)
\end{array}
herbie shell --seed 2023268
(FPCore (x y z)
:name "Diagrams.Color.HSV:lerp from diagrams-contrib-1.3.0.5"
:precision binary64
:herbie-target
(- y (* x (- y z)))
(+ (* (- 1.0 x) y) (* x z)))