
(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%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(if (or (<= x -5.2e+205)
(not
(or (<= x -4.6e+161)
(and (not (<= x -1000000000000.0)) (<= x 52.0)))))
(* x (cos y))
(- x (* z (sin y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.2e+205) || !((x <= -4.6e+161) || (!(x <= -1000000000000.0) && (x <= 52.0)))) {
tmp = x * cos(y);
} else {
tmp = x - (z * sin(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 ((x <= (-5.2d+205)) .or. (.not. (x <= (-4.6d+161)) .or. (.not. (x <= (-1000000000000.0d0))) .and. (x <= 52.0d0))) then
tmp = x * cos(y)
else
tmp = x - (z * sin(y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -5.2e+205) || !((x <= -4.6e+161) || (!(x <= -1000000000000.0) && (x <= 52.0)))) {
tmp = x * Math.cos(y);
} else {
tmp = x - (z * Math.sin(y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.2e+205) or not ((x <= -4.6e+161) or (not (x <= -1000000000000.0) and (x <= 52.0))): tmp = x * math.cos(y) else: tmp = x - (z * math.sin(y)) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.2e+205) || !((x <= -4.6e+161) || (!(x <= -1000000000000.0) && (x <= 52.0)))) tmp = Float64(x * cos(y)); else tmp = Float64(x - Float64(z * sin(y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -5.2e+205) || ~(((x <= -4.6e+161) || (~((x <= -1000000000000.0)) && (x <= 52.0))))) tmp = x * cos(y); else tmp = x - (z * sin(y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.2e+205], N[Not[Or[LessEqual[x, -4.6e+161], And[N[Not[LessEqual[x, -1000000000000.0]], $MachinePrecision], LessEqual[x, 52.0]]]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.2 \cdot 10^{+205} \lor \neg \left(x \leq -4.6 \cdot 10^{+161} \lor \neg \left(x \leq -1000000000000\right) \land x \leq 52\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x - z \cdot \sin y\\
\end{array}
\end{array}
if x < -5.1999999999999998e205 or -4.5999999999999999e161 < x < -1e12 or 52 < x Initial program 99.7%
Taylor expanded in x around 0 99.7%
mul-1-neg99.7%
distribute-rgt-neg-out99.7%
+-commutative99.7%
fma-udef99.7%
distribute-rgt-neg-out99.7%
*-commutative99.7%
distribute-rgt-neg-in99.7%
Simplified99.7%
Taylor expanded in x around inf 88.7%
if -5.1999999999999998e205 < x < -4.5999999999999999e161 or -1e12 < x < 52Initial program 99.8%
Taylor expanded in y around 0 92.4%
Final simplification90.7%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= x -2.5e-35)
t_0
(if (<= x -5.2e-187)
(- x (* y z))
(if (<= x 1.15e-11) (* z (- (sin y))) t_0)))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (x <= -2.5e-35) {
tmp = t_0;
} else if (x <= -5.2e-187) {
tmp = x - (y * z);
} else if (x <= 1.15e-11) {
tmp = z * -sin(y);
} 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) :: tmp
t_0 = x * cos(y)
if (x <= (-2.5d-35)) then
tmp = t_0
else if (x <= (-5.2d-187)) then
tmp = x - (y * z)
else if (x <= 1.15d-11) then
tmp = z * -sin(y)
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 tmp;
if (x <= -2.5e-35) {
tmp = t_0;
} else if (x <= -5.2e-187) {
tmp = x - (y * z);
} else if (x <= 1.15e-11) {
tmp = z * -Math.sin(y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.cos(y) tmp = 0 if x <= -2.5e-35: tmp = t_0 elif x <= -5.2e-187: tmp = x - (y * z) elif x <= 1.15e-11: tmp = z * -math.sin(y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (x <= -2.5e-35) tmp = t_0; elseif (x <= -5.2e-187) tmp = Float64(x - Float64(y * z)); elseif (x <= 1.15e-11) tmp = Float64(z * Float64(-sin(y))); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * cos(y); tmp = 0.0; if (x <= -2.5e-35) tmp = t_0; elseif (x <= -5.2e-187) tmp = x - (y * z); elseif (x <= 1.15e-11) tmp = z * -sin(y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -2.5e-35], t$95$0, If[LessEqual[x, -5.2e-187], N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.15e-11], N[(z * (-N[Sin[y], $MachinePrecision])), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;x \leq -2.5 \cdot 10^{-35}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -5.2 \cdot 10^{-187}:\\
\;\;\;\;x - y \cdot z\\
\mathbf{elif}\;x \leq 1.15 \cdot 10^{-11}:\\
\;\;\;\;z \cdot \left(-\sin y\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if x < -2.49999999999999982e-35 or 1.15000000000000007e-11 < x Initial program 99.7%
Taylor expanded in x around 0 99.7%
mul-1-neg99.7%
distribute-rgt-neg-out99.7%
+-commutative99.7%
fma-udef99.7%
distribute-rgt-neg-out99.7%
*-commutative99.7%
distribute-rgt-neg-in99.7%
Simplified99.7%
Taylor expanded in x around inf 84.0%
if -2.49999999999999982e-35 < x < -5.1999999999999999e-187Initial program 100.0%
Taylor expanded in y around 0 69.8%
+-commutative69.8%
mul-1-neg69.8%
unsub-neg69.8%
Simplified69.8%
if -5.1999999999999999e-187 < x < 1.15000000000000007e-11Initial program 99.8%
Taylor expanded in x around 0 80.9%
mul-1-neg80.9%
*-commutative80.9%
distribute-rgt-neg-in80.9%
Simplified80.9%
Final simplification81.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.0055) (not (<= y 0.35))) (* x (cos y)) (- x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0055) || !(y <= 0.35)) {
tmp = x * cos(y);
} 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.0055d0)) .or. (.not. (y <= 0.35d0))) then
tmp = x * cos(y)
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.0055) || !(y <= 0.35)) {
tmp = x * Math.cos(y);
} else {
tmp = x - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.0055) or not (y <= 0.35): tmp = x * math.cos(y) else: tmp = x - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.0055) || !(y <= 0.35)) tmp = Float64(x * cos(y)); else tmp = Float64(x - Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.0055) || ~((y <= 0.35))) tmp = x * cos(y); else tmp = x - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.0055], N[Not[LessEqual[y, 0.35]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0055 \lor \neg \left(y \leq 0.35\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x - y \cdot z\\
\end{array}
\end{array}
if y < -0.0054999999999999997 or 0.34999999999999998 < y Initial program 99.6%
Taylor expanded in x around 0 99.6%
mul-1-neg99.6%
distribute-rgt-neg-out99.6%
+-commutative99.6%
fma-udef99.6%
distribute-rgt-neg-out99.6%
*-commutative99.6%
distribute-rgt-neg-in99.6%
Simplified99.6%
Taylor expanded in x around inf 51.7%
if -0.0054999999999999997 < y < 0.34999999999999998Initial program 100.0%
Taylor expanded in y around 0 98.5%
+-commutative98.5%
mul-1-neg98.5%
unsub-neg98.5%
Simplified98.5%
Final simplification74.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%
+-commutative51.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%
Taylor expanded in x around 0 99.8%
mul-1-neg99.8%
distribute-rgt-neg-out99.8%
+-commutative99.8%
fma-udef99.8%
distribute-rgt-neg-out99.8%
*-commutative99.8%
distribute-rgt-neg-in99.8%
Simplified99.8%
Taylor expanded in y around 0 35.6%
Final simplification35.6%
herbie shell --seed 2023202
(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))))