
(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}
\\
\left(x + \cos y\right) - z \cdot \sin y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 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}
\\
\left(x + \cos y\right) - z \cdot \sin y
\end{array}
(FPCore (x y z) :precision binary64 (fma (sin y) (- z) (+ (cos y) x)))
double code(double x, double y, double z) {
return fma(sin(y), -z, (cos(y) + x));
}
function code(x, y, z) return fma(sin(y), Float64(-z), Float64(cos(y) + x)) end
code[x_, y_, z_] := N[(N[Sin[y], $MachinePrecision] * (-z) + N[(N[Cos[y], $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin y, -z, \cos y + x\right)
\end{array}
Initial program 99.9%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
lower-neg.f6499.9
lift-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ x (cos y))) (t_1 (* z (sin y))) (t_2 (- t_0 t_1)))
(if (or (<= t_2 -1e+15) (not (<= t_2 0.9841)))
(- (+ x 1.0) t_1)
(- t_0 (* z y)))))
double code(double x, double y, double z) {
double t_0 = x + cos(y);
double t_1 = z * sin(y);
double t_2 = t_0 - t_1;
double tmp;
if ((t_2 <= -1e+15) || !(t_2 <= 0.9841)) {
tmp = (x + 1.0) - t_1;
} else {
tmp = t_0 - (z * 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) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = x + cos(y)
t_1 = z * sin(y)
t_2 = t_0 - t_1
if ((t_2 <= (-1d+15)) .or. (.not. (t_2 <= 0.9841d0))) then
tmp = (x + 1.0d0) - t_1
else
tmp = t_0 - (z * y)
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 = z * Math.sin(y);
double t_2 = t_0 - t_1;
double tmp;
if ((t_2 <= -1e+15) || !(t_2 <= 0.9841)) {
tmp = (x + 1.0) - t_1;
} else {
tmp = t_0 - (z * y);
}
return tmp;
}
def code(x, y, z): t_0 = x + math.cos(y) t_1 = z * math.sin(y) t_2 = t_0 - t_1 tmp = 0 if (t_2 <= -1e+15) or not (t_2 <= 0.9841): tmp = (x + 1.0) - t_1 else: tmp = t_0 - (z * y) return tmp
function code(x, y, z) t_0 = Float64(x + cos(y)) t_1 = Float64(z * sin(y)) t_2 = Float64(t_0 - t_1) tmp = 0.0 if ((t_2 <= -1e+15) || !(t_2 <= 0.9841)) tmp = Float64(Float64(x + 1.0) - t_1); else tmp = Float64(t_0 - Float64(z * y)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x + cos(y); t_1 = z * sin(y); t_2 = t_0 - t_1; tmp = 0.0; if ((t_2 <= -1e+15) || ~((t_2 <= 0.9841))) tmp = (x + 1.0) - t_1; else tmp = t_0 - (z * y); 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[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 - t$95$1), $MachinePrecision]}, If[Or[LessEqual[t$95$2, -1e+15], N[Not[LessEqual[t$95$2, 0.9841]], $MachinePrecision]], N[(N[(x + 1.0), $MachinePrecision] - t$95$1), $MachinePrecision], N[(t$95$0 - N[(z * y), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x + \cos y\\
t_1 := z \cdot \sin y\\
t_2 := t\_0 - t\_1\\
\mathbf{if}\;t\_2 \leq -1 \cdot 10^{+15} \lor \neg \left(t\_2 \leq 0.9841\right):\\
\;\;\;\;\left(x + 1\right) - t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0 - z \cdot y\\
\end{array}
\end{array}
if (-.f64 (+.f64 x (cos.f64 y)) (*.f64 z (sin.f64 y))) < -1e15 or 0.98409999999999997 < (-.f64 (+.f64 x (cos.f64 y)) (*.f64 z (sin.f64 y))) Initial program 99.9%
Taylor expanded in y around 0
Applied rewrites97.4%
if -1e15 < (-.f64 (+.f64 x (cos.f64 y)) (*.f64 z (sin.f64 y))) < 0.98409999999999997Initial program 100.0%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f6465.0
Applied rewrites65.0%
Final simplification94.2%
(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}
\\
\left(x + \cos y\right) - z \cdot \sin y
\end{array}
Initial program 99.9%
(FPCore (x y z) :precision binary64 (if (or (<= z -520.0) (not (<= z 3.8e-24))) (- (+ x 1.0) (* z (sin y))) (fma (/ (cos y) x) x x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -520.0) || !(z <= 3.8e-24)) {
tmp = (x + 1.0) - (z * sin(y));
} else {
tmp = fma((cos(y) / x), x, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -520.0) || !(z <= 3.8e-24)) tmp = Float64(Float64(x + 1.0) - Float64(z * sin(y))); else tmp = fma(Float64(cos(y) / x), x, x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[z, -520.0], N[Not[LessEqual[z, 3.8e-24]], $MachinePrecision]], N[(N[(x + 1.0), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[y], $MachinePrecision] / x), $MachinePrecision] * x + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -520 \lor \neg \left(z \leq 3.8 \cdot 10^{-24}\right):\\
\;\;\;\;\left(x + 1\right) - z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\cos y}{x}, x, x\right)\\
\end{array}
\end{array}
if z < -520 or 3.80000000000000026e-24 < z Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites98.7%
if -520 < z < 3.80000000000000026e-24Initial program 100.0%
lift--.f64N/A
flip--N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip--N/A
lift--.f64N/A
inv-powN/A
lower-pow.f6499.8
Applied rewrites99.8%
Taylor expanded in x around inf
distribute-rgt-inN/A
*-lft-identityN/A
+-commutativeN/A
+-commutativeN/A
mul-1-negN/A
sub-negN/A
div-subN/A
sub-negN/A
mul-1-negN/A
lower-fma.f64N/A
Applied rewrites100.0%
Taylor expanded in z around 0
Applied rewrites100.0%
Final simplification99.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -7.6e+90) (not (<= z 2.8e+123))) (* (- z) (sin y)) (+ 1.0 x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -7.6e+90) || !(z <= 2.8e+123)) {
tmp = -z * sin(y);
} else {
tmp = 1.0 + 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 <= (-7.6d+90)) .or. (.not. (z <= 2.8d+123))) then
tmp = -z * sin(y)
else
tmp = 1.0d0 + x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -7.6e+90) || !(z <= 2.8e+123)) {
tmp = -z * Math.sin(y);
} else {
tmp = 1.0 + x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -7.6e+90) or not (z <= 2.8e+123): tmp = -z * math.sin(y) else: tmp = 1.0 + x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -7.6e+90) || !(z <= 2.8e+123)) tmp = Float64(Float64(-z) * sin(y)); else tmp = Float64(1.0 + x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -7.6e+90) || ~((z <= 2.8e+123))) tmp = -z * sin(y); else tmp = 1.0 + x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -7.6e+90], N[Not[LessEqual[z, 2.8e+123]], $MachinePrecision]], N[((-z) * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(1.0 + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.6 \cdot 10^{+90} \lor \neg \left(z \leq 2.8 \cdot 10^{+123}\right):\\
\;\;\;\;\left(-z\right) \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;1 + x\\
\end{array}
\end{array}
if z < -7.6000000000000002e90 or 2.80000000000000011e123 < z Initial program 99.7%
Taylor expanded in z around inf
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-sin.f6470.2
Applied rewrites70.2%
if -7.6000000000000002e90 < z < 2.80000000000000011e123Initial program 99.9%
Taylor expanded in y around 0
lower-+.f6478.7
Applied rewrites78.7%
Final simplification75.8%
(FPCore (x y z) :precision binary64 (- (+ x 1.0) (* z (sin y))))
double code(double x, double y, double z) {
return (x + 1.0) - (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 + 1.0d0) - (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x + 1.0) - (z * Math.sin(y));
}
def code(x, y, z): return (x + 1.0) - (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x + 1.0) - Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x + 1.0) - (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x + 1.0), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + 1\right) - z \cdot \sin y
\end{array}
Initial program 99.9%
Taylor expanded in y around 0
Applied rewrites89.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -9.5e+72) (not (<= y 9e+108))) (+ 1.0 x) (- x (fma z y -1.0))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -9.5e+72) || !(y <= 9e+108)) {
tmp = 1.0 + x;
} else {
tmp = x - fma(z, y, -1.0);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -9.5e+72) || !(y <= 9e+108)) tmp = Float64(1.0 + x); else tmp = Float64(x - fma(z, y, -1.0)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -9.5e+72], N[Not[LessEqual[y, 9e+108]], $MachinePrecision]], N[(1.0 + x), $MachinePrecision], N[(x - N[(z * y + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.5 \cdot 10^{+72} \lor \neg \left(y \leq 9 \cdot 10^{+108}\right):\\
\;\;\;\;1 + x\\
\mathbf{else}:\\
\;\;\;\;x - \mathsf{fma}\left(z, y, -1\right)\\
\end{array}
\end{array}
if y < -9.50000000000000054e72 or 9e108 < y Initial program 99.7%
Taylor expanded in y around 0
lower-+.f6440.6
Applied rewrites40.6%
if -9.50000000000000054e72 < y < 9e108Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
associate-+l-N/A
lower--.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f6488.0
Applied rewrites88.0%
Final simplification68.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.7e-31) (not (<= x 0.75))) (+ 1.0 x) (fma (- z) y 1.0)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.7e-31) || !(x <= 0.75)) {
tmp = 1.0 + x;
} else {
tmp = fma(-z, y, 1.0);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -2.7e-31) || !(x <= 0.75)) tmp = Float64(1.0 + x); else tmp = fma(Float64(-z), y, 1.0); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.7e-31], N[Not[LessEqual[x, 0.75]], $MachinePrecision]], N[(1.0 + x), $MachinePrecision], N[((-z) * y + 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.7 \cdot 10^{-31} \lor \neg \left(x \leq 0.75\right):\\
\;\;\;\;1 + x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-z, y, 1\right)\\
\end{array}
\end{array}
if x < -2.70000000000000014e-31 or 0.75 < x Initial program 99.9%
Taylor expanded in y around 0
lower-+.f6484.0
Applied rewrites84.0%
if -2.70000000000000014e-31 < x < 0.75Initial program 99.8%
Taylor expanded in y around 0
associate-+r+N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-+.f6446.0
Applied rewrites46.0%
Taylor expanded in x around 0
Applied rewrites45.8%
Taylor expanded in y around 0
Applied rewrites46.6%
Final simplification67.4%
(FPCore (x y z) :precision binary64 (+ 1.0 x))
double code(double x, double y, double z) {
return 1.0 + x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 1.0d0 + x
end function
public static double code(double x, double y, double z) {
return 1.0 + x;
}
def code(x, y, z): return 1.0 + x
function code(x, y, z) return Float64(1.0 + x) end
function tmp = code(x, y, z) tmp = 1.0 + x; end
code[x_, y_, z_] := N[(1.0 + x), $MachinePrecision]
\begin{array}{l}
\\
1 + x
\end{array}
Initial program 99.9%
Taylor expanded in y around 0
lower-+.f6462.3
Applied rewrites62.3%
Final simplification62.3%
(FPCore (x y z) :precision binary64 1.0)
double code(double x, double y, double z) {
return 1.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 1.0d0
end function
public static double code(double x, double y, double z) {
return 1.0;
}
def code(x, y, z): return 1.0
function code(x, y, z) return 1.0 end
function tmp = code(x, y, z) tmp = 1.0; end
code[x_, y_, z_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 99.9%
Taylor expanded in y around 0
lower-+.f6462.3
Applied rewrites62.3%
Taylor expanded in x around 0
Applied rewrites17.8%
Final simplification17.8%
herbie shell --seed 2024313
(FPCore (x y z)
:name "Graphics.Rasterific.Svg.PathConverter:segmentToBezier from rasterific-svg-0.2.3.1, B"
:precision binary64
(- (+ x (cos y)) (* z (sin y))))