
(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.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cos y) x)))
(if (<= x -6.6e+151)
t_0
(if (<= x 7.5e+51) (- (* 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 <= -6.6e+151) {
tmp = t_0;
} else if (x <= 7.5e+51) {
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 <= (-6.6d+151)) then
tmp = t_0
else if (x <= 7.5d+51) 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 <= -6.6e+151) {
tmp = t_0;
} else if (x <= 7.5e+51) {
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 <= -6.6e+151: tmp = t_0 elif x <= 7.5e+51: 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 <= -6.6e+151) tmp = t_0; elseif (x <= 7.5e+51) 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 <= -6.6e+151) tmp = t_0; elseif (x <= 7.5e+51) 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, -6.6e+151], t$95$0, If[LessEqual[x, 7.5e+51], 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 -6.6 \cdot 10^{+151}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 7.5 \cdot 10^{+51}:\\
\;\;\;\;1 \cdot x - \sin y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -6.60000000000000049e151 or 7.4999999999999999e51 < x Initial program 99.8%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6491.8
Applied rewrites91.8%
if -6.60000000000000049e151 < x < 7.4999999999999999e51Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites88.6%
Final simplification89.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (cos y) x))) (if (<= x -6.2e-74) t_0 (if (<= x 2e+42) (* (- z) (sin y)) t_0))))
double code(double x, double y, double z) {
double t_0 = cos(y) * x;
double tmp;
if (x <= -6.2e-74) {
tmp = t_0;
} else if (x <= 2e+42) {
tmp = -z * sin(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 = cos(y) * x
if (x <= (-6.2d-74)) then
tmp = t_0
else if (x <= 2d+42) then
tmp = -z * sin(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.cos(y) * x;
double tmp;
if (x <= -6.2e-74) {
tmp = t_0;
} else if (x <= 2e+42) {
tmp = -z * Math.sin(y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = math.cos(y) * x tmp = 0 if x <= -6.2e-74: tmp = t_0 elif x <= 2e+42: tmp = -z * math.sin(y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(cos(y) * x) tmp = 0.0 if (x <= -6.2e-74) tmp = t_0; elseif (x <= 2e+42) tmp = Float64(Float64(-z) * sin(y)); 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 <= -6.2e-74) tmp = t_0; elseif (x <= 2e+42) tmp = -z * sin(y); 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, -6.2e-74], t$95$0, If[LessEqual[x, 2e+42], N[((-z) * N[Sin[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos y \cdot x\\
\mathbf{if}\;x \leq -6.2 \cdot 10^{-74}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 2 \cdot 10^{+42}:\\
\;\;\;\;\left(-z\right) \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -6.2000000000000003e-74 or 2.00000000000000009e42 < x Initial program 99.8%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6485.7
Applied rewrites85.7%
if -6.2000000000000003e-74 < x < 2.00000000000000009e42Initial program 99.8%
Taylor expanded in z around inf
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-sin.f6474.9
Applied rewrites74.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cos y) x)))
(if (<= y -0.021)
t_0
(if (<= y 0.0285)
(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 = cos(y) * x;
double tmp;
if (y <= -0.021) {
tmp = t_0;
} else if (y <= 0.0285) {
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(cos(y) * x) tmp = 0.0 if (y <= -0.021) tmp = t_0; elseif (y <= 0.0285) 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[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[y, -0.021], t$95$0, If[LessEqual[y, 0.0285], 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 := \cos y \cdot x\\
\mathbf{if}\;y \leq -0.021:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.0285:\\
\;\;\;\;\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.0210000000000000013 or 0.028500000000000001 < y Initial program 99.6%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6450.6
Applied rewrites50.6%
if -0.0210000000000000013 < y < 0.028500000000000001Initial 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-*.f6499.9
Applied rewrites99.9%
(FPCore (x y z) :precision binary64 (if (<= x -6.8e-75) (* 1.0 x) (if (<= x 6e-66) (* (- z) y) (* 1.0 x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -6.8e-75) {
tmp = 1.0 * x;
} else if (x <= 6e-66) {
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.8d-75)) then
tmp = 1.0d0 * x
else if (x <= 6d-66) 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.8e-75) {
tmp = 1.0 * x;
} else if (x <= 6e-66) {
tmp = -z * y;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -6.8e-75: tmp = 1.0 * x elif x <= 6e-66: tmp = -z * y else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -6.8e-75) tmp = Float64(1.0 * x); elseif (x <= 6e-66) 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.8e-75) tmp = 1.0 * x; elseif (x <= 6e-66) tmp = -z * y; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -6.8e-75], N[(1.0 * x), $MachinePrecision], If[LessEqual[x, 6e-66], N[((-z) * y), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.8 \cdot 10^{-75}:\\
\;\;\;\;1 \cdot x\\
\mathbf{elif}\;x \leq 6 \cdot 10^{-66}:\\
\;\;\;\;\left(-z\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if x < -6.8000000000000003e-75 or 6.0000000000000004e-66 < x Initial program 99.8%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6479.5
Applied rewrites79.5%
Taylor expanded in y around 0
Applied rewrites47.8%
if -6.8000000000000003e-75 < x < 6.0000000000000004e-66Initial program 99.8%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6452.2
Applied rewrites52.2%
Taylor expanded in z around inf
Applied rewrites37.3%
(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-*.f6452.2
Applied rewrites52.2%
(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 z around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6458.3
Applied rewrites58.3%
Taylor expanded in y around 0
Applied rewrites36.7%
(FPCore (x y z) :precision binary64 (* z y))
double code(double x, double y, double z) {
return 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 = z * y
end function
public static double code(double x, double y, double z) {
return z * y;
}
def code(x, y, z): return z * y
function code(x, y, z) return Float64(z * y) end
function tmp = code(x, y, z) tmp = z * y; end
code[x_, y_, z_] := N[(z * y), $MachinePrecision]
\begin{array}{l}
\\
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-*.f6452.2
Applied rewrites52.2%
Taylor expanded in z around inf
Applied rewrites19.6%
Applied rewrites2.9%
herbie shell --seed 2024276
(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))))