
(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 (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(sin(y) * Float64(-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 \left(-z\right)\right)
\end{array}
Initial program 99.8%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.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 (<= y -12500000.0)
t_0
(if (<= y 9.2e-7) (- x (* z y)) (if (<= y 1.15e+19) t_0 (* x (cos y)))))))
double code(double x, double y, double z) {
double t_0 = sin(y) * -z;
double tmp;
if (y <= -12500000.0) {
tmp = t_0;
} else if (y <= 9.2e-7) {
tmp = x - (z * y);
} else if (y <= 1.15e+19) {
tmp = t_0;
} else {
tmp = x * cos(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) :: t_0
real(8) :: tmp
t_0 = sin(y) * -z
if (y <= (-12500000.0d0)) then
tmp = t_0
else if (y <= 9.2d-7) then
tmp = x - (z * y)
else if (y <= 1.15d+19) then
tmp = t_0
else
tmp = x * cos(y)
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 (y <= -12500000.0) {
tmp = t_0;
} else if (y <= 9.2e-7) {
tmp = x - (z * y);
} else if (y <= 1.15e+19) {
tmp = t_0;
} else {
tmp = x * Math.cos(y);
}
return tmp;
}
def code(x, y, z): t_0 = math.sin(y) * -z tmp = 0 if y <= -12500000.0: tmp = t_0 elif y <= 9.2e-7: tmp = x - (z * y) elif y <= 1.15e+19: tmp = t_0 else: tmp = x * math.cos(y) return tmp
function code(x, y, z) t_0 = Float64(sin(y) * Float64(-z)) tmp = 0.0 if (y <= -12500000.0) tmp = t_0; elseif (y <= 9.2e-7) tmp = Float64(x - Float64(z * y)); elseif (y <= 1.15e+19) tmp = t_0; else tmp = Float64(x * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = sin(y) * -z; tmp = 0.0; if (y <= -12500000.0) tmp = t_0; elseif (y <= 9.2e-7) tmp = x - (z * y); elseif (y <= 1.15e+19) tmp = t_0; else tmp = x * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] * (-z)), $MachinePrecision]}, If[LessEqual[y, -12500000.0], t$95$0, If[LessEqual[y, 9.2e-7], N[(x - N[(z * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.15e+19], t$95$0, N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin y \cdot \left(-z\right)\\
\mathbf{if}\;y \leq -12500000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 9.2 \cdot 10^{-7}:\\
\;\;\;\;x - z \cdot y\\
\mathbf{elif}\;y \leq 1.15 \cdot 10^{+19}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y\\
\end{array}
\end{array}
if y < -1.25e7 or 9.1999999999999998e-7 < y < 1.15e19Initial program 99.5%
Taylor expanded in z around inf
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-sin.f6468.2
Applied rewrites68.2%
if -1.25e7 < y < 9.1999999999999998e-7Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6498.7
Applied rewrites98.7%
if 1.15e19 < y Initial program 99.6%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6462.4
Applied rewrites62.4%
Final simplification81.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- (* 1.0 x) (* (sin y) z)))) (if (<= z -2.4e-45) t_0 (if (<= z 1.35e-42) (* x (cos y)) t_0))))
double code(double x, double y, double z) {
double t_0 = (1.0 * x) - (sin(y) * z);
double tmp;
if (z <= -2.4e-45) {
tmp = t_0;
} else if (z <= 1.35e-42) {
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 = (1.0d0 * x) - (sin(y) * z)
if (z <= (-2.4d-45)) then
tmp = t_0
else if (z <= 1.35d-42) 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 = (1.0 * x) - (Math.sin(y) * z);
double tmp;
if (z <= -2.4e-45) {
tmp = t_0;
} else if (z <= 1.35e-42) {
tmp = x * Math.cos(y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = (1.0 * x) - (math.sin(y) * z) tmp = 0 if z <= -2.4e-45: tmp = t_0 elif z <= 1.35e-42: tmp = x * math.cos(y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(Float64(1.0 * x) - Float64(sin(y) * z)) tmp = 0.0 if (z <= -2.4e-45) tmp = t_0; elseif (z <= 1.35e-42) tmp = Float64(x * cos(y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = (1.0 * x) - (sin(y) * z); tmp = 0.0; if (z <= -2.4e-45) tmp = t_0; elseif (z <= 1.35e-42) tmp = x * cos(y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(1.0 * x), $MachinePrecision] - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -2.4e-45], t$95$0, If[LessEqual[z, 1.35e-42], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 \cdot x - \sin y \cdot z\\
\mathbf{if}\;z \leq -2.4 \cdot 10^{-45}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.35 \cdot 10^{-42}:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -2.3999999999999999e-45 or 1.35e-42 < z Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites90.1%
if -2.3999999999999999e-45 < z < 1.35e-42Initial program 99.8%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6488.0
Applied rewrites88.0%
Final simplification89.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -0.215)
t_0
(if (<= y 5.5e+18)
(fma (- (* (fma 0.16666666666666666 (* z y) (* -0.5 x)) y) z) y x)
t_0))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -0.215) {
tmp = t_0;
} else if (y <= 5.5e+18) {
tmp = fma(((fma(0.16666666666666666, (z * y), (-0.5 * x)) * y) - z), y, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (y <= -0.215) tmp = t_0; elseif (y <= 5.5e+18) tmp = fma(Float64(Float64(fma(0.16666666666666666, Float64(z * y), Float64(-0.5 * x)) * y) - z), y, 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.215], t$95$0, If[LessEqual[y, 5.5e+18], N[(N[(N[(N[(0.16666666666666666 * N[(z * y), $MachinePrecision] + N[(-0.5 * x), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision] - z), $MachinePrecision] * y + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -0.215:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 5.5 \cdot 10^{+18}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, z \cdot y, -0.5 \cdot x\right) \cdot y - z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.214999999999999997 or 5.5e18 < y Initial program 99.5%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6448.2
Applied rewrites48.2%
if -0.214999999999999997 < y < 5.5e18Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6496.5
Applied rewrites96.5%
Final simplification72.7%
(FPCore (x y z) :precision binary64 (if (<= x -1.18e-153) (* 1.0 x) (if (<= x 8.2e-228) (* (- z) y) (* 1.0 x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.18e-153) {
tmp = 1.0 * x;
} else if (x <= 8.2e-228) {
tmp = -z * y;
} else {
tmp = 1.0 * 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 <= (-1.18d-153)) then
tmp = 1.0d0 * x
else if (x <= 8.2d-228) then
tmp = -z * y
else
tmp = 1.0d0 * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.18e-153) {
tmp = 1.0 * x;
} else if (x <= 8.2e-228) {
tmp = -z * y;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.18e-153: tmp = 1.0 * x elif x <= 8.2e-228: tmp = -z * y else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.18e-153) tmp = Float64(1.0 * x); elseif (x <= 8.2e-228) tmp = Float64(Float64(-z) * y); else tmp = Float64(1.0 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.18e-153) tmp = 1.0 * x; elseif (x <= 8.2e-228) tmp = -z * y; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.18e-153], N[(1.0 * x), $MachinePrecision], If[LessEqual[x, 8.2e-228], N[((-z) * y), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.18 \cdot 10^{-153}:\\
\;\;\;\;1 \cdot x\\
\mathbf{elif}\;x \leq 8.2 \cdot 10^{-228}:\\
\;\;\;\;\left(-z\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if x < -1.1800000000000001e-153 or 8.19999999999999995e-228 < x Initial program 99.8%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6451.2
Applied rewrites51.2%
Taylor expanded in x around inf
Applied rewrites51.2%
Taylor expanded in z around 0
Applied rewrites46.4%
if -1.1800000000000001e-153 < x < 8.19999999999999995e-228Initial program 99.8%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6451.9
Applied rewrites51.9%
Taylor expanded in z around inf
Applied rewrites38.8%
(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%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6451.3
Applied rewrites51.3%
(FPCore (x y z) :precision binary64 (* 1.0 x))
double code(double x, double y, double z) {
return 1.0 * x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 1.0d0 * x
end function
public static double code(double x, double y, double z) {
return 1.0 * x;
}
def code(x, y, z): return 1.0 * x
function code(x, y, z) return Float64(1.0 * x) end
function tmp = code(x, y, z) tmp = 1.0 * x; end
code[x_, y_, z_] := N[(1.0 * x), $MachinePrecision]
\begin{array}{l}
\\
1 \cdot x
\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-*.f6451.3
Applied rewrites51.3%
Taylor expanded in x around inf
Applied rewrites50.2%
Taylor expanded in z around 0
Applied rewrites40.0%
herbie shell --seed 2024243
(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))))