
(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 6 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 (* x (cos y))) (t_1 (* (sin y) (- z))))
(if (<= y -8.4e+193)
t_0
(if (<= y -0.065)
t_1
(if (<= y 0.032)
(+
x
(*
y
(+
z
(+
(* z -2.0)
(* y (+ (* x -0.5) (* (* y z) 0.16666666666666666)))))))
(if (<= y 1.7e+250) 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 <= -8.4e+193) {
tmp = t_0;
} else if (y <= -0.065) {
tmp = t_1;
} else if (y <= 0.032) {
tmp = x + (y * (z + ((z * -2.0) + (y * ((x * -0.5) + ((y * z) * 0.16666666666666666))))));
} else if (y <= 1.7e+250) {
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 <= (-8.4d+193)) then
tmp = t_0
else if (y <= (-0.065d0)) then
tmp = t_1
else if (y <= 0.032d0) then
tmp = x + (y * (z + ((z * (-2.0d0)) + (y * ((x * (-0.5d0)) + ((y * z) * 0.16666666666666666d0))))))
else if (y <= 1.7d+250) 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 <= -8.4e+193) {
tmp = t_0;
} else if (y <= -0.065) {
tmp = t_1;
} else if (y <= 0.032) {
tmp = x + (y * (z + ((z * -2.0) + (y * ((x * -0.5) + ((y * z) * 0.16666666666666666))))));
} else if (y <= 1.7e+250) {
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 <= -8.4e+193: tmp = t_0 elif y <= -0.065: tmp = t_1 elif y <= 0.032: tmp = x + (y * (z + ((z * -2.0) + (y * ((x * -0.5) + ((y * z) * 0.16666666666666666)))))) elif y <= 1.7e+250: 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 <= -8.4e+193) tmp = t_0; elseif (y <= -0.065) tmp = t_1; elseif (y <= 0.032) tmp = Float64(x + Float64(y * Float64(z + Float64(Float64(z * -2.0) + Float64(y * Float64(Float64(x * -0.5) + Float64(Float64(y * z) * 0.16666666666666666))))))); elseif (y <= 1.7e+250) 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 <= -8.4e+193) tmp = t_0; elseif (y <= -0.065) tmp = t_1; elseif (y <= 0.032) tmp = x + (y * (z + ((z * -2.0) + (y * ((x * -0.5) + ((y * z) * 0.16666666666666666)))))); elseif (y <= 1.7e+250) 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, -8.4e+193], t$95$0, If[LessEqual[y, -0.065], t$95$1, If[LessEqual[y, 0.032], N[(x + N[(y * N[(z + N[(N[(z * -2.0), $MachinePrecision] + N[(y * N[(N[(x * -0.5), $MachinePrecision] + N[(N[(y * z), $MachinePrecision] * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.7e+250], 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 -8.4 \cdot 10^{+193}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -0.065:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 0.032:\\
\;\;\;\;x + y \cdot \left(z + \left(z \cdot -2 + y \cdot \left(x \cdot -0.5 + \left(y \cdot z\right) \cdot 0.16666666666666666\right)\right)\right)\\
\mathbf{elif}\;y \leq 1.7 \cdot 10^{+250}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -8.4e193 or 1.69999999999999987e250 < y Initial program 99.6%
Taylor expanded in x around inf 68.1%
if -8.4e193 < y < -0.065000000000000002 or 0.032000000000000001 < y < 1.69999999999999987e250Initial program 99.7%
Taylor expanded in x around 0 58.5%
associate-*r*58.5%
neg-mul-158.5%
Simplified58.5%
if -0.065000000000000002 < y < 0.032000000000000001Initial 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%
Taylor expanded in z around 0 99.5%
*-commutative99.5%
*-commutative99.5%
Simplified99.5%
Final simplification80.1%
(FPCore (x y z)
:precision binary64
(if (or (<= y -0.0062) (not (<= y 0.065)))
(* x (cos y))
(+
x
(*
y
(+
z
(+ (* z -2.0) (* y (+ (* x -0.5) (* (* y z) 0.16666666666666666)))))))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0062) || !(y <= 0.065)) {
tmp = x * cos(y);
} else {
tmp = x + (y * (z + ((z * -2.0) + (y * ((x * -0.5) + ((y * z) * 0.16666666666666666))))));
}
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.0062d0)) .or. (.not. (y <= 0.065d0))) then
tmp = x * cos(y)
else
tmp = x + (y * (z + ((z * (-2.0d0)) + (y * ((x * (-0.5d0)) + ((y * z) * 0.16666666666666666d0))))))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0062) || !(y <= 0.065)) {
tmp = x * Math.cos(y);
} else {
tmp = x + (y * (z + ((z * -2.0) + (y * ((x * -0.5) + ((y * z) * 0.16666666666666666))))));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.0062) or not (y <= 0.065): tmp = x * math.cos(y) else: tmp = x + (y * (z + ((z * -2.0) + (y * ((x * -0.5) + ((y * z) * 0.16666666666666666)))))) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.0062) || !(y <= 0.065)) 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(Float64(y * z) * 0.16666666666666666))))))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.0062) || ~((y <= 0.065))) tmp = x * cos(y); else tmp = x + (y * (z + ((z * -2.0) + (y * ((x * -0.5) + ((y * z) * 0.16666666666666666)))))); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.0062], N[Not[LessEqual[y, 0.065]], $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[(N[(y * z), $MachinePrecision] * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0062 \lor \neg \left(y \leq 0.065\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(z + \left(z \cdot -2 + y \cdot \left(x \cdot -0.5 + \left(y \cdot z\right) \cdot 0.16666666666666666\right)\right)\right)\\
\end{array}
\end{array}
if y < -0.00619999999999999978 or 0.065000000000000002 < y Initial program 99.7%
Taylor expanded in x around inf 49.7%
if -0.00619999999999999978 < y < 0.065000000000000002Initial 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%
Taylor expanded in z around 0 100.0%
*-commutative100.0%
*-commutative100.0%
Simplified100.0%
Final simplification74.2%
(FPCore (x y z) :precision binary64 (if (<= x -1.95e-25) x (if (<= x 3.15e-99) (* y (- z)) x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.95e-25) {
tmp = x;
} else if (x <= 3.15e-99) {
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 <= (-1.95d-25)) then
tmp = x
else if (x <= 3.15d-99) 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 <= -1.95e-25) {
tmp = x;
} else if (x <= 3.15e-99) {
tmp = y * -z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.95e-25: tmp = x elif x <= 3.15e-99: tmp = y * -z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.95e-25) tmp = x; elseif (x <= 3.15e-99) tmp = Float64(y * Float64(-z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.95e-25) tmp = x; elseif (x <= 3.15e-99) tmp = y * -z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.95e-25], x, If[LessEqual[x, 3.15e-99], N[(y * (-z)), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.95 \cdot 10^{-25}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 3.15 \cdot 10^{-99}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1.95e-25 or 3.14999999999999996e-99 < x Initial program 99.9%
Taylor expanded in y around 0 46.6%
if -1.95e-25 < x < 3.14999999999999996e-99Initial program 99.7%
Taylor expanded in x around 0 75.6%
associate-*r*75.6%
neg-mul-175.6%
Simplified75.6%
Taylor expanded in y around 0 34.7%
Final simplification42.1%
(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%
*-commutative51.1%
Simplified51.1%
Final simplification51.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 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))))