
(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 10 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 (cos y) x (- (* z (sin y)))))
double code(double x, double y, double z) {
return fma(cos(y), x, -(z * sin(y)));
}
function code(x, y, z) return fma(cos(y), x, Float64(-Float64(z * sin(y)))) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * x + (-N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision])), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, x, -z \cdot \sin y\right)
\end{array}
Initial program 99.8%
lift-cos.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-neg.f6499.8
Applied egg-rr99.8%
(FPCore (x y z) :precision binary64 (- (* (cos y) x) (* z (sin y))))
double code(double x, double y, double z) {
return (cos(y) * 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 = (cos(y) * x) - (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (Math.cos(y) * x) - (z * Math.sin(y));
}
def code(x, y, z): return (math.cos(y) * x) - (z * math.sin(y))
function code(x, y, z) return Float64(Float64(cos(y) * x) - Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (cos(y) * x) - (z * sin(y)); end
code[x_, y_, z_] := N[(N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos y \cdot x - z \cdot \sin y
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cos y) x)))
(if (<= x -1e+80)
t_0
(if (<= x 6.2e-78) (fma (/ -1.0 (/ 1.0 z)) (sin y) x) t_0))))
double code(double x, double y, double z) {
double t_0 = cos(y) * x;
double tmp;
if (x <= -1e+80) {
tmp = t_0;
} else if (x <= 6.2e-78) {
tmp = fma((-1.0 / (1.0 / z)), sin(y), x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(cos(y) * x) tmp = 0.0 if (x <= -1e+80) tmp = t_0; elseif (x <= 6.2e-78) tmp = fma(Float64(-1.0 / Float64(1.0 / z)), sin(y), x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, -1e+80], t$95$0, If[LessEqual[x, 6.2e-78], N[(N[(-1.0 / N[(1.0 / z), $MachinePrecision]), $MachinePrecision] * N[Sin[y], $MachinePrecision] + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos y \cdot x\\
\mathbf{if}\;x \leq -1 \cdot 10^{+80}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 6.2 \cdot 10^{-78}:\\
\;\;\;\;\mathsf{fma}\left(\frac{-1}{\frac{1}{z}}, \sin y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1e80 or 6.20000000000000035e-78 < x Initial program 99.9%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6489.7
Simplified89.7%
if -1e80 < x < 6.20000000000000035e-78Initial program 99.8%
lift-cos.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
sub-negN/A
+-commutativeN/A
neg-sub0N/A
flip--N/A
metadata-evalN/A
neg-sub0N/A
div-invN/A
lower-fma.f64N/A
Applied egg-rr47.1%
Taylor expanded in y around 0
Simplified39.7%
Applied egg-rr91.6%
Final simplification90.7%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cos y) x)))
(if (<= x -1e+80)
t_0
(if (<= x 6.2e-78) (- x (* x (* z (/ (sin y) x)))) t_0))))
double code(double x, double y, double z) {
double t_0 = cos(y) * x;
double tmp;
if (x <= -1e+80) {
tmp = t_0;
} else if (x <= 6.2e-78) {
tmp = x - (x * (z * (sin(y) / x)));
} 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 = cos(y) * x
if (x <= (-1d+80)) then
tmp = t_0
else if (x <= 6.2d-78) then
tmp = x - (x * (z * (sin(y) / x)))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = Math.cos(y) * x;
double tmp;
if (x <= -1e+80) {
tmp = t_0;
} else if (x <= 6.2e-78) {
tmp = x - (x * (z * (Math.sin(y) / x)));
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = math.cos(y) * x tmp = 0 if x <= -1e+80: tmp = t_0 elif x <= 6.2e-78: tmp = x - (x * (z * (math.sin(y) / x))) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(cos(y) * x) tmp = 0.0 if (x <= -1e+80) tmp = t_0; elseif (x <= 6.2e-78) tmp = Float64(x - Float64(x * Float64(z * Float64(sin(y) / x)))); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = cos(y) * x; tmp = 0.0; if (x <= -1e+80) tmp = t_0; elseif (x <= 6.2e-78) tmp = x - (x * (z * (sin(y) / x))); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, -1e+80], t$95$0, If[LessEqual[x, 6.2e-78], N[(x - N[(x * N[(z * N[(N[Sin[y], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos y \cdot x\\
\mathbf{if}\;x \leq -1 \cdot 10^{+80}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 6.2 \cdot 10^{-78}:\\
\;\;\;\;x - x \cdot \left(z \cdot \frac{\sin y}{x}\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1e80 or 6.20000000000000035e-78 < x Initial program 99.9%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6489.7
Simplified89.7%
if -1e80 < x < 6.20000000000000035e-78Initial program 99.8%
lift-cos.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-neg.f6499.8
Applied egg-rr99.8%
Applied egg-rr99.6%
Taylor expanded in y around 0
Simplified91.6%
Taylor expanded in x around inf
distribute-rgt-inN/A
*-lft-identityN/A
mul-1-negN/A
distribute-lft-neg-outN/A
unsub-negN/A
lower--.f64N/A
lower-*.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
lower-sin.f6475.0
Simplified75.0%
Final simplification81.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- (* z (sin y)))))
(if (<= y -4.3e+265)
t_0
(if (<= y -0.075)
(* (cos y) x)
(if (<= y 0.1)
(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 = -(z * sin(y));
double tmp;
if (y <= -4.3e+265) {
tmp = t_0;
} else if (y <= -0.075) {
tmp = cos(y) * x;
} else if (y <= 0.1) {
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(-Float64(z * sin(y))) tmp = 0.0 if (y <= -4.3e+265) tmp = t_0; elseif (y <= -0.075) tmp = Float64(cos(y) * x); elseif (y <= 0.1) 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[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision])}, If[LessEqual[y, -4.3e+265], t$95$0, If[LessEqual[y, -0.075], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], If[LessEqual[y, 0.1], 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 := -z \cdot \sin y\\
\mathbf{if}\;y \leq -4.3 \cdot 10^{+265}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -0.075:\\
\;\;\;\;\cos y \cdot x\\
\mathbf{elif}\;y \leq 0.1:\\
\;\;\;\;\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 < -4.29999999999999973e265 or 0.10000000000000001 < y Initial program 99.7%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f64N/A
lower-*.f64N/A
lower-sin.f6459.8
Simplified59.8%
if -4.29999999999999973e265 < y < -0.0749999999999999972Initial program 99.5%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6463.5
Simplified63.5%
if -0.0749999999999999972 < y < 0.10000000000000001Initial 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.f64100.0
Simplified100.0%
Final simplification82.1%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cos y) x)))
(if (<= y -0.075)
t_0
(if (<= y 25.0)
(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 = cos(y) * x;
double tmp;
if (y <= -0.075) {
tmp = t_0;
} else if (y <= 25.0) {
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(cos(y) * x) tmp = 0.0 if (y <= -0.075) tmp = t_0; elseif (y <= 25.0) 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[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[y, -0.075], t$95$0, If[LessEqual[y, 25.0], 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 := \cos y \cdot x\\
\mathbf{if}\;y \leq -0.075:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 25:\\
\;\;\;\;\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.0749999999999999972 or 25 < y Initial program 99.6%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6452.8
Simplified52.8%
if -0.0749999999999999972 < y < 25Initial 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.3
Simplified99.3%
Final simplification77.9%
(FPCore (x y z) :precision binary64 (fma 1.0 x (/ -1.0 (/ (fma 0.16666666666666666 (/ (* y y) z) (/ 1.0 z)) y))))
double code(double x, double y, double z) {
return fma(1.0, x, (-1.0 / (fma(0.16666666666666666, ((y * y) / z), (1.0 / z)) / y)));
}
function code(x, y, z) return fma(1.0, x, Float64(-1.0 / Float64(fma(0.16666666666666666, Float64(Float64(y * y) / z), Float64(1.0 / z)) / y))) end
code[x_, y_, z_] := N[(1.0 * x + N[(-1.0 / N[(N[(0.16666666666666666 * N[(N[(y * y), $MachinePrecision] / z), $MachinePrecision] + N[(1.0 / z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(1, x, \frac{-1}{\frac{\mathsf{fma}\left(0.16666666666666666, \frac{y \cdot y}{z}, \frac{1}{z}\right)}{y}}\right)
\end{array}
Initial program 99.8%
lift-cos.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-neg.f6499.8
Applied egg-rr99.8%
Applied egg-rr99.7%
Taylor expanded in y around 0
Simplified77.5%
Taylor expanded in y around 0
*-commutativeN/A
associate-*l/N/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
lower-/.f64N/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
associate-*l/N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f6456.1
Simplified56.1%
(FPCore (x y z) :precision binary64 (if (<= y -5.2e+28) (- x) (- x (* y z))))
double code(double x, double y, double z) {
double tmp;
if (y <= -5.2e+28) {
tmp = -x;
} else {
tmp = 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 <= (-5.2d+28)) then
tmp = -x
else
tmp = x - (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -5.2e+28) {
tmp = -x;
} else {
tmp = x - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -5.2e+28: tmp = -x else: tmp = x - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -5.2e+28) tmp = Float64(-x); else tmp = Float64(x - Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -5.2e+28) tmp = -x; else tmp = x - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -5.2e+28], (-x), N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.2 \cdot 10^{+28}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;x - y \cdot z\\
\end{array}
\end{array}
if y < -5.2000000000000004e28Initial program 99.5%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f644.2
Simplified4.2%
lift-*.f64N/A
sub-negN/A
flip3-+N/A
cube-negN/A
sub-negN/A
lower-/.f64N/A
Applied egg-rr1.0%
Taylor expanded in y around 0
+-commutativeN/A
unpow2N/A
distribute-lft-inN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f642.7
Simplified2.7%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f6411.0
Simplified11.0%
if -5.2000000000000004e28 < y Initial program 99.9%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6471.1
Simplified71.1%
Final simplification57.3%
(FPCore (x y z) :precision binary64 (if (<= z 1.15e+241) x (* y (- z))))
double code(double x, double y, double z) {
double tmp;
if (z <= 1.15e+241) {
tmp = x;
} else {
tmp = 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.15d+241) then
tmp = x
else
tmp = y * -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 1.15e+241) {
tmp = x;
} else {
tmp = y * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 1.15e+241: tmp = x else: tmp = y * -z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 1.15e+241) tmp = x; else tmp = Float64(y * Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 1.15e+241) tmp = x; else tmp = y * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 1.15e+241], x, N[(y * (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.15 \cdot 10^{+241}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\end{array}
\end{array}
if z < 1.15e241Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6467.7
Simplified67.7%
Taylor expanded in y around 0
Simplified44.3%
*-rgt-identity44.3
Applied egg-rr44.3%
if 1.15e241 < z Initial program 99.9%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6466.2
Simplified66.2%
Taylor expanded in x around 0
mul-1-negN/A
distribute-rgt-neg-inN/A
lower-*.f64N/A
lower-neg.f6449.5
Simplified49.5%
(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 x around inf
lower-*.f64N/A
lower-cos.f6464.5
Simplified64.5%
Taylor expanded in y around 0
Simplified42.8%
*-rgt-identity42.8
Applied egg-rr42.8%
herbie shell --seed 2024211
(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))))