
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * cos(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * cos(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * cos(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
Initial program 99.8%
(FPCore (x y z)
:precision binary64
(if (<= x -1.6e-99)
(* z (+ 1.0 (* x (/ (sin y) z))))
(if (<= x 2.5e-53)
(* z (cos y))
(if (<= x 3.5e+223) (* z (+ 1.0 (/ x (/ z (sin y))))) (* x (sin y))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.6e-99) {
tmp = z * (1.0 + (x * (sin(y) / z)));
} else if (x <= 2.5e-53) {
tmp = z * cos(y);
} else if (x <= 3.5e+223) {
tmp = z * (1.0 + (x / (z / sin(y))));
} else {
tmp = x * sin(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 <= (-1.6d-99)) then
tmp = z * (1.0d0 + (x * (sin(y) / z)))
else if (x <= 2.5d-53) then
tmp = z * cos(y)
else if (x <= 3.5d+223) then
tmp = z * (1.0d0 + (x / (z / sin(y))))
else
tmp = x * sin(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.6e-99) {
tmp = z * (1.0 + (x * (Math.sin(y) / z)));
} else if (x <= 2.5e-53) {
tmp = z * Math.cos(y);
} else if (x <= 3.5e+223) {
tmp = z * (1.0 + (x / (z / Math.sin(y))));
} else {
tmp = x * Math.sin(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.6e-99: tmp = z * (1.0 + (x * (math.sin(y) / z))) elif x <= 2.5e-53: tmp = z * math.cos(y) elif x <= 3.5e+223: tmp = z * (1.0 + (x / (z / math.sin(y)))) else: tmp = x * math.sin(y) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.6e-99) tmp = Float64(z * Float64(1.0 + Float64(x * Float64(sin(y) / z)))); elseif (x <= 2.5e-53) tmp = Float64(z * cos(y)); elseif (x <= 3.5e+223) tmp = Float64(z * Float64(1.0 + Float64(x / Float64(z / sin(y))))); else tmp = Float64(x * sin(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.6e-99) tmp = z * (1.0 + (x * (sin(y) / z))); elseif (x <= 2.5e-53) tmp = z * cos(y); elseif (x <= 3.5e+223) tmp = z * (1.0 + (x / (z / sin(y)))); else tmp = x * sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.6e-99], N[(z * N[(1.0 + N[(x * N[(N[Sin[y], $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2.5e-53], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 3.5e+223], N[(z * N[(1.0 + N[(x / N[(z / N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.6 \cdot 10^{-99}:\\
\;\;\;\;z \cdot \left(1 + x \cdot \frac{\sin y}{z}\right)\\
\mathbf{elif}\;x \leq 2.5 \cdot 10^{-53}:\\
\;\;\;\;z \cdot \cos y\\
\mathbf{elif}\;x \leq 3.5 \cdot 10^{+223}:\\
\;\;\;\;z \cdot \left(1 + \frac{x}{\frac{z}{\sin y}}\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \sin y\\
\end{array}
\end{array}
if x < -1.6e-99Initial program 99.8%
expm1-log1p-u99.7%
Applied egg-rr99.7%
Taylor expanded in y around 0 83.7%
Taylor expanded in z around inf 74.4%
associate-/l*74.4%
Simplified74.4%
if -1.6e-99 < x < 2.5e-53Initial program 99.9%
Taylor expanded in x around 0 90.9%
if 2.5e-53 < x < 3.5000000000000001e223Initial program 99.8%
expm1-log1p-u99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 82.0%
Taylor expanded in z around inf 80.0%
associate-/l*79.8%
Simplified79.8%
clear-num79.8%
un-div-inv79.9%
Applied egg-rr79.9%
if 3.5000000000000001e223 < x Initial program 99.7%
Taylor expanded in x around inf 89.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (+ 1.0 (* x (/ (sin y) z))))))
(if (<= x -5.5e-99)
t_0
(if (<= x 4.8e-50)
(* z (cos y))
(if (<= x 8.5e+212) t_0 (* x (sin y)))))))
double code(double x, double y, double z) {
double t_0 = z * (1.0 + (x * (sin(y) / z)));
double tmp;
if (x <= -5.5e-99) {
tmp = t_0;
} else if (x <= 4.8e-50) {
tmp = z * cos(y);
} else if (x <= 8.5e+212) {
tmp = t_0;
} else {
tmp = x * sin(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) :: t_0
real(8) :: tmp
t_0 = z * (1.0d0 + (x * (sin(y) / z)))
if (x <= (-5.5d-99)) then
tmp = t_0
else if (x <= 4.8d-50) then
tmp = z * cos(y)
else if (x <= 8.5d+212) then
tmp = t_0
else
tmp = x * sin(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * (1.0 + (x * (Math.sin(y) / z)));
double tmp;
if (x <= -5.5e-99) {
tmp = t_0;
} else if (x <= 4.8e-50) {
tmp = z * Math.cos(y);
} else if (x <= 8.5e+212) {
tmp = t_0;
} else {
tmp = x * Math.sin(y);
}
return tmp;
}
def code(x, y, z): t_0 = z * (1.0 + (x * (math.sin(y) / z))) tmp = 0 if x <= -5.5e-99: tmp = t_0 elif x <= 4.8e-50: tmp = z * math.cos(y) elif x <= 8.5e+212: tmp = t_0 else: tmp = x * math.sin(y) return tmp
function code(x, y, z) t_0 = Float64(z * Float64(1.0 + Float64(x * Float64(sin(y) / z)))) tmp = 0.0 if (x <= -5.5e-99) tmp = t_0; elseif (x <= 4.8e-50) tmp = Float64(z * cos(y)); elseif (x <= 8.5e+212) tmp = t_0; else tmp = Float64(x * sin(y)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * (1.0 + (x * (sin(y) / z))); tmp = 0.0; if (x <= -5.5e-99) tmp = t_0; elseif (x <= 4.8e-50) tmp = z * cos(y); elseif (x <= 8.5e+212) tmp = t_0; else tmp = x * sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[(1.0 + N[(x * N[(N[Sin[y], $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -5.5e-99], t$95$0, If[LessEqual[x, 4.8e-50], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 8.5e+212], t$95$0, N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(1 + x \cdot \frac{\sin y}{z}\right)\\
\mathbf{if}\;x \leq -5.5 \cdot 10^{-99}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 4.8 \cdot 10^{-50}:\\
\;\;\;\;z \cdot \cos y\\
\mathbf{elif}\;x \leq 8.5 \cdot 10^{+212}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x \cdot \sin y\\
\end{array}
\end{array}
if x < -5.49999999999999991e-99 or 4.80000000000000004e-50 < x < 8.49999999999999979e212Initial program 99.8%
expm1-log1p-u99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 82.9%
Taylor expanded in z around inf 76.7%
associate-/l*76.6%
Simplified76.6%
if -5.49999999999999991e-99 < x < 4.80000000000000004e-50Initial program 99.9%
Taylor expanded in x around 0 90.9%
if 8.49999999999999979e212 < x Initial program 99.7%
Taylor expanded in x around inf 89.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.046) (not (<= y 2.25e-8))) (* z (cos y)) (+ z (* y (+ x (* y (+ (* z -0.5) (* -0.16666666666666666 (* x y)))))))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.046) || !(y <= 2.25e-8)) {
tmp = z * cos(y);
} else {
tmp = z + (y * (x + (y * ((z * -0.5) + (-0.16666666666666666 * (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 ((y <= (-0.046d0)) .or. (.not. (y <= 2.25d-8))) then
tmp = z * cos(y)
else
tmp = z + (y * (x + (y * ((z * (-0.5d0)) + ((-0.16666666666666666d0) * (x * y))))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.046) || !(y <= 2.25e-8)) {
tmp = z * Math.cos(y);
} else {
tmp = z + (y * (x + (y * ((z * -0.5) + (-0.16666666666666666 * (x * y))))));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.046) or not (y <= 2.25e-8): tmp = z * math.cos(y) else: tmp = z + (y * (x + (y * ((z * -0.5) + (-0.16666666666666666 * (x * y)))))) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.046) || !(y <= 2.25e-8)) tmp = Float64(z * cos(y)); else tmp = Float64(z + Float64(y * Float64(x + Float64(y * Float64(Float64(z * -0.5) + Float64(-0.16666666666666666 * Float64(x * y))))))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.046) || ~((y <= 2.25e-8))) tmp = z * cos(y); else tmp = z + (y * (x + (y * ((z * -0.5) + (-0.16666666666666666 * (x * y)))))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.046], N[Not[LessEqual[y, 2.25e-8]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(z + N[(y * N[(x + N[(y * N[(N[(z * -0.5), $MachinePrecision] + N[(-0.16666666666666666 * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.046 \lor \neg \left(y \leq 2.25 \cdot 10^{-8}\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot \left(x + y \cdot \left(z \cdot -0.5 + -0.16666666666666666 \cdot \left(x \cdot y\right)\right)\right)\\
\end{array}
\end{array}
if y < -0.045999999999999999 or 2.24999999999999996e-8 < y Initial program 99.6%
Taylor expanded in x around 0 59.3%
if -0.045999999999999999 < y < 2.24999999999999996e-8Initial program 100.0%
Taylor expanded in y around 0 99.4%
Final simplification79.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.032) (not (<= y 0.26))) (* x (sin y)) (+ z (* y (+ x (* -0.5 (* y z)))))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.032) || !(y <= 0.26)) {
tmp = x * sin(y);
} else {
tmp = z + (y * (x + (-0.5 * (y * 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 ((y <= (-0.032d0)) .or. (.not. (y <= 0.26d0))) then
tmp = x * sin(y)
else
tmp = z + (y * (x + ((-0.5d0) * (y * z))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.032) || !(y <= 0.26)) {
tmp = x * Math.sin(y);
} else {
tmp = z + (y * (x + (-0.5 * (y * z))));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.032) or not (y <= 0.26): tmp = x * math.sin(y) else: tmp = z + (y * (x + (-0.5 * (y * z)))) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.032) || !(y <= 0.26)) tmp = Float64(x * sin(y)); else tmp = Float64(z + Float64(y * Float64(x + Float64(-0.5 * Float64(y * z))))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.032) || ~((y <= 0.26))) tmp = x * sin(y); else tmp = z + (y * (x + (-0.5 * (y * z)))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.032], N[Not[LessEqual[y, 0.26]], $MachinePrecision]], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(z + N[(y * N[(x + N[(-0.5 * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.032 \lor \neg \left(y \leq 0.26\right):\\
\;\;\;\;x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot \left(x + -0.5 \cdot \left(y \cdot z\right)\right)\\
\end{array}
\end{array}
if y < -0.032000000000000001 or 0.26000000000000001 < y Initial program 99.6%
Taylor expanded in x around inf 44.1%
if -0.032000000000000001 < y < 0.26000000000000001Initial program 100.0%
Taylor expanded in y around 0 99.3%
Final simplification71.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.5e+70) (not (<= x 6.5e+218))) (* x y) z))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.5e+70) || !(x <= 6.5e+218)) {
tmp = x * y;
} 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 <= (-5.5d+70)) .or. (.not. (x <= 6.5d+218))) then
tmp = x * y
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -5.5e+70) || !(x <= 6.5e+218)) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.5e+70) or not (x <= 6.5e+218): tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.5e+70) || !(x <= 6.5e+218)) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -5.5e+70) || ~((x <= 6.5e+218))) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.5e+70], N[Not[LessEqual[x, 6.5e+218]], $MachinePrecision]], N[(x * y), $MachinePrecision], z]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.5 \cdot 10^{+70} \lor \neg \left(x \leq 6.5 \cdot 10^{+218}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if x < -5.49999999999999986e70 or 6.4999999999999999e218 < x Initial program 99.7%
Taylor expanded in y around 0 51.1%
+-commutative51.1%
Simplified51.1%
Taylor expanded in x around inf 51.0%
Taylor expanded in x around inf 35.5%
*-commutative35.5%
Simplified35.5%
if -5.49999999999999986e70 < x < 6.4999999999999999e218Initial program 99.8%
expm1-log1p-u99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 49.9%
Final simplification46.8%
(FPCore (x y z) :precision binary64 (+ z (* x y)))
double code(double x, double y, double z) {
return z + (x * 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 * y)
end function
public static double code(double x, double y, double z) {
return z + (x * y);
}
def code(x, y, z): return z + (x * y)
function code(x, y, z) return Float64(z + Float64(x * y)) end
function tmp = code(x, y, z) tmp = z + (x * y); end
code[x_, y_, z_] := N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + x \cdot y
\end{array}
Initial program 99.8%
Taylor expanded in y around 0 53.5%
+-commutative53.5%
Simplified53.5%
Final simplification53.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 99.8%
expm1-log1p-u99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 42.9%
herbie shell --seed 2024170
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ (* x (sin y)) (* z (cos y))))