
(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 (* z (- (sin y)))) (t_1 (* x (- 1.0 (* z (/ (sin y) x))))))
(if (<= z -1.8e+223)
t_0
(if (<= z -4.8e-36)
t_1
(if (<= z 7e-68) (* x (cos y)) (if (<= z 2e+164) t_1 t_0))))))
double code(double x, double y, double z) {
double t_0 = z * -sin(y);
double t_1 = x * (1.0 - (z * (sin(y) / x)));
double tmp;
if (z <= -1.8e+223) {
tmp = t_0;
} else if (z <= -4.8e-36) {
tmp = t_1;
} else if (z <= 7e-68) {
tmp = x * cos(y);
} else if (z <= 2e+164) {
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 = z * -sin(y)
t_1 = x * (1.0d0 - (z * (sin(y) / x)))
if (z <= (-1.8d+223)) then
tmp = t_0
else if (z <= (-4.8d-36)) then
tmp = t_1
else if (z <= 7d-68) then
tmp = x * cos(y)
else if (z <= 2d+164) 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 = z * -Math.sin(y);
double t_1 = x * (1.0 - (z * (Math.sin(y) / x)));
double tmp;
if (z <= -1.8e+223) {
tmp = t_0;
} else if (z <= -4.8e-36) {
tmp = t_1;
} else if (z <= 7e-68) {
tmp = x * Math.cos(y);
} else if (z <= 2e+164) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * -math.sin(y) t_1 = x * (1.0 - (z * (math.sin(y) / x))) tmp = 0 if z <= -1.8e+223: tmp = t_0 elif z <= -4.8e-36: tmp = t_1 elif z <= 7e-68: tmp = x * math.cos(y) elif z <= 2e+164: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * Float64(-sin(y))) t_1 = Float64(x * Float64(1.0 - Float64(z * Float64(sin(y) / x)))) tmp = 0.0 if (z <= -1.8e+223) tmp = t_0; elseif (z <= -4.8e-36) tmp = t_1; elseif (z <= 7e-68) tmp = Float64(x * cos(y)); elseif (z <= 2e+164) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * -sin(y); t_1 = x * (1.0 - (z * (sin(y) / x))); tmp = 0.0; if (z <= -1.8e+223) tmp = t_0; elseif (z <= -4.8e-36) tmp = t_1; elseif (z <= 7e-68) tmp = x * cos(y); elseif (z <= 2e+164) tmp = t_1; else tmp = t_0; 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[(1.0 - N[(z * N[(N[Sin[y], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.8e+223], t$95$0, If[LessEqual[z, -4.8e-36], t$95$1, If[LessEqual[z, 7e-68], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2e+164], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \left(-\sin y\right)\\
t_1 := x \cdot \left(1 - z \cdot \frac{\sin y}{x}\right)\\
\mathbf{if}\;z \leq -1.8 \cdot 10^{+223}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -4.8 \cdot 10^{-36}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 7 \cdot 10^{-68}:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{elif}\;z \leq 2 \cdot 10^{+164}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.79999999999999996e223 or 2e164 < z Initial program 99.7%
Taylor expanded in x around 0 90.7%
neg-mul-190.7%
distribute-lft-neg-in90.7%
Simplified90.7%
if -1.79999999999999996e223 < z < -4.8e-36 or 7.00000000000000026e-68 < z < 2e164Initial program 99.8%
Taylor expanded in x around inf 91.5%
mul-1-neg91.5%
unsub-neg91.5%
associate-/l*91.3%
Simplified91.3%
Taylor expanded in y around 0 78.2%
if -4.8e-36 < z < 7.00000000000000026e-68Initial program 99.8%
Taylor expanded in x around inf 93.5%
Final simplification86.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.072) (not (<= y 750.0))) (* x (cos y)) (+ x (* y (- (* y (+ (* x -0.5) (* 0.16666666666666666 (* y z)))) z)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.072) || !(y <= 750.0)) {
tmp = x * cos(y);
} else {
tmp = x + (y * ((y * ((x * -0.5) + (0.16666666666666666 * (y * z)))) - 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.072d0)) .or. (.not. (y <= 750.0d0))) then
tmp = x * cos(y)
else
tmp = x + (y * ((y * ((x * (-0.5d0)) + (0.16666666666666666d0 * (y * z)))) - z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.072) || !(y <= 750.0)) {
tmp = x * Math.cos(y);
} else {
tmp = x + (y * ((y * ((x * -0.5) + (0.16666666666666666 * (y * z)))) - z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.072) or not (y <= 750.0): tmp = x * math.cos(y) else: tmp = x + (y * ((y * ((x * -0.5) + (0.16666666666666666 * (y * z)))) - z)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.072) || !(y <= 750.0)) tmp = Float64(x * cos(y)); else tmp = Float64(x + Float64(y * Float64(Float64(y * Float64(Float64(x * -0.5) + Float64(0.16666666666666666 * Float64(y * z)))) - z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.072) || ~((y <= 750.0))) tmp = x * cos(y); else tmp = x + (y * ((y * ((x * -0.5) + (0.16666666666666666 * (y * z)))) - z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.072], N[Not[LessEqual[y, 750.0]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(N[(y * N[(N[(x * -0.5), $MachinePrecision] + N[(0.16666666666666666 * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.072 \lor \neg \left(y \leq 750\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(y \cdot \left(x \cdot -0.5 + 0.16666666666666666 \cdot \left(y \cdot z\right)\right) - z\right)\\
\end{array}
\end{array}
if y < -0.0719999999999999946 or 750 < y Initial program 99.6%
Taylor expanded in x around inf 50.5%
if -0.0719999999999999946 < y < 750Initial program 100.0%
Taylor expanded in y around 0 98.7%
Final simplification73.8%
(FPCore (x y z)
:precision binary64
(if (<= y -2.7e+14)
(* z (- (sin y)))
(if (<= y 750.0)
(+ x (* y (- (* y (+ (* x -0.5) (* 0.16666666666666666 (* y z)))) z)))
(* x (cos y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.7e+14) {
tmp = z * -sin(y);
} else if (y <= 750.0) {
tmp = x + (y * ((y * ((x * -0.5) + (0.16666666666666666 * (y * z)))) - z));
} 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 (y <= (-2.7d+14)) then
tmp = z * -sin(y)
else if (y <= 750.0d0) then
tmp = x + (y * ((y * ((x * (-0.5d0)) + (0.16666666666666666d0 * (y * z)))) - z))
else
tmp = x * cos(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -2.7e+14) {
tmp = z * -Math.sin(y);
} else if (y <= 750.0) {
tmp = x + (y * ((y * ((x * -0.5) + (0.16666666666666666 * (y * z)))) - z));
} else {
tmp = x * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.7e+14: tmp = z * -math.sin(y) elif y <= 750.0: tmp = x + (y * ((y * ((x * -0.5) + (0.16666666666666666 * (y * z)))) - z)) else: tmp = x * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.7e+14) tmp = Float64(z * Float64(-sin(y))); elseif (y <= 750.0) tmp = Float64(x + Float64(y * Float64(Float64(y * Float64(Float64(x * -0.5) + Float64(0.16666666666666666 * Float64(y * z)))) - z))); else tmp = Float64(x * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.7e+14) tmp = z * -sin(y); elseif (y <= 750.0) tmp = x + (y * ((y * ((x * -0.5) + (0.16666666666666666 * (y * z)))) - z)); else tmp = x * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.7e+14], N[(z * (-N[Sin[y], $MachinePrecision])), $MachinePrecision], If[LessEqual[y, 750.0], N[(x + N[(y * N[(N[(y * N[(N[(x * -0.5), $MachinePrecision] + N[(0.16666666666666666 * N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.7 \cdot 10^{+14}:\\
\;\;\;\;z \cdot \left(-\sin y\right)\\
\mathbf{elif}\;y \leq 750:\\
\;\;\;\;x + y \cdot \left(y \cdot \left(x \cdot -0.5 + 0.16666666666666666 \cdot \left(y \cdot z\right)\right) - z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y\\
\end{array}
\end{array}
if y < -2.7e14Initial program 99.7%
Taylor expanded in x around 0 62.6%
neg-mul-162.6%
distribute-lft-neg-in62.6%
Simplified62.6%
if -2.7e14 < y < 750Initial program 100.0%
Taylor expanded in y around 0 97.9%
if 750 < y Initial program 99.6%
Taylor expanded in x around inf 56.7%
Final simplification78.0%
(FPCore (x y z) :precision binary64 (if (<= x -4.4e-200) x (if (<= x 7.2e-158) (* y (- z)) x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.4e-200) {
tmp = x;
} else if (x <= 7.2e-158) {
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 <= (-4.4d-200)) then
tmp = x
else if (x <= 7.2d-158) 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 <= -4.4e-200) {
tmp = x;
} else if (x <= 7.2e-158) {
tmp = y * -z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.4e-200: tmp = x elif x <= 7.2e-158: tmp = y * -z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.4e-200) tmp = x; elseif (x <= 7.2e-158) tmp = Float64(y * Float64(-z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -4.4e-200) tmp = x; elseif (x <= 7.2e-158) tmp = y * -z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.4e-200], x, If[LessEqual[x, 7.2e-158], N[(y * (-z)), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.4 \cdot 10^{-200}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 7.2 \cdot 10^{-158}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -4.40000000000000027e-200 or 7.19999999999999982e-158 < x Initial program 99.8%
Taylor expanded in x around inf 96.1%
mul-1-neg96.1%
unsub-neg96.1%
associate-/l*96.0%
Simplified96.0%
Taylor expanded in y around 0 47.5%
clear-num47.5%
un-div-inv47.5%
Applied egg-rr47.5%
Taylor expanded in y around 0 45.0%
if -4.40000000000000027e-200 < x < 7.19999999999999982e-158Initial program 99.7%
Taylor expanded in y around 0 51.3%
mul-1-neg51.3%
unsub-neg51.3%
Simplified51.3%
Taylor expanded in x around 0 40.6%
mul-1-neg40.6%
distribute-rgt-neg-out40.6%
Simplified40.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 50.8%
mul-1-neg50.8%
unsub-neg50.8%
Simplified50.8%
(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 x around inf 88.9%
mul-1-neg88.9%
unsub-neg88.9%
associate-/l*88.8%
Simplified88.8%
Taylor expanded in y around 0 42.7%
clear-num42.7%
un-div-inv42.7%
Applied egg-rr42.7%
Taylor expanded in y around 0 37.8%
herbie shell --seed 2024116
(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))))