
(FPCore (x y z) :precision binary64 (+ (+ x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x + sin(y)) + (z * cos(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 + sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x + Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x + math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x + sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x + sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + \sin y\right) + z \cdot \cos y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (+ x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x + sin(y)) + (z * cos(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 + sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x + Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x + math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x + sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x + sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + \sin y\right) + z \cdot \cos y
\end{array}
(FPCore (x y z) :precision binary64 (fma (cos y) z (+ (sin y) x)))
double code(double x, double y, double z) {
return fma(cos(y), z, (sin(y) + x));
}
function code(x, y, z) return fma(cos(y), z, Float64(sin(y) + x)) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * z + N[(N[Sin[y], $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, z, \sin y + x\right)
\end{array}
Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.9
lift-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
(FPCore (x y z) :precision binary64 (let* ((t_0 (+ (+ x (sin y)) (* z (cos y))))) (if (or (<= t_0 -0.95) (not (<= t_0 0.02))) (+ z x) (+ (+ y x) z))))
double code(double x, double y, double z) {
double t_0 = (x + sin(y)) + (z * cos(y));
double tmp;
if ((t_0 <= -0.95) || !(t_0 <= 0.02)) {
tmp = z + x;
} else {
tmp = (y + x) + 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 + sin(y)) + (z * cos(y))
if ((t_0 <= (-0.95d0)) .or. (.not. (t_0 <= 0.02d0))) then
tmp = z + x
else
tmp = (y + x) + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = (x + Math.sin(y)) + (z * Math.cos(y));
double tmp;
if ((t_0 <= -0.95) || !(t_0 <= 0.02)) {
tmp = z + x;
} else {
tmp = (y + x) + z;
}
return tmp;
}
def code(x, y, z): t_0 = (x + math.sin(y)) + (z * math.cos(y)) tmp = 0 if (t_0 <= -0.95) or not (t_0 <= 0.02): tmp = z + x else: tmp = (y + x) + z return tmp
function code(x, y, z) t_0 = Float64(Float64(x + sin(y)) + Float64(z * cos(y))) tmp = 0.0 if ((t_0 <= -0.95) || !(t_0 <= 0.02)) tmp = Float64(z + x); else tmp = Float64(Float64(y + x) + z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = (x + sin(y)) + (z * cos(y)); tmp = 0.0; if ((t_0 <= -0.95) || ~((t_0 <= 0.02))) tmp = z + x; else tmp = (y + x) + z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -0.95], N[Not[LessEqual[t$95$0, 0.02]], $MachinePrecision]], N[(z + x), $MachinePrecision], N[(N[(y + x), $MachinePrecision] + z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x + \sin y\right) + z \cdot \cos y\\
\mathbf{if}\;t\_0 \leq -0.95 \lor \neg \left(t\_0 \leq 0.02\right):\\
\;\;\;\;z + x\\
\mathbf{else}:\\
\;\;\;\;\left(y + x\right) + z\\
\end{array}
\end{array}
if (+.f64 (+.f64 x (sin.f64 y)) (*.f64 z (cos.f64 y))) < -0.94999999999999996 or 0.0200000000000000004 < (+.f64 (+.f64 x (sin.f64 y)) (*.f64 z (cos.f64 y))) Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
lower-+.f6474.1
Applied rewrites74.1%
if -0.94999999999999996 < (+.f64 (+.f64 x (sin.f64 y)) (*.f64 z (cos.f64 y))) < 0.0200000000000000004Initial program 100.0%
Taylor expanded in y around 0
associate-+r+N/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f6477.9
Applied rewrites77.9%
Final simplification74.7%
(FPCore (x y z) :precision binary64 (if (<= x -3e-85) (fma 1.0 z (+ (sin y) x)) (if (<= x 1.1e+50) (fma (cos y) z (sin y)) (+ z x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3e-85) {
tmp = fma(1.0, z, (sin(y) + x));
} else if (x <= 1.1e+50) {
tmp = fma(cos(y), z, sin(y));
} else {
tmp = z + x;
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -3e-85) tmp = fma(1.0, z, Float64(sin(y) + x)); elseif (x <= 1.1e+50) tmp = fma(cos(y), z, sin(y)); else tmp = Float64(z + x); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -3e-85], N[(1.0 * z + N[(N[Sin[y], $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.1e+50], N[(N[Cos[y], $MachinePrecision] * z + N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(z + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3 \cdot 10^{-85}:\\
\;\;\;\;\mathsf{fma}\left(1, z, \sin y + x\right)\\
\mathbf{elif}\;x \leq 1.1 \cdot 10^{+50}:\\
\;\;\;\;\mathsf{fma}\left(\cos y, z, \sin y\right)\\
\mathbf{else}:\\
\;\;\;\;z + x\\
\end{array}
\end{array}
if x < -3.00000000000000022e-85Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.9
lift-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
Taylor expanded in y around 0
Applied rewrites94.5%
if -3.00000000000000022e-85 < x < 1.10000000000000008e50Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f64N/A
lower-sin.f6496.6
Applied rewrites96.6%
if 1.10000000000000008e50 < x Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
lower-+.f6492.6
Applied rewrites92.6%
Final simplification95.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -9e+55) (not (<= z 1.35e+112))) (fma (cos y) z (+ x y)) (fma 1.0 z (+ (sin y) x))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -9e+55) || !(z <= 1.35e+112)) {
tmp = fma(cos(y), z, (x + y));
} else {
tmp = fma(1.0, z, (sin(y) + x));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -9e+55) || !(z <= 1.35e+112)) tmp = fma(cos(y), z, Float64(x + y)); else tmp = fma(1.0, z, Float64(sin(y) + x)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[z, -9e+55], N[Not[LessEqual[z, 1.35e+112]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * z + N[(x + y), $MachinePrecision]), $MachinePrecision], N[(1.0 * z + N[(N[Sin[y], $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9 \cdot 10^{+55} \lor \neg \left(z \leq 1.35 \cdot 10^{+112}\right):\\
\;\;\;\;\mathsf{fma}\left(\cos y, z, x + y\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(1, z, \sin y + x\right)\\
\end{array}
\end{array}
if z < -8.99999999999999996e55 or 1.3500000000000001e112 < z Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
lower-+.f6491.6
Applied rewrites91.6%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6491.6
Applied rewrites91.6%
if -8.99999999999999996e55 < z < 1.3500000000000001e112Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
lift-+.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites93.3%
Final simplification92.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.25e+179) (not (<= z 5.2e+179))) (* (cos y) z) (fma 1.0 z (+ (sin y) x))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.25e+179) || !(z <= 5.2e+179)) {
tmp = cos(y) * z;
} else {
tmp = fma(1.0, z, (sin(y) + x));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -1.25e+179) || !(z <= 5.2e+179)) tmp = Float64(cos(y) * z); else tmp = fma(1.0, z, Float64(sin(y) + x)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.25e+179], N[Not[LessEqual[z, 5.2e+179]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], N[(1.0 * z + N[(N[Sin[y], $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.25 \cdot 10^{+179} \lor \neg \left(z \leq 5.2 \cdot 10^{+179}\right):\\
\;\;\;\;\cos y \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(1, z, \sin y + x\right)\\
\end{array}
\end{array}
if z < -1.25e179 or 5.2000000000000004e179 < z Initial program 99.8%
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.6
Applied rewrites99.6%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6491.9
Applied rewrites91.9%
if -1.25e179 < z < 5.2000000000000004e179Initial program 100.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f64100.0
lift-+.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in y around 0
Applied rewrites90.4%
Final simplification90.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -27500000000000.0) (not (<= y 0.4))) (+ (sin y) x) (fma (fma (* -0.5 y) z 1.0) y (+ z x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -27500000000000.0) || !(y <= 0.4)) {
tmp = sin(y) + x;
} else {
tmp = fma(fma((-0.5 * y), z, 1.0), y, (z + x));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -27500000000000.0) || !(y <= 0.4)) tmp = Float64(sin(y) + x); else tmp = fma(fma(Float64(-0.5 * y), z, 1.0), y, Float64(z + x)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -27500000000000.0], N[Not[LessEqual[y, 0.4]], $MachinePrecision]], N[(N[Sin[y], $MachinePrecision] + x), $MachinePrecision], N[(N[(N[(-0.5 * y), $MachinePrecision] * z + 1.0), $MachinePrecision] * y + N[(z + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -27500000000000 \lor \neg \left(y \leq 0.4\right):\\
\;\;\;\;\sin y + x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-0.5 \cdot y, z, 1\right), y, z + x\right)\\
\end{array}
\end{array}
if y < -2.75e13 or 0.40000000000000002 < y Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.9
lift-+.f64N/A
+-commutativeN/A
lower-+.f6499.9
Applied rewrites99.9%
Taylor expanded in x around inf
+-commutativeN/A
associate-+r+N/A
distribute-rgt-inN/A
+-commutativeN/A
associate-*l/N/A
associate-/l*N/A
*-inversesN/A
rgt-mult-inverseN/A
associate-*r/N/A
*-rgt-identityN/A
associate-/l*N/A
associate-*l/N/A
*-commutativeN/A
lower-fma.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-cos.f64N/A
Applied rewrites92.8%
Taylor expanded in z around 0
Applied rewrites70.6%
if -2.75e13 < y < 0.40000000000000002Initial program 100.0%
Taylor expanded in y around 0
associate-+r+N/A
+-commutativeN/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6499.3
Applied rewrites99.3%
Final simplification85.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -38000000000000.0) (not (<= y 155000000000.0))) (+ z x) (fma (fma (fma -0.16666666666666666 y (* -0.5 z)) y 1.0) y (+ z x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -38000000000000.0) || !(y <= 155000000000.0)) {
tmp = z + x;
} else {
tmp = fma(fma(fma(-0.16666666666666666, y, (-0.5 * z)), y, 1.0), y, (z + x));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -38000000000000.0) || !(y <= 155000000000.0)) tmp = Float64(z + x); else tmp = fma(fma(fma(-0.16666666666666666, y, Float64(-0.5 * z)), y, 1.0), y, Float64(z + x)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -38000000000000.0], N[Not[LessEqual[y, 155000000000.0]], $MachinePrecision]], N[(z + x), $MachinePrecision], N[(N[(N[(-0.16666666666666666 * y + N[(-0.5 * z), $MachinePrecision]), $MachinePrecision] * y + 1.0), $MachinePrecision] * y + N[(z + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -38000000000000 \lor \neg \left(y \leq 155000000000\right):\\
\;\;\;\;z + x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, y, -0.5 \cdot z\right), y, 1\right), y, z + x\right)\\
\end{array}
\end{array}
if y < -3.8e13 or 1.55e11 < y Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
lower-+.f6447.8
Applied rewrites47.8%
if -3.8e13 < y < 1.55e11Initial program 100.0%
Taylor expanded in y around 0
associate-+r+N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6498.0
Applied rewrites98.0%
Final simplification74.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -29000000000000.0) (not (<= y 1100000000000.0))) (+ z x) (fma (fma (* -0.5 y) z 1.0) y (+ z x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -29000000000000.0) || !(y <= 1100000000000.0)) {
tmp = z + x;
} else {
tmp = fma(fma((-0.5 * y), z, 1.0), y, (z + x));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -29000000000000.0) || !(y <= 1100000000000.0)) tmp = Float64(z + x); else tmp = fma(fma(Float64(-0.5 * y), z, 1.0), y, Float64(z + x)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -29000000000000.0], N[Not[LessEqual[y, 1100000000000.0]], $MachinePrecision]], N[(z + x), $MachinePrecision], N[(N[(N[(-0.5 * y), $MachinePrecision] * z + 1.0), $MachinePrecision] * y + N[(z + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -29000000000000 \lor \neg \left(y \leq 1100000000000\right):\\
\;\;\;\;z + x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-0.5 \cdot y, z, 1\right), y, z + x\right)\\
\end{array}
\end{array}
if y < -2.9e13 or 1.1e12 < y Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
lower-+.f6447.8
Applied rewrites47.8%
if -2.9e13 < y < 1.1e12Initial program 100.0%
Taylor expanded in y around 0
associate-+r+N/A
+-commutativeN/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6498.0
Applied rewrites98.0%
Final simplification74.9%
(FPCore (x y z) :precision binary64 (+ z x))
double code(double x, double y, double z) {
return z + x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + x
end function
public static double code(double x, double y, double z) {
return z + x;
}
def code(x, y, z): return z + x
function code(x, y, z) return Float64(z + x) end
function tmp = code(x, y, z) tmp = z + x; end
code[x_, y_, z_] := N[(z + x), $MachinePrecision]
\begin{array}{l}
\\
z + x
\end{array}
Initial program 99.9%
Taylor expanded in y around 0
+-commutativeN/A
lower-+.f6470.9
Applied rewrites70.9%
Final simplification70.9%
(FPCore (x y z) :precision binary64 (+ z y))
double code(double x, double y, double z) {
return z + y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + y
end function
public static double code(double x, double y, double z) {
return z + y;
}
def code(x, y, z): return z + y
function code(x, y, z) return Float64(z + y) end
function tmp = code(x, y, z) tmp = z + y; end
code[x_, y_, z_] := N[(z + y), $MachinePrecision]
\begin{array}{l}
\\
z + y
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-cos.f64N/A
lower-sin.f6455.5
Applied rewrites55.5%
Taylor expanded in y around 0
Applied rewrites30.8%
Final simplification30.8%
herbie shell --seed 2024299
(FPCore (x y z)
:name "Graphics.Rasterific.Svg.PathConverter:segmentToBezier from rasterific-svg-0.2.3.1, C"
:precision binary64
(+ (+ x (sin y)) (* z (cos y))))