
(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 6 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 (- (* x (+ z y)) z))
double code(double x, double y, double z) {
return (x * (z + 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 * (z + y)) - z
end function
public static double code(double x, double y, double z) {
return (x * (z + y)) - z;
}
def code(x, y, z): return (x * (z + y)) - z
function code(x, y, z) return Float64(Float64(x * Float64(z + y)) - z) end
function tmp = code(x, y, z) tmp = (x * (z + y)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(z + y\right) - z
\end{array}
Initial program 97.6%
*-commutative97.6%
sub-neg97.6%
distribute-rgt-in97.6%
metadata-eval97.6%
neg-mul-197.6%
associate-+r+97.6%
unsub-neg97.6%
+-commutative97.6%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -1.2e-49)
(* x y)
(if (<= x 7.2e-87)
(- z)
(if (or (<= x 3.2e+122) (not (<= x 6.2e+173))) (* x y) (* x z)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.2e-49) {
tmp = x * y;
} else if (x <= 7.2e-87) {
tmp = -z;
} else if ((x <= 3.2e+122) || !(x <= 6.2e+173)) {
tmp = x * y;
} else {
tmp = 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) :: tmp
if (x <= (-1.2d-49)) then
tmp = x * y
else if (x <= 7.2d-87) then
tmp = -z
else if ((x <= 3.2d+122) .or. (.not. (x <= 6.2d+173))) then
tmp = x * y
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -1.2e-49) {
tmp = x * y;
} else if (x <= 7.2e-87) {
tmp = -z;
} else if ((x <= 3.2e+122) || !(x <= 6.2e+173)) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.2e-49: tmp = x * y elif x <= 7.2e-87: tmp = -z elif (x <= 3.2e+122) or not (x <= 6.2e+173): tmp = x * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.2e-49) tmp = Float64(x * y); elseif (x <= 7.2e-87) tmp = Float64(-z); elseif ((x <= 3.2e+122) || !(x <= 6.2e+173)) tmp = Float64(x * y); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.2e-49) tmp = x * y; elseif (x <= 7.2e-87) tmp = -z; elseif ((x <= 3.2e+122) || ~((x <= 6.2e+173))) tmp = x * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.2e-49], N[(x * y), $MachinePrecision], If[LessEqual[x, 7.2e-87], (-z), If[Or[LessEqual[x, 3.2e+122], N[Not[LessEqual[x, 6.2e+173]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.2 \cdot 10^{-49}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 7.2 \cdot 10^{-87}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 3.2 \cdot 10^{+122} \lor \neg \left(x \leq 6.2 \cdot 10^{+173}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -1.19999999999999996e-49 or 7.19999999999999986e-87 < x < 3.20000000000000012e122 or 6.2e173 < x Initial program 96.6%
Taylor expanded in y around inf 63.6%
if -1.19999999999999996e-49 < x < 7.19999999999999986e-87Initial program 100.0%
Taylor expanded in x around 0 79.6%
mul-1-neg79.6%
Simplified79.6%
if 3.20000000000000012e122 < x < 6.2e173Initial program 92.7%
Taylor expanded in y around 0 66.0%
Taylor expanded in x around inf 66.0%
*-commutative66.0%
Simplified66.0%
Final simplification69.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.5e-50) (not (<= x 8.5e-84))) (* x (+ z y)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.5e-50) || !(x <= 8.5e-84)) {
tmp = x * (z + 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 <= (-6.5d-50)) .or. (.not. (x <= 8.5d-84))) then
tmp = x * (z + y)
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -6.5e-50) || !(x <= 8.5e-84)) {
tmp = x * (z + y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.5e-50) or not (x <= 8.5e-84): tmp = x * (z + y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.5e-50) || !(x <= 8.5e-84)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -6.5e-50) || ~((x <= 8.5e-84))) tmp = x * (z + y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.5e-50], N[Not[LessEqual[x, 8.5e-84]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.5 \cdot 10^{-50} \lor \neg \left(x \leq 8.5 \cdot 10^{-84}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -6.49999999999999987e-50 or 8.4999999999999994e-84 < x Initial program 96.3%
Taylor expanded in x around inf 93.9%
+-commutative93.9%
Simplified93.9%
if -6.49999999999999987e-50 < x < 8.4999999999999994e-84Initial program 100.0%
Taylor expanded in x around 0 79.6%
mul-1-neg79.6%
Simplified79.6%
Final simplification88.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -7.6e-50) (not (<= x 6.6e-86))) (* x (+ z y)) (* z (+ x -1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7.6e-50) || !(x <= 6.6e-86)) {
tmp = x * (z + y);
} 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 <= (-7.6d-50)) .or. (.not. (x <= 6.6d-86))) then
tmp = x * (z + y)
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 <= -7.6e-50) || !(x <= 6.6e-86)) {
tmp = x * (z + y);
} else {
tmp = z * (x + -1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7.6e-50) or not (x <= 6.6e-86): tmp = x * (z + y) else: tmp = z * (x + -1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7.6e-50) || !(x <= 6.6e-86)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(z * Float64(x + -1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -7.6e-50) || ~((x <= 6.6e-86))) tmp = x * (z + y); else tmp = z * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7.6e-50], N[Not[LessEqual[x, 6.6e-86]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], N[(z * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.6 \cdot 10^{-50} \lor \neg \left(x \leq 6.6 \cdot 10^{-86}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if x < -7.5999999999999998e-50 or 6.59999999999999974e-86 < x Initial program 96.3%
Taylor expanded in x around inf 93.9%
+-commutative93.9%
Simplified93.9%
if -7.5999999999999998e-50 < x < 6.59999999999999974e-86Initial program 100.0%
Taylor expanded in y around 0 79.6%
Final simplification88.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.2e-49) (not (<= x 7.5e-83))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.2e-49) || !(x <= 7.5e-83)) {
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 <= (-1.2d-49)) .or. (.not. (x <= 7.5d-83))) 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 <= -1.2e-49) || !(x <= 7.5e-83)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.2e-49) or not (x <= 7.5e-83): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.2e-49) || !(x <= 7.5e-83)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.2e-49) || ~((x <= 7.5e-83))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.2e-49], N[Not[LessEqual[x, 7.5e-83]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.2 \cdot 10^{-49} \lor \neg \left(x \leq 7.5 \cdot 10^{-83}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1.19999999999999996e-49 or 7.4999999999999997e-83 < x Initial program 96.3%
Taylor expanded in y around inf 61.3%
if -1.19999999999999996e-49 < x < 7.4999999999999997e-83Initial program 100.0%
Taylor expanded in x around 0 79.6%
mul-1-neg79.6%
Simplified79.6%
Final simplification68.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 97.6%
Taylor expanded in x around 0 34.0%
mul-1-neg34.0%
Simplified34.0%
Final simplification34.0%
herbie shell --seed 2023310
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))