
(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 7 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 (- (* 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}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.02e-120) (not (<= z 1.45e-146))) (- x (* z (sin y))) (- (* x (cos y)) (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.02e-120) || !(z <= 1.45e-146)) {
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 <= (-1.02d-120)) .or. (.not. (z <= 1.45d-146))) 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 <= -1.02e-120) || !(z <= 1.45e-146)) {
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 <= -1.02e-120) or not (z <= 1.45e-146): 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 <= -1.02e-120) || !(z <= 1.45e-146)) 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 <= -1.02e-120) || ~((z <= 1.45e-146))) 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, -1.02e-120], N[Not[LessEqual[z, 1.45e-146]], $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 -1.02 \cdot 10^{-120} \lor \neg \left(z \leq 1.45 \cdot 10^{-146}\right):\\
\;\;\;\;x - z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y - y \cdot z\\
\end{array}
\end{array}
if z < -1.02e-120 or 1.45000000000000005e-146 < z Initial program 99.8%
Taylor expanded in y around 0 82.4%
if -1.02e-120 < z < 1.45000000000000005e-146Initial program 99.8%
Taylor expanded in y around 0 84.8%
Final simplification83.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.112) (not (<= y 27.0))) (* z (- (sin y))) (+ x (* y (- (* -0.5 (* x y)) z)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.112) || !(y <= 27.0)) {
tmp = z * -sin(y);
} else {
tmp = x + (y * ((-0.5 * (x * 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.112d0)) .or. (.not. (y <= 27.0d0))) then
tmp = z * -sin(y)
else
tmp = x + (y * (((-0.5d0) * (x * y)) - z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.112) || !(y <= 27.0)) {
tmp = z * -Math.sin(y);
} else {
tmp = x + (y * ((-0.5 * (x * y)) - z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.112) or not (y <= 27.0): tmp = z * -math.sin(y) else: tmp = x + (y * ((-0.5 * (x * y)) - z)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.112) || !(y <= 27.0)) tmp = Float64(z * Float64(-sin(y))); else tmp = Float64(x + Float64(y * Float64(Float64(-0.5 * Float64(x * y)) - z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.112) || ~((y <= 27.0))) tmp = z * -sin(y); else tmp = x + (y * ((-0.5 * (x * y)) - z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.112], N[Not[LessEqual[y, 27.0]], $MachinePrecision]], N[(z * (-N[Sin[y], $MachinePrecision])), $MachinePrecision], N[(x + N[(y * N[(N[(-0.5 * N[(x * y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.112 \lor \neg \left(y \leq 27\right):\\
\;\;\;\;z \cdot \left(-\sin y\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(-0.5 \cdot \left(x \cdot y\right) - z\right)\\
\end{array}
\end{array}
if y < -0.112000000000000002 or 27 < y Initial program 99.6%
Taylor expanded in y around 0 49.1%
Taylor expanded in x around 0 45.1%
associate-*r*45.1%
neg-mul-145.1%
*-commutative45.1%
Simplified45.1%
if -0.112000000000000002 < y < 27Initial program 100.0%
Taylor expanded in y around 0 99.0%
Taylor expanded in y around 0 99.0%
Taylor expanded in y around 0 98.8%
*-commutative98.8%
Simplified98.8%
Final simplification73.2%
(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.8%
Taylor expanded in y around 0 74.8%
Final simplification74.8%
(FPCore (x y z) :precision binary64 (if (<= z 2.35e+63) x (* z (- y))))
double code(double x, double y, double z) {
double tmp;
if (z <= 2.35e+63) {
tmp = x;
} else {
tmp = z * -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 (z <= 2.35d+63) then
tmp = x
else
tmp = z * -y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 2.35e+63) {
tmp = x;
} else {
tmp = z * -y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 2.35e+63: tmp = x else: tmp = z * -y return tmp
function code(x, y, z) tmp = 0.0 if (z <= 2.35e+63) tmp = x; else tmp = Float64(z * Float64(-y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 2.35e+63) tmp = x; else tmp = z * -y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 2.35e+63], x, N[(z * (-y)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 2.35 \cdot 10^{+63}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-y\right)\\
\end{array}
\end{array}
if z < 2.3500000000000001e63Initial program 99.8%
Taylor expanded in y around 0 71.4%
Taylor expanded in x around inf 46.3%
if 2.3500000000000001e63 < z Initial program 99.8%
Taylor expanded in y around 0 88.4%
Taylor expanded in y around 0 58.2%
mul-1-neg58.2%
unsub-neg58.2%
*-commutative58.2%
Simplified58.2%
Taylor expanded in x around 0 40.5%
associate-*r*40.5%
neg-mul-140.5%
*-commutative40.5%
Simplified40.5%
Final simplification45.1%
(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.8%
Taylor expanded in y around 0 74.8%
Taylor expanded in y around 0 54.2%
mul-1-neg54.2%
unsub-neg54.2%
*-commutative54.2%
Simplified54.2%
Final simplification54.2%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.8%
Taylor expanded in y around 0 74.8%
Taylor expanded in x around inf 41.0%
Final simplification41.0%
herbie shell --seed 2024059
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, A"
:precision binary64
(- (* x (cos y)) (* z (sin y))))