
(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 5 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 (- z y))))
double code(double x, double y, double z) {
return z - (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 = z - (x * (z - y))
end function
public static double code(double x, double y, double z) {
return z - (x * (z - y));
}
def code(x, y, z): return z - (x * (z - y))
function code(x, y, z) return Float64(z - Float64(x * Float64(z - y))) end
function tmp = code(x, y, z) tmp = z - (x * (z - y)); end
code[x_, y_, z_] := N[(z - N[(x * N[(z - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z - x \cdot \left(z - y\right)
\end{array}
Initial program 96.9%
+-commutative96.9%
remove-double-neg96.9%
distribute-rgt-neg-out96.9%
neg-sub096.9%
neg-sub096.9%
*-commutative96.9%
distribute-lft-neg-in96.9%
remove-double-neg96.9%
distribute-rgt-out--96.9%
*-lft-identity96.9%
associate-+l-96.9%
distribute-lft-out--100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.95e-163) (not (<= y 6.4e+31))) (+ z (* x y)) (- z (* z x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.95e-163) || !(y <= 6.4e+31)) {
tmp = z + (x * y);
} else {
tmp = z - (z * 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 ((y <= (-1.95d-163)) .or. (.not. (y <= 6.4d+31))) then
tmp = z + (x * y)
else
tmp = z - (z * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.95e-163) || !(y <= 6.4e+31)) {
tmp = z + (x * y);
} else {
tmp = z - (z * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.95e-163) or not (y <= 6.4e+31): tmp = z + (x * y) else: tmp = z - (z * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.95e-163) || !(y <= 6.4e+31)) tmp = Float64(z + Float64(x * y)); else tmp = Float64(z - Float64(z * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.95e-163) || ~((y <= 6.4e+31))) tmp = z + (x * y); else tmp = z - (z * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.95e-163], N[Not[LessEqual[y, 6.4e+31]], $MachinePrecision]], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(z - N[(z * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.95 \cdot 10^{-163} \lor \neg \left(y \leq 6.4 \cdot 10^{+31}\right):\\
\;\;\;\;z + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z - z \cdot x\\
\end{array}
\end{array}
if y < -1.9500000000000001e-163 or 6.4000000000000001e31 < y Initial program 95.7%
+-commutative95.7%
remove-double-neg95.7%
distribute-rgt-neg-out95.7%
neg-sub095.7%
neg-sub095.7%
*-commutative95.7%
distribute-lft-neg-in95.7%
remove-double-neg95.7%
distribute-rgt-out--95.7%
*-lft-identity95.7%
associate-+l-95.7%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around 0 88.9%
mul-1-neg88.9%
distribute-rgt-neg-out88.9%
Simplified88.9%
if -1.9500000000000001e-163 < y < 6.4000000000000001e31Initial program 98.9%
+-commutative98.9%
remove-double-neg98.9%
distribute-rgt-neg-out98.9%
neg-sub098.9%
neg-sub098.9%
*-commutative98.9%
distribute-lft-neg-in98.9%
remove-double-neg98.9%
distribute-rgt-out--98.9%
*-lft-identity98.9%
associate-+l-98.9%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around inf 89.4%
Final simplification89.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -14500000.0) (not (<= x 1950.0))) (* z (- x)) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -14500000.0) || !(x <= 1950.0)) {
tmp = z * -x;
} 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 <= (-14500000.0d0)) .or. (.not. (x <= 1950.0d0))) then
tmp = z * -x
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -14500000.0) || !(x <= 1950.0)) {
tmp = z * -x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -14500000.0) or not (x <= 1950.0): tmp = z * -x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -14500000.0) || !(x <= 1950.0)) tmp = Float64(z * Float64(-x)); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -14500000.0) || ~((x <= 1950.0))) tmp = z * -x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -14500000.0], N[Not[LessEqual[x, 1950.0]], $MachinePrecision]], N[(z * (-x)), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -14500000 \lor \neg \left(x \leq 1950\right):\\
\;\;\;\;z \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -1.45e7 or 1950 < x Initial program 93.5%
+-commutative93.5%
remove-double-neg93.5%
distribute-rgt-neg-out93.5%
neg-sub093.5%
neg-sub093.5%
*-commutative93.5%
distribute-lft-neg-in93.5%
remove-double-neg93.5%
distribute-rgt-out--93.5%
*-lft-identity93.5%
associate-+l-93.5%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around inf 57.8%
Taylor expanded in x around inf 57.1%
associate-*r*57.1%
neg-mul-157.1%
*-commutative57.1%
Simplified57.1%
if -1.45e7 < x < 1950Initial program 100.0%
+-commutative100.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 z around inf 68.8%
Taylor expanded in x around 0 67.9%
Final simplification62.7%
(FPCore (x y z) :precision binary64 (- z (* z x)))
double code(double x, double y, double z) {
return z - (z * x);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z - (z * x)
end function
public static double code(double x, double y, double z) {
return z - (z * x);
}
def code(x, y, z): return z - (z * x)
function code(x, y, z) return Float64(z - Float64(z * x)) end
function tmp = code(x, y, z) tmp = z - (z * x); end
code[x_, y_, z_] := N[(z - N[(z * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z - z \cdot x
\end{array}
Initial program 96.9%
+-commutative96.9%
remove-double-neg96.9%
distribute-rgt-neg-out96.9%
neg-sub096.9%
neg-sub096.9%
*-commutative96.9%
distribute-lft-neg-in96.9%
remove-double-neg96.9%
distribute-rgt-out--96.9%
*-lft-identity96.9%
associate-+l-96.9%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around inf 63.5%
Final simplification63.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 96.9%
+-commutative96.9%
remove-double-neg96.9%
distribute-rgt-neg-out96.9%
neg-sub096.9%
neg-sub096.9%
*-commutative96.9%
distribute-lft-neg-in96.9%
remove-double-neg96.9%
distribute-rgt-out--96.9%
*-lft-identity96.9%
associate-+l-96.9%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in z around inf 63.5%
Taylor expanded in x around 0 36.6%
Final simplification36.6%
herbie shell --seed 2024077
(FPCore (x y z)
:name "Diagrams.Backend.Rasterific:$crender from diagrams-rasterific-1.3.1.3"
:precision binary64
(+ (* x y) (* (- 1.0 x) z)))