
(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 9 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 (sin y) (- z) (* x (cos y))))
double code(double x, double y, double z) {
return fma(sin(y), -z, (x * cos(y)));
}
function code(x, y, z) return fma(sin(y), Float64(-z), Float64(x * cos(y))) end
code[x_, y_, z_] := N[(N[Sin[y], $MachinePrecision] * (-z) + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin y, -z, x \cdot \cos y\right)
\end{array}
Initial program 99.8%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lower-neg.f6499.8
Applied rewrites99.8%
(FPCore (x y z) :precision binary64 (fma (cos y) x (- (* (sin y) z))))
double code(double x, double y, double z) {
return fma(cos(y), x, -(sin(y) * z));
}
function code(x, y, z) return fma(cos(y), x, Float64(-Float64(sin(y) * z))) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * x + (-N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision])), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, x, -\sin y \cdot z\right)
\end{array}
Initial program 99.8%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-neg.f6499.8
Applied rewrites99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (- (* x (cos y)) (* (sin y) z)))
double code(double x, double y, double z) {
return (x * cos(y)) - (sin(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 * cos(y)) - (sin(y) * z)
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) - (Math.sin(y) * z);
}
def code(x, y, z): return (x * math.cos(y)) - (math.sin(y) * z)
function code(x, y, z) return Float64(Float64(x * cos(y)) - Float64(sin(y) * z)) end
function tmp = code(x, y, z) tmp = (x * cos(y)) - (sin(y) * z); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y - \sin y \cdot z
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (sin y) z)))
(if (<= z -1.6e-60)
(- (fma (* y (* y x)) (fma y (* y 0.041666666666666664) -0.5) x) t_0)
(if (<= z 1.35e+37) (* x (cos y)) (- t_0)))))
double code(double x, double y, double z) {
double t_0 = sin(y) * z;
double tmp;
if (z <= -1.6e-60) {
tmp = fma((y * (y * x)), fma(y, (y * 0.041666666666666664), -0.5), x) - t_0;
} else if (z <= 1.35e+37) {
tmp = x * cos(y);
} else {
tmp = -t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(sin(y) * z) tmp = 0.0 if (z <= -1.6e-60) tmp = Float64(fma(Float64(y * Float64(y * x)), fma(y, Float64(y * 0.041666666666666664), -0.5), x) - t_0); elseif (z <= 1.35e+37) tmp = Float64(x * cos(y)); else tmp = Float64(-t_0); end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[z, -1.6e-60], N[(N[(N[(y * N[(y * x), $MachinePrecision]), $MachinePrecision] * N[(y * N[(y * 0.041666666666666664), $MachinePrecision] + -0.5), $MachinePrecision] + x), $MachinePrecision] - t$95$0), $MachinePrecision], If[LessEqual[z, 1.35e+37], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], (-t$95$0)]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin y \cdot z\\
\mathbf{if}\;z \leq -1.6 \cdot 10^{-60}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot \left(y \cdot x\right), \mathsf{fma}\left(y, y \cdot 0.041666666666666664, -0.5\right), x\right) - t\_0\\
\mathbf{elif}\;z \leq 1.35 \cdot 10^{+37}:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;-t\_0\\
\end{array}
\end{array}
if z < -1.6000000000000001e-60Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
distribute-rgt-inN/A
associate-*r*N/A
*-commutativeN/A
*-commutativeN/A
associate-*l*N/A
distribute-lft-outN/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower-fma.f64N/A
Applied rewrites70.4%
if -1.6000000000000001e-60 < z < 1.34999999999999993e37Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6488.9
Applied rewrites88.9%
if 1.34999999999999993e37 < z Initial program 99.7%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f64N/A
lower-*.f64N/A
lower-sin.f6470.4
Applied rewrites70.4%
Final simplification79.4%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- (* (sin y) z)))) (if (<= z -3e+66) t_0 (if (<= z 1.35e+37) (* x (cos y)) t_0))))
double code(double x, double y, double z) {
double t_0 = -(sin(y) * z);
double tmp;
if (z <= -3e+66) {
tmp = t_0;
} else if (z <= 1.35e+37) {
tmp = x * cos(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 = -(sin(y) * z)
if (z <= (-3d+66)) then
tmp = t_0
else if (z <= 1.35d+37) then
tmp = x * cos(y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = -(Math.sin(y) * z);
double tmp;
if (z <= -3e+66) {
tmp = t_0;
} else if (z <= 1.35e+37) {
tmp = x * Math.cos(y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -(math.sin(y) * z) tmp = 0 if z <= -3e+66: tmp = t_0 elif z <= 1.35e+37: tmp = x * math.cos(y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(-Float64(sin(y) * z)) tmp = 0.0 if (z <= -3e+66) tmp = t_0; elseif (z <= 1.35e+37) tmp = Float64(x * cos(y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -(sin(y) * z); tmp = 0.0; if (z <= -3e+66) tmp = t_0; elseif (z <= 1.35e+37) tmp = x * cos(y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = (-N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision])}, If[LessEqual[z, -3e+66], t$95$0, If[LessEqual[z, 1.35e+37], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -\sin y \cdot z\\
\mathbf{if}\;z \leq -3 \cdot 10^{+66}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.35 \cdot 10^{+37}:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -3.00000000000000002e66 or 1.34999999999999993e37 < z Initial program 99.7%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f64N/A
lower-*.f64N/A
lower-sin.f6469.5
Applied rewrites69.5%
if -3.00000000000000002e66 < z < 1.34999999999999993e37Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6486.9
Applied rewrites86.9%
Final simplification79.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -0.118)
t_0
(if (<= y 3.6e-22)
(fma y (fma y (fma z (* y 0.16666666666666666) (* x -0.5)) (- z)) x)
t_0))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -0.118) {
tmp = t_0;
} else if (y <= 3.6e-22) {
tmp = fma(y, fma(y, fma(z, (y * 0.16666666666666666), (x * -0.5)), -z), x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (y <= -0.118) tmp = t_0; elseif (y <= 3.6e-22) tmp = fma(y, fma(y, fma(z, Float64(y * 0.16666666666666666), Float64(x * -0.5)), Float64(-z)), x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.118], t$95$0, If[LessEqual[y, 3.6e-22], N[(y * N[(y * N[(z * N[(y * 0.16666666666666666), $MachinePrecision] + N[(x * -0.5), $MachinePrecision]), $MachinePrecision] + (-z)), $MachinePrecision] + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -0.118:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 3.6 \cdot 10^{-22}:\\
\;\;\;\;\mathsf{fma}\left(y, \mathsf{fma}\left(y, \mathsf{fma}\left(z, y \cdot 0.16666666666666666, x \cdot -0.5\right), -z\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.11799999999999999 or 3.5999999999999998e-22 < y Initial program 99.6%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6453.3
Applied rewrites53.3%
if -0.11799999999999999 < y < 3.5999999999999998e-22Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f64N/A
sub-negN/A
lower-fma.f64N/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-neg.f6499.8
Applied rewrites99.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- (* y z)))) (if (<= z -2.25e+223) t_0 (if (<= z 3.5e+202) (* x 1.0) t_0))))
double code(double x, double y, double z) {
double t_0 = -(y * z);
double tmp;
if (z <= -2.25e+223) {
tmp = t_0;
} else if (z <= 3.5e+202) {
tmp = x * 1.0;
} 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 = -(y * z)
if (z <= (-2.25d+223)) then
tmp = t_0
else if (z <= 3.5d+202) then
tmp = x * 1.0d0
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = -(y * z);
double tmp;
if (z <= -2.25e+223) {
tmp = t_0;
} else if (z <= 3.5e+202) {
tmp = x * 1.0;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -(y * z) tmp = 0 if z <= -2.25e+223: tmp = t_0 elif z <= 3.5e+202: tmp = x * 1.0 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(-Float64(y * z)) tmp = 0.0 if (z <= -2.25e+223) tmp = t_0; elseif (z <= 3.5e+202) tmp = Float64(x * 1.0); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -(y * z); tmp = 0.0; if (z <= -2.25e+223) tmp = t_0; elseif (z <= 3.5e+202) tmp = x * 1.0; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = (-N[(y * z), $MachinePrecision])}, If[LessEqual[z, -2.25e+223], t$95$0, If[LessEqual[z, 3.5e+202], N[(x * 1.0), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -y \cdot z\\
\mathbf{if}\;z \leq -2.25 \cdot 10^{+223}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 3.5 \cdot 10^{+202}:\\
\;\;\;\;x \cdot 1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -2.25e223 or 3.49999999999999987e202 < z Initial program 99.7%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f64N/A
lower-*.f64N/A
lower-sin.f6481.3
Applied rewrites81.3%
Taylor expanded in y around 0
Applied rewrites42.1%
if -2.25e223 < z < 3.49999999999999987e202Initial program 99.8%
lift--.f64N/A
flip--N/A
div-subN/A
sub-negN/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
Applied rewrites79.6%
Taylor expanded in x around inf
+-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
metadata-evalN/A
distribute-lft-neg-inN/A
cos-negN/A
lower-cos.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
lower-cos.f6471.0
Applied rewrites71.0%
Taylor expanded in y around 0
Applied rewrites45.3%
(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
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6452.7
Applied rewrites52.7%
Final simplification52.7%
(FPCore (x y z) :precision binary64 (* x 1.0))
double code(double x, double y, double z) {
return x * 1.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * 1.0d0
end function
public static double code(double x, double y, double z) {
return x * 1.0;
}
def code(x, y, z): return x * 1.0
function code(x, y, z) return Float64(x * 1.0) end
function tmp = code(x, y, z) tmp = x * 1.0; end
code[x_, y_, z_] := N[(x * 1.0), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 1
\end{array}
Initial program 99.8%
lift--.f64N/A
flip--N/A
div-subN/A
sub-negN/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
Applied rewrites65.9%
Taylor expanded in x around inf
+-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
metadata-evalN/A
distribute-lft-neg-inN/A
cos-negN/A
lower-cos.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cos.f64N/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
lower-cos.f6461.5
Applied rewrites61.5%
Taylor expanded in y around 0
Applied rewrites39.6%
herbie shell --seed 2024221
(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))))