
(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 6 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 (- (* (cos y) x) (* (sin y) z)))
double code(double x, double y, double z) {
return (cos(y) * x) - (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 = (cos(y) * x) - (sin(y) * z)
end function
public static double code(double x, double y, double z) {
return (Math.cos(y) * x) - (Math.sin(y) * z);
}
def code(x, y, z): return (math.cos(y) * x) - (math.sin(y) * z)
function code(x, y, z) return Float64(Float64(cos(y) * x) - Float64(sin(y) * z)) end
function tmp = code(x, y, z) tmp = (cos(y) * x) - (sin(y) * z); end
code[x_, y_, z_] := N[(N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision] - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos y \cdot x - \sin y \cdot z
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cos y) x)))
(if (<= x -4.9e+117)
t_0
(if (<= x 1.5e+21) (- (* 1.0 x) (* (sin y) z)) t_0))))
double code(double x, double y, double z) {
double t_0 = cos(y) * x;
double tmp;
if (x <= -4.9e+117) {
tmp = t_0;
} else if (x <= 1.5e+21) {
tmp = (1.0 * x) - (sin(y) * z);
} 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 <= (-4.9d+117)) then
tmp = t_0
else if (x <= 1.5d+21) then
tmp = (1.0d0 * x) - (sin(y) * z)
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 <= -4.9e+117) {
tmp = t_0;
} else if (x <= 1.5e+21) {
tmp = (1.0 * x) - (Math.sin(y) * z);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = math.cos(y) * x tmp = 0 if x <= -4.9e+117: tmp = t_0 elif x <= 1.5e+21: tmp = (1.0 * x) - (math.sin(y) * z) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(cos(y) * x) tmp = 0.0 if (x <= -4.9e+117) tmp = t_0; elseif (x <= 1.5e+21) tmp = Float64(Float64(1.0 * x) - Float64(sin(y) * z)); 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 <= -4.9e+117) tmp = t_0; elseif (x <= 1.5e+21) tmp = (1.0 * x) - (sin(y) * z); 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, -4.9e+117], t$95$0, If[LessEqual[x, 1.5e+21], N[(N[(1.0 * x), $MachinePrecision] - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos y \cdot x\\
\mathbf{if}\;x \leq -4.9 \cdot 10^{+117}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.5 \cdot 10^{+21}:\\
\;\;\;\;1 \cdot x - \sin y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -4.9000000000000001e117 or 1.5e21 < x Initial program 99.9%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6490.7
Applied rewrites90.7%
if -4.9000000000000001e117 < x < 1.5e21Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites85.0%
Final simplification87.4%
(FPCore (x y z) :precision binary64 (if (<= y -0.45) (* (- z) (sin y)) (if (<= y 90000.0) (fma (- (* -0.5 (* y x)) z) y x) (* (cos y) x))))
double code(double x, double y, double z) {
double tmp;
if (y <= -0.45) {
tmp = -z * sin(y);
} else if (y <= 90000.0) {
tmp = fma(((-0.5 * (y * x)) - z), y, x);
} else {
tmp = cos(y) * x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (y <= -0.45) tmp = Float64(Float64(-z) * sin(y)); elseif (y <= 90000.0) tmp = fma(Float64(Float64(-0.5 * Float64(y * x)) - z), y, x); else tmp = Float64(cos(y) * x); end return tmp end
code[x_, y_, z_] := If[LessEqual[y, -0.45], N[((-z) * N[Sin[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 90000.0], N[(N[(N[(-0.5 * N[(y * x), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision] * y + x), $MachinePrecision], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.45:\\
\;\;\;\;\left(-z\right) \cdot \sin y\\
\mathbf{elif}\;y \leq 90000:\\
\;\;\;\;\mathsf{fma}\left(-0.5 \cdot \left(y \cdot x\right) - z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\cos y \cdot x\\
\end{array}
\end{array}
if y < -0.450000000000000011Initial program 99.6%
Taylor expanded in z around inf
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-sin.f6459.9
Applied rewrites59.9%
if -0.450000000000000011 < y < 9e4Initial 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-*.f6498.8
Applied rewrites98.8%
if 9e4 < y Initial program 99.6%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6461.3
Applied rewrites61.3%
Final simplification80.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cos y) x)))
(if (<= y -0.038)
t_0
(if (<= y 90000.0) (fma (- (* -0.5 (* y x)) z) y x) t_0))))
double code(double x, double y, double z) {
double t_0 = cos(y) * x;
double tmp;
if (y <= -0.038) {
tmp = t_0;
} else if (y <= 90000.0) {
tmp = fma(((-0.5 * (y * x)) - z), y, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(cos(y) * x) tmp = 0.0 if (y <= -0.038) tmp = t_0; elseif (y <= 90000.0) tmp = fma(Float64(Float64(-0.5 * Float64(y * x)) - z), 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[y, -0.038], t$95$0, If[LessEqual[y, 90000.0], N[(N[(N[(-0.5 * N[(y * x), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision] * y + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos y \cdot x\\
\mathbf{if}\;y \leq -0.038:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 90000:\\
\;\;\;\;\mathsf{fma}\left(-0.5 \cdot \left(y \cdot x\right) - z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.0379999999999999991 or 9e4 < y Initial program 99.6%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6449.4
Applied rewrites49.4%
if -0.0379999999999999991 < y < 9e4Initial 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-*.f6499.3
Applied rewrites99.3%
Final simplification75.5%
(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-*.f6455.2
Applied rewrites55.2%
(FPCore (x y z) :precision binary64 (* (- y) z))
double code(double x, double y, double z) {
return -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 = -y * z
end function
public static double code(double x, double y, double z) {
return -y * z;
}
def code(x, y, z): return -y * z
function code(x, y, z) return Float64(Float64(-y) * z) end
function tmp = code(x, y, z) tmp = -y * z; end
code[x_, y_, z_] := N[((-y) * z), $MachinePrecision]
\begin{array}{l}
\\
\left(-y\right) \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-*.f6455.2
Applied rewrites55.2%
Taylor expanded in z around inf
Applied rewrites14.0%
herbie shell --seed 2024249
(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))))