
(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 99.6%
*-commutative99.6%
distribute-rgt-out--99.6%
cancel-sign-sub-inv99.6%
metadata-eval99.6%
neg-mul-199.6%
associate-+r+99.6%
unsub-neg99.6%
+-commutative99.6%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -1e+133)
(* x y)
(if (<= x -1.25e+114)
(* x z)
(if (<= x -7e-36)
(* x y)
(if (<= x 1.8e-85)
(- z)
(if (or (<= x 5.2e+27) (not (<= x 1.1e+183))) (* x y) (* x z)))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1e+133) {
tmp = x * y;
} else if (x <= -1.25e+114) {
tmp = x * z;
} else if (x <= -7e-36) {
tmp = x * y;
} else if (x <= 1.8e-85) {
tmp = -z;
} else if ((x <= 5.2e+27) || !(x <= 1.1e+183)) {
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 <= (-1d+133)) then
tmp = x * y
else if (x <= (-1.25d+114)) then
tmp = x * z
else if (x <= (-7d-36)) then
tmp = x * y
else if (x <= 1.8d-85) then
tmp = -z
else if ((x <= 5.2d+27) .or. (.not. (x <= 1.1d+183))) 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 <= -1e+133) {
tmp = x * y;
} else if (x <= -1.25e+114) {
tmp = x * z;
} else if (x <= -7e-36) {
tmp = x * y;
} else if (x <= 1.8e-85) {
tmp = -z;
} else if ((x <= 5.2e+27) || !(x <= 1.1e+183)) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1e+133: tmp = x * y elif x <= -1.25e+114: tmp = x * z elif x <= -7e-36: tmp = x * y elif x <= 1.8e-85: tmp = -z elif (x <= 5.2e+27) or not (x <= 1.1e+183): tmp = x * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1e+133) tmp = Float64(x * y); elseif (x <= -1.25e+114) tmp = Float64(x * z); elseif (x <= -7e-36) tmp = Float64(x * y); elseif (x <= 1.8e-85) tmp = Float64(-z); elseif ((x <= 5.2e+27) || !(x <= 1.1e+183)) 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 <= -1e+133) tmp = x * y; elseif (x <= -1.25e+114) tmp = x * z; elseif (x <= -7e-36) tmp = x * y; elseif (x <= 1.8e-85) tmp = -z; elseif ((x <= 5.2e+27) || ~((x <= 1.1e+183))) tmp = x * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1e+133], N[(x * y), $MachinePrecision], If[LessEqual[x, -1.25e+114], N[(x * z), $MachinePrecision], If[LessEqual[x, -7e-36], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.8e-85], (-z), If[Or[LessEqual[x, 5.2e+27], N[Not[LessEqual[x, 1.1e+183]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{+133}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq -1.25 \cdot 10^{+114}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -7 \cdot 10^{-36}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.8 \cdot 10^{-85}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 5.2 \cdot 10^{+27} \lor \neg \left(x \leq 1.1 \cdot 10^{+183}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -1e133 or -1.25e114 < x < -6.9999999999999999e-36 or 1.7999999999999999e-85 < x < 5.20000000000000018e27 or 1.09999999999999995e183 < x Initial program 99.0%
*-commutative99.0%
distribute-rgt-out--99.0%
cancel-sign-sub-inv99.0%
metadata-eval99.0%
neg-mul-199.0%
associate-+r+99.0%
unsub-neg99.0%
+-commutative99.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 65.9%
if -1e133 < x < -1.25e114 or 5.20000000000000018e27 < x < 1.09999999999999995e183Initial program 100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
cancel-sign-sub-inv100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in z around inf 74.5%
*-commutative74.5%
Simplified74.5%
if -6.9999999999999999e-36 < x < 1.7999999999999999e-85Initial program 100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
cancel-sign-sub-inv100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 81.2%
neg-mul-181.2%
Simplified81.2%
Final simplification74.0%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.6e-46) (not (<= x 2.1e-85))) (* x (+ z y)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.6e-46) || !(x <= 2.1e-85)) {
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 <= (-5.6d-46)) .or. (.not. (x <= 2.1d-85))) 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 <= -5.6e-46) || !(x <= 2.1e-85)) {
tmp = x * (z + y);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.6e-46) or not (x <= 2.1e-85): tmp = x * (z + y) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.6e-46) || !(x <= 2.1e-85)) 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 <= -5.6e-46) || ~((x <= 2.1e-85))) tmp = x * (z + y); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.6e-46], N[Not[LessEqual[x, 2.1e-85]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.6 \cdot 10^{-46} \lor \neg \left(x \leq 2.1 \cdot 10^{-85}\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -5.5999999999999997e-46 or 2.1e-85 < x Initial program 99.3%
*-commutative99.3%
distribute-rgt-out--99.3%
cancel-sign-sub-inv99.3%
metadata-eval99.3%
neg-mul-199.3%
associate-+r+99.3%
unsub-neg99.3%
+-commutative99.3%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 94.6%
+-commutative94.6%
Simplified94.6%
if -5.5999999999999997e-46 < x < 2.1e-85Initial program 100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
cancel-sign-sub-inv100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 81.2%
neg-mul-181.2%
Simplified81.2%
Final simplification88.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -310000000000.0) (not (<= x 0.0048))) (* x (+ z y)) (- (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -310000000000.0) || !(x <= 0.0048)) {
tmp = x * (z + y);
} else {
tmp = (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 ((x <= (-310000000000.0d0)) .or. (.not. (x <= 0.0048d0))) then
tmp = x * (z + y)
else
tmp = (x * y) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -310000000000.0) || !(x <= 0.0048)) {
tmp = x * (z + y);
} else {
tmp = (x * y) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -310000000000.0) or not (x <= 0.0048): tmp = x * (z + y) else: tmp = (x * y) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -310000000000.0) || !(x <= 0.0048)) tmp = Float64(x * Float64(z + y)); else tmp = Float64(Float64(x * y) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -310000000000.0) || ~((x <= 0.0048))) tmp = x * (z + y); else tmp = (x * y) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -310000000000.0], N[Not[LessEqual[x, 0.0048]], $MachinePrecision]], N[(x * N[(z + y), $MachinePrecision]), $MachinePrecision], N[(N[(x * y), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -310000000000 \lor \neg \left(x \leq 0.0048\right):\\
\;\;\;\;x \cdot \left(z + y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y - z\\
\end{array}
\end{array}
if x < -3.1e11 or 0.00479999999999999958 < x Initial program 99.2%
*-commutative99.2%
distribute-rgt-out--99.2%
cancel-sign-sub-inv99.2%
metadata-eval99.2%
neg-mul-199.2%
associate-+r+99.2%
unsub-neg99.2%
+-commutative99.2%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
+-commutative100.0%
Simplified100.0%
if -3.1e11 < x < 0.00479999999999999958Initial program 100.0%
fma-define100.0%
remove-double-neg100.0%
distribute-rgt-neg-out100.0%
distribute-rgt-neg-in100.0%
sub-neg100.0%
metadata-eval100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in y around inf 88.1%
Taylor expanded in x around 0 87.5%
associate-*r/87.5%
neg-mul-187.5%
Simplified87.5%
Taylor expanded in y around 0 98.9%
+-commutative98.9%
fma-define99.0%
mul-1-neg99.0%
fma-neg98.9%
Simplified98.9%
Final simplification99.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.1e-38) (not (<= x 1.9e-85))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.1e-38) || !(x <= 1.9e-85)) {
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.1d-38)) .or. (.not. (x <= 1.9d-85))) 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.1e-38) || !(x <= 1.9e-85)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.1e-38) or not (x <= 1.9e-85): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.1e-38) || !(x <= 1.9e-85)) 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.1e-38) || ~((x <= 1.9e-85))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.1e-38], N[Not[LessEqual[x, 1.9e-85]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.1 \cdot 10^{-38} \lor \neg \left(x \leq 1.9 \cdot 10^{-85}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1.10000000000000004e-38 or 1.8999999999999999e-85 < x Initial program 99.3%
*-commutative99.3%
distribute-rgt-out--99.3%
cancel-sign-sub-inv99.3%
metadata-eval99.3%
neg-mul-199.3%
associate-+r+99.3%
unsub-neg99.3%
+-commutative99.3%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in z around 0 55.8%
if -1.10000000000000004e-38 < x < 1.8999999999999999e-85Initial program 100.0%
*-commutative100.0%
distribute-rgt-out--100.0%
cancel-sign-sub-inv100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
+-commutative100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 81.2%
neg-mul-181.2%
Simplified81.2%
Final simplification67.2%
(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 99.6%
*-commutative99.6%
distribute-rgt-out--99.6%
cancel-sign-sub-inv99.6%
metadata-eval99.6%
neg-mul-199.6%
associate-+r+99.6%
unsub-neg99.6%
+-commutative99.6%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 40.5%
neg-mul-140.5%
Simplified40.5%
Final simplification40.5%
herbie shell --seed 2024067
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))