
(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%
sub-neg98.0%
+-commutative98.0%
distribute-rgt1-in98.0%
associate-+l+98.0%
+-commutative98.0%
*-commutative98.0%
neg-mul-198.0%
associate-*r*98.0%
*-commutative98.0%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- y))))
(if (<= x -1e+45)
(* x z)
(if (<= x -1.55e+27)
t_0
(if (<= x -1.5e-12)
(* x z)
(if (<= x 7.5e-123)
y
(if (<= x 7.5e-72)
(* x z)
(if (<= x 3.7e-32)
y
(if (<= x 3.1e+182)
(* x z)
(if (<= x 1.6e+206) t_0 (* x z)))))))))))
double code(double x, double y, double z) {
double t_0 = x * -y;
double tmp;
if (x <= -1e+45) {
tmp = x * z;
} else if (x <= -1.55e+27) {
tmp = t_0;
} else if (x <= -1.5e-12) {
tmp = x * z;
} else if (x <= 7.5e-123) {
tmp = y;
} else if (x <= 7.5e-72) {
tmp = x * z;
} else if (x <= 3.7e-32) {
tmp = y;
} else if (x <= 3.1e+182) {
tmp = x * z;
} else if (x <= 1.6e+206) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = x * -y
if (x <= (-1d+45)) then
tmp = x * z
else if (x <= (-1.55d+27)) then
tmp = t_0
else if (x <= (-1.5d-12)) then
tmp = x * z
else if (x <= 7.5d-123) then
tmp = y
else if (x <= 7.5d-72) then
tmp = x * z
else if (x <= 3.7d-32) then
tmp = y
else if (x <= 3.1d+182) then
tmp = x * z
else if (x <= 1.6d+206) then
tmp = t_0
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * -y;
double tmp;
if (x <= -1e+45) {
tmp = x * z;
} else if (x <= -1.55e+27) {
tmp = t_0;
} else if (x <= -1.5e-12) {
tmp = x * z;
} else if (x <= 7.5e-123) {
tmp = y;
} else if (x <= 7.5e-72) {
tmp = x * z;
} else if (x <= 3.7e-32) {
tmp = y;
} else if (x <= 3.1e+182) {
tmp = x * z;
} else if (x <= 1.6e+206) {
tmp = t_0;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): t_0 = x * -y tmp = 0 if x <= -1e+45: tmp = x * z elif x <= -1.55e+27: tmp = t_0 elif x <= -1.5e-12: tmp = x * z elif x <= 7.5e-123: tmp = y elif x <= 7.5e-72: tmp = x * z elif x <= 3.7e-32: tmp = y elif x <= 3.1e+182: tmp = x * z elif x <= 1.6e+206: tmp = t_0 else: tmp = x * z return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-y)) tmp = 0.0 if (x <= -1e+45) tmp = Float64(x * z); elseif (x <= -1.55e+27) tmp = t_0; elseif (x <= -1.5e-12) tmp = Float64(x * z); elseif (x <= 7.5e-123) tmp = y; elseif (x <= 7.5e-72) tmp = Float64(x * z); elseif (x <= 3.7e-32) tmp = y; elseif (x <= 3.1e+182) tmp = Float64(x * z); elseif (x <= 1.6e+206) tmp = t_0; else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -y; tmp = 0.0; if (x <= -1e+45) tmp = x * z; elseif (x <= -1.55e+27) tmp = t_0; elseif (x <= -1.5e-12) tmp = x * z; elseif (x <= 7.5e-123) tmp = y; elseif (x <= 7.5e-72) tmp = x * z; elseif (x <= 3.7e-32) tmp = y; elseif (x <= 3.1e+182) tmp = x * z; elseif (x <= 1.6e+206) tmp = t_0; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-y)), $MachinePrecision]}, If[LessEqual[x, -1e+45], N[(x * z), $MachinePrecision], If[LessEqual[x, -1.55e+27], t$95$0, If[LessEqual[x, -1.5e-12], N[(x * z), $MachinePrecision], If[LessEqual[x, 7.5e-123], y, If[LessEqual[x, 7.5e-72], N[(x * z), $MachinePrecision], If[LessEqual[x, 3.7e-32], y, If[LessEqual[x, 3.1e+182], N[(x * z), $MachinePrecision], If[LessEqual[x, 1.6e+206], t$95$0, N[(x * z), $MachinePrecision]]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-y\right)\\
\mathbf{if}\;x \leq -1 \cdot 10^{+45}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -1.55 \cdot 10^{+27}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -1.5 \cdot 10^{-12}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 7.5 \cdot 10^{-123}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq 7.5 \cdot 10^{-72}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 3.7 \cdot 10^{-32}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq 3.1 \cdot 10^{+182}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 1.6 \cdot 10^{+206}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -9.9999999999999993e44 or -1.54999999999999998e27 < x < -1.5000000000000001e-12 or 7.50000000000000011e-123 < x < 7.5000000000000004e-72 or 3.7e-32 < x < 3.09999999999999996e182 or 1.60000000000000003e206 < x Initial program 96.7%
Taylor expanded in y around 0 66.6%
if -9.9999999999999993e44 < x < -1.54999999999999998e27 or 3.09999999999999996e182 < x < 1.60000000000000003e206Initial program 95.0%
sub-neg95.0%
+-commutative95.0%
distribute-rgt1-in95.0%
associate-+l+95.0%
+-commutative95.0%
*-commutative95.0%
neg-mul-195.0%
associate-*r*95.0%
*-commutative95.0%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in z around 0 80.3%
mul-1-neg80.3%
distribute-rgt-neg-in80.3%
Simplified80.3%
if -1.5000000000000001e-12 < x < 7.50000000000000011e-123 or 7.5000000000000004e-72 < x < 3.7e-32Initial program 100.0%
Taylor expanded in x around 0 77.0%
Final simplification72.3%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- z y))))
(if (<= x -5.4e-13)
t_0
(if (<= x 1.45e-126)
y
(if (<= x 8.5e-72) (* x z) (if (<= x 1.9e-31) y t_0))))))
double code(double x, double y, double z) {
double t_0 = x * (z - y);
double tmp;
if (x <= -5.4e-13) {
tmp = t_0;
} else if (x <= 1.45e-126) {
tmp = y;
} else if (x <= 8.5e-72) {
tmp = x * z;
} else if (x <= 1.9e-31) {
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 <= (-5.4d-13)) then
tmp = t_0
else if (x <= 1.45d-126) then
tmp = y
else if (x <= 8.5d-72) then
tmp = x * z
else if (x <= 1.9d-31) 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 <= -5.4e-13) {
tmp = t_0;
} else if (x <= 1.45e-126) {
tmp = y;
} else if (x <= 8.5e-72) {
tmp = x * z;
} else if (x <= 1.9e-31) {
tmp = y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * (z - y) tmp = 0 if x <= -5.4e-13: tmp = t_0 elif x <= 1.45e-126: tmp = y elif x <= 8.5e-72: tmp = x * z elif x <= 1.9e-31: 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 <= -5.4e-13) tmp = t_0; elseif (x <= 1.45e-126) tmp = y; elseif (x <= 8.5e-72) tmp = Float64(x * z); elseif (x <= 1.9e-31) 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 <= -5.4e-13) tmp = t_0; elseif (x <= 1.45e-126) tmp = y; elseif (x <= 8.5e-72) tmp = x * z; elseif (x <= 1.9e-31) 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, -5.4e-13], t$95$0, If[LessEqual[x, 1.45e-126], y, If[LessEqual[x, 8.5e-72], N[(x * z), $MachinePrecision], If[LessEqual[x, 1.9e-31], y, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(z - y\right)\\
\mathbf{if}\;x \leq -5.4 \cdot 10^{-13}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 1.45 \cdot 10^{-126}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq 8.5 \cdot 10^{-72}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 1.9 \cdot 10^{-31}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < -5.40000000000000021e-13 or 1.9e-31 < x Initial program 96.1%
sub-neg96.1%
+-commutative96.1%
distribute-rgt1-in96.1%
associate-+l+96.1%
+-commutative96.1%
*-commutative96.1%
neg-mul-196.1%
associate-*r*96.1%
*-commutative96.1%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 98.0%
if -5.40000000000000021e-13 < x < 1.44999999999999994e-126 or 8.50000000000000008e-72 < x < 1.9e-31Initial program 100.0%
Taylor expanded in x around 0 77.0%
if 1.44999999999999994e-126 < x < 8.50000000000000008e-72Initial program 100.0%
Taylor expanded in y around 0 84.3%
Final simplification88.0%
(FPCore (x y z)
:precision binary64
(if (<= x -2.7e-8)
(* x z)
(if (<= x 3.9e-124)
y
(if (<= x 5.6e-73) (* x z) (if (<= x 1.75e-32) y (* x z))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.7e-8) {
tmp = x * z;
} else if (x <= 3.9e-124) {
tmp = y;
} else if (x <= 5.6e-73) {
tmp = x * z;
} else if (x <= 1.75e-32) {
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 <= (-2.7d-8)) then
tmp = x * z
else if (x <= 3.9d-124) then
tmp = y
else if (x <= 5.6d-73) then
tmp = x * z
else if (x <= 1.75d-32) 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 <= -2.7e-8) {
tmp = x * z;
} else if (x <= 3.9e-124) {
tmp = y;
} else if (x <= 5.6e-73) {
tmp = x * z;
} else if (x <= 1.75e-32) {
tmp = y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.7e-8: tmp = x * z elif x <= 3.9e-124: tmp = y elif x <= 5.6e-73: tmp = x * z elif x <= 1.75e-32: tmp = y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.7e-8) tmp = Float64(x * z); elseif (x <= 3.9e-124) tmp = y; elseif (x <= 5.6e-73) tmp = Float64(x * z); elseif (x <= 1.75e-32) tmp = y; else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.7e-8) tmp = x * z; elseif (x <= 3.9e-124) tmp = y; elseif (x <= 5.6e-73) tmp = x * z; elseif (x <= 1.75e-32) tmp = y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.7e-8], N[(x * z), $MachinePrecision], If[LessEqual[x, 3.9e-124], y, If[LessEqual[x, 5.6e-73], N[(x * z), $MachinePrecision], If[LessEqual[x, 1.75e-32], y, N[(x * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.7 \cdot 10^{-8}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 3.9 \cdot 10^{-124}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq 5.6 \cdot 10^{-73}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 1.75 \cdot 10^{-32}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -2.70000000000000002e-8 or 3.89999999999999993e-124 < x < 5.60000000000000023e-73 or 1.7499999999999999e-32 < x Initial program 96.4%
Taylor expanded in y around 0 60.4%
if -2.70000000000000002e-8 < x < 3.89999999999999993e-124 or 5.60000000000000023e-73 < x < 1.7499999999999999e-32Initial program 100.0%
Taylor expanded in x around 0 77.0%
Final simplification67.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (* x (- z y)) (+ y (* x z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.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 <= (-1.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 <= -1.0) || !(x <= 1.0)) {
tmp = x * (z - y);
} else {
tmp = y + (x * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.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 <= -1.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 <= -1.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, -1.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 -1 \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 < -1 or 1 < x Initial program 95.9%
sub-neg95.9%
+-commutative95.9%
distribute-rgt1-in95.9%
associate-+l+95.9%
+-commutative95.9%
*-commutative95.9%
neg-mul-195.9%
associate-*r*95.9%
*-commutative95.9%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around inf 99.5%
if -1 < x < 1Initial program 100.0%
sub-neg100.0%
+-commutative100.0%
distribute-rgt1-in100.0%
associate-+l+100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
associate-*r*100.0%
*-commutative100.0%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in z around inf 99.2%
Final simplification99.4%
(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%
sub-neg98.0%
+-commutative98.0%
distribute-rgt1-in98.0%
associate-+l+98.0%
+-commutative98.0%
*-commutative98.0%
neg-mul-198.0%
associate-*r*98.0%
*-commutative98.0%
distribute-rgt-out100.0%
fma-def100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.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 37.0%
Final simplification37.0%
(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 2023199
(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)))