
(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 z (- (sin y)) (* x (cos y))))
double code(double x, double y, double z) {
return fma(z, -sin(y), (x * cos(y)));
}
function code(x, y, z) return fma(z, Float64(-sin(y)), Float64(x * cos(y))) end
code[x_, y_, z_] := N[(z * (-N[Sin[y], $MachinePrecision]) + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, -\sin y, x \cdot \cos y\right)
\end{array}
Initial program 99.9%
cancel-sign-sub-inv99.9%
+-commutative99.9%
distribute-lft-neg-out99.9%
distribute-rgt-neg-in99.9%
sin-neg99.9%
fma-define99.9%
sin-neg99.9%
Simplified99.9%
(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.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (- (sin y)))) (t_1 (* x (cos y))))
(if (<= y -1.05e+161)
t_0
(if (<= y -0.0077)
t_1
(if (<= y 1.22e+33)
(+ x (* y (- (* y (* (* z y) 0.16666666666666666)) z)))
(if (<= y 1.1e+149) t_0 t_1))))))
double code(double x, double y, double z) {
double t_0 = z * -sin(y);
double t_1 = x * cos(y);
double tmp;
if (y <= -1.05e+161) {
tmp = t_0;
} else if (y <= -0.0077) {
tmp = t_1;
} else if (y <= 1.22e+33) {
tmp = x + (y * ((y * ((z * y) * 0.16666666666666666)) - z));
} else if (y <= 1.1e+149) {
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 = z * -sin(y)
t_1 = x * cos(y)
if (y <= (-1.05d+161)) then
tmp = t_0
else if (y <= (-0.0077d0)) then
tmp = t_1
else if (y <= 1.22d+33) then
tmp = x + (y * ((y * ((z * y) * 0.16666666666666666d0)) - z))
else if (y <= 1.1d+149) 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 = z * -Math.sin(y);
double t_1 = x * Math.cos(y);
double tmp;
if (y <= -1.05e+161) {
tmp = t_0;
} else if (y <= -0.0077) {
tmp = t_1;
} else if (y <= 1.22e+33) {
tmp = x + (y * ((y * ((z * y) * 0.16666666666666666)) - z));
} else if (y <= 1.1e+149) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = z * -math.sin(y) t_1 = x * math.cos(y) tmp = 0 if y <= -1.05e+161: tmp = t_0 elif y <= -0.0077: tmp = t_1 elif y <= 1.22e+33: tmp = x + (y * ((y * ((z * y) * 0.16666666666666666)) - z)) elif y <= 1.1e+149: tmp = t_0 else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(z * Float64(-sin(y))) t_1 = Float64(x * cos(y)) tmp = 0.0 if (y <= -1.05e+161) tmp = t_0; elseif (y <= -0.0077) tmp = t_1; elseif (y <= 1.22e+33) tmp = Float64(x + Float64(y * Float64(Float64(y * Float64(Float64(z * y) * 0.16666666666666666)) - z))); elseif (y <= 1.1e+149) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * -sin(y); t_1 = x * cos(y); tmp = 0.0; if (y <= -1.05e+161) tmp = t_0; elseif (y <= -0.0077) tmp = t_1; elseif (y <= 1.22e+33) tmp = x + (y * ((y * ((z * y) * 0.16666666666666666)) - z)); elseif (y <= 1.1e+149) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * (-N[Sin[y], $MachinePrecision])), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.05e+161], t$95$0, If[LessEqual[y, -0.0077], t$95$1, If[LessEqual[y, 1.22e+33], N[(x + N[(y * N[(N[(y * N[(N[(z * y), $MachinePrecision] * 0.16666666666666666), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.1e+149], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(-\sin y\right)\\
t_1 := x \cdot \cos y\\
\mathbf{if}\;y \leq -1.05 \cdot 10^{+161}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -0.0077:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 1.22 \cdot 10^{+33}:\\
\;\;\;\;x + y \cdot \left(y \cdot \left(\left(z \cdot y\right) \cdot 0.16666666666666666\right) - z\right)\\
\mathbf{elif}\;y \leq 1.1 \cdot 10^{+149}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -1.05e161 or 1.22000000000000005e33 < y < 1.1e149Initial program 99.7%
Taylor expanded in x around 0 65.0%
neg-mul-165.0%
distribute-rgt-neg-in65.0%
Simplified65.0%
if -1.05e161 < y < -0.0077000000000000002 or 1.1e149 < y Initial program 99.8%
Taylor expanded in x around inf 71.1%
if -0.0077000000000000002 < y < 1.22000000000000005e33Initial program 100.0%
Taylor expanded in y around 0 97.9%
Taylor expanded in x around 0 98.0%
*-commutative98.0%
*-commutative98.0%
Simplified98.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (- (sin y)))) (t_1 (* x (cos y))))
(if (<= y -5.9e+159)
t_0
(if (<= y 1e+81) (- t_1 (* z y)) (if (<= y 1.1e+154) t_0 t_1)))))
double code(double x, double y, double z) {
double t_0 = z * -sin(y);
double t_1 = x * cos(y);
double tmp;
if (y <= -5.9e+159) {
tmp = t_0;
} else if (y <= 1e+81) {
tmp = t_1 - (z * y);
} else if (y <= 1.1e+154) {
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 = z * -sin(y)
t_1 = x * cos(y)
if (y <= (-5.9d+159)) then
tmp = t_0
else if (y <= 1d+81) then
tmp = t_1 - (z * y)
else if (y <= 1.1d+154) 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 = z * -Math.sin(y);
double t_1 = x * Math.cos(y);
double tmp;
if (y <= -5.9e+159) {
tmp = t_0;
} else if (y <= 1e+81) {
tmp = t_1 - (z * y);
} else if (y <= 1.1e+154) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = z * -math.sin(y) t_1 = x * math.cos(y) tmp = 0 if y <= -5.9e+159: tmp = t_0 elif y <= 1e+81: tmp = t_1 - (z * y) elif y <= 1.1e+154: tmp = t_0 else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(z * Float64(-sin(y))) t_1 = Float64(x * cos(y)) tmp = 0.0 if (y <= -5.9e+159) tmp = t_0; elseif (y <= 1e+81) tmp = Float64(t_1 - Float64(z * y)); elseif (y <= 1.1e+154) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * -sin(y); t_1 = x * cos(y); tmp = 0.0; if (y <= -5.9e+159) tmp = t_0; elseif (y <= 1e+81) tmp = t_1 - (z * y); elseif (y <= 1.1e+154) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * (-N[Sin[y], $MachinePrecision])), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -5.9e+159], t$95$0, If[LessEqual[y, 1e+81], N[(t$95$1 - N[(z * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.1e+154], t$95$0, t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(-\sin y\right)\\
t_1 := x \cdot \cos y\\
\mathbf{if}\;y \leq -5.9 \cdot 10^{+159}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 10^{+81}:\\
\;\;\;\;t\_1 - z \cdot y\\
\mathbf{elif}\;y \leq 1.1 \cdot 10^{+154}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -5.89999999999999993e159 or 9.99999999999999921e80 < y < 1.1000000000000001e154Initial program 99.7%
Taylor expanded in x around 0 66.7%
neg-mul-166.7%
distribute-rgt-neg-in66.7%
Simplified66.7%
if -5.89999999999999993e159 < y < 9.99999999999999921e80Initial program 99.9%
Taylor expanded in y around 0 90.7%
if 1.1000000000000001e154 < y Initial program 99.8%
Taylor expanded in x around inf 71.9%
Final simplification83.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.044) (not (<= y 0.145))) (* x (cos y)) (+ x (* y (- (* y (+ (* x -0.5) (* (* z y) 0.16666666666666666))) z)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.044) || !(y <= 0.145)) {
tmp = x * cos(y);
} else {
tmp = x + (y * ((y * ((x * -0.5) + ((z * y) * 0.16666666666666666))) - 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.044d0)) .or. (.not. (y <= 0.145d0))) then
tmp = x * cos(y)
else
tmp = x + (y * ((y * ((x * (-0.5d0)) + ((z * y) * 0.16666666666666666d0))) - z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.044) || !(y <= 0.145)) {
tmp = x * Math.cos(y);
} else {
tmp = x + (y * ((y * ((x * -0.5) + ((z * y) * 0.16666666666666666))) - z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.044) or not (y <= 0.145): tmp = x * math.cos(y) else: tmp = x + (y * ((y * ((x * -0.5) + ((z * y) * 0.16666666666666666))) - z)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.044) || !(y <= 0.145)) tmp = Float64(x * cos(y)); else tmp = Float64(x + Float64(y * Float64(Float64(y * Float64(Float64(x * -0.5) + Float64(Float64(z * y) * 0.16666666666666666))) - z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.044) || ~((y <= 0.145))) tmp = x * cos(y); else tmp = x + (y * ((y * ((x * -0.5) + ((z * y) * 0.16666666666666666))) - z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.044], N[Not[LessEqual[y, 0.145]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(N[(y * N[(N[(x * -0.5), $MachinePrecision] + N[(N[(z * y), $MachinePrecision] * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.044 \lor \neg \left(y \leq 0.145\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(y \cdot \left(x \cdot -0.5 + \left(z \cdot y\right) \cdot 0.16666666666666666\right) - z\right)\\
\end{array}
\end{array}
if y < -0.043999999999999997 or 0.14499999999999999 < y Initial program 99.7%
Taylor expanded in x around inf 55.7%
if -0.043999999999999997 < y < 0.14499999999999999Initial program 100.0%
Taylor expanded in y around 0 99.7%
Final simplification79.1%
(FPCore (x y z) :precision binary64 (if (<= z 1.3e+106) x (* z (- y))))
double code(double x, double y, double z) {
double tmp;
if (z <= 1.3e+106) {
tmp = x;
} else {
tmp = z * -y;
}
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 <= 1.3d+106) then
tmp = x
else
tmp = z * -y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 1.3e+106) {
tmp = x;
} else {
tmp = z * -y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 1.3e+106: tmp = x else: tmp = z * -y return tmp
function code(x, y, z) tmp = 0.0 if (z <= 1.3e+106) tmp = x; else tmp = Float64(z * Float64(-y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 1.3e+106) tmp = x; else tmp = z * -y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 1.3e+106], x, N[(z * (-y)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.3 \cdot 10^{+106}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-y\right)\\
\end{array}
\end{array}
if z < 1.3000000000000001e106Initial program 99.9%
Taylor expanded in y around 0 55.7%
mul-1-neg55.7%
unsub-neg55.7%
Simplified55.7%
Taylor expanded in x around inf 45.9%
if 1.3000000000000001e106 < z Initial program 99.8%
Taylor expanded in y around 0 53.7%
mul-1-neg53.7%
unsub-neg53.7%
Simplified53.7%
Taylor expanded in x around 0 43.9%
associate-*r*43.9%
neg-mul-143.9%
*-commutative43.9%
Simplified43.9%
(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 55.4%
mul-1-neg55.4%
unsub-neg55.4%
Simplified55.4%
Final simplification55.4%
(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.9%
Taylor expanded in y around 0 55.4%
mul-1-neg55.4%
unsub-neg55.4%
Simplified55.4%
Taylor expanded in x around inf 40.3%
herbie shell --seed 2024101
(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))))