
(FPCore (x y z) :precision binary64 (+ (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x * cos(y)) + (z * sin(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 * cos(y)) + (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) + (z * Math.sin(y));
}
def code(x, y, z): return (x * math.cos(y)) + (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x * cos(y)) + Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x * cos(y)) + (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y + z \cdot \sin y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x * cos(y)) + (z * sin(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 * cos(y)) + (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) + (z * Math.sin(y));
}
def code(x, y, z): return (x * math.cos(y)) + (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x * cos(y)) + Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x * cos(y)) + (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y + z \cdot \sin y
\end{array}
(FPCore (x y z) :precision binary64 (fma x (cos y) (* z (sin y))))
double code(double x, double y, double z) {
return fma(x, cos(y), (z * sin(y)));
}
function code(x, y, z) return fma(x, cos(y), Float64(z * sin(y))) end
code[x_, y_, z_] := N[(x * N[Cos[y], $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, \cos y, z \cdot \sin y\right)
\end{array}
Initial program 99.7%
fma-def99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (+ (* z (sin y)) (* x (cos y))))
double code(double x, double y, double z) {
return (z * sin(y)) + (x * 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 = (z * sin(y)) + (x * cos(y))
end function
public static double code(double x, double y, double z) {
return (z * Math.sin(y)) + (x * Math.cos(y));
}
def code(x, y, z): return (z * math.sin(y)) + (x * math.cos(y))
function code(x, y, z) return Float64(Float64(z * sin(y)) + Float64(x * cos(y))) end
function tmp = code(x, y, z) tmp = (z * sin(y)) + (x * cos(y)); end
code[x_, y_, z_] := N[(N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \sin y + x \cdot \cos y
\end{array}
Initial program 99.7%
Final simplification99.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -6.5e-22) (not (<= z 1.75e-68))) (+ x (* z (sin y))) (+ (* x (cos y)) (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -6.5e-22) || !(z <= 1.75e-68)) {
tmp = x + (z * sin(y));
} else {
tmp = (x * cos(y)) + (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 ((z <= (-6.5d-22)) .or. (.not. (z <= 1.75d-68))) then
tmp = x + (z * sin(y))
else
tmp = (x * cos(y)) + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -6.5e-22) || !(z <= 1.75e-68)) {
tmp = x + (z * Math.sin(y));
} else {
tmp = (x * Math.cos(y)) + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -6.5e-22) or not (z <= 1.75e-68): tmp = x + (z * math.sin(y)) else: tmp = (x * math.cos(y)) + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -6.5e-22) || !(z <= 1.75e-68)) tmp = Float64(x + Float64(z * sin(y))); else tmp = Float64(Float64(x * cos(y)) + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -6.5e-22) || ~((z <= 1.75e-68))) tmp = x + (z * sin(y)); else tmp = (x * cos(y)) + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -6.5e-22], N[Not[LessEqual[z, 1.75e-68]], $MachinePrecision]], N[(x + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.5 \cdot 10^{-22} \lor \neg \left(z \leq 1.75 \cdot 10^{-68}\right):\\
\;\;\;\;x + z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y + y \cdot z\\
\end{array}
\end{array}
if z < -6.50000000000000043e-22 or 1.75000000000000006e-68 < z Initial program 99.8%
Taylor expanded in y around 0 84.0%
if -6.50000000000000043e-22 < z < 1.75000000000000006e-68Initial program 99.7%
Taylor expanded in y around 0 77.0%
Final simplification80.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.0148) (not (<= y 0.145))) (* z (sin y)) (+ (* y z) (* x (+ 1.0 (* -0.5 (* y y)))))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0148) || !(y <= 0.145)) {
tmp = z * sin(y);
} else {
tmp = (y * z) + (x * (1.0 + (-0.5 * (y * 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.0148d0)) .or. (.not. (y <= 0.145d0))) then
tmp = z * sin(y)
else
tmp = (y * z) + (x * (1.0d0 + ((-0.5d0) * (y * y))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0148) || !(y <= 0.145)) {
tmp = z * Math.sin(y);
} else {
tmp = (y * z) + (x * (1.0 + (-0.5 * (y * y))));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.0148) or not (y <= 0.145): tmp = z * math.sin(y) else: tmp = (y * z) + (x * (1.0 + (-0.5 * (y * y)))) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.0148) || !(y <= 0.145)) tmp = Float64(z * sin(y)); else tmp = Float64(Float64(y * z) + Float64(x * Float64(1.0 + Float64(-0.5 * Float64(y * y))))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.0148) || ~((y <= 0.145))) tmp = z * sin(y); else tmp = (y * z) + (x * (1.0 + (-0.5 * (y * y)))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.0148], N[Not[LessEqual[y, 0.145]], $MachinePrecision]], N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(N[(y * z), $MachinePrecision] + N[(x * N[(1.0 + N[(-0.5 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0148 \lor \neg \left(y \leq 0.145\right):\\
\;\;\;\;z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;y \cdot z + x \cdot \left(1 + -0.5 \cdot \left(y \cdot y\right)\right)\\
\end{array}
\end{array}
if y < -0.014800000000000001 or 0.14499999999999999 < y Initial program 99.5%
Taylor expanded in x around 0 45.8%
if -0.014800000000000001 < y < 0.14499999999999999Initial program 100.0%
Taylor expanded in y around 0 99.6%
unpow299.6%
Simplified99.6%
Taylor expanded in y around 0 99.6%
Final simplification69.3%
(FPCore (x y z) :precision binary64 (+ x (* z (sin y))))
double code(double x, double y, double z) {
return x + (z * sin(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 + (z * sin(y))
end function
public static double code(double x, double y, double z) {
return x + (z * Math.sin(y));
}
def code(x, y, z): return x + (z * math.sin(y))
function code(x, y, z) return Float64(x + Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = x + (z * sin(y)); end
code[x_, y_, z_] := N[(x + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + z \cdot \sin y
\end{array}
Initial program 99.7%
Taylor expanded in y around 0 72.5%
Final simplification72.5%
(FPCore (x y z) :precision binary64 (if (<= x -4.8e-261) x (if (<= x 1.98e-81) (* y z) x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.8e-261) {
tmp = x;
} else if (x <= 1.98e-81) {
tmp = y * z;
} else {
tmp = 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 (x <= (-4.8d-261)) then
tmp = x
else if (x <= 1.98d-81) then
tmp = y * z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -4.8e-261) {
tmp = x;
} else if (x <= 1.98e-81) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.8e-261: tmp = x elif x <= 1.98e-81: tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.8e-261) tmp = x; elseif (x <= 1.98e-81) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -4.8e-261) tmp = x; elseif (x <= 1.98e-81) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.8e-261], x, If[LessEqual[x, 1.98e-81], N[(y * z), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.8 \cdot 10^{-261}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1.98 \cdot 10^{-81}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -4.80000000000000028e-261 or 1.98e-81 < x Initial program 99.7%
Taylor expanded in y around 0 47.3%
flip-+28.2%
clear-num28.2%
pow228.2%
Applied egg-rr28.2%
Taylor expanded in y around 0 44.5%
add-log-exp5.0%
remove-double-div5.0%
*-un-lft-identity5.0%
log-prod5.0%
metadata-eval5.0%
add-log-exp44.6%
Applied egg-rr44.6%
if -4.80000000000000028e-261 < x < 1.98e-81Initial program 99.8%
Taylor expanded in y around 0 47.2%
Taylor expanded in y around inf 41.6%
Final simplification44.0%
(FPCore (x y z) :precision binary64 (+ x (* y z)))
double code(double x, double y, double z) {
return 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 = x + (y * z)
end function
public static double code(double x, double y, double z) {
return x + (y * z);
}
def code(x, y, z): return x + (y * z)
function code(x, y, z) return Float64(x + Float64(y * z)) end
function tmp = code(x, y, z) tmp = x + (y * z); end
code[x_, y_, z_] := N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot z
\end{array}
Initial program 99.7%
Taylor expanded in y around 0 47.3%
Final simplification47.3%
(FPCore (x y z) :precision binary64 (* y z))
double code(double x, double y, double z) {
return 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 * z
end function
public static double code(double x, double y, double z) {
return y * z;
}
def code(x, y, z): return y * z
function code(x, y, z) return Float64(y * z) end
function tmp = code(x, y, z) tmp = y * z; end
code[x_, y_, z_] := N[(y * z), $MachinePrecision]
\begin{array}{l}
\\
y \cdot z
\end{array}
Initial program 99.7%
Taylor expanded in y around 0 47.3%
Taylor expanded in y around inf 14.3%
Final simplification14.3%
herbie shell --seed 2023207
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))