
(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 7 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 (- (* 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}
Initial program 99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (sin y) (- z))) (t_1 (* x (- 1.0 (* z (/ (sin y) x))))))
(if (<= z -7.6e+192)
t_0
(if (<= z -1.75e-127)
t_1
(if (<= z 4.3e-114) (* x (cos y)) (if (<= z 4.1e+252) t_1 t_0))))))
double code(double x, double y, double z) {
double t_0 = sin(y) * -z;
double t_1 = x * (1.0 - (z * (sin(y) / x)));
double tmp;
if (z <= -7.6e+192) {
tmp = t_0;
} else if (z <= -1.75e-127) {
tmp = t_1;
} else if (z <= 4.3e-114) {
tmp = x * cos(y);
} else if (z <= 4.1e+252) {
tmp = t_1;
} 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) :: t_1
real(8) :: tmp
t_0 = sin(y) * -z
t_1 = x * (1.0d0 - (z * (sin(y) / x)))
if (z <= (-7.6d+192)) then
tmp = t_0
else if (z <= (-1.75d-127)) then
tmp = t_1
else if (z <= 4.3d-114) then
tmp = x * cos(y)
else if (z <= 4.1d+252) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = Math.sin(y) * -z;
double t_1 = x * (1.0 - (z * (Math.sin(y) / x)));
double tmp;
if (z <= -7.6e+192) {
tmp = t_0;
} else if (z <= -1.75e-127) {
tmp = t_1;
} else if (z <= 4.3e-114) {
tmp = x * Math.cos(y);
} else if (z <= 4.1e+252) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = math.sin(y) * -z t_1 = x * (1.0 - (z * (math.sin(y) / x))) tmp = 0 if z <= -7.6e+192: tmp = t_0 elif z <= -1.75e-127: tmp = t_1 elif z <= 4.3e-114: tmp = x * math.cos(y) elif z <= 4.1e+252: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(sin(y) * Float64(-z)) t_1 = Float64(x * Float64(1.0 - Float64(z * Float64(sin(y) / x)))) tmp = 0.0 if (z <= -7.6e+192) tmp = t_0; elseif (z <= -1.75e-127) tmp = t_1; elseif (z <= 4.3e-114) tmp = Float64(x * cos(y)); elseif (z <= 4.1e+252) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = sin(y) * -z; t_1 = x * (1.0 - (z * (sin(y) / x))); tmp = 0.0; if (z <= -7.6e+192) tmp = t_0; elseif (z <= -1.75e-127) tmp = t_1; elseif (z <= 4.3e-114) tmp = x * cos(y); elseif (z <= 4.1e+252) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] * (-z)), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[(1.0 - N[(z * N[(N[Sin[y], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -7.6e+192], t$95$0, If[LessEqual[z, -1.75e-127], t$95$1, If[LessEqual[z, 4.3e-114], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 4.1e+252], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin y \cdot \left(-z\right)\\
t_1 := x \cdot \left(1 - z \cdot \frac{\sin y}{x}\right)\\
\mathbf{if}\;z \leq -7.6 \cdot 10^{+192}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -1.75 \cdot 10^{-127}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 4.3 \cdot 10^{-114}:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{elif}\;z \leq 4.1 \cdot 10^{+252}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -7.5999999999999999e192 or 4.1000000000000003e252 < z Initial program 99.9%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f64N/A
lower-*.f64N/A
lower-sin.f6487.9
Simplified87.9%
if -7.5999999999999999e192 < z < -1.74999999999999995e-127 or 4.3e-114 < z < 4.1000000000000003e252Initial program 99.8%
lift-cos.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
flip--N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip--N/A
lift--.f64N/A
lower-/.f6499.6
Applied egg-rr99.6%
Taylor expanded in x around inf
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-cos.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
lower-sin.f6494.2
Simplified94.2%
Taylor expanded in y around 0
Simplified83.4%
if -1.74999999999999995e-127 < z < 4.3e-114Initial program 99.8%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6497.0
Simplified97.0%
Final simplification87.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (sin y) (- z))))
(if (<= y -0.0046)
t_0
(if (<= y 0.5)
(fma
x
(* y (* y -0.5))
(fma (* y z) (fma 0.16666666666666666 (* y y) -1.0) x))
t_0))))
double code(double x, double y, double z) {
double t_0 = sin(y) * -z;
double tmp;
if (y <= -0.0046) {
tmp = t_0;
} else if (y <= 0.5) {
tmp = fma(x, (y * (y * -0.5)), fma((y * z), fma(0.16666666666666666, (y * y), -1.0), x));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(sin(y) * Float64(-z)) tmp = 0.0 if (y <= -0.0046) tmp = t_0; elseif (y <= 0.5) tmp = fma(x, Float64(y * Float64(y * -0.5)), fma(Float64(y * z), fma(0.16666666666666666, Float64(y * y), -1.0), x)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] * (-z)), $MachinePrecision]}, If[LessEqual[y, -0.0046], t$95$0, If[LessEqual[y, 0.5], N[(x * N[(y * N[(y * -0.5), $MachinePrecision]), $MachinePrecision] + N[(N[(y * z), $MachinePrecision] * N[(0.16666666666666666 * N[(y * y), $MachinePrecision] + -1.0), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin y \cdot \left(-z\right)\\
\mathbf{if}\;y \leq -0.0046:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.5:\\
\;\;\;\;\mathsf{fma}\left(x, y \cdot \left(y \cdot -0.5\right), \mathsf{fma}\left(y \cdot z, \mathsf{fma}\left(0.16666666666666666, y \cdot y, -1\right), x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.0045999999999999999 or 0.5 < y Initial program 99.6%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f64N/A
lower-*.f64N/A
lower-sin.f6459.9
Simplified59.9%
if -0.0045999999999999999 < y < 0.5Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f64N/A
sub-negN/A
lower-fma.f64N/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-neg.f6499.4
Simplified99.4%
Taylor expanded in z around 0
+-commutativeN/A
associate-+l+N/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
sub-negN/A
metadata-evalN/A
distribute-rgt-inN/A
associate-*r*N/A
mul-1-negN/A
sub-negN/A
lower-fma.f64N/A
Simplified99.4%
Final simplification80.6%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -75000000.0)
t_0
(if (<= y 0.036)
(fma
x
(* y (* y -0.5))
(fma (* y z) (fma 0.16666666666666666 (* y y) -1.0) x))
t_0))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -75000000.0) {
tmp = t_0;
} else if (y <= 0.036) {
tmp = fma(x, (y * (y * -0.5)), fma((y * z), fma(0.16666666666666666, (y * y), -1.0), x));
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (y <= -75000000.0) tmp = t_0; elseif (y <= 0.036) tmp = fma(x, Float64(y * Float64(y * -0.5)), fma(Float64(y * z), fma(0.16666666666666666, Float64(y * y), -1.0), 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, -75000000.0], t$95$0, If[LessEqual[y, 0.036], N[(x * N[(y * N[(y * -0.5), $MachinePrecision]), $MachinePrecision] + N[(N[(y * z), $MachinePrecision] * N[(0.16666666666666666 * N[(y * y), $MachinePrecision] + -1.0), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -75000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.036:\\
\;\;\;\;\mathsf{fma}\left(x, y \cdot \left(y \cdot -0.5\right), \mathsf{fma}\left(y \cdot z, \mathsf{fma}\left(0.16666666666666666, y \cdot y, -1\right), x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -7.5e7 or 0.0359999999999999973 < y Initial program 99.6%
Taylor expanded in x around inf
lower-*.f64N/A
lower-cos.f6443.7
Simplified43.7%
if -7.5e7 < y < 0.0359999999999999973Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
lower-fma.f64N/A
sub-negN/A
lower-fma.f64N/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-neg.f6497.0
Simplified97.0%
Taylor expanded in z around 0
+-commutativeN/A
associate-+l+N/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
sub-negN/A
metadata-evalN/A
distribute-rgt-inN/A
associate-*r*N/A
mul-1-negN/A
sub-negN/A
lower-fma.f64N/A
Simplified97.0%
Final simplification72.5%
(FPCore (x y z) :precision binary64 (let* ((t_0 (- (* y z)))) (if (<= z -7e+116) t_0 (if (<= z 1.8e+259) x t_0))))
double code(double x, double y, double z) {
double t_0 = -(y * z);
double tmp;
if (z <= -7e+116) {
tmp = t_0;
} else if (z <= 1.8e+259) {
tmp = x;
} 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 = -(y * z)
if (z <= (-7d+116)) then
tmp = t_0
else if (z <= 1.8d+259) then
tmp = x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = -(y * z);
double tmp;
if (z <= -7e+116) {
tmp = t_0;
} else if (z <= 1.8e+259) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = -(y * z) tmp = 0 if z <= -7e+116: tmp = t_0 elif z <= 1.8e+259: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(-Float64(y * z)) tmp = 0.0 if (z <= -7e+116) tmp = t_0; elseif (z <= 1.8e+259) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = -(y * z); tmp = 0.0; if (z <= -7e+116) tmp = t_0; elseif (z <= 1.8e+259) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = (-N[(y * z), $MachinePrecision])}, If[LessEqual[z, -7e+116], t$95$0, If[LessEqual[z, 1.8e+259], x, t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -y \cdot z\\
\mathbf{if}\;z \leq -7 \cdot 10^{+116}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.8 \cdot 10^{+259}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -6.99999999999999993e116 or 1.8000000000000001e259 < z Initial program 99.9%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6448.1
Simplified48.1%
Taylor expanded in x around 0
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6437.3
Simplified37.3%
if -6.99999999999999993e116 < z < 1.8000000000000001e259Initial program 99.8%
lift-cos.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
flip--N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip--N/A
lift--.f64N/A
lower-/.f6499.6
Applied egg-rr99.6%
Taylor expanded in x around inf
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-cos.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
lower-sin.f6496.2
Simplified96.2%
Taylor expanded in y around 0
Simplified49.6%
*-rgt-identity49.6
Applied egg-rr49.6%
Final simplification46.6%
(FPCore (x y z) :precision binary64 (- x (* y z)))
double code(double x, double y, double z) {
return x - (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 - (y * z)
end function
public static double code(double x, double y, double z) {
return x - (y * z);
}
def code(x, y, z): return x - (y * z)
function code(x, y, z) return Float64(x - Float64(y * z)) end
function tmp = code(x, y, z) tmp = x - (y * z); end
code[x_, y_, z_] := N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - y \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.1
Simplified55.1%
Final simplification55.1%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.8%
lift-cos.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
lift-*.f64N/A
flip--N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip--N/A
lift--.f64N/A
lower-/.f6499.6
Applied egg-rr99.6%
Taylor expanded in x around inf
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-cos.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
lower-sin.f6488.3
Simplified88.3%
Taylor expanded in y around 0
Simplified39.9%
*-rgt-identity39.9
Applied egg-rr39.9%
herbie shell --seed 2024207
(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))))