
(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 3 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 (+ 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%
remove-double-neg98.0%
distribute-rgt-neg-out98.0%
neg-sub098.0%
neg-sub098.0%
*-commutative98.0%
distribute-lft-neg-in98.0%
remove-double-neg98.0%
distribute-rgt-out--98.0%
*-lft-identity98.0%
associate-+l-98.0%
distribute-lft-out--100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.1e+74) (not (<= z 1.35e-99))) (+ y (* x z)) (- y (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.1e+74) || !(z <= 1.35e-99)) {
tmp = y + (x * z);
} else {
tmp = y - (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 <= (-3.1d+74)) .or. (.not. (z <= 1.35d-99))) then
tmp = y + (x * z)
else
tmp = y - (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3.1e+74) || !(z <= 1.35e-99)) {
tmp = y + (x * z);
} else {
tmp = y - (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.1e+74) or not (z <= 1.35e-99): tmp = y + (x * z) else: tmp = y - (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.1e+74) || !(z <= 1.35e-99)) tmp = Float64(y + Float64(x * z)); else tmp = Float64(y - Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.1e+74) || ~((z <= 1.35e-99))) tmp = y + (x * z); else tmp = y - (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.1e+74], N[Not[LessEqual[z, 1.35e-99]], $MachinePrecision]], N[(y + N[(x * z), $MachinePrecision]), $MachinePrecision], N[(y - N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.1 \cdot 10^{+74} \lor \neg \left(z \leq 1.35 \cdot 10^{-99}\right):\\
\;\;\;\;y + x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y - y \cdot x\\
\end{array}
\end{array}
if z < -3.10000000000000021e74 or 1.35e-99 < z Initial program 96.2%
remove-double-neg96.2%
distribute-rgt-neg-out96.2%
neg-sub096.2%
neg-sub096.2%
*-commutative96.2%
distribute-lft-neg-in96.2%
remove-double-neg96.2%
distribute-rgt-out--96.2%
*-lft-identity96.2%
associate-+l-96.2%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in y around 0 94.0%
associate-*r*94.0%
*-commutative94.0%
mul-1-neg94.0%
Simplified94.0%
if -3.10000000000000021e74 < z < 1.35e-99Initial program 100.0%
remove-double-neg100.0%
distribute-rgt-neg-out100.0%
neg-sub0100.0%
neg-sub0100.0%
*-commutative100.0%
distribute-lft-neg-in100.0%
remove-double-neg100.0%
distribute-rgt-out--100.0%
*-lft-identity100.0%
associate-+l-100.0%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in y around inf 88.3%
Final simplification91.3%
(FPCore (x y z) :precision binary64 (- y (* y x)))
double code(double x, double y, double z) {
return y - (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 - (y * x)
end function
public static double code(double x, double y, double z) {
return y - (y * x);
}
def code(x, y, z): return y - (y * x)
function code(x, y, z) return Float64(y - Float64(y * x)) end
function tmp = code(x, y, z) tmp = y - (y * x); end
code[x_, y_, z_] := N[(y - N[(y * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y - y \cdot x
\end{array}
Initial program 98.0%
remove-double-neg98.0%
distribute-rgt-neg-out98.0%
neg-sub098.0%
neg-sub098.0%
*-commutative98.0%
distribute-lft-neg-in98.0%
remove-double-neg98.0%
distribute-rgt-out--98.0%
*-lft-identity98.0%
associate-+l-98.0%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in y around inf 61.4%
Final simplification61.4%
(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 2023322
(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)))