
(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 (fma (cos y) x (* (sin y) (- z))))
double code(double x, double y, double z) {
return fma(cos(y), x, (sin(y) * -z));
}
function code(x, y, z) return fma(cos(y), x, Float64(sin(y) * Float64(-z))) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * x + N[(N[Sin[y], $MachinePrecision] * (-z)), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, x, \sin y \cdot \left(-z\right)\right)
\end{array}
Initial program 99.8%
*-commutative99.8%
fma-neg99.8%
distribute-rgt-neg-in99.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (- (* (cos y) x) (* z (sin y))))
double code(double x, double y, double z) {
return (cos(y) * x) - (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 = (cos(y) * x) - (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (Math.cos(y) * x) - (z * Math.sin(y));
}
def code(x, y, z): return (math.cos(y) * x) - (z * math.sin(y))
function code(x, y, z) return Float64(Float64(cos(y) * x) - Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (cos(y) * x) - (z * sin(y)); end
code[x_, y_, z_] := N[(N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos y \cdot x - z \cdot \sin y
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (sin y) (- z))) (t_1 (* (cos y) x)))
(if (<= y -5.2e+84)
t_0
(if (<= y -5.8e+21)
t_1
(if (<= y -0.015)
t_0
(if (<= y 0.23)
(- x (* y z))
(if (or (<= y 8.8e+126) (not (<= y 7e+221))) t_0 t_1)))))))
double code(double x, double y, double z) {
double t_0 = sin(y) * -z;
double t_1 = cos(y) * x;
double tmp;
if (y <= -5.2e+84) {
tmp = t_0;
} else if (y <= -5.8e+21) {
tmp = t_1;
} else if (y <= -0.015) {
tmp = t_0;
} else if (y <= 0.23) {
tmp = x - (y * z);
} else if ((y <= 8.8e+126) || !(y <= 7e+221)) {
tmp = t_0;
} else {
tmp = t_1;
}
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 = cos(y) * x
if (y <= (-5.2d+84)) then
tmp = t_0
else if (y <= (-5.8d+21)) then
tmp = t_1
else if (y <= (-0.015d0)) then
tmp = t_0
else if (y <= 0.23d0) then
tmp = x - (y * z)
else if ((y <= 8.8d+126) .or. (.not. (y <= 7d+221))) then
tmp = t_0
else
tmp = t_1
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 = Math.cos(y) * x;
double tmp;
if (y <= -5.2e+84) {
tmp = t_0;
} else if (y <= -5.8e+21) {
tmp = t_1;
} else if (y <= -0.015) {
tmp = t_0;
} else if (y <= 0.23) {
tmp = x - (y * z);
} else if ((y <= 8.8e+126) || !(y <= 7e+221)) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = math.sin(y) * -z t_1 = math.cos(y) * x tmp = 0 if y <= -5.2e+84: tmp = t_0 elif y <= -5.8e+21: tmp = t_1 elif y <= -0.015: tmp = t_0 elif y <= 0.23: tmp = x - (y * z) elif (y <= 8.8e+126) or not (y <= 7e+221): tmp = t_0 else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(sin(y) * Float64(-z)) t_1 = Float64(cos(y) * x) tmp = 0.0 if (y <= -5.2e+84) tmp = t_0; elseif (y <= -5.8e+21) tmp = t_1; elseif (y <= -0.015) tmp = t_0; elseif (y <= 0.23) tmp = Float64(x - Float64(y * z)); elseif ((y <= 8.8e+126) || !(y <= 7e+221)) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = sin(y) * -z; t_1 = cos(y) * x; tmp = 0.0; if (y <= -5.2e+84) tmp = t_0; elseif (y <= -5.8e+21) tmp = t_1; elseif (y <= -0.015) tmp = t_0; elseif (y <= 0.23) tmp = x - (y * z); elseif ((y <= 8.8e+126) || ~((y <= 7e+221))) tmp = t_0; else tmp = t_1; 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[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[y, -5.2e+84], t$95$0, If[LessEqual[y, -5.8e+21], t$95$1, If[LessEqual[y, -0.015], t$95$0, If[LessEqual[y, 0.23], N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 8.8e+126], N[Not[LessEqual[y, 7e+221]], $MachinePrecision]], t$95$0, t$95$1]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin y \cdot \left(-z\right)\\
t_1 := \cos y \cdot x\\
\mathbf{if}\;y \leq -5.2 \cdot 10^{+84}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -5.8 \cdot 10^{+21}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq -0.015:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 0.23:\\
\;\;\;\;x - y \cdot z\\
\mathbf{elif}\;y \leq 8.8 \cdot 10^{+126} \lor \neg \left(y \leq 7 \cdot 10^{+221}\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if y < -5.2000000000000002e84 or -5.8e21 < y < -0.014999999999999999 or 0.23000000000000001 < y < 8.79999999999999994e126 or 7.0000000000000003e221 < y Initial program 99.6%
Taylor expanded in x around 0 63.2%
mul-1-neg63.2%
*-commutative63.2%
distribute-rgt-neg-in63.2%
Simplified63.2%
if -5.2000000000000002e84 < y < -5.8e21 or 8.79999999999999994e126 < y < 7.0000000000000003e221Initial program 99.7%
Taylor expanded in x around inf 70.1%
if -0.014999999999999999 < y < 0.23000000000000001Initial program 100.0%
Taylor expanded in y around 0 99.0%
mul-1-neg99.0%
unsub-neg99.0%
Simplified99.0%
Final simplification81.6%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (sin y) (- z))) (t_1 (* (cos y) x)))
(if (<= y -5e+83)
t_0
(if (<= y -9e+22)
t_1
(if (<= y -1850.0)
t_0
(if (<= y 7900000000000.0)
(- t_1 (* y z))
(if (or (<= y 3.1e+125) (not (<= y 3.6e+220))) t_0 t_1)))))))
double code(double x, double y, double z) {
double t_0 = sin(y) * -z;
double t_1 = cos(y) * x;
double tmp;
if (y <= -5e+83) {
tmp = t_0;
} else if (y <= -9e+22) {
tmp = t_1;
} else if (y <= -1850.0) {
tmp = t_0;
} else if (y <= 7900000000000.0) {
tmp = t_1 - (y * z);
} else if ((y <= 3.1e+125) || !(y <= 3.6e+220)) {
tmp = t_0;
} else {
tmp = t_1;
}
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 = cos(y) * x
if (y <= (-5d+83)) then
tmp = t_0
else if (y <= (-9d+22)) then
tmp = t_1
else if (y <= (-1850.0d0)) then
tmp = t_0
else if (y <= 7900000000000.0d0) then
tmp = t_1 - (y * z)
else if ((y <= 3.1d+125) .or. (.not. (y <= 3.6d+220))) then
tmp = t_0
else
tmp = t_1
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 = Math.cos(y) * x;
double tmp;
if (y <= -5e+83) {
tmp = t_0;
} else if (y <= -9e+22) {
tmp = t_1;
} else if (y <= -1850.0) {
tmp = t_0;
} else if (y <= 7900000000000.0) {
tmp = t_1 - (y * z);
} else if ((y <= 3.1e+125) || !(y <= 3.6e+220)) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = math.sin(y) * -z t_1 = math.cos(y) * x tmp = 0 if y <= -5e+83: tmp = t_0 elif y <= -9e+22: tmp = t_1 elif y <= -1850.0: tmp = t_0 elif y <= 7900000000000.0: tmp = t_1 - (y * z) elif (y <= 3.1e+125) or not (y <= 3.6e+220): tmp = t_0 else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(sin(y) * Float64(-z)) t_1 = Float64(cos(y) * x) tmp = 0.0 if (y <= -5e+83) tmp = t_0; elseif (y <= -9e+22) tmp = t_1; elseif (y <= -1850.0) tmp = t_0; elseif (y <= 7900000000000.0) tmp = Float64(t_1 - Float64(y * z)); elseif ((y <= 3.1e+125) || !(y <= 3.6e+220)) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = sin(y) * -z; t_1 = cos(y) * x; tmp = 0.0; if (y <= -5e+83) tmp = t_0; elseif (y <= -9e+22) tmp = t_1; elseif (y <= -1850.0) tmp = t_0; elseif (y <= 7900000000000.0) tmp = t_1 - (y * z); elseif ((y <= 3.1e+125) || ~((y <= 3.6e+220))) tmp = t_0; else tmp = t_1; 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[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[y, -5e+83], t$95$0, If[LessEqual[y, -9e+22], t$95$1, If[LessEqual[y, -1850.0], t$95$0, If[LessEqual[y, 7900000000000.0], N[(t$95$1 - N[(y * z), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 3.1e+125], N[Not[LessEqual[y, 3.6e+220]], $MachinePrecision]], t$95$0, t$95$1]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin y \cdot \left(-z\right)\\
t_1 := \cos y \cdot x\\
\mathbf{if}\;y \leq -5 \cdot 10^{+83}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -9 \cdot 10^{+22}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq -1850:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 7900000000000:\\
\;\;\;\;t_1 - y \cdot z\\
\mathbf{elif}\;y \leq 3.1 \cdot 10^{+125} \lor \neg \left(y \leq 3.6 \cdot 10^{+220}\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if y < -5.00000000000000029e83 or -8.9999999999999996e22 < y < -1850 or 7.9e12 < y < 3.1e125 or 3.60000000000000019e220 < y Initial program 99.6%
Taylor expanded in x around 0 64.1%
mul-1-neg64.1%
*-commutative64.1%
distribute-rgt-neg-in64.1%
Simplified64.1%
if -5.00000000000000029e83 < y < -8.9999999999999996e22 or 3.1e125 < y < 3.60000000000000019e220Initial program 99.7%
Taylor expanded in x around inf 70.1%
if -1850 < y < 7.9e12Initial program 100.0%
Taylor expanded in y around 0 99.0%
Final simplification82.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.00082) (not (<= y 0.0065))) (* (cos y) x) (- x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00082) || !(y <= 0.0065)) {
tmp = cos(y) * x;
} else {
tmp = x - (y * z);
}
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 ((y <= (-0.00082d0)) .or. (.not. (y <= 0.0065d0))) then
tmp = cos(y) * x
else
tmp = x - (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00082) || !(y <= 0.0065)) {
tmp = Math.cos(y) * x;
} else {
tmp = x - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.00082) or not (y <= 0.0065): tmp = math.cos(y) * x else: tmp = x - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.00082) || !(y <= 0.0065)) tmp = Float64(cos(y) * x); else tmp = Float64(x - Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.00082) || ~((y <= 0.0065))) tmp = cos(y) * x; else tmp = x - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.00082], N[Not[LessEqual[y, 0.0065]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.00082 \lor \neg \left(y \leq 0.0065\right):\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x - y \cdot z\\
\end{array}
\end{array}
if y < -8.1999999999999998e-4 or 0.0064999999999999997 < y Initial program 99.6%
Taylor expanded in x around inf 46.8%
if -8.1999999999999998e-4 < y < 0.0064999999999999997Initial program 100.0%
Taylor expanded in y around 0 99.5%
mul-1-neg99.5%
unsub-neg99.5%
Simplified99.5%
Final simplification72.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.7e+217) (not (<= z 6.6e+183))) (* y (- z)) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.7e+217) || !(z <= 6.6e+183)) {
tmp = y * -z;
} else {
tmp = 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 ((z <= (-3.7d+217)) .or. (.not. (z <= 6.6d+183))) then
tmp = y * -z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3.7e+217) || !(z <= 6.6e+183)) {
tmp = y * -z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.7e+217) or not (z <= 6.6e+183): tmp = y * -z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.7e+217) || !(z <= 6.6e+183)) tmp = Float64(y * Float64(-z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.7e+217) || ~((z <= 6.6e+183))) tmp = y * -z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.7e+217], N[Not[LessEqual[z, 6.6e+183]], $MachinePrecision]], N[(y * (-z)), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.7 \cdot 10^{+217} \lor \neg \left(z \leq 6.6 \cdot 10^{+183}\right):\\
\;\;\;\;y \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -3.70000000000000011e217 or 6.60000000000000019e183 < z Initial program 99.9%
Taylor expanded in y around 0 52.4%
Taylor expanded in x around 0 40.2%
associate-*r*40.2%
neg-mul-140.2%
Simplified40.2%
if -3.70000000000000011e217 < z < 6.60000000000000019e183Initial program 99.8%
*-commutative99.8%
fma-neg99.8%
distribute-rgt-neg-in99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 45.6%
Final simplification44.7%
(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 51.0%
mul-1-neg51.0%
unsub-neg51.0%
Simplified51.0%
Final simplification51.0%
(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%
*-commutative99.8%
fma-neg99.8%
distribute-rgt-neg-in99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 40.5%
Final simplification40.5%
herbie shell --seed 2024020
(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))))