
(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 (fma z (- (sin y)) (* x (cos y))))
double code(double x, double y, double z) {
return fma(z, -sin(y), (x * cos(y)));
}
function code(x, y, z) return fma(z, Float64(-sin(y)), Float64(x * cos(y))) end
code[x_, y_, z_] := N[(z * (-N[Sin[y], $MachinePrecision]) + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, -\sin y, x \cdot \cos y\right)
\end{array}
Initial program 99.8%
cancel-sign-sub-inv99.8%
+-commutative99.8%
distribute-lft-neg-out99.8%
distribute-rgt-neg-in99.8%
sin-neg99.8%
fma-def99.8%
sin-neg99.8%
Simplified99.8%
Final simplification99.8%
(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
(let* ((t_0 (* x (cos y))))
(if (<= x -1.9e-28)
t_0
(if (<= x 2.25e-131)
(* z (- (sin y)))
(if (<= x 2.35e-67) (- t_0 (* z y)) t_0)))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (x <= -1.9e-28) {
tmp = t_0;
} else if (x <= 2.25e-131) {
tmp = z * -sin(y);
} else if (x <= 2.35e-67) {
tmp = t_0 - (z * y);
} else {
tmp = t_0;
}
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 = x * cos(y)
if (x <= (-1.9d-28)) then
tmp = t_0
else if (x <= 2.25d-131) then
tmp = z * -sin(y)
else if (x <= 2.35d-67) then
tmp = t_0 - (z * y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * Math.cos(y);
double tmp;
if (x <= -1.9e-28) {
tmp = t_0;
} else if (x <= 2.25e-131) {
tmp = z * -Math.sin(y);
} else if (x <= 2.35e-67) {
tmp = t_0 - (z * y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.cos(y) tmp = 0 if x <= -1.9e-28: tmp = t_0 elif x <= 2.25e-131: tmp = z * -math.sin(y) elif x <= 2.35e-67: tmp = t_0 - (z * y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (x <= -1.9e-28) tmp = t_0; elseif (x <= 2.25e-131) tmp = Float64(z * Float64(-sin(y))); elseif (x <= 2.35e-67) tmp = Float64(t_0 - Float64(z * y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * cos(y); tmp = 0.0; if (x <= -1.9e-28) tmp = t_0; elseif (x <= 2.25e-131) tmp = z * -sin(y); elseif (x <= 2.35e-67) tmp = t_0 - (z * y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.9e-28], t$95$0, If[LessEqual[x, 2.25e-131], N[(z * (-N[Sin[y], $MachinePrecision])), $MachinePrecision], If[LessEqual[x, 2.35e-67], N[(t$95$0 - N[(z * y), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;x \leq -1.9 \cdot 10^{-28}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 2.25 \cdot 10^{-131}:\\
\;\;\;\;z \cdot \left(-\sin y\right)\\
\mathbf{elif}\;x \leq 2.35 \cdot 10^{-67}:\\
\;\;\;\;t_0 - z \cdot y\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < -1.90000000000000005e-28 or 2.35000000000000002e-67 < x Initial program 99.8%
cancel-sign-sub-inv99.8%
+-commutative99.8%
distribute-lft-neg-out99.8%
distribute-rgt-neg-in99.8%
sin-neg99.8%
fma-def99.8%
sin-neg99.8%
Simplified99.8%
Taylor expanded in z around 0 84.9%
if -1.90000000000000005e-28 < x < 2.2500000000000001e-131Initial program 99.8%
cancel-sign-sub-inv99.8%
+-commutative99.8%
distribute-lft-neg-out99.8%
distribute-rgt-neg-in99.8%
sin-neg99.8%
fma-def99.8%
sin-neg99.8%
Simplified99.8%
Taylor expanded in z around inf 79.0%
neg-mul-179.0%
*-commutative79.0%
distribute-rgt-neg-in79.0%
Simplified79.0%
if 2.2500000000000001e-131 < x < 2.35000000000000002e-67Initial program 99.9%
Taylor expanded in y around 0 88.7%
Final simplification83.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.3e-28) (not (<= x 7.2e-130))) (* x (cos y)) (* z (- (sin y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.3e-28) || !(x <= 7.2e-130)) {
tmp = x * cos(y);
} else {
tmp = z * -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 <= (-2.3d-28)) .or. (.not. (x <= 7.2d-130))) then
tmp = x * cos(y)
else
tmp = z * -sin(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.3e-28) || !(x <= 7.2e-130)) {
tmp = x * Math.cos(y);
} else {
tmp = z * -Math.sin(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.3e-28) or not (x <= 7.2e-130): tmp = x * math.cos(y) else: tmp = z * -math.sin(y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.3e-28) || !(x <= 7.2e-130)) tmp = Float64(x * cos(y)); else tmp = Float64(z * Float64(-sin(y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.3e-28) || ~((x <= 7.2e-130))) tmp = x * cos(y); else tmp = z * -sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.3e-28], N[Not[LessEqual[x, 7.2e-130]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(z * (-N[Sin[y], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.3 \cdot 10^{-28} \lor \neg \left(x \leq 7.2 \cdot 10^{-130}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-\sin y\right)\\
\end{array}
\end{array}
if x < -2.29999999999999986e-28 or 7.2000000000000003e-130 < x Initial program 99.8%
cancel-sign-sub-inv99.8%
+-commutative99.8%
distribute-lft-neg-out99.8%
distribute-rgt-neg-in99.8%
sin-neg99.8%
fma-def99.8%
sin-neg99.8%
Simplified99.8%
Taylor expanded in z around 0 82.6%
if -2.29999999999999986e-28 < x < 7.2000000000000003e-130Initial program 99.8%
cancel-sign-sub-inv99.8%
+-commutative99.8%
distribute-lft-neg-out99.8%
distribute-rgt-neg-in99.8%
sin-neg99.8%
fma-def99.8%
sin-neg99.8%
Simplified99.8%
Taylor expanded in z around inf 79.0%
neg-mul-179.0%
*-commutative79.0%
distribute-rgt-neg-in79.0%
Simplified79.0%
Final simplification81.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.038) (not (<= y 0.00145))) (* x (cos y)) (+ x (* y (- (* y (* x -0.5)) z)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.038) || !(y <= 0.00145)) {
tmp = x * cos(y);
} else {
tmp = x + (y * ((y * (x * -0.5)) - 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.038d0)) .or. (.not. (y <= 0.00145d0))) then
tmp = x * cos(y)
else
tmp = x + (y * ((y * (x * (-0.5d0))) - z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.038) || !(y <= 0.00145)) {
tmp = x * Math.cos(y);
} else {
tmp = x + (y * ((y * (x * -0.5)) - z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.038) or not (y <= 0.00145): tmp = x * math.cos(y) else: tmp = x + (y * ((y * (x * -0.5)) - z)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.038) || !(y <= 0.00145)) tmp = Float64(x * cos(y)); else tmp = Float64(x + Float64(y * Float64(Float64(y * Float64(x * -0.5)) - z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.038) || ~((y <= 0.00145))) tmp = x * cos(y); else tmp = x + (y * ((y * (x * -0.5)) - z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.038], N[Not[LessEqual[y, 0.00145]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(N[(y * N[(x * -0.5), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.038 \lor \neg \left(y \leq 0.00145\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(y \cdot \left(x \cdot -0.5\right) - z\right)\\
\end{array}
\end{array}
if y < -0.0379999999999999991 or 0.00145 < y Initial program 99.5%
cancel-sign-sub-inv99.5%
+-commutative99.5%
distribute-lft-neg-out99.5%
distribute-rgt-neg-in99.5%
sin-neg99.5%
fma-def99.6%
sin-neg99.6%
Simplified99.6%
Taylor expanded in z around 0 51.6%
if -0.0379999999999999991 < y < 0.00145Initial program 100.0%
cancel-sign-sub-inv100.0%
+-commutative100.0%
distribute-lft-neg-out100.0%
distribute-rgt-neg-in100.0%
sin-neg100.0%
fma-def100.0%
sin-neg100.0%
Simplified100.0%
Taylor expanded in y around 0 99.0%
+-commutative99.0%
mul-1-neg99.0%
unsub-neg99.0%
associate-*r*99.0%
unpow299.0%
associate-*r*99.0%
*-commutative99.0%
distribute-rgt-out--99.0%
*-commutative99.0%
Simplified99.0%
Final simplification75.9%
(FPCore (x y z) :precision binary64 (- x (* z y)))
double code(double x, double y, double z) {
return 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 = x - (z * y)
end function
public static double code(double x, double y, double z) {
return x - (z * y);
}
def code(x, y, z): return x - (z * y)
function code(x, y, z) return Float64(x - Float64(z * y)) end
function tmp = code(x, y, z) tmp = x - (z * y); end
code[x_, y_, z_] := N[(x - N[(z * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - z \cdot y
\end{array}
Initial program 99.8%
cancel-sign-sub-inv99.8%
+-commutative99.8%
distribute-lft-neg-out99.8%
distribute-rgt-neg-in99.8%
sin-neg99.8%
fma-def99.8%
sin-neg99.8%
Simplified99.8%
Taylor expanded in y around 0 53.5%
mul-1-neg53.5%
unsub-neg53.5%
Simplified53.5%
Final simplification53.5%
(FPCore (x y z) :precision binary64 (- (* z y)))
double code(double x, double y, double z) {
return -(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 * y)
end function
public static double code(double x, double y, double z) {
return -(z * y);
}
def code(x, y, z): return -(z * y)
function code(x, y, z) return Float64(-Float64(z * y)) end
function tmp = code(x, y, z) tmp = -(z * y); end
code[x_, y_, z_] := (-N[(z * y), $MachinePrecision])
\begin{array}{l}
\\
-z \cdot y
\end{array}
Initial program 99.8%
cancel-sign-sub-inv99.8%
+-commutative99.8%
distribute-lft-neg-out99.8%
distribute-rgt-neg-in99.8%
sin-neg99.8%
fma-def99.8%
sin-neg99.8%
Simplified99.8%
Taylor expanded in z around inf 38.8%
neg-mul-138.8%
*-commutative38.8%
distribute-rgt-neg-in38.8%
Simplified38.8%
Taylor expanded in y around 0 15.6%
mul-1-neg15.6%
distribute-rgt-neg-in15.6%
Simplified15.6%
Final simplification15.6%
herbie shell --seed 2023275
(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))))