
(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 9 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)) (t_1 (/ (sin y) (/ -1.0 z))))
(if (<= y -1.7e+194)
t_0
(if (<= y -0.0225)
t_1
(if (<= y 0.0055)
(fma (- (* (fma 0.16666666666666666 (* z y) (* -0.5 x)) y) z) y x)
(if (<= y 9.5e+122) t_0 (if (<= y 1.5e+253) t_1 t_0)))))))
double code(double x, double y, double z) {
double t_0 = cos(y) * x;
double t_1 = sin(y) / (-1.0 / z);
double tmp;
if (y <= -1.7e+194) {
tmp = t_0;
} else if (y <= -0.0225) {
tmp = t_1;
} else if (y <= 0.0055) {
tmp = fma(((fma(0.16666666666666666, (z * y), (-0.5 * x)) * y) - z), y, x);
} else if (y <= 9.5e+122) {
tmp = t_0;
} else if (y <= 1.5e+253) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(cos(y) * x) t_1 = Float64(sin(y) / Float64(-1.0 / z)) tmp = 0.0 if (y <= -1.7e+194) tmp = t_0; elseif (y <= -0.0225) tmp = t_1; elseif (y <= 0.0055) tmp = fma(Float64(Float64(fma(0.16666666666666666, Float64(z * y), Float64(-0.5 * x)) * y) - z), y, x); elseif (y <= 9.5e+122) tmp = t_0; elseif (y <= 1.5e+253) tmp = t_1; else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision]}, Block[{t$95$1 = N[(N[Sin[y], $MachinePrecision] / N[(-1.0 / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.7e+194], t$95$0, If[LessEqual[y, -0.0225], t$95$1, If[LessEqual[y, 0.0055], N[(N[(N[(N[(0.16666666666666666 * N[(z * y), $MachinePrecision] + N[(-0.5 * x), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision] - z), $MachinePrecision] * y + x), $MachinePrecision], If[LessEqual[y, 9.5e+122], t$95$0, If[LessEqual[y, 1.5e+253], t$95$1, t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos y \cdot x\\
t_1 := \frac{\sin y}{\frac{-1}{z}}\\
\mathbf{if}\;y \leq -1.7 \cdot 10^{+194}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -0.0225:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 0.0055:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, z \cdot y, -0.5 \cdot x\right) \cdot y - z, y, x\right)\\
\mathbf{elif}\;y \leq 9.5 \cdot 10^{+122}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.5 \cdot 10^{+253}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.7000000000000001e194 or 0.0054999999999999997 < y < 9.49999999999999986e122 or 1.4999999999999999e253 < y Initial program 99.5%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6476.2
Applied rewrites76.2%
if -1.7000000000000001e194 < y < -0.022499999999999999 or 9.49999999999999986e122 < y < 1.4999999999999999e253Initial 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.f6467.0
Applied rewrites67.0%
Applied rewrites26.6%
Applied rewrites67.1%
if -0.022499999999999999 < y < 0.0054999999999999997Initial 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-*.f64100.0
Applied rewrites100.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* (fma (- z) (/ 1.0 (/ x (sin y))) 1.0) x))) (if (<= z -1.55e-16) t_0 (if (<= z 1.62e+34) (* (cos y) x) t_0))))
double code(double x, double y, double z) {
double t_0 = fma(-z, (1.0 / (x / sin(y))), 1.0) * x;
double tmp;
if (z <= -1.55e-16) {
tmp = t_0;
} else if (z <= 1.62e+34) {
tmp = cos(y) * x;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(fma(Float64(-z), Float64(1.0 / Float64(x / sin(y))), 1.0) * x) tmp = 0.0 if (z <= -1.55e-16) tmp = t_0; elseif (z <= 1.62e+34) tmp = Float64(cos(y) * x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[((-z) * N[(1.0 / N[(x / N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[z, -1.55e-16], t$95$0, If[LessEqual[z, 1.62e+34], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(-z, \frac{1}{\frac{x}{\sin y}}, 1\right) \cdot x\\
\mathbf{if}\;z \leq -1.55 \cdot 10^{-16}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.62 \cdot 10^{+34}:\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.55e-16 or 1.62000000000000006e34 < z Initial program 99.8%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
flip-+N/A
sqr-negN/A
clear-numN/A
lower-/.f64N/A
lower-/.f64N/A
Applied rewrites52.2%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-/l*N/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6487.2
Applied rewrites87.2%
Applied rewrites86.8%
Taylor expanded in y around 0
Applied rewrites78.8%
if -1.55e-16 < z < 1.62000000000000006e34Initial program 99.8%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6486.0
Applied rewrites86.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cos y) x)) (t_1 (* (- z) (sin y))))
(if (<= y -1.7e+194)
t_0
(if (<= y -0.0225)
t_1
(if (<= y 0.0055)
(fma (- (* (fma 0.16666666666666666 (* z y) (* -0.5 x)) y) z) y x)
(if (<= y 6.3e+121) t_0 (if (<= y 6.6e+253) t_1 t_0)))))))
double code(double x, double y, double z) {
double t_0 = cos(y) * x;
double t_1 = -z * sin(y);
double tmp;
if (y <= -1.7e+194) {
tmp = t_0;
} else if (y <= -0.0225) {
tmp = t_1;
} else if (y <= 0.0055) {
tmp = fma(((fma(0.16666666666666666, (z * y), (-0.5 * x)) * y) - z), y, x);
} else if (y <= 6.3e+121) {
tmp = t_0;
} else if (y <= 6.6e+253) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(cos(y) * x) t_1 = Float64(Float64(-z) * sin(y)) tmp = 0.0 if (y <= -1.7e+194) tmp = t_0; elseif (y <= -0.0225) tmp = t_1; elseif (y <= 0.0055) tmp = fma(Float64(Float64(fma(0.16666666666666666, Float64(z * y), Float64(-0.5 * x)) * y) - z), y, x); elseif (y <= 6.3e+121) tmp = t_0; elseif (y <= 6.6e+253) tmp = t_1; else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision]}, Block[{t$95$1 = N[((-z) * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.7e+194], t$95$0, If[LessEqual[y, -0.0225], t$95$1, If[LessEqual[y, 0.0055], N[(N[(N[(N[(0.16666666666666666 * N[(z * y), $MachinePrecision] + N[(-0.5 * x), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision] - z), $MachinePrecision] * y + x), $MachinePrecision], If[LessEqual[y, 6.3e+121], t$95$0, If[LessEqual[y, 6.6e+253], t$95$1, t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos y \cdot x\\
t_1 := \left(-z\right) \cdot \sin y\\
\mathbf{if}\;y \leq -1.7 \cdot 10^{+194}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -0.0225:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 0.0055:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, z \cdot y, -0.5 \cdot x\right) \cdot y - z, y, x\right)\\
\mathbf{elif}\;y \leq 6.3 \cdot 10^{+121}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 6.6 \cdot 10^{+253}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.7000000000000001e194 or 0.0054999999999999997 < y < 6.29999999999999956e121 or 6.5999999999999998e253 < y Initial program 99.5%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6476.2
Applied rewrites76.2%
if -1.7000000000000001e194 < y < -0.022499999999999999 or 6.29999999999999956e121 < y < 6.5999999999999998e253Initial 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.f6467.0
Applied rewrites67.0%
if -0.022499999999999999 < y < 0.0054999999999999997Initial 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-*.f64100.0
Applied rewrites100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cos y) x)))
(if (<= y -9.5e+17)
t_0
(if (<= y 0.0055)
(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 <= -9.5e+17) {
tmp = t_0;
} else if (y <= 0.0055) {
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 <= -9.5e+17) tmp = t_0; elseif (y <= 0.0055) 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, -9.5e+17], t$95$0, If[LessEqual[y, 0.0055], 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 -9.5 \cdot 10^{+17}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.0055:\\
\;\;\;\;\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 < -9.5e17 or 0.0054999999999999997 < y Initial program 99.6%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6454.0
Applied rewrites54.0%
if -9.5e17 < y < 0.0054999999999999997Initial 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-*.f6497.5
Applied rewrites97.5%
(FPCore (x y z) :precision binary64 (if (<= x -5e-133) (* 1.0 x) (if (<= x 2.5e-279) (* (- z) y) (* 1.0 x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -5e-133) {
tmp = 1.0 * x;
} else if (x <= 2.5e-279) {
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 <= (-5d-133)) then
tmp = 1.0d0 * x
else if (x <= 2.5d-279) 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 <= -5e-133) {
tmp = 1.0 * x;
} else if (x <= 2.5e-279) {
tmp = -z * y;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -5e-133: tmp = 1.0 * x elif x <= 2.5e-279: tmp = -z * y else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -5e-133) tmp = Float64(1.0 * x); elseif (x <= 2.5e-279) 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 <= -5e-133) tmp = 1.0 * x; elseif (x <= 2.5e-279) tmp = -z * y; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -5e-133], N[(1.0 * x), $MachinePrecision], If[LessEqual[x, 2.5e-279], N[((-z) * y), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-133}:\\
\;\;\;\;1 \cdot x\\
\mathbf{elif}\;x \leq 2.5 \cdot 10^{-279}:\\
\;\;\;\;\left(-z\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if x < -4.9999999999999999e-133 or 2.49999999999999984e-279 < x Initial program 99.8%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
flip-+N/A
sqr-negN/A
clear-numN/A
lower-/.f64N/A
lower-/.f64N/A
Applied rewrites51.3%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-/l*N/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6494.9
Applied rewrites94.9%
Taylor expanded in y around 0
Applied rewrites48.1%
if -4.9999999999999999e-133 < x < 2.49999999999999984e-279Initial program 99.9%
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 rewrites41.7%
(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.8%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
flip-+N/A
sqr-negN/A
clear-numN/A
lower-/.f64N/A
lower-/.f64N/A
Applied rewrites54.4%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f6456.3
Applied rewrites56.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-*.f6456.3
Applied rewrites56.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%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
flip-+N/A
sqr-negN/A
clear-numN/A
lower-/.f64N/A
lower-/.f64N/A
Applied rewrites54.4%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-/l*N/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
lower-sin.f64N/A
lower-cos.f6493.5
Applied rewrites93.5%
Taylor expanded in y around 0
Applied rewrites42.1%
herbie shell --seed 2024257
(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))))