
(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%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -9.2e+254)
t_0
(if (<= y -1.04e+105)
(* z (- (sin y)))
(if (or (<= y -0.00195) (not (<= y 0.0095)))
t_0
(+ (* -0.5 (* x (* y y))) (- x (* y z))))))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -9.2e+254) {
tmp = t_0;
} else if (y <= -1.04e+105) {
tmp = z * -sin(y);
} else if ((y <= -0.00195) || !(y <= 0.0095)) {
tmp = t_0;
} else {
tmp = (-0.5 * (x * (y * y))) + (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) :: t_0
real(8) :: tmp
t_0 = x * cos(y)
if (y <= (-9.2d+254)) then
tmp = t_0
else if (y <= (-1.04d+105)) then
tmp = z * -sin(y)
else if ((y <= (-0.00195d0)) .or. (.not. (y <= 0.0095d0))) then
tmp = t_0
else
tmp = ((-0.5d0) * (x * (y * y))) + (x - (y * z))
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 (y <= -9.2e+254) {
tmp = t_0;
} else if (y <= -1.04e+105) {
tmp = z * -Math.sin(y);
} else if ((y <= -0.00195) || !(y <= 0.0095)) {
tmp = t_0;
} else {
tmp = (-0.5 * (x * (y * y))) + (x - (y * z));
}
return tmp;
}
def code(x, y, z): t_0 = x * math.cos(y) tmp = 0 if y <= -9.2e+254: tmp = t_0 elif y <= -1.04e+105: tmp = z * -math.sin(y) elif (y <= -0.00195) or not (y <= 0.0095): tmp = t_0 else: tmp = (-0.5 * (x * (y * y))) + (x - (y * z)) return tmp
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (y <= -9.2e+254) tmp = t_0; elseif (y <= -1.04e+105) tmp = Float64(z * Float64(-sin(y))); elseif ((y <= -0.00195) || !(y <= 0.0095)) tmp = t_0; else tmp = Float64(Float64(-0.5 * Float64(x * Float64(y * y))) + Float64(x - Float64(y * z))); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * cos(y); tmp = 0.0; if (y <= -9.2e+254) tmp = t_0; elseif (y <= -1.04e+105) tmp = z * -sin(y); elseif ((y <= -0.00195) || ~((y <= 0.0095))) tmp = t_0; else tmp = (-0.5 * (x * (y * y))) + (x - (y * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -9.2e+254], t$95$0, If[LessEqual[y, -1.04e+105], N[(z * (-N[Sin[y], $MachinePrecision])), $MachinePrecision], If[Or[LessEqual[y, -0.00195], N[Not[LessEqual[y, 0.0095]], $MachinePrecision]], t$95$0, N[(N[(-0.5 * N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -9.2 \cdot 10^{+254}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -1.04 \cdot 10^{+105}:\\
\;\;\;\;z \cdot \left(-\sin y\right)\\
\mathbf{elif}\;y \leq -0.00195 \lor \neg \left(y \leq 0.0095\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(x \cdot \left(y \cdot y\right)\right) + \left(x - y \cdot z\right)\\
\end{array}
\end{array}
if y < -9.19999999999999994e254 or -1.04e105 < y < -0.0019499999999999999 or 0.00949999999999999976 < y Initial program 99.6%
add-sqr-sqrt40.1%
pow240.1%
Applied egg-rr40.1%
Taylor expanded in z around 0 60.4%
if -9.19999999999999994e254 < y < -1.04e105Initial program 99.6%
Taylor expanded in x around 0 65.9%
mul-1-neg65.9%
*-commutative65.9%
distribute-rgt-neg-in65.9%
Simplified65.9%
if -0.0019499999999999999 < y < 0.00949999999999999976Initial program 100.0%
Taylor expanded in y around 0 99.6%
+-commutative99.6%
mul-1-neg99.6%
unsub-neg99.6%
fma-def99.6%
unpow299.6%
associate-*l*99.6%
Simplified99.6%
fma-udef99.6%
associate--l+99.6%
associate-*r*99.6%
*-commutative99.6%
*-commutative99.6%
Applied egg-rr99.6%
Final simplification81.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.88e-34) (not (<= z 1.85e-134))) (- x (* z (sin y))) (* x (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.88e-34) || !(z <= 1.85e-134)) {
tmp = x - (z * sin(y));
} 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.88d-34)) .or. (.not. (z <= 1.85d-134))) then
tmp = x - (z * sin(y))
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.88e-34) || !(z <= 1.85e-134)) {
tmp = x - (z * Math.sin(y));
} else {
tmp = x * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.88e-34) or not (z <= 1.85e-134): tmp = x - (z * math.sin(y)) else: tmp = x * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.88e-34) || !(z <= 1.85e-134)) tmp = Float64(x - Float64(z * sin(y))); else tmp = Float64(x * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.88e-34) || ~((z <= 1.85e-134))) tmp = x - (z * sin(y)); else tmp = x * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.88e-34], N[Not[LessEqual[z, 1.85e-134]], $MachinePrecision]], N[(x - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.88 \cdot 10^{-34} \lor \neg \left(z \leq 1.85 \cdot 10^{-134}\right):\\
\;\;\;\;x - z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y\\
\end{array}
\end{array}
if z < -1.88e-34 or 1.85e-134 < z Initial program 99.8%
Taylor expanded in y around 0 87.0%
if -1.88e-34 < z < 1.85e-134Initial program 99.8%
add-sqr-sqrt47.2%
pow247.2%
Applied egg-rr47.2%
Taylor expanded in z around 0 93.2%
Final simplification89.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.00195) (not (<= y 0.0082))) (* x (cos y)) (+ (* -0.5 (* x (* y y))) (- x (* y z)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00195) || !(y <= 0.0082)) {
tmp = x * cos(y);
} else {
tmp = (-0.5 * (x * (y * y))) + (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.00195d0)) .or. (.not. (y <= 0.0082d0))) then
tmp = x * cos(y)
else
tmp = ((-0.5d0) * (x * (y * y))) + (x - (y * z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00195) || !(y <= 0.0082)) {
tmp = x * Math.cos(y);
} else {
tmp = (-0.5 * (x * (y * y))) + (x - (y * z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.00195) or not (y <= 0.0082): tmp = x * math.cos(y) else: tmp = (-0.5 * (x * (y * y))) + (x - (y * z)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.00195) || !(y <= 0.0082)) tmp = Float64(x * cos(y)); else tmp = Float64(Float64(-0.5 * Float64(x * Float64(y * y))) + Float64(x - Float64(y * z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.00195) || ~((y <= 0.0082))) tmp = x * cos(y); else tmp = (-0.5 * (x * (y * y))) + (x - (y * z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.00195], N[Not[LessEqual[y, 0.0082]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(N[(-0.5 * N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.00195 \lor \neg \left(y \leq 0.0082\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(x \cdot \left(y \cdot y\right)\right) + \left(x - y \cdot z\right)\\
\end{array}
\end{array}
if y < -0.0019499999999999999 or 0.00820000000000000069 < y Initial program 99.6%
add-sqr-sqrt41.0%
pow241.0%
Applied egg-rr41.0%
Taylor expanded in z around 0 54.2%
if -0.0019499999999999999 < y < 0.00820000000000000069Initial program 100.0%
Taylor expanded in y around 0 99.6%
+-commutative99.6%
mul-1-neg99.6%
unsub-neg99.6%
fma-def99.6%
unpow299.6%
associate-*l*99.6%
Simplified99.6%
fma-udef99.6%
associate--l+99.6%
associate-*r*99.6%
*-commutative99.6%
*-commutative99.6%
Applied egg-rr99.6%
Final simplification77.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -9e+245) (not (<= z 4.6e+149))) (* y (- z)) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -9e+245) || !(z <= 4.6e+149)) {
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 ((z <= (-9d+245)) .or. (.not. (z <= 4.6d+149))) 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 ((z <= -9e+245) || !(z <= 4.6e+149)) {
tmp = y * -z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -9e+245) or not (z <= 4.6e+149): tmp = y * -z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -9e+245) || !(z <= 4.6e+149)) tmp = Float64(y * Float64(-z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -9e+245) || ~((z <= 4.6e+149))) tmp = y * -z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -9e+245], N[Not[LessEqual[z, 4.6e+149]], $MachinePrecision]], N[(y * (-z)), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9 \cdot 10^{+245} \lor \neg \left(z \leq 4.6 \cdot 10^{+149}\right):\\
\;\;\;\;y \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -9e245 or 4.5999999999999997e149 < z Initial program 99.8%
Taylor expanded in y around 0 54.9%
+-commutative54.9%
mul-1-neg54.9%
unsub-neg54.9%
fma-def54.9%
unpow254.9%
associate-*l*54.9%
Simplified54.9%
fma-udef54.9%
associate--l+54.9%
associate-*r*54.9%
*-commutative54.9%
*-commutative54.9%
Applied egg-rr54.9%
Taylor expanded in x around 0 42.9%
mul-1-neg42.9%
distribute-rgt-neg-in42.9%
Simplified42.9%
if -9e245 < z < 4.5999999999999997e149Initial program 99.8%
Taylor expanded in y around 0 52.0%
+-commutative52.0%
mul-1-neg52.0%
unsub-neg52.0%
fma-def52.0%
unpow252.0%
associate-*l*52.0%
Simplified52.0%
Taylor expanded in y around 0 46.1%
Final simplification45.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 53.8%
+-commutative53.8%
mul-1-neg53.8%
unsub-neg53.8%
Simplified53.8%
Final simplification53.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 y around 0 52.4%
+-commutative52.4%
mul-1-neg52.4%
unsub-neg52.4%
fma-def52.4%
unpow252.4%
associate-*l*52.5%
Simplified52.5%
Taylor expanded in y around 0 40.9%
Final simplification40.9%
herbie shell --seed 2023279
(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))))