
(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 (- (* (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.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (- z) (sin y))) (t_1 (* (cos y) x)))
(if (<= y -3.5e+224)
t_0
(if (<= y -10000000.0)
t_1
(if (<= y 0.098)
(-
(* 1.0 x)
(*
(fma
(* (fma 0.008333333333333333 (* y y) -0.16666666666666666) z)
(* y y)
z)
y))
(if (<= y 1.76e+137) t_0 t_1))))))
double code(double x, double y, double z) {
double t_0 = -z * sin(y);
double t_1 = cos(y) * x;
double tmp;
if (y <= -3.5e+224) {
tmp = t_0;
} else if (y <= -10000000.0) {
tmp = t_1;
} else if (y <= 0.098) {
tmp = (1.0 * x) - (fma((fma(0.008333333333333333, (y * y), -0.16666666666666666) * z), (y * y), z) * y);
} else if (y <= 1.76e+137) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(Float64(-z) * sin(y)) t_1 = Float64(cos(y) * x) tmp = 0.0 if (y <= -3.5e+224) tmp = t_0; elseif (y <= -10000000.0) tmp = t_1; elseif (y <= 0.098) tmp = Float64(Float64(1.0 * x) - Float64(fma(Float64(fma(0.008333333333333333, Float64(y * y), -0.16666666666666666) * z), Float64(y * y), z) * y)); elseif (y <= 1.76e+137) tmp = t_0; else tmp = t_1; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[((-z) * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[y, -3.5e+224], t$95$0, If[LessEqual[y, -10000000.0], t$95$1, If[LessEqual[y, 0.098], N[(N[(1.0 * x), $MachinePrecision] - N[(N[(N[(N[(0.008333333333333333 * N[(y * y), $MachinePrecision] + -0.16666666666666666), $MachinePrecision] * z), $MachinePrecision] * N[(y * y), $MachinePrecision] + z), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.76e+137], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-z\right) \cdot \sin y\\
t_1 := \cos y \cdot x\\
\mathbf{if}\;y \leq -3.5 \cdot 10^{+224}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -10000000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 0.098:\\
\;\;\;\;1 \cdot x - \mathsf{fma}\left(\mathsf{fma}\left(0.008333333333333333, y \cdot y, -0.16666666666666666\right) \cdot z, y \cdot y, z\right) \cdot y\\
\mathbf{elif}\;y \leq 1.76 \cdot 10^{+137}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -3.5e224 or 0.098000000000000004 < y < 1.76e137Initial program 99.7%
Taylor expanded in z around inf
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-sin.f6477.4
Applied rewrites77.4%
if -3.5e224 < y < -1e7 or 1.76e137 < y Initial program 99.7%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6461.7
Applied rewrites61.7%
if -1e7 < y < 0.098000000000000004Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites99.8%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.1%
Final simplification83.7%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cos y) x)))
(if (<= x -2e+86)
t_0
(if (<= x 1.92e+34) (- (* 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 <= -2e+86) {
tmp = t_0;
} else if (x <= 1.92e+34) {
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 <= (-2d+86)) then
tmp = t_0
else if (x <= 1.92d+34) 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 <= -2e+86) {
tmp = t_0;
} else if (x <= 1.92e+34) {
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 <= -2e+86: tmp = t_0 elif x <= 1.92e+34: 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 <= -2e+86) tmp = t_0; elseif (x <= 1.92e+34) 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 <= -2e+86) tmp = t_0; elseif (x <= 1.92e+34) 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, -2e+86], t$95$0, If[LessEqual[x, 1.92e+34], 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 -2 \cdot 10^{+86}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.92 \cdot 10^{+34}:\\
\;\;\;\;1 \cdot x - \sin y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -2e86 or 1.92e34 < x Initial program 99.9%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6489.0
Applied rewrites89.0%
if -2e86 < x < 1.92e34Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites87.2%
Final simplification87.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cos y) x)))
(if (<= y -10000000.0)
t_0
(if (<= y 0.6)
(-
(* 1.0 x)
(*
(fma
(* (fma 0.008333333333333333 (* y y) -0.16666666666666666) z)
(* y y)
z)
y))
t_0))))
double code(double x, double y, double z) {
double t_0 = cos(y) * x;
double tmp;
if (y <= -10000000.0) {
tmp = t_0;
} else if (y <= 0.6) {
tmp = (1.0 * x) - (fma((fma(0.008333333333333333, (y * y), -0.16666666666666666) * z), (y * y), z) * y);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(cos(y) * x) tmp = 0.0 if (y <= -10000000.0) tmp = t_0; elseif (y <= 0.6) tmp = Float64(Float64(1.0 * x) - Float64(fma(Float64(fma(0.008333333333333333, Float64(y * y), -0.16666666666666666) * z), Float64(y * y), z) * y)); 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, -10000000.0], t$95$0, If[LessEqual[y, 0.6], N[(N[(1.0 * x), $MachinePrecision] - N[(N[(N[(N[(0.008333333333333333 * N[(y * y), $MachinePrecision] + -0.16666666666666666), $MachinePrecision] * z), $MachinePrecision] * N[(y * y), $MachinePrecision] + z), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos y \cdot x\\
\mathbf{if}\;y \leq -10000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.6:\\
\;\;\;\;1 \cdot x - \mathsf{fma}\left(\mathsf{fma}\left(0.008333333333333333, y \cdot y, -0.16666666666666666\right) \cdot z, y \cdot y, z\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1e7 or 0.599999999999999978 < y Initial program 99.7%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6449.1
Applied rewrites49.1%
if -1e7 < y < 0.599999999999999978Initial program 100.0%
Taylor expanded in y around 0
Applied rewrites99.8%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites98.3%
Final simplification74.9%
(FPCore (x y z) :precision binary64 (if (<= x -6.2e-120) (* 1.0 x) (if (<= x 2.7e-199) (* (- z) y) (* 1.0 x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -6.2e-120) {
tmp = 1.0 * x;
} else if (x <= 2.7e-199) {
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 <= (-6.2d-120)) then
tmp = 1.0d0 * x
else if (x <= 2.7d-199) 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 <= -6.2e-120) {
tmp = 1.0 * x;
} else if (x <= 2.7e-199) {
tmp = -z * y;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -6.2e-120: tmp = 1.0 * x elif x <= 2.7e-199: tmp = -z * y else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -6.2e-120) tmp = Float64(1.0 * x); elseif (x <= 2.7e-199) 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 <= -6.2e-120) tmp = 1.0 * x; elseif (x <= 2.7e-199) tmp = -z * y; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -6.2e-120], N[(1.0 * x), $MachinePrecision], If[LessEqual[x, 2.7e-199], N[((-z) * y), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.2 \cdot 10^{-120}:\\
\;\;\;\;1 \cdot x\\
\mathbf{elif}\;x \leq 2.7 \cdot 10^{-199}:\\
\;\;\;\;\left(-z\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if x < -6.20000000000000038e-120 or 2.69999999999999989e-199 < x Initial program 99.8%
lift--.f64N/A
flip--N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip--N/A
lift--.f64N/A
inv-powN/A
lower-pow.f6499.6
Applied rewrites99.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
mul-1-negN/A
*-commutativeN/A
associate-/l*N/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-sin.f64N/A
lower-/.f64N/A
lower-cos.f6495.8
Applied rewrites95.8%
Taylor expanded in y around 0
Applied rewrites45.7%
if -6.20000000000000038e-120 < x < 2.69999999999999989e-199Initial program 99.9%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6452.3
Applied rewrites52.3%
Taylor expanded in z around inf
Applied rewrites41.9%
(FPCore (x y z) :precision binary64 (fma (- z) y x))
double code(double x, double y, double z) {
return fma(-z, y, x);
}
function code(x, y, z) return fma(Float64(-z), y, x) end
code[x_, y_, z_] := N[((-z) * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(-z, y, x\right)
\end{array}
Initial program 99.9%
lift--.f64N/A
flip--N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip--N/A
lift--.f64N/A
inv-powN/A
lower-pow.f6499.6
Applied rewrites99.7%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f6454.0
Applied rewrites54.0%
(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.9%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6454.0
Applied rewrites54.0%
(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.9%
lift--.f64N/A
flip--N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip--N/A
lift--.f64N/A
inv-powN/A
lower-pow.f6499.6
Applied rewrites99.7%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
mul-1-negN/A
*-commutativeN/A
associate-/l*N/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-sin.f64N/A
lower-/.f64N/A
lower-cos.f6488.3
Applied rewrites88.3%
Taylor expanded in y around 0
Applied rewrites37.7%
herbie shell --seed 2024254
(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))))