
(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
(if (<= z -1.85e+109)
(* (sin y) (- z))
(if (or (<= z -66000000.0) (not (<= z 2.9e-173)))
(* x (- 1.0 (* (sin y) (/ z x))))
(* x (cos y)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.85e+109) {
tmp = sin(y) * -z;
} else if ((z <= -66000000.0) || !(z <= 2.9e-173)) {
tmp = x * (1.0 - (sin(y) * (z / x)));
} else {
tmp = x * cos(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.85d+109)) then
tmp = sin(y) * -z
else if ((z <= (-66000000.0d0)) .or. (.not. (z <= 2.9d-173))) then
tmp = x * (1.0d0 - (sin(y) * (z / x)))
else
tmp = x * cos(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.85e+109) {
tmp = Math.sin(y) * -z;
} else if ((z <= -66000000.0) || !(z <= 2.9e-173)) {
tmp = x * (1.0 - (Math.sin(y) * (z / x)));
} else {
tmp = x * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.85e+109: tmp = math.sin(y) * -z elif (z <= -66000000.0) or not (z <= 2.9e-173): tmp = x * (1.0 - (math.sin(y) * (z / x))) else: tmp = x * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.85e+109) tmp = Float64(sin(y) * Float64(-z)); elseif ((z <= -66000000.0) || !(z <= 2.9e-173)) tmp = Float64(x * Float64(1.0 - Float64(sin(y) * Float64(z / x)))); else tmp = Float64(x * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.85e+109) tmp = sin(y) * -z; elseif ((z <= -66000000.0) || ~((z <= 2.9e-173))) tmp = x * (1.0 - (sin(y) * (z / x))); else tmp = x * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.85e+109], N[(N[Sin[y], $MachinePrecision] * (-z)), $MachinePrecision], If[Or[LessEqual[z, -66000000.0], N[Not[LessEqual[z, 2.9e-173]], $MachinePrecision]], N[(x * N[(1.0 - N[(N[Sin[y], $MachinePrecision] * N[(z / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.85 \cdot 10^{+109}:\\
\;\;\;\;\sin y \cdot \left(-z\right)\\
\mathbf{elif}\;z \leq -66000000 \lor \neg \left(z \leq 2.9 \cdot 10^{-173}\right):\\
\;\;\;\;x \cdot \left(1 - \sin y \cdot \frac{z}{x}\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y\\
\end{array}
\end{array}
if z < -1.8500000000000001e109Initial program 99.9%
Taylor expanded in x around 0 69.0%
mul-1-neg69.0%
*-commutative69.0%
distribute-rgt-neg-in69.0%
Simplified69.0%
if -1.8500000000000001e109 < z < -6.6e7 or 2.8999999999999998e-173 < z Initial program 99.8%
Taylor expanded in x around inf 92.5%
mul-1-neg92.5%
unsub-neg92.5%
*-commutative92.5%
associate-/l*89.3%
Simplified89.3%
Taylor expanded in y around 0 77.9%
if -6.6e7 < z < 2.8999999999999998e-173Initial program 99.8%
Taylor expanded in x around inf 93.1%
Final simplification81.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))) (t_1 (* (sin y) (- z))))
(if (<= y -6e+193)
t_0
(if (<= y -0.05)
t_1
(if (<= y 0.0185)
(+
x
(*
y
(+
z
(+
(* z -2.0)
(*
y
(+
(* x -0.5)
(*
y
(+ (* z -0.16666666666666666) (* z 0.3333333333333333)))))))))
(if (<= y 2.45e+252) t_1 t_0))))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double t_1 = sin(y) * -z;
double tmp;
if (y <= -6e+193) {
tmp = t_0;
} else if (y <= -0.05) {
tmp = t_1;
} else if (y <= 0.0185) {
tmp = x + (y * (z + ((z * -2.0) + (y * ((x * -0.5) + (y * ((z * -0.16666666666666666) + (z * 0.3333333333333333))))))));
} else if (y <= 2.45e+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 = x * cos(y)
t_1 = sin(y) * -z
if (y <= (-6d+193)) then
tmp = t_0
else if (y <= (-0.05d0)) then
tmp = t_1
else if (y <= 0.0185d0) then
tmp = x + (y * (z + ((z * (-2.0d0)) + (y * ((x * (-0.5d0)) + (y * ((z * (-0.16666666666666666d0)) + (z * 0.3333333333333333d0))))))))
else if (y <= 2.45d+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 = x * Math.cos(y);
double t_1 = Math.sin(y) * -z;
double tmp;
if (y <= -6e+193) {
tmp = t_0;
} else if (y <= -0.05) {
tmp = t_1;
} else if (y <= 0.0185) {
tmp = x + (y * (z + ((z * -2.0) + (y * ((x * -0.5) + (y * ((z * -0.16666666666666666) + (z * 0.3333333333333333))))))));
} else if (y <= 2.45e+252) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.cos(y) t_1 = math.sin(y) * -z tmp = 0 if y <= -6e+193: tmp = t_0 elif y <= -0.05: tmp = t_1 elif y <= 0.0185: tmp = x + (y * (z + ((z * -2.0) + (y * ((x * -0.5) + (y * ((z * -0.16666666666666666) + (z * 0.3333333333333333)))))))) elif y <= 2.45e+252: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * cos(y)) t_1 = Float64(sin(y) * Float64(-z)) tmp = 0.0 if (y <= -6e+193) tmp = t_0; elseif (y <= -0.05) tmp = t_1; elseif (y <= 0.0185) tmp = Float64(x + Float64(y * Float64(z + Float64(Float64(z * -2.0) + Float64(y * Float64(Float64(x * -0.5) + Float64(y * Float64(Float64(z * -0.16666666666666666) + Float64(z * 0.3333333333333333))))))))); elseif (y <= 2.45e+252) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * cos(y); t_1 = sin(y) * -z; tmp = 0.0; if (y <= -6e+193) tmp = t_0; elseif (y <= -0.05) tmp = t_1; elseif (y <= 0.0185) tmp = x + (y * (z + ((z * -2.0) + (y * ((x * -0.5) + (y * ((z * -0.16666666666666666) + (z * 0.3333333333333333)))))))); elseif (y <= 2.45e+252) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Sin[y], $MachinePrecision] * (-z)), $MachinePrecision]}, If[LessEqual[y, -6e+193], t$95$0, If[LessEqual[y, -0.05], t$95$1, If[LessEqual[y, 0.0185], N[(x + N[(y * N[(z + N[(N[(z * -2.0), $MachinePrecision] + N[(y * N[(N[(x * -0.5), $MachinePrecision] + N[(y * N[(N[(z * -0.16666666666666666), $MachinePrecision] + N[(z * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.45e+252], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
t_1 := \sin y \cdot \left(-z\right)\\
\mathbf{if}\;y \leq -6 \cdot 10^{+193}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -0.05:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 0.0185:\\
\;\;\;\;x + y \cdot \left(z + \left(z \cdot -2 + y \cdot \left(x \cdot -0.5 + y \cdot \left(z \cdot -0.16666666666666666 + z \cdot 0.3333333333333333\right)\right)\right)\right)\\
\mathbf{elif}\;y \leq 2.45 \cdot 10^{+252}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -6e193 or 2.4499999999999999e252 < y Initial program 99.6%
Taylor expanded in x around inf 68.1%
if -6e193 < y < -0.050000000000000003 or 0.0184999999999999991 < y < 2.4499999999999999e252Initial program 99.7%
Taylor expanded in x around 0 58.5%
mul-1-neg58.5%
*-commutative58.5%
distribute-rgt-neg-in58.5%
Simplified58.5%
if -0.050000000000000003 < y < 0.0184999999999999991Initial program 100.0%
prod-diff100.0%
*-commutative100.0%
fma-define100.0%
associate-+l+100.0%
distribute-rgt-neg-in100.0%
fma-define99.7%
*-commutative99.7%
fma-undefine100.0%
distribute-lft-neg-in100.0%
*-commutative100.0%
distribute-rgt-neg-in100.0%
fma-define99.7%
Applied egg-rr99.7%
Taylor expanded in y around 0 99.5%
Final simplification80.1%
(FPCore (x y z)
:precision binary64
(if (or (<= y -0.0066) (not (<= y 0.035)))
(* x (cos y))
(+
x
(*
y
(+
z
(+
(* z -2.0)
(*
y
(+
(* x -0.5)
(* y (+ (* z -0.16666666666666666) (* z 0.3333333333333333)))))))))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0066) || !(y <= 0.035)) {
tmp = x * cos(y);
} else {
tmp = x + (y * (z + ((z * -2.0) + (y * ((x * -0.5) + (y * ((z * -0.16666666666666666) + (z * 0.3333333333333333))))))));
}
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.0066d0)) .or. (.not. (y <= 0.035d0))) then
tmp = x * cos(y)
else
tmp = x + (y * (z + ((z * (-2.0d0)) + (y * ((x * (-0.5d0)) + (y * ((z * (-0.16666666666666666d0)) + (z * 0.3333333333333333d0))))))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0066) || !(y <= 0.035)) {
tmp = x * Math.cos(y);
} else {
tmp = x + (y * (z + ((z * -2.0) + (y * ((x * -0.5) + (y * ((z * -0.16666666666666666) + (z * 0.3333333333333333))))))));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.0066) or not (y <= 0.035): tmp = x * math.cos(y) else: tmp = x + (y * (z + ((z * -2.0) + (y * ((x * -0.5) + (y * ((z * -0.16666666666666666) + (z * 0.3333333333333333)))))))) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.0066) || !(y <= 0.035)) tmp = Float64(x * cos(y)); else tmp = Float64(x + Float64(y * Float64(z + Float64(Float64(z * -2.0) + Float64(y * Float64(Float64(x * -0.5) + Float64(y * Float64(Float64(z * -0.16666666666666666) + Float64(z * 0.3333333333333333))))))))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.0066) || ~((y <= 0.035))) tmp = x * cos(y); else tmp = x + (y * (z + ((z * -2.0) + (y * ((x * -0.5) + (y * ((z * -0.16666666666666666) + (z * 0.3333333333333333)))))))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.0066], N[Not[LessEqual[y, 0.035]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(z + N[(N[(z * -2.0), $MachinePrecision] + N[(y * N[(N[(x * -0.5), $MachinePrecision] + N[(y * N[(N[(z * -0.16666666666666666), $MachinePrecision] + N[(z * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0066 \lor \neg \left(y \leq 0.035\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(z + \left(z \cdot -2 + y \cdot \left(x \cdot -0.5 + y \cdot \left(z \cdot -0.16666666666666666 + z \cdot 0.3333333333333333\right)\right)\right)\right)\\
\end{array}
\end{array}
if y < -0.0066 or 0.035000000000000003 < y Initial program 99.7%
Taylor expanded in x around inf 49.7%
if -0.0066 < y < 0.035000000000000003Initial program 100.0%
prod-diff100.0%
*-commutative100.0%
fma-define100.0%
associate-+l+100.0%
distribute-rgt-neg-in100.0%
fma-define99.7%
*-commutative99.7%
fma-undefine100.0%
distribute-lft-neg-in100.0%
*-commutative100.0%
distribute-rgt-neg-in100.0%
fma-define99.7%
Applied egg-rr99.7%
Taylor expanded in y around 0 100.0%
Final simplification74.2%
(FPCore (x y z) :precision binary64 (if (<= x -3.25e-25) x (if (<= x 2.9e-100) (* y (- z)) x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.25e-25) {
tmp = x;
} else if (x <= 2.9e-100) {
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 (x <= (-3.25d-25)) then
tmp = x
else if (x <= 2.9d-100) 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 (x <= -3.25e-25) {
tmp = x;
} else if (x <= 2.9e-100) {
tmp = y * -z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.25e-25: tmp = x elif x <= 2.9e-100: tmp = y * -z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.25e-25) tmp = x; elseif (x <= 2.9e-100) tmp = Float64(y * Float64(-z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -3.25e-25) tmp = x; elseif (x <= 2.9e-100) tmp = y * -z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.25e-25], x, If[LessEqual[x, 2.9e-100], N[(y * (-z)), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.25 \cdot 10^{-25}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 2.9 \cdot 10^{-100}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -3.25e-25 or 2.89999999999999975e-100 < x Initial program 99.9%
Taylor expanded in y around 0 51.6%
mul-1-neg51.6%
unsub-neg51.6%
Simplified51.6%
Taylor expanded in x around inf 46.6%
if -3.25e-25 < x < 2.89999999999999975e-100Initial program 99.7%
Taylor expanded in y around 0 50.4%
mul-1-neg50.4%
unsub-neg50.4%
Simplified50.4%
Taylor expanded in x around 0 34.7%
neg-mul-134.7%
distribute-rgt-neg-in34.7%
Simplified34.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.1%
mul-1-neg51.1%
unsub-neg51.1%
Simplified51.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%
Taylor expanded in y around 0 51.1%
mul-1-neg51.1%
unsub-neg51.1%
Simplified51.1%
Taylor expanded in x around inf 36.7%
herbie shell --seed 2024137
(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))))