
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * 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) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * 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) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (fma x (+ y z) (- z)))
double code(double x, double y, double z) {
return fma(x, (y + z), -z);
}
function code(x, y, z) return fma(x, Float64(y + z), Float64(-z)) end
code[x_, y_, z_] := N[(x * N[(y + z), $MachinePrecision] + (-z)), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y + z, -z\right)
\end{array}
Initial program 98.0%
*-commutative98.0%
distribute-rgt-out--98.0%
cancel-sign-sub-inv98.0%
metadata-eval98.0%
neg-mul-198.0%
associate-+r+98.0%
distribute-lft-out100.0%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (<= x -19.0) (* x y) (if (<= x 45.0) (- z) (if (<= x 2.8e+143) (* x z) (* x y)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -19.0) {
tmp = x * y;
} else if (x <= 45.0) {
tmp = -z;
} else if (x <= 2.8e+143) {
tmp = x * z;
} else {
tmp = x * 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 <= (-19.0d0)) then
tmp = x * y
else if (x <= 45.0d0) then
tmp = -z
else if (x <= 2.8d+143) then
tmp = x * z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -19.0) {
tmp = x * y;
} else if (x <= 45.0) {
tmp = -z;
} else if (x <= 2.8e+143) {
tmp = x * z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -19.0: tmp = x * y elif x <= 45.0: tmp = -z elif x <= 2.8e+143: tmp = x * z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -19.0) tmp = Float64(x * y); elseif (x <= 45.0) tmp = Float64(-z); elseif (x <= 2.8e+143) tmp = Float64(x * z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -19.0) tmp = x * y; elseif (x <= 45.0) tmp = -z; elseif (x <= 2.8e+143) tmp = x * z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -19.0], N[(x * y), $MachinePrecision], If[LessEqual[x, 45.0], (-z), If[LessEqual[x, 2.8e+143], N[(x * z), $MachinePrecision], N[(x * y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -19:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 45:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 2.8 \cdot 10^{+143}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -19 or 2.79999999999999998e143 < x Initial program 95.9%
Taylor expanded in y around inf 54.4%
if -19 < x < 45Initial program 100.0%
Taylor expanded in x around 0 75.6%
mul-1-neg75.6%
Simplified75.6%
if 45 < x < 2.79999999999999998e143Initial program 96.8%
Taylor expanded in x around inf 95.0%
+-commutative95.0%
Simplified95.0%
Taylor expanded in z around inf 63.2%
*-commutative63.2%
Simplified63.2%
Final simplification66.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -8.8e-8) (not (<= x 0.0085))) (* x (+ y z)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8.8e-8) || !(x <= 0.0085)) {
tmp = x * (y + z);
} else {
tmp = -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 ((x <= (-8.8d-8)) .or. (.not. (x <= 0.0085d0))) then
tmp = x * (y + z)
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -8.8e-8) || !(x <= 0.0085)) {
tmp = x * (y + z);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8.8e-8) or not (x <= 0.0085): tmp = x * (y + z) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8.8e-8) || !(x <= 0.0085)) tmp = Float64(x * Float64(y + z)); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -8.8e-8) || ~((x <= 0.0085))) tmp = x * (y + z); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8.8e-8], N[Not[LessEqual[x, 0.0085]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.8 \cdot 10^{-8} \lor \neg \left(x \leq 0.0085\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -8.7999999999999994e-8 or 0.0085000000000000006 < x Initial program 96.2%
Taylor expanded in x around inf 97.8%
+-commutative97.8%
Simplified97.8%
if -8.7999999999999994e-8 < x < 0.0085000000000000006Initial program 100.0%
Taylor expanded in x around 0 76.7%
mul-1-neg76.7%
Simplified76.7%
Final simplification87.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -22.0) (not (<= x 1800000000000.0))) (* x (+ y z)) (* z (+ x -1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -22.0) || !(x <= 1800000000000.0)) {
tmp = x * (y + z);
} else {
tmp = z * (x + -1.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) :: tmp
if ((x <= (-22.0d0)) .or. (.not. (x <= 1800000000000.0d0))) then
tmp = x * (y + z)
else
tmp = z * (x + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -22.0) || !(x <= 1800000000000.0)) {
tmp = x * (y + z);
} else {
tmp = z * (x + -1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -22.0) or not (x <= 1800000000000.0): tmp = x * (y + z) else: tmp = z * (x + -1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -22.0) || !(x <= 1800000000000.0)) tmp = Float64(x * Float64(y + z)); else tmp = Float64(z * Float64(x + -1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -22.0) || ~((x <= 1800000000000.0))) tmp = x * (y + z); else tmp = z * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -22.0], N[Not[LessEqual[x, 1800000000000.0]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], N[(z * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -22 \lor \neg \left(x \leq 1800000000000\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if x < -22 or 1.8e12 < x Initial program 96.0%
Taylor expanded in x around inf 99.5%
+-commutative99.5%
Simplified99.5%
if -22 < x < 1.8e12Initial program 100.0%
Taylor expanded in y around 0 77.9%
Final simplification88.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -19.0) (not (<= x 0.0075))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -19.0) || !(x <= 0.0075)) {
tmp = x * y;
} else {
tmp = -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 ((x <= (-19.0d0)) .or. (.not. (x <= 0.0075d0))) then
tmp = x * y
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -19.0) || !(x <= 0.0075)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -19.0) or not (x <= 0.0075): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -19.0) || !(x <= 0.0075)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -19.0) || ~((x <= 0.0075))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -19.0], N[Not[LessEqual[x, 0.0075]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -19 \lor \neg \left(x \leq 0.0075\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -19 or 0.0074999999999999997 < x Initial program 96.1%
Taylor expanded in y around inf 49.3%
if -19 < x < 0.0074999999999999997Initial program 100.0%
Taylor expanded in x around 0 76.2%
mul-1-neg76.2%
Simplified76.2%
Final simplification62.5%
(FPCore (x y z) :precision binary64 (- (* x (+ y z)) z))
double code(double x, double y, double z) {
return (x * (y + z)) - 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)) - z
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) - z;
}
def code(x, y, z): return (x * (y + z)) - z
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) - z) end
function tmp = code(x, y, z) tmp = (x * (y + z)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(y + z\right) - z
\end{array}
Initial program 98.0%
*-commutative98.0%
distribute-rgt-out--98.0%
cancel-sign-sub-inv98.0%
metadata-eval98.0%
neg-mul-198.0%
unsub-neg98.0%
associate-+r-98.0%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (- z))
double code(double x, double y, double z) {
return -z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = -z
end function
public static double code(double x, double y, double z) {
return -z;
}
def code(x, y, z): return -z
function code(x, y, z) return Float64(-z) end
function tmp = code(x, y, z) tmp = -z; end
code[x_, y_, z_] := (-z)
\begin{array}{l}
\\
-z
\end{array}
Initial program 98.0%
Taylor expanded in x around 0 39.0%
mul-1-neg39.0%
Simplified39.0%
Final simplification39.0%
herbie shell --seed 2023301
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))